1
votes

Well, let's see if I understand the idea behind the shadow mapping.

  1. create a number of FBOs that lights (maximum 8)
  2. create same number of depth textures (shadow maps) for those FBOs
  3. for every FBO perform off-screen rendering (render to texture, drawing the scene from the point of view of each of the lights, maximum 8 times)

Is this correct?

But how do I render the final scene with shadows then? Do I have to render the whole scene for each shadow map?

int main() {

    //Number of lights = 8;

    glUseProgram(programa);
      glUniformli(shadowM0,4);
      glActivateTexture(GL_TEXTURE4);
      glBindTexture(GL_TEXTURE_2D,depthT0);
      //Draw Escene?
    
      glUniformli(shadowM1,5);
      glActivateTexture(GL_TEXTURE5);
      glBindTexture(GL_TEXTURE_2D,depthT1);
      //Draw Escene?
    
      glUniformli(shadowM2,6);
      glActivateTexture(GL_TEXTURE6);
      glBindTexture(GL_TEXTURE_2D,depthT2);
      //Draw Escene?
      
      ...
    glUseProgram(0);
  
    ...  
}

And if not, how should I do the final render of the scene?

Would appreciate any corrections to the above steps in case I missed something or any recommendations for improving the idea using forward rendering.

1
An omnidirectional light would require multiple shadow maps. - JWWalker
Okay, only I use point lights. But then this code is right? Could I use less FBOs or less texture objects for the same number of lights (8)? Thank you. - Javier Ramírez
A point light does shine in every direction, yes? - JWWalker
It is true. Sorry I mean directional lights. - Javier Ramírez

1 Answers

2
votes

There is more than one way.

Simplest solution would be - use only one shadowmap/FBO

foreach light {
  render shadowmap;
  foreach object {
    calculate lighting for given light with given shadowmap;
    additively blend with framebuffer;
  }
}

By additive I mean glBlendFunc(GL_ONE, GL_ONE);

Other way is to calculate many lights at once, but it introduces other problems, like if shader expects to calculate 8 lights, but you only have 7? And if you have 16, you'll need to draw twice (with additive blend, as usual).

glUseProgram(programa);
  glUniformli(shadowM0,4);
  glActivateTexture(GL_TEXTURE4);
  glBindTexture(GL_TEXTURE_2D,depthT0);

  glUniformli(shadowM1,5);
  glActivateTexture(GL_TEXTURE5);
  glBindTexture(GL_TEXTURE_2D,depthT1);

  glUniformli(shadowM2,6);
  glActivateTexture(GL_TEXTURE6);
  glBindTexture(GL_TEXTURE_2D,depthT2);

  // ... <set all other shadowmaps>

  // now draw. once. and use all shadowmaps you've set in shader