render shadows with fbo

Started by
-1 comments, last by fazekaim 18 years, 8 months ago
Hello, i would like to use fbo to render model shadows. It's outdoor rendering, so the Sun light up the terrain. I used fbo to render water like this:

water.setRenderabla( false );
gl.glBindFramebufferEXT( GL.GL_FRAMEBUFFER_EXT, FBO[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.glScalef( 1.0f, -1.0f, 1.0f );
   gl.glFrontFace(GL.GL_CW);
   terrain.render(); // without water
gl.glPopMatrix();    

water.setRenderabla( true );
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);
    terrain.render(); // with water
gl.glPopMatrix();             

This works well. My plan is to use fbo in displaying models' shadows. Here is my code-plan: 1. set fbo, call gl methods ( glBindFramebufferEXT, etc) 2. set color maskes to false // to render models with black on a white texture 3. look from Sun position 3. render only the objects on the terrain 4. unset fbo 5. set fbo with 0 // normal render, glClear, glMatrixMode, glLoadIdentity, gluLookAt 6. render the whole scene, terrain receive the black and white texture. with a shader discovering a black pixel on a texture, the terrain is in shadow by a model. My question is: Can it work? Or is the plan bad? What parameters should i specify when i create this fbo texture?

This topic is closed to new replies.

Advertisement