• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

3D 3d Vertex Lighting

RujiK

Member
I'm trying to implement a bare-bones diffuse style lighting for a 3d model. (Lighting that is calculated by the angle of the triangle face vs the angle of the light ray)

I have found many tutorials for this, but so far all of them involve baking your normals into your vertex buffer. Unfortunately, my 3d model is going to be heavily animated by the vertex shader, so baking the normals won't really work (I think?) since the triangles will be moving and turning.

So, I guess my specific question is: Can you calculate the normal, and thus the lighting, of a vertex inside the vertex shader?

Thank you for your time.
 

Binsk

Member
Modify your normal value with the same rotations as your vertex before calculating the light in the shader. Normals are pretty essential for lighting.
 

Fanatrick

Member
You always need to "bake" normals into a vertex buffer, how else would you represent facing direction per vertex? You're already translating/rotating their position components, you can do the same with the normal.

EDIT: ^ beat me to it
 

Yal

šŸ§ *penguin noises*
GMC Elder
Unfortunately, my 3d model is going to be heavily animated by the vertex shader, so baking the normals won't really work (I think?) since the triangles will be moving and turning.
Transform the normals with the same operations as you do the vertices, then pass them on as a varying to the fragment shader? Normals are pretty much essential to lighting, there's no getting away from them.
 
Top