Circular Texture


Today I added a new little effect that only happens when you hit the wall. I might change it a little bit more to like fade in / out depending on how close you are to the wall but that's a "deciding tomorrow" kinda thing.

I wanted to write this tech post to describe how I made the texture i'm referring to and also tell you how to fade the opacity in / out to draw said generated texture onto a quad such that it looks like you drew a circle when sampling the texture. Video for visual help here: https://twitter.com/AndrewNReinke/status/1459223000549449731

To start, you will need to set a width and height. In my case, height = width = 1024

You'll want to have some notion of the origin being at 0,0 so you just halve height and width to get the max x,y bound, so 512,512.

Then, you have a loop that only fills pixels on every N iteration for the Y and continue on after that for about U iterations to make the lines on the horiztonal be more thick. For the X iterations, you'll have the same code only if you're not to be filling any color, so you check each X to see if it lines up with the N iteration.

So something like
for(y = 0; y < height; y++)
{
if((!(y % N)) || YCont)
{
if(!YCont){YCont = U;} else{YCont--;}
for(x = 0; x < width; x++)
{fill texels and use alpha obtained by distance check func}
}
else
{
for(x = 0; x < width; x++)
{
if((!(x % N)) || XCont)
{
if(!XCont){XCont = U;}else{XCont--;}
fill texel with alpha value or'd into color
}
else
{
fill with no color / alpha;
}
}
}
}


Alpha is gotten by taking current X and Y and subtracting by 512 (in my case) to then divide it by the 512 and 512 respectively. After, you'll get the squared magnitude of it (dot with itself) and subtract the result by 2.0; After you'll take the absolute value of that subtraction and multiply it by half 256 to get the current alpha value (since result of sub and abs will be a decimal, you'll get a percentage of max alpha but halved due to a mistake I think (so the X or Y sub first might be by max texture size and then you just sub 1 but i'm unsure since I haven't tested it yet and just thought of it lol)).

That's it! You can see the code in the video I posted if you want to get more clarification / just ask me in the comments and I will help!

Please let me know your thoughts on my game thus far! Thank you for reading and have an awesome day :]

Files

Funmi_Zip.7z 4.1 MB
Nov 12, 2021

Get Funmi

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.