Advertisement Jump to content
Sign in to follow this  
fazekaim

render shadows with fbo

This topic is 4908 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, 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?

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!