zoombapup wrote:
I noticed that in model.shader the FS_AMBIENT and FS_LIGHTING passes. This is a bit confusing, as ambient light is part of the lighting calculation. I'm wondering if anyone has any ideas why there would be two passes for this?
Hi Zoombapup,
This is the general technique for forward rendering and afaik this is exactly how Doom 3 does it except that a shared shadow map is used vs the stencil shadow technique (each light renders the geometry again) so technically the geometry is rendered 3 times if the light has a shadowmap context attached (1 ambient, 1 shadowmap & 1 light additively blended like Worstplayer explained and should give an accurate light calculation from the ambient pass) although the shadowmap pass will have different geometry rendered due to the light's position culling based on its view frustum and not the camera's. Also notable is that the ambient pass also did a z pre-pass so these additive lights on top will be cheaper due to the z-testing and only render to the fragments which pass the z-test.
It's done this way so that each light is its own pass and can have its own shadowmap context and keeps the system general-purpose (and is relatively memory-efficient due to the same shadowmap context getting re-used). It's not very scalable performance-wise with more lights but hey, that's what deferred shading is set out to fix, or light pre-pass...