Jump to content
  • Advertisement
Sign in to follow this  
fazekaim

problem using fbo to shadow mapping

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, So, i render the models of the scene from the view of the sun with black color to the fbo texture. I cache the projection and model matrices. Then i render the whole scene, binding the fbo texture to the terrain. Rendering the terrain, i call glMultMatrixf method with the cashed model and projection matrices. In the terrain's shader, when the fbo texture is black, the terrain color is multiplied by 0.5 otherwise by 1.0. And the result is: http://delfin.unideb.hu/~fazekaim/shadow.jpg I see, the shadow is right in place at the models, but far away from models, the models' shadow is mapped again. (marked with red) So, i see the models' shadow under the models, and on the other side of the terrain to. i think, my projection is wrong. Can anyone help me? I post my render code: render cycle
...
if( ableToRenderFBO ){
                gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, SHADOWFBO[0] );
                gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
                gl.glMatrixMode(GL.GL_MODELVIEW);
                gl.glLoadIdentity();
                float distance = Distance( focus, eye );
                Vector34f sun_ = new Vector34f(sun.x,sun.y,sun.z).normalise().scale(distance).add( focus ); // compute the sun ray vector to the focus point.
                glu.gluLookAt( sun_.x, sun_.y, sun_.z,
                        focus.x, focus.y, focus.z,
                        up.x, up.y, up.z
                );
                gl.glGetFloatv(GL.GL_PROJECTION_MATRIX, projectionlMatrix); // store projection and model matrixes from sun view
                gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, modelMatrix); // store projection and model matrixes from sun view

                gl.glPushMatrix();
                    scene.renderShadow(); // render models in black
                gl.glPopMatrix();

                gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, 0 );
                gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
                gl.glMatrixMode(GL.GL_MODELVIEW);
                gl.glLoadIdentity();
                glu.gluLookAt( eye.x, eye.y, eye.z, focus.x, focus.y, focus.z, up.x, up.y, up.z );
            }

            gl.glPushMatrix();
                gl.glFrontFace(GL.GL_CCW);
                scene.render();
            gl.glPopMatrix();
...

scene rendering:
...
gl.glMatrixMode( GL.GL_TEXTURE );
        gl.glLoadIdentity();
        gl.glScalef(0.5f, 0.5f, 1.0f);
        gl.glTranslatef(1.0f, 1.0f, 0.0f);

        gl.glMultMatrixf( MeadowLand.projectionlMatrix );
        gl.glMultMatrixf( MeadowLand.modelMatrix );

        gl.glMatrixMode( GL.GL_MODELVIEW );

// texture bindings
gl.glUseProgramObjectARB( meadowShaderObj[0] );
    gl.glUniform1i( ... );
    ...
    gl.glDrawRangeElements( ... );
gl.glUseProgramObjectARB( 0 );
// texture unbindings
gl.glMatrixMode( GL.GL_TEXTURE );
        gl.glLoadIdentity();
        gl.glMatrixMode( GL.GL_MODELVIEW );
...

Vertex Shader code segment:
void main(void)
{
  ...
  gl_TexCoord[2] = gl_TextureMatrix[0] * gl_Vertex;
}

Framgent Shader code segment:
uniform sampler2D shadowtexture;
...
void main (void)
{
  vec4 shadow = texture2DProj(shadowtexture,gl_TexCoord[2]);
  ... // terrain texture computation
  gl_FragColor = gl_FragColor * (shadow.r < 0.1 ? 0.5 : 1.0);
}

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
i identified the problem.
i post a demo picture showing the problem. http://delfin.unideb.hu/~fazekaim/demo.jpg

i render the scene from the sun (yellow ray) at the same distance as the eye (red ray) is far from focus (to improve sharp shadows). When the camera is in front of the sun (in x and z direction -- y is up), the opengl render objects (green filled circles) that can be seen from the camera and can not be seen from the sun position (behind the sun). so the texture mapping from projection and model matrixes creates texture coordinate like 1.6 or 3.0, so opengl tiles the shadow texture. That's why, multiple shadow of an object can be seen from certain camera positions.

If i render the shadows from the sun with a distance to able to render all object of the scene, the shadow is ugly because the relative low texture resolution (same as the screen).
If i keep the distance from the focus, the shadow is sharp, but the effect explained above accours. What can i do? Any idea?

[Edited by - fazekaim on August 16, 2005 3:45:54 PM]

Share this post


Link to post
Share on other sites
the texture repeats are from using GL_REPEAT with the texture
use GL_CLAMP_TO_BORDER (not supporter on all hardware eg gf2 doesnt support it)
set the bordercolor to white or to another color for debugging purposes (to see how much area the shadowmap takes up)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!