Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shadow map with a multiple textured scene

Started by dchristopherfennell Feb 14, 2006 at 12:46 PM 1 replies 850+ views
Original Post
dchristopherfennell
dchristopherfennell
All the tutorial examples I see using shadow maps use one texture, the shadow map texture, and apply it to a scene with no textures The scene depth information is rendered to a shadow map The scene is rendered using a low ambient light The scene is finally rendered with the shadow map applied. I'm not using shaders for my shadows. I'm having trouble understanding how to apply this in a scene with multiple textures. All examples I see have the shadow map bound to glActiveTextureARB(GL_TEXTURE0_ARB), then apply the "compare R" to texture node and render the scene (spheres, boxes, pyramids etc...without textures) If you are rendering a scene that binds textures to GL_TEXTURE0_ARB texture unit (trees, buildings, etc), then I assume you can set the shadow map to glActiveTextureARB(GL_TEXTURE1_ARB) or higher (glActiveTextureARB(GL_TEXTURE7_ARB), for example) and it would work. However, I do not get any shadows. What if the scene is multi-textured? First Pass: Render the scene from the light point of view Copy the depth information to a depth texture Second Pass: Render the scene with a low ambient/diffuse light to make the shadow color Third pass: Render the scene by applying the shadow map Code for third pass (From one of the tutorials)

    glEnable(GL_DEPTH);
    glDepthFunc(GL_LEQUAL);
  
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity(); 
    glTranslatef(0.5f, 0.5f, 0.5f);
    glScalef(0.5f, 0.5f, 0.5f);
    glMultMatrixf(lightProjection);
    glMultMatrixf(lightModelview);
    glMatrixMode(GL_MODELVIEW);
    
    GLfloat splane[4] = {1, 0, 0, 0};
    GLfloat tplane[4] = {0, 1, 0, 0};
    GLfloat rplane[4] = {0, 0, 1, 0};
    GLfloat qplane[4] = {0, 0, 0, 1};
  
    glActiveTextureARB(GL_TEXTURE1_ARB); <----- HERE IS WHAT HAS CHANGED
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, _shadowtexture);

    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glEnable(GL_TEXTURE_GEN_R);
    glEnable(GL_TEXTURE_GEN_Q);
  
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
    glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
    glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);

    glTexGenfv(GL_S, GL_EYE_PLANE, splane);
    glTexGenfv(GL_T, GL_EYE_PLANE, tplane);
    glTexGenfv(GL_R, GL_EYE_PLANE, rplane);
    glTexGenfv(GL_Q, GL_EYE_PLANE, qplane);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
    glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
 
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.9);
 

    RenderScene();

    // Reset states here

I have not been able to find a solution for this that does not use shaders. Any help or insight is appreciated.
berith
berith
This may not be correct, but don't you need to set glActiveTextureARB(GL_TEXTURE1_ARB) prior to setting your GL_TEXTURE matrix? You want to ensure you're modifying the texture matrix on the right texture unit.
dchristopherfennell
dchristopherfennell
You are right about the texture matrix. I discovered that problem yesterday after I posted.

The texture matrix needs to be set for the correct texture unit and the shadows now appear.

...Now to solve all the other visual anomalies :)

Thanks for the input

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.