void Scene::CreateShadowMap( FrameBuffer *shadMapBuf, float *shadMapMatrixTranspose, int lightNum, float shadowMapBias ) { // Go ahead and render the shadow map glPushAttrib( GL_COLOR_BUFFER_BIT ); glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); shadMapBuf->BindBuffer(); shadMapBuf->ClearBuffers(); glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); LightPerspectiveMatrix( lightNum, shadMapBuf->GetAspectRatio() ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); LightLookAtMatrix( lightNum ); //this->Draw( MATL_FLAGS_NONE, OBJECT_OPTION_NONE, true ); this->Draw( MATL_FLAGS_NONE, OBJECT_OPTION_USE_LOWRES, true ); glPopMatrix(); glMatrixMode( GL_PROJECTION ); glPopMatrix(); glMatrixMode( GL_MODELVIEW ); shadMapBuf->UnbindBuffer(); glPopAttrib(); // Now compute the shadow map matrix for use by the current eye/camera view glPushMatrix(); glLoadIdentity(); glTranslatef( 0.5f, 0.5f, 0.5f + shadowMapBias ); glScalef( 0.5f, 0.5f, 0.5f ); LightPerspectiveMatrix( lightNum, shadMapBuf->GetAspectRatio() ); LightLookAtMatrix( lightNum ); camera->InverseLookAtMatrix(); glGetFloatv(GL_TRANSPOSE_MODELVIEW_MATRIX, shadMapMatrixTranspose); glGetFloatv(GL_TRANSPOSE_MODELVIEW_MATRIX, shadMapTransMatrix[lightNum]); // The scene's internal storage glGetFloatv(GL_MODELVIEW_MATRIX, shadMapMatrix[lightNum]); // The scene's internal storage glPopMatrix(); shadowMapTexID[lightNum] = shadMapBuf->GetDepthTextureID(); }
// This creates a shadow map. The rendering pass is already done for you, but you need to // fill in the matrix creation code (though all the subparts are available in the framework) void Scene::CreateShadowMap( FrameBuffer *shadMapBuf, float *shadMapMatrixTranspose, int lightNum, float shadowMapBias ) { // Go ahead and render the shadow map glPushAttrib( GL_COLOR_BUFFER_BIT ); glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); shadMapBuf->BindBuffer(); shadMapBuf->ClearBuffers(); // Set up the projection matrix for the shadow map glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); LightPerspectiveMatrix( lightNum, shadMapBuf->GetAspectRatio() ); // Set up the modelview ( i.e., light gluLookAt() ) glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); LightLookAtMatrix( lightNum ); this->Draw( MATL_FLAGS_NONE, OBJECT_OPTION_NONE, true ); glPopMatrix(); // Go ahead and pop off the new projection and modelview matrices glMatrixMode( GL_PROJECTION ); glPopMatrix(); glMatrixMode( GL_MODELVIEW ); shadMapBuf->UnbindBuffer(); glPopAttrib(); // Now compute the shadow map matrix for use by the current eye/camera view glPushMatrix(); glLoadIdentity(); // Put here the commands to create the shadow map matrix. Note: The // Scene and Camera classes give you access to functions that multiply // bits of the shadow map matrix onto the current matrix stack. You // simply need to discover what they are and apply them in the right // order here. The scale and bias matrix needs to be done yourself, // however (and you should try to use the shadowMapBias) parameter. glGetFloatv(GL_TRANSPOSE_MODELVIEW_MATRIX, shadMapMatrixTranspose); // Copy the transpose matrix glGetFloatv(GL_TRANSPOSE_MODELVIEW_MATRIX, shadMapTransMatrix); // Also copy to the scene's internal storage glPopMatrix(); // Make sure the Scene class knows where the shadow map is stored. shadowMapTexID = shadMapBuf->GetDepthTextureID(); }