OpenGL engine thingie - smooth shading, simple light attenuation!

preview_player
Показать описание
I spent about two or three days trying to figure out why the hell OpenGL wouldn't interpolate my normals for the fragment shader. I read on StackOverflow that the mistake was in the model data: normals should be per-face, not per-vertex. So I used Blender to change that, exported the model with the correction, and nothing in the program changed: I was still getting flat shading. What the hell, right? So I spent a lot of time trying to figure out what was going wrong with the code...

Well, as it turns out... I had clones of the same repository in two separate local folders. I had one of them open with Visual Studio, but exported the corrected models to the other. Duh! I've now sorted that out. The teapots look kinda weird after changing the normals, though.

Another change here is that I've added some simple, trivial and possibly incorrect light attenuation. I'm just multiplying the final color by 1 / (the distance between the light position and the lit surface position, squared), times a little constant (namely 150 in this case) to get the lighting up. The teapot sitting near (0, 0, 0) (where I've positioned my light) is suuuuper bright whereas other objects aren't as much. Apparently you're supposed to add or multiply the inverse square distance by a constant, a linear factor and a quadratic factor, or some such thing, but I'm not touching on that right now. Just finally figuring out what was happening to my Phong interpolation was good enough for today, lol
Рекомендации по теме