Lighting System B
Check the video out so you know what i'm talking about please https://twitter.com/AndrewNReinke/status/144654093057237811
So yea, basic lighting works! I have to say that my original attempts before looking for further assistance were not so successful unfortunately.
To get an idea on how I approached this problem, check out yesterday's post https://andrewnreinke.itch.io/funmi/devlog/301736/lighting-system-a
So by approaching the problem by just thinking about light really simply in the sense that the closer you are to the light, you get a percentage of amount lit does indeed work to give you some sort of result. I am not actually sure if many old games did this because their hardware wasn't so good, but I wouldn't be surprised as actually starting to write a ray tracer back in those days, while surely possible, it would take a good chunk of processor time.
In Funmi's case, I honestly think I may not do any sort of ray tracing (ie just simulate photons bouncing around to determine how much the scene is lit, so just an expansion to the current system) as I already am bogged down with water simulation code taking a good amount of CPU.
I can optimize the code to allow for ray tracing later though, but for now I don't see it as totally neccisary. Also, i'm not so sure what most platforms have these days in terms of processor power, but I think even with ray tracing, water sim, physics, and all that jazz, I could make a game that still runs on everything "modern" (phone, console, rasp pi 4, etc).
One other thing I have thought about with regards to not ray tracing is that by not doing it, you kinda get an artstyle if that makes sense. Like, the artstyle's specific goal is to not be 100% accurate to how real world physics / light and phenomeona work so it wouldn't be too much of a wrong thing to not have ray tracing I think but idk. This is just extra rambling that I have been thinking about but it also makes the post longer so that's something I guess lol.
Ok but for the actual tech stuff: the first thing I tried was to just take the dot product of the X vertex's position relative to the light with itself.
So you'd have something like vector R = VertexPos - LightPos; DotResult = dot(R, R);
Next, I just divided 1 by R so you'd have R = 1 / R;
The think about this is that you have math here that would guarantee that further away points, ie 1/4000 = small decimal while 1 / 20 would be a larger decimal (so .00025 for the first and 0.05 for the second). I then just multiplied that fraction by the light's strength and added it to a final "light amount". This was all fine and dandy but I didn't have a good scheme for how to change the actual texel's color when running the pixel or fragment shader or really just fill pixel routine part of the pipe. I was just multiplying the final color by the resulting amount but I didn't get the best results. Do note though, that I was getting the light strength value from the vertex shader. So the actual result was constant for a given vertex and wasn't properly interpolated across the triangle per "to fill" texel / pixel.
Still though, I don't think the results would've been better if I had done the above math while filling the triangle's tex / pix because it just didn't seem right in terms of math. So like I usually do when i'm in doubt, I looked up some lighting math on Handmade Hero (https://guide.handmadehero.org/code/day389/) and watched / understood what Casey does and just implemented his equation. It works really nice and produces the result I was looking for so that's what the game is using atm! Thanks to Casey :)
That's about all I got though. Pretty tired so this is the end of the post for today! Let me know what your thoughts are on the build before this lighting build because i'm not pushing it yet due to me being indecisive about maybe adding direcitonal lights or just doing some ambient light tricks so I can get the notion of a big ol' sun shining down onto the world. Have an awesome day!
Get Funmi
Funmi
Rotate the boat in air to get a high score
Status | In development |
Author | AndrewNReinke |
Genre | Action |
Tags | 3D, Arcade, DRM Free, handmade-engine, High Score, Low-poly, Retro, Rotation, Singleplayer, Third Person |
Languages | English, Japanese |
More posts
- Steam ReleaseDec 24, 2021
- Lots Of Changes With Text and StuffNov 19, 2021
- Text Texture AtlasNov 16, 2021
- Very Smol FixNov 15, 2021
- Font GenerationNov 14, 2021
- Added Fade In / Out And New Particle SystemNov 13, 2021
- Circular TextureNov 12, 2021
- I Wrote This Technique Thingy While Being Really Tired lmaoNov 11, 2021
- Collapsing UI Code Into One PipeNov 09, 2021
- Fixed Timers & Collision Volume BugsNov 08, 2021
Leave a comment
Log in with itch.io to leave a comment.