- Home /
Vertex shader lighting
Hey, I'm having a huge trouble with vertex shaders, everything works great for the main directional light, however I don't get how you add other directional lights, point lights, their shadows etc. Could someone explain to me how this is done? Also, I have just one TEXCOORD left to use in v2f struct (optionally I can get rid of fog coords if one isn't enough)
Answer by tanoshimi · Jun 29, 2017 at 07:50 PM
This is the best reference guide I know to writing Cg shaders for Unity: https://en.wikibooks.org/wiki/Cg_Programming/Unity/Multiple_Lights
But is there a good reason why you're writing a vertex shader rather than a surface shader which will handle all the lighting calculations for you?
The problem is, I'm using triplanar mapping (procedural mesh) so I need to get worldNormal and I'm also using normal maps, so it requires INTERNAL_DATA in this case, which seems to messup normal maps (they look really weird). Another reason are my geometry shaders (grass, leaves) which can't be done with surface shaders.
In the end I figured out how to get light from multiple lights (guide above this^ one), but... Shadows are still a black magic for me :/ Only base pass seems to cast them.