Some questions on deferred lighting.

Hey guys
Some time ago I started working at a engine that uses deferred lighting.
Works nice but I don’t have some features yet like spotlights.
I tried adding it but I think I have a problem with the spot direction not being in the viewspace

I’ve read I have to do something like this


vec3 sd = vec3(0,1,0);
float spotEffect = dot(normalize(l),sd);
if(spotEffect > cos(45.0))
{
  //Draw the pixel
}

I’m not usre how to fix this and searching around the internet I didn’t find anything about a deferred spotlight example.

Also I want to implement shadow maps but for omnidirectinal lights I’ve read the about the cubemap. However I can’t afford to render the scene 6 times for a single light so then I got to dual paraboloid mapping. That seems to be more normal for me. My question here is: If I have more light sources how do I combine all the shadow maps in one to render all the lights with all the shadows. I hope I dont have to make a shadowmap for each light because I want to have a lot of lights in the scene. Now for omnidirectinal without shadows I can run up to 4k lights on the scene. I imagine that will drastically lower with shadows but I still hope to get a big number.

Another question is about instancing.
What is the method that gives the best performance? Ive read about storing all the data in a texture. Is that the best way?

I have more questions but for now these are the most important.

I have no idea if this is helpful (i am relatively new to all this myself…), but regarding your spot direction question …since the spot direction is a direction like normals are - have you considered multiplying the direction with the gl_NormalMatrix to switch to eye space?

Yes but the thing is that in the lighting pass I don’t have the normal matrix anymore

Spotlights: I see no difference from non-deferred rendering.
You can reconstruct the world position of a fragment, so it’s not a problem to find an angle (probably cos(alpha)) and compare it with threshold of the spotlight.

Combined shadow maps: I have no idea how to combine them.
The most I can suggest is to use one single shadow map iterating across light sources.
Disadvantage - bad job parallelism - each operation requires result of the previous.

Omni-directional lights: You probably don’t need to render each object 6 times if setting up proper CPU-side frustum culling.
If the number of draws still matters, consider tetrahedral mapping.

“You can reconstruct the world position of a fragment”
I reconstruct the viewspace position not the world position. I also get the light in the viewspace position to use it.

Whatever space you prefer… you have light position & direction in this space as well as fragment position.
What’s the problem with spot light? Calculate the ‘cos’ of light direction and sample direction vectors, then compare with falloff ‘cos’.