- Timestamp:
- 09/01/08 18:33:14 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2891 r2892 93 93 ShadowMapping::~ShadowMapping() 94 94 { 95 if (sCgShadowProgram) 96 cgDestroyProgram(sCgShadowProgram); 97 95 //if (sCgShadowProgram) cgDestroyProgram(sCgShadowProgram); 98 96 DEL_PTR(mFbo); 99 97 } … … 126 124 mLight = light; 127 125 128 const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f);129 const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f);126 const float xlen = Magnitude(mSceneBox.Diagonal());// * 0.5f); 127 const float ylen = Magnitude(mSceneBox.Diagonal());// * 0.5f); 130 128 131 129 mShadowCam->SetDirection(light->GetDirection()); … … 138 136 139 137 mFbo->Bind(); 140 138 141 139 glDrawBuffers(1, mrt); 142 140 … … 150 148 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 151 149 152 glPolygonOffset(1.0f, 40 00.0f);153 //glEnable(GL_POLYGON_OFFSET_FILL);150 glPolygonOffset(1.0f, 40.0f); 151 glEnable(GL_POLYGON_OFFSET_FILL); 154 152 155 153 glShadeModel(GL_FLAT); … … 158 156 glMatrixMode(GL_PROJECTION); 159 157 glPushMatrix(); 160 161 glOrtho(+xlen, -xlen, ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal())); 158 glLoadIdentity(); 159 160 glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, 100);//Magnitude(mSceneBox.Diagonal())); 161 162 162 163 163 glMatrixMode(GL_MODELVIEW); 164 164 glPushMatrix(); 165 165 166 glLoadIdentity(); 167 168 166 169 mShadowCam->SetupCameraView(); 167 168 mShadowCam->GetModelViewMatrix(mShadowMatrix); 170 mShadowCam->GetModelViewMatrix(mLightViewMatrix); 171 172 mShadowCam->GetProjectionMatrix(mLightProjectionMatrix); 173 //glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mLightProjectionMatrix.x); 169 174 170 175 traverser->RenderScene(); 171 176 172 177 glDisable(GL_POLYGON_OFFSET_FILL); 173 178 glMatrixMode(GL_MODELVIEW); 174 179 glPopMatrix(); 175 180 … … 184 189 ExportDepthBuffer(data, mSize); 185 190 186 delete [] data;*/ 191 delete [] data; 192 */ 193 PrintGLerror("shadow map"); 187 194 188 195 FrameBufferObject::Release(); … … 270 277 0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] 271 278 272 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);279 /*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 273 280 274 281 // update the camera, so that the user can have a free look … … 280 287 281 288 cam->SetupCameraView(); 282 289 */ 283 290 // store the inverse of the resulting modelview matrix for the shadow computation 284 291 glGetFloatv(GL_MODELVIEW_MATRIX, (float *)cam_inverse_modelview.x); … … 287 294 // bind shadow map 288 295 glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, mFbo->GetDepthTex()); 289 290 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);291 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);292 293 PrintGLerror("texture");294 296 295 297 // compute a matrix that transforms from camera eye space to light clip space … … 300 302 301 303 glLoadMatrixf((float *)biasMatrix.x); 302 glMultMatrixf((float *)m ShadowMatrix.x);304 glMultMatrixf((float *)mLightViewMatrix.x); 303 305 304 306 // multiply the light's (bias * crop * proj * modelview) by the inverse camera modelview … … 308 310 RgbaColor white(1, 1, 1, 0); 309 311 RgbaColor dark(0.2, 0.2, 0.2, 0); 312 313 glDisable(GL_LIGHTING); 314 315 /*glDisable(GL_LIGHT0); 316 glDisable(GL_LIGHT1); 310 317 311 318 //Use dim light to represent shadowed areas … … 315 322 //glLightfv(GL_LIGHT1, GL_SPECULAR, black); 316 323 glEnable(GL_LIGHT1); 317 glEnable(GL_LIGHTING); 318 319 324 glEnable(GL_LIGHTING);*/ 325 326 PrintGLerror("firstpass"); 327 320 328 // finally, draw the scene 321 329 traverser->RenderScene(); 322 330 323 331 332 glEnable(GL_LIGHTING); 333 324 334 325 335 //3rd pass 326 336 //Draw with bright light 327 glLightfv(GL_LIGHT1, GL_DIFFUSE, (float *)&white.r); 328 glLightfv(GL_LIGHT1, GL_SPECULAR, (float *)&white.r); 329 330 Matrix4x4 textureMatrix;// = biasMatrix * mLightProjectionMatrix * mLightViewMatrix; 337 //glLightfv(GL_LIGHT1, GL_DIFFUSE, (float *)&white.r); 338 //glLightfv(GL_LIGHT1, GL_SPECULAR, (float *)&white.r); 339 340 Matrix4x4 textureMatrix = biasMatrix * mLightProjectionMatrix * mLightViewMatrix; 341 342 Matrix4x4 texMatT = Transpose(textureMatrix); 331 343 332 344 //Set up texture coordinate generation. 333 345 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 334 //glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));346 glTexGenfv(GL_S, GL_EYE_PLANE, texMatT.x[0]); 335 347 glEnable(GL_TEXTURE_GEN_S); 336 348 337 349 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 338 //glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1));350 glTexGenfv(GL_T, GL_EYE_PLANE, texMatT.x[1]); 339 351 glEnable(GL_TEXTURE_GEN_T); 340 352 341 353 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 342 //glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2));354 glTexGenfv(GL_R, GL_EYE_PLANE, texMatT.x[2]); 343 355 glEnable(GL_TEXTURE_GEN_R); 344 356 345 357 glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 346 //glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3));358 glTexGenfv(GL_Q, GL_EYE_PLANE, texMatT.x[3]); 347 359 glEnable(GL_TEXTURE_GEN_Q); 348 360 … … 363 375 glAlphaFunc(GL_GEQUAL, 0.99f); 364 376 glEnable(GL_ALPHA_TEST); 377 378 PrintGLerror("texture"); 365 379 366 380 traverser->RenderScene();
Note: See TracChangeset
for help on using the changeset viewer.