Changeset 3207 for GTP/trunk/App
- Timestamp:
- 12/03/08 01:14:40 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln ¶
r3107 r3207 12 12 EndProject 13 13 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VboFormatConverter", "VboFormatConverter.vcproj", "{93A522E1-76F0-4D46-9C97-30DC2DDB531B}" 14 EndProject 15 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrradianceMapping", "IrradianceMapping.vcproj", "{91680C49-A358-48AE-A02C-66CB884B7D7F}" 14 16 EndProject 15 17 Global … … 35 37 {93A522E1-76F0-4D46-9C97-30DC2DDB531B}.Release|Win32.ActiveCfg = Release|Win32 36 38 {93A522E1-76F0-4D46-9C97-30DC2DDB531B}.Release|Win32.Build.0 = Release|Win32 39 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.ActiveCfg = Debug|Win32 40 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.Build.0 = Debug|Win32 41 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win32 42 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win32 37 43 EndGlobalSection 38 44 GlobalSection(SolutionProperties) = preSolution -
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/irradiance.cpp ¶
r3037 r3207 18 18 #include <time.h> 19 19 #include "glInterface.h" 20 21 #include <Cg/cg.h>22 #include <Cg/cgGL.h>23 20 24 21 … … 53 50 #include "Light.h" 54 51 #include "SceneEntityConverter.h" 55 #include "ObjConverter.h"56 52 #include "SkyPreetham.h" 57 53 #include "Texture.h" 58 #include "EntityMerger.h" 54 #include "ShaderManager.h" 55 #include "MotionPath.h" 56 #include "ShaderProgram.h" 57 #include "Shape.h" 58 59 59 60 60 using namespace std; … … 62 62 63 63 64 /// the environment for the program parameter 64 65 static Environment env; 65 66 66 #define MAX_DEPTH_CONST 10.0f 67 68 // fbo67 68 GLuint fontTex; 69 /// the fbo used for MRT 69 70 FrameBufferObject *fbo = NULL; 70 71 GLuint fontTex;72 73 71 /// the renderable scene geometry 74 72 SceneEntityContainer sceneEntities; 75 73 SceneEntityContainer dynamicObjects; 76 74 // traverses and renders the hierarchy 77 75 RenderTraverser *traverser = NULL; … … 79 77 Bvh *bvh = NULL; 80 78 /// handles scene loading 81 ResourceManager *loader = NULL; 79 ResourceManager *resourceManager = NULL; 80 /// handles scene loading 81 ShaderManager *shaderManager = NULL; 82 82 /// the scene camera 83 Camera *camera = NULL;83 PerspectiveCamera *camera = NULL; 84 84 /// the scene camera 85 Camera *visCamera = NULL;85 PerspectiveCamera *visCamera = NULL; 86 86 /// the visualization 87 87 Visualization *visualization = NULL; 88 /// the current render state89 RenderState state;88 /// the current render renderState 89 RenderState renderState; 90 90 /// the rendering algorithm 91 91 int renderMode = RenderTraverser::CHCPLUSPLUS; 92 // eye near plane distance 93 float nearDist = 0.2f; 92 /// eye near plane distance 93 const float nearDist = 0.2f; 94 //const float nearDist = 1.0f; 95 /// eye far plane distance 94 96 float farDist = 1e6f; 95 97 /// the field of view 96 float fov = 50.0f; 97 /// the pixel threshold where a node is still considered invisible 98 int threshold; 99 100 int assumedVisibleFrames = 10; 101 int maxBatchSize = 50; 102 103 int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES; 98 const float fov = 50.0f; 104 99 105 100 SceneQuery *sceneQuery = NULL; 106 101 RenderQueue *renderQueue = NULL; 107 108 // traverses and renders the hierarchy 102 /// traverses and renders the hierarchy 109 103 RenderTraverser *shadowTraverser = NULL; 110 104 /// the skylight + skydome model 111 105 SkyPreetham *preetham = NULL; 106 107 MotionPath *motionPath = NULL; 108 /// max depth where candidates for tighter bounds are searched 109 int maxDepthForTestingChildren = 3; 110 111 112 /// the technique used for rendering 113 enum RenderTechnique 114 { 115 FORWARD, 116 DEFERRED, 117 DEPTH_PASS 118 }; 112 119 113 120 … … 115 122 enum RenderMethod 116 123 { 117 RENDER_F IXED,124 RENDER_FORWARD, 118 125 RENDER_DEPTH_PASS, 119 126 RENDER_DEFERRED, … … 123 130 124 131 /// one of four possible render methods 125 int renderMethod = RENDER_FIXED; 126 132 int renderMethod = RENDER_FORWARD; 133 134 static int winWidth = 1024; 135 static int winHeight = 768; 136 static float winAspectRatio = 1.0f; 127 137 128 138 /// these values get scaled with the frame rate … … 131 141 132 142 /// elapsed time in milliseconds 133 double elapsedTime = 1000.0 f;134 double algTime = 1000.0 f;135 136 static int winWidth = 1024;137 static int winHeight = 768;143 double elapsedTime = 1000.0; 144 double algTime = 1000.0; 145 double accumulatedTime = 1000.0; 146 float fps = 1e3f; 147 float turbitity = 5.0f; 138 148 139 149 int shadowSize = 2048; 140 141 static float winAspectRatio = 1.0f; 142 143 double accumulatedTime = 1000; 144 float fps = 1e3f; 145 150 /// the hud font 146 151 glfont::GLFont myfont; 147 152 … … 161 166 int numBatches = 0; 162 167 163 164 // mouse navigation state 168 // mouse navigation renderState 165 169 int xEyeBegin = 0; 166 170 int yEyeBegin = 0; … … 168 172 int verticalMotionBegin = 0; 169 173 int horizontalMotionBegin = 0; 170 171 174 172 175 bool leftKeyPressed = false; … … 176 179 bool descendKeyPressed = false; 177 180 bool ascendKeyPressed = false; 181 bool leftStrafeKeyPressed = false; 182 bool rightStrafeKeyPressed = false; 183 184 bool altKeyPressed = false; 178 185 179 186 bool showHelp = false; … … 200 207 bool showShadowMap = false; 201 208 bool renderLightView = false; 202 203 bool altKeyPressed = false;204 205 209 bool useHDR = true; 206 207 static float ssaoTempCohFactor = 255.0; 208 210 bool useAntiAliasing = true; 209 211 210 212 PerfTimer frameTimer, algTimer; 211 212 static int sCurrentMrtSet = 0; 213 213 /// the performance window 214 214 PerformanceGraph *perfGraph = NULL; 215 216 float ssaoTempCohFactor = 255.0; 217 bool sortSamples = true; 218 int sCurrentMrtSet = 0; 219 220 static Matrix4x4 invTrafo = IdentityMatrix(); 221 222 223 ////////////// 224 //-- algorithm parameters 225 226 /// the pixel threshold where a node is still considered invisible 227 /// (should be zero for conservative visibility) 228 int threshold; 229 int assumedVisibleFrames = 10; 230 int maxBatchSize = 50; 231 int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES; 232 233 ////////////// 234 235 enum {CAMERA_PASS = 0, LIGHT_PASS = 1}; 215 236 216 237 … … 220 241 ShadowMap *shadowMap = NULL; 221 242 DirectionalLight *light = NULL; 222 DeferredRenderer * ssaoShader = NULL;223 224 SceneEntity *cube = NULL; 225 SceneEntity * aeroplane= NULL;243 DeferredRenderer *deferredShader = NULL; 244 245 246 SceneEntity *buddha = NULL; 226 247 SceneEntity *skyDome = NULL; 227 248 228 249 229 230 // function forward declarations 250 //////////////////// 251 //--- function forward declarations 252 231 253 void InitExtensions(); 254 void InitGLstate(); 255 232 256 void DisplayVisualization(); 233 void InitGLstate(); 234 void InitRenderTexture(); 235 void InitCg(); 257 /// destroys all allocated resources 236 258 void CleanUp(); 237 259 void SetupEyeView(); 238 void UpdateEyeMtx();239 260 void SetupLighting(); 240 261 void DisplayStats(); 241 void Output(int x, int y, const char *string); 262 /// draw the help screen 242 263 void DrawHelpMessage(); 264 /// render the sky dome 243 265 void RenderSky(); 266 /// render the objects found visible in the depth pass 244 267 void RenderVisibleObjects(); 245 268 246 269 void Begin2D(); 247 270 void End2D(); 271 /// the main loop 272 void MainLoop(); 273 248 274 void KeyBoard(unsigned char c, int x, int y); 249 void DrawStatistics();250 void Display();251 275 void Special(int c, int x, int y); 252 276 void KeyUp(unsigned char c, int x, int y); 253 277 void SpecialKeyUp(int c, int x, int y); 254 278 void Reshape(int w, int h); 255 void Mouse(int button, int state, int x, int y);279 void Mouse(int button, int renderState, int x, int y); 256 280 void LeftMotion(int x, int y); 257 281 void RightMotion(int x, int y); 258 282 void MiddleMotion(int x, int y); 259 void CalcDecimalPoint(string &str, int d);260 261 RenderTraverser *CreateTraverser(Camera *cam);262 263 283 void KeyHorizontalMotion(float shift); 264 284 void KeyVerticalMotion(float shift); 265 285 /// returns the string representation of a number with the decimal points 286 void CalcDecimalPoint(string &str, int d); 287 /// Creates the traversal method (vfc, stopandwait, chc, chc++) 288 RenderTraverser *CreateTraverser(PerspectiveCamera *cam); 289 /// place the viewer on the floor plane 266 290 void PlaceViewer(const Vector3 &oldPos); 291 // initialise the frame buffer objects 292 void InitFBO(); 293 /// changes the sunlight direction 294 void RightMotionLight(int x, int y); 295 /// render the shader map 296 void RenderShadowMap(float newfar); 297 /// function that touches each material once in order to accelarate render queue 298 void PrepareRenderQueue(); 299 /// loads the specified model 300 void LoadModel(const string &model, SceneEntityContainer &entities); 267 301 268 302 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 269 303 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 270 // initialise the frame buffer objects 271 void InitFBO(); 272 273 void RightMotionLight(int x, int y); 274 275 void RenderShadowMap(float newfar); 276 277 278 279 ///////// 280 //-- cg stuff 281 282 static CGcontext sCgContext = NULL; 283 284 static CGparameter sEyePosParamTex; 285 static CGparameter sEyePosParam; 286 304 305 void CreateAnimation(); 306 307 SceneQuery *GetOrCreateSceneQuery(); 308 309 310 // new view projection matrix of the camera 287 311 static Matrix4x4 viewProjMat = IdentityMatrix(); 312 // the old view projection matrix of the camera 288 313 static Matrix4x4 oldViewProjMat = IdentityMatrix(); 289 314 290 291 292 static void cgErrorCallback()293 {294 CGerror lastError = cgGetError();295 296 if(lastError)297 {298 printf("%s\n\n", cgGetErrorString(lastError));299 printf("%s\n", cgGetLastListing(sCgContext));300 301 printf("Cg error, exiting...\n");302 303 exit(0);304 }305 }306 315 307 316 … … 321 330 int main(int argc, char* argv[]) 322 331 { 323 /*324 332 #ifdef _CRT_SET 325 326 333 //Now just call this function at the start of your program and if you're 327 334 //compiling in debug mode (F5), any leaks will be displayed in the Output … … 334 341 _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 335 342 #endif 336 */ 343 337 344 cout << "=== reading environment file ===" << endl << endl; 338 345 … … 355 362 env.GetIntParam(string("maxBatchSize"), maxBatchSize); 356 363 env.GetIntParam(string("trianglesPerVirtualLeaf"), trianglesPerVirtualLeaf); 364 env.GetIntParam(string("winWidth"), winWidth); 365 env.GetIntParam(string("winHeight"), winHeight); 366 env.GetIntParam(string("shadowSize"), shadowSize); 367 env.GetIntParam(string("maxDepthForTestingChildren"), maxDepthForTestingChildren); 357 368 358 369 env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion); 359 370 env.GetFloatParam(string("keyRotation"), keyRotation); 360 361 env.GetIntParam(string("winWidth"), winWidth);362 env.GetIntParam(string("winHeight"), winHeight);363 364 env.GetBoolParam(string("useFullScreen"), useFullScreen);365 371 env.GetFloatParam(string("tempCohFactor"), ssaoTempCohFactor); 372 env.GetFloatParam(string("turbitity"), turbitity); 373 366 374 env.GetVectorParam(string("camPosition"), camPos); 367 375 env.GetVectorParam(string("camDirection"), camDir); 368 376 env.GetVectorParam(string("lightDirection"), lightDir); 369 377 378 env.GetBoolParam(string("useFullScreen"), useFullScreen); 370 379 env.GetBoolParam(string("useLODs"), useLODs); 371 env.GetIntParam(string("shadowSize"), shadowSize);372 373 380 env.GetBoolParam(string("useHDR"), useHDR); 381 env.GetBoolParam(string("useAA"), useAntiAliasing); 382 env.GetBoolParam(string("useAdvancedShading"), useAdvancedShading); 383 384 env.GetIntParam(string("renderMethod"), renderMethod); 374 385 375 386 //env.GetStringParam(string("modelPath"), model_path); … … 389 400 cout << "temporal coherence: " << ssaoTempCohFactor << endl; 390 401 cout << "shadow size: " << shadowSize << endl; 402 cout << "render method: " << renderMethod << endl; 403 cout << "use antialiasing: " << useAntiAliasing << endl; 404 cout << "use advanced shading: " << useAdvancedShading << endl; 405 cout << "turbitity: " << turbitity << endl; 391 406 392 407 //cout << "model path: " << model_path << endl; 393 394 408 cout << "**** end parameters ****" << endl << endl; 395 409 } … … 397 411 /////////////////////////// 398 412 399 camera = new Camera(winWidth,winHeight, fov);413 camera = new PerspectiveCamera(winWidth / winHeight, fov); 400 414 camera->SetNear(nearDist); 401 415 camera->SetFar(1000); … … 404 418 camera->SetPosition(camPos); 405 419 406 visCamera = new Camera(winWidth,winHeight, fov);420 visCamera = new PerspectiveCamera(winWidth / winHeight, fov); 407 421 visCamera->SetNear(0.0f); 408 422 visCamera->Yaw(.5 * M_PI); … … 410 424 // create a new light 411 425 light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1), RgbaColor(1, 1, 1, 1)); 412 413 414 renderQueue = new RenderQueue(&state, camera); 426 // the render queue for material sorting 427 renderQueue = new RenderQueue(&renderState); 415 428 416 429 glutInitWindowSize(winWidth, winHeight); … … 432 445 } 433 446 434 glutDisplayFunc( Display);447 glutDisplayFunc(MainLoop); 435 448 glutKeyboardFunc(KeyBoard); 436 449 glutSpecialFunc(Special); 437 450 glutReshapeFunc(Reshape); 438 451 glutMouseFunc(Mouse); 439 glutIdleFunc( Display);452 glutIdleFunc(MainLoop); 440 453 glutKeyboardUpFunc(KeyUp); 441 454 glutSpecialUpFunc(SpecialKeyUp); … … 452 465 MiddleMotion(0, 0); 453 466 454 // init cg shader programs455 InitCg();456 457 467 perfGraph = new PerformanceGraph(1000); 458 468 459 loader = ResourceManager::GetSingleton(); 460 461 const string filename = string(model_path + "city.dem"); 462 463 if (loader->Load(filename, sceneEntities)) 464 cout << "model " << filename << " loaded" << endl; 465 else 466 { 467 cerr << "loading model " << filename << " failed" << endl; 468 CleanUp(); 469 exit(0); 470 } 471 469 resourceManager = ResourceManager::GetSingleton(); 470 shaderManager = ShaderManager::GetSingleton(); 471 472 /////////// 473 //-- load the static scene geometry 474 475 LoadModel("city.dem", sceneEntities); 476 477 478 ////////// 479 //-- load some dynamic stuff 480 481 //resourceManager->mUseNormalMapping = true; 482 //resourceManager->mUseNormalMapping = false; 483 484 //LoadModel("fisch.dem", dynamicObjects); 485 LoadModel("hbuddha.dem", dynamicObjects); 486 //LoadModel("venusm.dem", dynamicObjects); 487 //LoadModel("camel.dem", dynamicObjects); 488 //LoadModel("toyplane2.dem", dynamicObjects); 489 //LoadModel("elephal.dem", dynamicObjects); 490 491 resourceManager->mUseNormalMapping = false; 492 493 buddha = dynamicObjects.back(); 494 495 const Vector3 sceneCenter(470.398f, 240.364f, 181.7f); 496 //const Vector3 sceneCenter(470.398f, 240.364f, 180.3); 497 498 Matrix4x4 transl = TranslationMatrix(sceneCenter); 499 buddha->GetTransform()->SetMatrix(transl); 500 501 for (int i = 0; i < 10; ++ i) 502 { 503 SceneEntity *ent = new SceneEntity(*buddha); 504 resourceManager->AddSceneEntity(ent); 505 506 Vector3 offs = Vector3::ZERO(); 507 508 offs.x = RandomValue(.0f, 50.0f); 509 offs.y = RandomValue(.0f, 50.0f); 510 511 Vector3 newPos = sceneCenter + offs; 512 513 transl = TranslationMatrix(newPos); 514 Transform3 *transform = resourceManager->CreateTransform(transl); 515 516 ent->SetTransform(transform); 517 dynamicObjects.push_back(ent); 518 } 519 520 521 /////////// 522 //-- load the associated static bvh 472 523 473 524 const string bvh_filename = string(model_path + "city.bvh"); 525 474 526 BvhLoader bvhLoader; 475 bvh = bvhLoader.Load(bvh_filename, sceneEntities );527 bvh = bvhLoader.Load(bvh_filename, sceneEntities, dynamicObjects, maxDepthForTestingChildren); 476 528 477 529 if (!bvh) … … 482 534 } 483 535 536 /// set the depth of the bvh depending on the triangles per leaf node 537 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 538 484 539 // set far plane based on scene extent 485 540 farDist = 10.0f * Magnitude(bvh->GetBox().Diagonal()); 486 bvh->SetVirtualLeaves(trianglesPerVirtualLeaf); 487 488 camera->SetFar(Magnitude(bvh->GetBox().Diagonal())); 489 490 Vector3 cubeCenter(470.398f, 240.364f, 182.5f); 491 492 Matrix4x4 transl = TranslationMatrix(cubeCenter); 493 494 SceneEntityContainer dummy; 495 496 string skyDomeStr(model_path + "sky.dem"); 497 498 if (loader->Load(skyDomeStr, sceneEntities)) 499 { 500 cout << "successfully loaded " << sceneEntities.size() << " scene entities" << endl; 501 } 502 else 503 { 504 cerr << "loading file " << skyDomeStr << " failed" << endl; 505 506 CleanUp(); 507 exit(0); 508 } 509 541 camera->SetFar(farDist); 542 543 544 ////////////////// 545 //-- setup the skydome model 546 547 LoadModel("sky.dem", sceneEntities); 510 548 skyDome = sceneEntities.back(); 511 549 512 //InitCg(); 513 514 const float turbitiy = 5.0f; 515 preetham = new SkyPreetham(turbitiy, skyDome); 516 517 // initialize the render traverser 550 /// the turbitity of the sky (from clear to hazy, use <3 for clear sky) 551 preetham = new SkyPreetham(turbitity, skyDome); 552 553 CreateAnimation(); 554 555 556 ////////// 557 //-- initialize the traversal algorithm 558 518 559 traverser = CreateTraverser(camera); 519 520 visualization = new Visualization(bvh, camera, NULL, &state); 521 522 state.SetRenderPassType(RenderState::FIXED); 523 560 561 // the bird-eye visualization 562 visualization = new Visualization(bvh, camera, NULL, &renderState); 563 564 // this function assign the render queue bucket ids of the materials in beforehand 565 // => probably a little less overhead for new parts of the scene that are not yet assigned 566 PrepareRenderQueue(); 567 /// forward rendering is the default 568 renderState.SetRenderTechnique(FORWARD); 524 569 // frame time is restarted every frame 525 570 frameTimer.Start(); … … 527 572 // the rendering loop 528 573 glutMainLoop(); 529 574 530 575 // clean up 531 576 CleanUp(); … … 535 580 536 581 537 void InitCg(void)538 {539 // setup cg540 cgSetErrorCallback(cgErrorCallback);541 542 // create context.543 sCgContext = cgCreateContext();544 545 // get the optimal profile546 RenderState::sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);547 cgGLSetOptimalOptions(RenderState::sCgFragmentProfile);548 549 RenderState::sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);550 cgGLSetOptimalOptions(RenderState::sCgVertexProfile);551 552 // set textures to auto load553 cgGLSetManageTextureParameters(sCgContext, false);554 555 RenderState::sCgMrtVertexProgram =556 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgVertexProfile, "vtx");557 558 if (!RenderState::sCgMrtVertexProgram->IsValid())559 cerr << "fragment program failed to load" << endl;560 561 RenderState::sCgMrtFragmentTexProgram =562 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "fragtex");563 564 565 if (!RenderState::sCgMrtFragmentTexProgram->IsValid())566 cerr << "fragment tex program failed to load" << endl;567 568 RenderState::sCgMrtFragmentTexProgram->AddParameter("tex", 0);569 570 RenderState::sCgMrtFragmentProgram =571 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "frag");572 573 if (!RenderState::sCgMrtFragmentProgram->IsValid())574 cerr << "fragment program failed to load" << endl;575 576 577 PrintGLerror("init");578 579 DeferredRenderer::InitCG(sCgContext);580 SkyPreetham::InitCG(sCgContext);581 582 cout << "cg initialization successful" << endl;583 }584 585 586 582 void InitFBO() 587 583 { … … 589 585 590 586 // this fbo basicly stores the scene information we get from standard rendering of a frame 591 // we store colors, normals, positions (for the ssao)587 // we store diffuse colors, eye space depth and normals 592 588 fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32); 593 //fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_24);594 589 595 590 // the diffuse color buffer 596 591 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); 597 592 // the normals buffer 598 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 599 // the positions buffer 600 //fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 601 fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 593 //fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 594 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 595 // a rgb buffer which could hold material properties 596 //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 597 // buffer holding the difference vector to the old frame 598 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 602 599 // another color buffer 603 600 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); 604 601 605 PrintGLerror("fbo"); 602 for (int i = 0; i < 4; ++ i) 603 FrameBufferObject::InitBuffer(fbo, i); 604 605 PrintGLerror("init fbo"); 606 606 } 607 607 … … 741 741 742 742 743 RenderTraverser *CreateTraverser( Camera *cam)743 RenderTraverser *CreateTraverser(PerspectiveCamera *cam) 744 744 { 745 745 RenderTraverser *tr; 746 746 747 bvh->ResetNodeClassifications();748 749 747 switch (renderMode) 750 748 { … … 769 767 tr->SetHierarchy(bvh); 770 768 tr->SetRenderQueue(renderQueue); 771 tr->SetRenderState(& state);769 tr->SetRenderState(&renderState); 772 770 tr->SetUseOptimization(useOptimization); 773 771 tr->SetUseRenderQueue(useRenderQueue); … … 779 777 tr->SetUseDepthPass((renderMethod == RENDER_DEPTH_PASS) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)); 780 778 tr->SetRenderQueue(renderQueue); 779 tr->SetShowBounds(showBoundingVolumes); 780 781 bvh->ResetNodeClassifications(); 782 781 783 782 784 return tr; 783 785 } 784 786 785 787 /** Setup sunlight 788 */ 786 789 void SetupLighting() 787 790 { … … 800 803 801 804 802 const bool useToneMapping = ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || (renderMethod == RENDER_DEFERRED)) && useHDR; 805 const bool useHDRValues = 806 ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || 807 (renderMethod == RENDER_DEFERRED)) && useHDR; 808 803 809 804 810 Vector3 sunAmbient; 805 811 Vector3 sunDiffuse; 806 812 807 preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse, !useToneMapping); 813 #if 1 814 preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse, !useHDRValues); 808 815 809 816 ambient[0] = sunAmbient.x; … … 811 818 ambient[2] = sunAmbient.z; 812 819 813 // no tone mapping => scale814 if (!useToneMapping)815 {816 const float maxComponent = sunDiffuse.MaxComponent();817 sunDiffuse /= maxComponent;818 }819 820 820 diffuse[0] = sunDiffuse.x; 821 821 diffuse[1] = sunDiffuse.y; 822 822 diffuse[2] = sunDiffuse.z; 823 823 824 #else 825 826 ambient[0] = .2f; 827 ambient[1] = .2f; 828 ambient[2] = .2f; 829 830 diffuse[0] = 1.0f; 831 diffuse[1] = 1.0f; 832 diffuse[2] = 1.0f; 833 834 #endif 835 824 836 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 825 837 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); … … 836 848 oldViewProjMat = viewProjMat; 837 849 838 glMatrixMode(GL_PROJECTION); 839 glLoadIdentity(); 840 gluPerspective(fov, winAspectRatio, nearDist, farDist); 841 842 glMatrixMode(GL_MODELVIEW); 843 844 // set up the camera view 845 camera->SetupCameraView(); 846 847 850 camera->SetupViewProjection(); 851 852 848 853 ///////////////// 854 //-- compute view projection matrix and store for later use 849 855 850 856 Matrix4x4 matViewing, matProjection; … … 853 859 camera->GetProjectionMatrix(matProjection); 854 860 855 // store matrix for later use856 861 viewProjMat = matViewing * matProjection; 857 862 } … … 881 886 882 887 883 static void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br) 884 { 885 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 886 887 camera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 888 889 bl = Normalize(nbl - fbl); 890 br = Normalize(nbr - fbr); 891 tl = Normalize(ntl - ftl); 892 tr = Normalize(ntr - ftr); 893 } 894 895 888 void KeyStrafe(float shift) 889 { 890 Vector3 viewDir = camera->GetDirection(); 891 Vector3 pos = camera->GetPosition(); 892 893 // the 90 degree rotated view vector 894 // z zero so we don't move in the vertical 895 Vector3 rVec(viewDir[0], viewDir[1], 0); 896 897 Matrix4x4 rot = RotationZMatrix(M_PI * 0.5f); 898 rVec = rot * rVec; 899 pos += rVec * shift; 900 901 camera->SetPosition(pos); 902 } 903 904 905 /** Initialize the deferred rendering pass. 906 */ 896 907 void InitDeferredRendering() 897 908 { … … 901 912 // multisampling does not work with deferred shading 902 913 glDisable(GL_MULTISAMPLE_ARB); 903 904 state.SetRenderPassType(RenderState::DEFERRED); 905 906 cgGLEnableProfile(RenderState::sCgVertexProfile); 907 RenderState::sCgMrtVertexProgram->Bind(); 908 909 cgGLEnableProfile(RenderState::sCgFragmentProfile); 910 RenderState::sCgMrtFragmentProgram->Bind(); 911 912 const Vector3 pos = camera->GetPosition(); 913 914 915 // draw to 3 color buffers 916 // a color, normal, and positions buffer 914 renderState.SetRenderTechnique(DEFERRED); 915 916 917 // draw to 3 render targets 917 918 if (sCurrentMrtSet == 0) 918 919 { 919 920 DeferredRenderer::colorBufferIdx = 0; 920 glDrawBuffers( 2, mrt);921 glDrawBuffers(3, mrt); 921 922 } 922 923 else 923 924 { 924 925 DeferredRenderer::colorBufferIdx = 3; 925 glDrawBuffers( 2, mrt2);926 glDrawBuffers(3, mrt2); 926 927 } 927 928 … … 930 931 931 932 932 // the main rendering loop 933 void Display() 933 /** the main rendering loop 934 */ 935 void MainLoop() 934 936 { 937 #if 1 938 GPUProgramParameters *vtxParams = 939 buddha->GetShape(0)->GetMaterial()->GetTechnique(1)->GetVertexProgramParameters(); 940 941 Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix(); 942 Vector3 buddhaPos = motionPath->GetCurrentPosition(); 943 Matrix4x4 trafo = TranslationMatrix(buddhaPos); 944 945 buddha->GetTransform()->SetMatrix(trafo); 946 947 /*for (int i = 0; i < 10; ++ i) 948 { 949 SceneEntity *ent = dynamicObjects[i]; 950 Vector3 newPos = ent->GetWorldCenter(); 951 952 if (GetOrCreateSceneQuery()->CalcIntersection(newPos)) 953 { 954 Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter()); 955 ent->GetTransform()->SetMatrix(mat); 956 } 957 }*/ 958 959 Matrix4x4 rotMatrix = RotationZMatrix(M_PI * 1e-3f); 960 dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 961 962 963 ///////////////////////// 964 //-- update animations 965 966 motionPath->Move(0.01f); 967 968 #endif 969 970 971 ///////////// 972 935 973 Vector3 oldPos = camera->GetPosition(); 936 974 … … 947 985 if (descendKeyPressed) 948 986 KeyVerticalMotion(-KeyShift()); 987 if (leftStrafeKeyPressed) 988 KeyStrafe(KeyShift()); 989 if (rightStrafeKeyPressed) 990 KeyStrafe(-KeyShift()); 991 949 992 950 993 // place view on ground … … 958 1001 959 1002 960 961 1003 if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView)) 962 1004 { … … 971 1013 // bring eye modelview matrix up-to-date 972 1014 SetupEyeView(); 973 974 // hack 1015 // set frame related parameters for GPU programs 1016 GPUProgramParameters::InitFrame(camera, light); 1017 1018 // hack: store current rendering method and restore later 975 1019 int oldRenderMethod = renderMethod; 976 977 if (renderLightView) 978 renderMethod = RenderState::FIXED; 979 1020 // for rendering the light view, we use forward rendering 1021 if (renderLightView) renderMethod = FORWARD; 1022 1023 /// enable vbo vertex array 980 1024 glEnableClientState(GL_VERTEX_ARRAY); 981 982 1025 983 1026 // render with the specified method (forward rendering, forward + depth, deferred) 984 1027 switch (renderMethod) 985 1028 { 986 case RENDER_F IXED:1029 case RENDER_FORWARD: 987 1030 988 1031 glEnable(GL_MULTISAMPLE_ARB); 989 990 state.SetRenderPassType(RenderState::FIXED); 991 glEnable(GL_LIGHTING); 992 993 cgGLDisableProfile(RenderState::sCgFragmentProfile); 994 cgGLDisableProfile(RenderState::sCgVertexProfile); 1032 renderState.SetRenderTechnique(FORWARD); 1033 //glEnable(GL_LIGHTING); 995 1034 996 1035 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 997 998 1036 glEnableClientState(GL_NORMAL_ARRAY); 999 1000 1037 break; 1001 1038 … … 1003 1040 1004 1041 glDisable(GL_MULTISAMPLE_ARB); 1005 state.SetUseAlphaToCoverage(false);1006 1007 state.SetRenderPassType(RenderState::DEPTH_PASS); 1008 1009 if (!fbo) InitFBO();fbo->Bind();1042 renderState.SetUseAlphaToCoverage(false); 1043 renderState.SetRenderTechnique(DEPTH_PASS); 1044 1045 if (!fbo) InitFBO(); 1046 fbo->Bind(); 1010 1047 1011 1048 glDrawBuffers(1, mrt); 1012 1049 1013 cgGLDisableProfile(RenderState::sCgFragmentProfile);1014 cgGLDisableProfile(RenderState::sCgVertexProfile);1015 1016 1050 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1017 1051 1018 // the scene is rendered withouth any shading 1052 // the scene is rendered withouth any shading 1053 // (should be handled by render renderState) 1019 1054 glShadeModel(GL_FLAT); 1020 glDisable(GL_LIGHTING);1021 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);1022 1023 1024 1055 break; 1025 1056 … … 1027 1058 1028 1059 glEnable(GL_MULTISAMPLE_ARB); 1029 1030 cgGLDisableProfile(RenderState::sCgFragmentProfile); 1031 cgGLDisableProfile(RenderState::sCgVertexProfile); 1032 1033 state.SetRenderPassType(RenderState::DEPTH_PASS); 1034 1035 // the scene is rendered withouth any shading 1060 renderState.SetRenderTechnique(DEPTH_PASS); 1061 1062 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1063 1064 // the scene is rendered withouth any shading 1065 // (should be handled by render renderState) 1036 1066 glShadeModel(GL_FLAT); 1037 glDisable(GL_LIGHTING); 1038 1039 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1040 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 1041 1042 1043 break; 1044 1045 case RenderState::DEFERRED: 1067 break; 1068 1069 case RENDER_DEFERRED: 1046 1070 1047 1071 if (showShadowMap && !renderLightView) … … 1055 1079 glEnableClientState(GL_NORMAL_ARRAY); 1056 1080 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1057 1058 1081 break; 1059 1082 } 1060 1083 1061 1084 glDepthFunc(GL_LESS); 1062 1063 1085 glDisable(GL_TEXTURE_2D); 1064 1086 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 1065 1087 1066 1088 1067 // reset lod levels for current frame1089 // set proper lod levels for current frame using current eye point 1068 1090 LODLevel::InitFrame(camera->GetPosition()); 1069 1070 // set up lights 1091 // set up sunlight 1071 1092 SetupLighting(); 1072 1093 … … 1074 1095 if (renderLightView) 1075 1096 { 1076 // change CHC++ set of state variables (must be done for each change of camera because 1077 // otherwise the temporal coherency is broken 1078 BvhNode::SetCurrentState(1); 1097 // change CHC++ set of renderState variables: 1098 // must be done for each change of camera because otherwise 1099 // the temporal coherency is broken 1100 BvhNode::SetCurrentState(LIGHT_PASS); 1079 1101 shadowMap->RenderShadowView(shadowTraverser, viewProjMat); 1080 BvhNode::SetCurrentState( 0);1102 BvhNode::SetCurrentState(CAMERA_PASS); 1081 1103 } 1082 1104 else … … 1112 1134 FrameBufferObject::Release(); 1113 1135 1114 cgGLDisableProfile(RenderState::sCgVertexProfile); 1115 cgGLDisableProfile(RenderState::sCgFragmentProfile); 1116 1117 if (!ssaoShader) ssaoShader = 1118 new DeferredRenderer(texWidth, texHeight, camera, farDist / MAX_DEPTH_CONST); 1136 if (!deferredShader) deferredShader = 1137 new DeferredRenderer(texWidth, texHeight, camera); 1119 1138 1120 1139 DeferredRenderer::SHADING_METHOD shadingMethod; … … 1130 1149 shadingMethod = DeferredRenderer::DEFAULT; 1131 1150 1132 1133 ssaoShader->SetShadingMethod(shadingMethod);1134 ssaoShader->SetSamplingMethod(samplingMethod);1135 ssaoShader->SetUseTemporalCoherence(useTemporalCoherence);1151 deferredShader->SetShadingMethod(shadingMethod); 1152 deferredShader->SetSamplingMethod(samplingMethod); 1153 deferredShader->SetUseTemporalCoherence(useTemporalCoherence); 1154 deferredShader->SetSortSamples(sortSamples); 1136 1155 1137 1156 ShadowMap *sm = showShadowMap ? shadowMap : NULL; 1138 ssaoShader->Render(fbo, oldViewProjMat, viewProjMat, ssaoTempCohFactor, light, useHDR, sm);1139 } 1140 1141 1142 state.SetRenderPassType(RenderState::FIXED);1143 state.Reset();1157 deferredShader->Render(fbo, ssaoTempCohFactor, light, useHDR, useAntiAliasing, sm); 1158 } 1159 1160 1161 renderState.SetRenderTechnique(FORWARD); 1162 renderState.Reset(); 1144 1163 1145 1164 … … 1184 1203 { 1185 1204 case 27: 1205 Debug << "camPosition=" << camera->GetPosition().x << " " << camera->GetPosition().y << " " << camera->GetPosition().z << endl; 1206 Debug << "camDirection=" << camera->GetDirection().x << " " << camera->GetDirection().y << " " << camera->GetDirection().z << endl; 1207 1186 1208 CleanUp(); 1187 1209 exit(0); 1188 break;1189 1210 case 32: // space 1190 1211 renderMode = (renderMode + 1) % RenderTraverser::NUM_TRAVERSAL_TYPES; … … 1250 1271 //if (ssaoTempCohFactor > 1.0f) ssaoExpFactor = 1.0f; 1251 1272 break; 1252 case '9': 1273 case 'l': 1274 case 'L': 1253 1275 useLODs = !useLODs; 1254 1276 SceneEntity::SetUseLODs(useLODs); … … 1292 1314 downKeyPressed = true; 1293 1315 break; 1316 case 'j': 1317 case 'J': 1318 leftStrafeKeyPressed = true; 1319 break; 1320 case 'k': 1321 case 'K': 1322 rightStrafeKeyPressed = true; 1323 break; 1294 1324 case 'r': 1295 1325 case 'R': 1296 1326 useRenderQueue = !useRenderQueue; 1297 1327 traverser->SetUseRenderQueue(useRenderQueue); 1298 1299 1328 break; 1300 1329 case 'b': … … 1303 1332 traverser->SetUseTightBounds(useTightBounds); 1304 1333 break; 1305 case ' l':1306 case ' L':1334 case 'v': 1335 case 'V': 1307 1336 renderLightView = !renderLightView; 1308 1337 break; … … 1311 1340 useHDR = !useHDR; 1312 1341 break; 1342 case 'i': 1343 case 'I': 1344 useAntiAliasing = !useAntiAliasing; 1345 break; 1346 case '9': 1347 sortSamples = !sortSamples; 1348 break; 1313 1349 default: 1314 1350 return; … … 1371 1407 ascendKeyPressed = false; 1372 1408 break; 1373 1409 case 'j': 1410 case 'J': 1411 leftStrafeKeyPressed = false; 1412 break; 1413 case 'k': 1414 case 'K': 1415 rightStrafeKeyPressed = false; 1416 break; 1374 1417 default: 1375 1418 return; … … 1479 1522 1480 1523 1481 void Mouse(int button, int state, int x, int y)1482 { 1483 if ((button == GLUT_LEFT_BUTTON) && ( state == GLUT_DOWN))1524 void Mouse(int button, int renderState, int x, int y) 1525 { 1526 if ((button == GLUT_LEFT_BUTTON) && (renderState == GLUT_DOWN)) 1484 1527 { 1485 1528 xEyeBegin = x; … … 1488 1531 glutMotionFunc(LeftMotion); 1489 1532 } 1490 else if ((button == GLUT_RIGHT_BUTTON) && ( state == GLUT_DOWN))1533 else if ((button == GLUT_RIGHT_BUTTON) && (renderState == GLUT_DOWN)) 1491 1534 { 1492 1535 xEyeBegin = x; … … 1499 1542 glutMotionFunc(RightMotionLight); 1500 1543 } 1501 else if ((button == GLUT_MIDDLE_BUTTON) && ( state == GLUT_DOWN))1544 else if ((button == GLUT_MIDDLE_BUTTON) && (renderState == GLUT_DOWN)) 1502 1545 { 1503 1546 horizontalMotionBegin = x; … … 1579 1622 1580 1623 1581 // strafe 1624 /** strafe 1625 */ 1582 1626 void MiddleMotion(int x, int y) 1583 1627 { … … 1683 1727 1684 1728 glLoadIdentity(); 1685 1686 1729 glOrtho(-offs, offs, -offs, offs, 0.0f, box.Size().z * 100.0f); 1687 1730 … … 1711 1754 //-- visualization of the occlusion culling 1712 1755 1713 visualization->Render( );1756 visualization->Render(showShadowMap); 1714 1757 1715 1758 … … 1735 1778 DEL_PTR(perfGraph); 1736 1779 DEL_PTR(fbo); 1737 DEL_PTR( ssaoShader);1780 DEL_PTR(deferredShader); 1738 1781 DEL_PTR(light); 1739 1782 DEL_PTR(visCamera); … … 1741 1784 DEL_PTR(shadowMap); 1742 1785 DEL_PTR(shadowTraverser); 1743 DEL_PTR(RenderState::sCgMrtFragmentProgram); 1744 DEL_PTR(RenderState::sCgMrtFragmentTexProgram); 1745 DEL_PTR(RenderState::sCgMrtVertexProgram); 1746 1786 DEL_PTR(motionPath); 1787 1747 1788 ResourceManager::DelSingleton(); 1748 loader = NULL; 1749 1750 DeferredRenderer::ReleaseCG(); 1751 SkyPreetham::ReleaseCG(); 1752 1753 if (sCgContext) 1754 cgDestroyContext(sCgContext); 1789 ShaderManager::DelSingleton(); 1790 1791 resourceManager = NULL; 1792 shaderManager = NULL; 1755 1793 } 1756 1794 … … 1878 1916 1879 1917 glEnable(GL_TEXTURE_2D); 1880 1881 1918 myfont.Begin(); 1882 1919 … … 1884 1921 { 1885 1922 glColor3f(0.0f, 1.0f, 0.0f); 1886 1887 1923 int i = 0; 1888 1924 1889 static char *renderMethodStr[] = {"forward", "depth pass + forward", "deferred shading", "depth pass + deferred"};1890 1925 static char *renderMethodStr[] = 1926 {"forward", "depth pass + forward", "deferred shading", "depth pass + deferred"}; 1891 1927 sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d", 1892 useMultiQueries, useTightBounds, useRenderQueue); 1893 1928 useMultiQueries, useTightBounds, useRenderQueue); 1894 1929 sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderMethodStr[renderMethod], useAdvancedShading); 1895 1896 1930 sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf); 1897 1898 1931 sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d", 1899 1932 assumedVisibleFrames, maxBatchSize); … … 1912 1945 int len = 10; 1913 1946 CalcDecimalPoint(objStr, renderedObjects, len); 1914 CalcDecimalPoint(totalObjStr, (int) loader->GetNumEntities(), len);1947 CalcDecimalPoint(totalObjStr, (int)resourceManager->GetNumEntities(), len); 1915 1948 1916 1949 CalcDecimalPoint(triStr, renderedTriangles, len); … … 1932 1965 sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d", 1933 1966 traversedNodes, frustumCulledNodes, queryCulledNodes); 1934 1935 sprintf(msg[i ++], "issued queries: %5d, state changes: %5d, render batches: %5d", 1967 sprintf(msg[i ++], "issued queries: %5d, renderState changes: %5d, render batches: %5d", 1936 1968 issuedQueries, stateChanges, numBatches); 1937 1969 … … 1944 1976 1945 1977 if (!showAlgorithmTime) 1946 1978 sprintf(msg[7], "%s: %6.1f fps", alg_str[renderMode], fps); 1947 1979 else 1948 1980 sprintf(msg[7], "%s: %6.1f ms", alg_str[renderMode], rTime); … … 1963 1995 void RenderSky() 1964 1996 { 1965 cgGLEnableProfile(RenderState::sCgVertexProfile);1966 1967 1997 if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 1968 state.SetRenderPassType(RenderState::DEFERRED);1998 renderState.SetRenderTechnique(DEFERRED); 1969 1999 1970 2000 const bool useToneMapping = 1971 2001 ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) || 1972 2002 (renderMethod == RENDER_DEFERRED)) && useHDR; 1973 1974 preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping); 1975 1976 cgGLDisableProfile(RenderState::sCgVertexProfile); 1977 cgGLDisableProfile(RenderState::sCgFragmentProfile); 2003 2004 preetham->RenderSkyDome(-light->GetDirection(), camera, &renderState, !useToneMapping); 2005 /// once again reset the renderState 2006 renderState.Reset(); 1978 2007 } 1979 2008 … … 1986 2015 if (showShadowMap && !renderLightView) 1987 2016 { 1988 float minVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 1989 RenderShadowMap(minVisibleDist); 2017 // usethe maximal visible distance to focus shadow map 2018 float maxVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance()); 2019 RenderShadowMap(maxVisibleDist); 1990 2020 } 1991 1992 glDisable(GL_LIGHTING); 1993 glViewport(0, 0, texWidth, texHeight); 1994 2021 // initialize deferred rendering 1995 2022 InitDeferredRendering(); 1996 2023 } 1997 2024 else 1998 2025 { 1999 glEnable(GL_LIGHTING); 2000 state.SetRenderPassType(RenderState::FIXED); 2001 } 2002 2026 renderState.SetRenderTechnique(FORWARD); 2027 } 2028 2029 2030 ///////////////// 2031 //-- reset gl renderState before the final visible objects pass 2032 2033 renderState.Reset(); 2034 2035 glEnableClientState(GL_NORMAL_ARRAY); 2036 /// switch back to smooth shading 2003 2037 glShadeModel(GL_SMOOTH); 2004 glEnableClientState(GL_NORMAL_ARRAY); 2005 2006 // draw all objects that have exactly the same depth as the current sample 2007 glDepthFunc(GL_LEQUAL); 2008 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 2009 2038 /// reset alpha to coverage flag 2039 renderState.SetUseAlphaToCoverage(true); 2040 // clear color 2010 2041 glClear(GL_COLOR_BUFFER_BIT); 2011 2012 state.SetUseAlphaToCoverage(true);2013 state.Reset();2042 2043 // draw only objects having exactly the same depth as the current sample 2044 glDepthFunc(GL_EQUAL); 2014 2045 2015 2046 //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl; 2016 2047 2017 SceneEntityContainer::const_iterator sit, 2048 SceneEntityContainer::const_iterator sit, 2018 2049 sit_end = traverser->GetVisibleObjects().end(); 2019 2050 … … 2022 2053 renderQueue->Enqueue(*sit); 2023 2054 } 2024 2055 /// now render out everything in one giant pass 2025 2056 renderQueue->Apply(); 2026 2057 2058 // switch back to standard depth func 2027 2059 glDepthFunc(GL_LESS); 2028 state.Reset();2060 renderState.Reset(); 2029 2061 2030 2062 PrintGLerror("visibleobjects"); … … 2032 2064 2033 2065 2066 SceneQuery *GetOrCreateSceneQuery() 2067 { 2068 if (!sceneQuery) 2069 sceneQuery = new SceneQuery(bvh->GetBox(), traverser, &renderState); 2070 2071 return sceneQuery; 2072 } 2073 2074 2034 2075 void PlaceViewer(const Vector3 &oldPos) 2035 2076 { 2036 if (!sceneQuery)2037 sceneQuery = new SceneQuery(bvh->GetBox(), traverser);2038 2039 2077 Vector3 playerPos = camera->GetPosition(); 2040 bool validIntersect = sceneQuery->CalcIntersection(playerPos);2078 bool validIntersect = GetOrCreateSceneQuery()->CalcIntersection(playerPos); 2041 2079 2042 2080 if (validIntersect) … … 2050 2088 void RenderShadowMap(float newfar) 2051 2089 { 2052 cgGLDisableProfile(RenderState::sCgFragmentProfile);2053 cgGLDisableProfile(RenderState::sCgVertexProfile);2054 2055 2090 glDisableClientState(GL_NORMAL_ARRAY); 2056 2057 state.SetRenderPassType(RenderState::DEPTH_PASS); 2058 state.LockCullFaceEnabled(true); 2059 state.SetUseAlphaToCoverage(false); 2060 2061 // change CHC++ set of state variables 2091 renderState.SetRenderTechnique(DEPTH_PASS); 2092 2093 // hack: disable cull face because of alpha textured balconies 2094 glDisable(GL_CULL_FACE); 2095 renderState.LockCullFaceEnabled(true); 2096 2097 /// don't use alpha to coverage for the depth map (problems with fbo rendering) 2098 renderState.SetUseAlphaToCoverage(false); 2099 2100 // change CHC++ set of renderState variables 2062 2101 // this must be done for each change of camera because 2063 2102 // otherwise the temporal coherency is broken 2064 BvhNode::SetCurrentState(1); 2065 2103 BvhNode::SetCurrentState(LIGHT_PASS); 2066 2104 // hack: temporarily change camera far plane 2067 2105 camera->SetFar(newfar); 2068 glDisable(GL_CULL_FACE);2069 2070 2106 // the scene is rendered withouth any shading 2071 2107 shadowMap->ComputeShadowMap(shadowTraverser, viewProjMat); 2072 2108 2109 camera->SetFar(farDist); 2110 2111 renderState.SetUseAlphaToCoverage(true); 2112 renderState.LockCullFaceEnabled(false); 2073 2113 glEnable(GL_CULL_FACE); 2074 camera->SetFar(farDist);2075 2076 state.SetUseAlphaToCoverage(true);2077 state.LockCullFaceEnabled(false);2078 2114 2079 2115 glEnableClientState(GL_NORMAL_ARRAY); 2080 2081 // change back state 2082 BvhNode::SetCurrentState(0); 2083 } 2116 // change back renderState 2117 BvhNode::SetCurrentState(CAMERA_PASS); 2118 } 2119 2120 2121 /** Touch each material once in order to preload the render queue 2122 bucket id of each material 2123 */ 2124 void PrepareRenderQueue() 2125 { 2126 for (int i = 0; i < 3; ++ i) 2127 { 2128 renderState.SetRenderTechnique(i); 2129 2130 // fill all shapes into the render queue once so we can establish the buckets 2131 ShapeContainer::const_iterator sit, sit_end = (*resourceManager->GetShapes()).end(); 2132 2133 for (sit = (*resourceManager->GetShapes()).begin(); sit != sit_end; ++ sit) 2134 { 2135 static Transform3 dummy(IdentityMatrix()); 2136 renderQueue->Enqueue(*sit, NULL); 2137 } 2138 2139 // just clear queue again 2140 renderQueue->Clear(); 2141 } 2142 } 2143 2144 2145 void LoadModel(const string &model, SceneEntityContainer &entities) 2146 { 2147 const string filename = string(model_path + model); 2148 2149 cout << "\nloading model " << filename << endl; 2150 if (resourceManager->Load(filename, entities)) 2151 cout << "model " << filename << " successfully loaded" << endl; 2152 else 2153 { 2154 cerr << "loading model " << filename << " failed" << endl; 2155 CleanUp(); 2156 exit(0); 2157 } 2158 } 2159 2160 2161 void CreateAnimation() 2162 { 2163 const float radius = 5.0f; 2164 const Vector3 center(480.398f, 268.364f, 181.3); 2165 2166 VertexArray vertices; 2167 2168 /*for (int i = 0; i < 360; ++ i) 2169 { 2170 float angle = (float)i * M_PI / 180.0f; 2171 2172 Vector3 offs = Vector3(cos(angle) * radius, sin(angle) * radius, 0); 2173 vertices.push_back(center + offs); 2174 }*/ 2175 2176 for (int i = 0; i < 5; ++ i) 2177 { 2178 Vector3 offs = Vector3(i, 0, 0); 2179 vertices.push_back(center + offs); 2180 } 2181 2182 2183 for (int i = 0; i < 5; ++ i) 2184 { 2185 Vector3 offs = Vector3(4 -i, 0, 0); 2186 vertices.push_back(center + offs); 2187 } 2188 2189 motionPath = new MotionPath(vertices); 2190 } -
TabularUnified GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg ¶
r3206 r3207 267 267 // actually 0 means pixel is valid 268 268 const float pixelIsValid = 0.0f; 269 // means that we only use slight temporal coherence over some frames 270 // so that there si no noticeable drag 269 271 const float pixelCouldBeValid = 2.0f; 272 // this pixel information has to be discarded in order to not create artifacts 270 273 const float pixelNotValid = 10.0f; 271 274
Note: See TracChangeset
for help on using the changeset viewer.