- Timestamp:
- 10/09/08 18:36:03 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
r3017 r3019 7 7 EndProject 8 8 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MainApp", "MainApp.vcproj", "{A564071F-D054-4556-883B-999D7F9CC58C}" 9 ProjectSection(ProjectDependencies) = postProject10 {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023}11 EndProjectSection12 EndProject13 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrradianceMapping", "IrradianceMapping.vcproj", "{91680C49-A358-48AE-A02C-66CB884B7D7F}"14 9 ProjectSection(ProjectDependencies) = postProject 15 10 {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023} … … 34 29 {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.ActiveCfg = Release|Win32 35 30 {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.Build.0 = Release|Win32 36 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.ActiveCfg = Debug|Win3237 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.Build.0 = Debug|Win3238 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win3239 {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win3240 31 EndGlobalSection 41 32 GlobalSection(SolutionProperties) = preSolution -
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3016 r3019 18 18 <Configuration 19 19 Name="Debug|Win32" 20 OutputDirectory="$(SolutionDir)/ bin/$(ConfigurationName)"20 OutputDirectory="$(SolutionDir)/lib/$(ConfigurationName)" 21 21 IntermediateDirectory="obj/$(ConfigurationName)" 22 ConfigurationType=" 1"22 ConfigurationType="4" 23 23 CharacterSet="1" 24 24 > … … 62 62 /> 63 63 <Tool 64 Name="VCLinkerTool" 65 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib" 66 LinkIncremental="2" 67 AdditionalLibraryDirectories="libs/GL;libs/Devil/lib;libs/Zlib/lib;"$(CG_LIB_PATH)"" 68 IgnoreDefaultLibraryNames="LIBCMT" 69 GenerateDebugInformation="true" 70 SubSystem="1" 71 TargetMachine="1" 64 Name="VCLibrarianTool" 72 65 /> 73 66 <Tool … … 75 68 /> 76 69 <Tool 77 Name="VCManifestTool"78 />79 <Tool80 70 Name="VCXDCMakeTool" 81 71 /> … … 85 75 <Tool 86 76 Name="VCFxCopTool" 87 />88 <Tool89 Name="VCAppVerifierTool"90 />91 <Tool92 Name="VCWebDeploymentTool"93 77 /> 94 78 <Tool … … 128 112 EnableFiberSafeOptimizations="true" 129 113 AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;"$(CG_INC_PATH)"" 130 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE; 114 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS" 131 115 StringPooling="true" 132 116 RuntimeLibrary="2" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj
r3012 r3019 41 41 Name="VCCLCompilerTool" 42 42 Optimization="0" 43 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" 43 AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;"$(CG_INC_PATH)"" 44 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SET" 44 45 MinimalRebuild="true" 45 46 BasicRuntimeChecks="3" … … 61 62 <Tool 62 63 Name="VCLinkerTool" 64 AdditionalDependencies="DemoEngine.lib glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib" 65 OutputFile="$(OutDir)\FriendlyCulling.exe" 63 66 LinkIncremental="2" 67 AdditionalLibraryDirectories=""lib/$(ConfigurationName)";libs;"$(CG_LIB_PATH)";libs/GL;libs/Devil/lib;libs/Zlib/lib" 64 68 GenerateDebugInformation="true" 65 69 SubSystem="1" … … 122 126 EnableFiberSafeOptimizations="true" 123 127 AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;"$(CG_INC_PATH)"" 124 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE; 128 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS" 125 129 RuntimeLibrary="2" 126 130 EnableEnhancedInstructionSet="2" -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3018 r3019 61 61 62 62 63 ShaderContainer DeferredRenderer::sShaders; 63 64 64 65 /////////////////////////////////////// … … 296 297 297 298 299 static void InitBuffer(FrameBufferObject *fbo, int index) 300 { 301 // read the second buffer, write to the first buffer 302 fbo->Bind(); 303 glDrawBuffers(1, mrt + index); 304 305 //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 306 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 307 308 glEnd(); 309 310 FrameBufferObject::Release(); 311 } 312 313 298 314 DeferredRenderer::DeferredRenderer(int w, int h, Camera *cam, float scaleFactor): 299 315 mWidth(w), mHeight(h), … … 303 319 mSamplingMethod(SAMPLING_POISSON), 304 320 mShadingMethod(DEFAULT), 305 m FboIndex(0)321 mIllumFboIndex(0) 306 322 { 307 323 // create noise texture for ssao … … 312 328 //-- the flip-flop fbos 313 329 314 mFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 315 //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 316 317 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 318 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 319 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 320 mFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 330 mIllumFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 331 mFBOs.push_back(mIllumFbo); 332 333 for (int i = 0; i < 4; ++ i) 334 { 335 mIllumFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 336 InitBuffer(mIllumFbo, i); 337 } 321 338 322 339 mDownSampleFbo = new FrameBufferObject(w / 2, h / 2, FrameBufferObject::DEPTH_NONE); 323 324 340 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 325 341 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 326 } 327 342 343 mFBOs.push_back(mDownSampleFbo); 344 } 328 345 329 346 330 347 DeferredRenderer::~DeferredRenderer() 331 348 { 332 if (sCgSsaoProgram) cgDestroyProgram(sCgSsaoProgram); 333 if (sCgDeferredProgram) cgDestroyProgram(sCgDeferredProgram); 334 if (sCgSsaoProgram) cgDestroyProgram(sCgSsaoProgram); 335 if (sCgGiProgram) cgDestroyProgram(sCgGiProgram); 336 if (sCgAntiAliasingProgram) cgDestroyProgram(sCgAntiAliasingProgram); 337 338 DEL_PTR(mFbo); 349 CLEAR_CONTAINER(sShaders); 350 CLEAR_CONTAINER(mFBOs); 339 351 340 352 glDeleteTextures(1, &noiseTex); … … 350 362 void DeferredRenderer::Init(CGcontext context) 351 363 { 364 ShaderProgram *pr; 365 366 352 367 sCgDeferredProgram = 353 368 cgCreateProgramFromFile(context, … … 368 383 369 384 sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 385 386 pr = new ShaderProgram(sCgDeferredProgram); 387 sShaders.push_back(pr); 370 388 } 371 389 else … … 407 425 sBRParam = cgGetNamedParameter(sCgSsaoProgram, "br"); 408 426 sBLParam = cgGetNamedParameter(sCgSsaoProgram, "bl"); 427 428 pr = new ShaderProgram(sCgSsaoProgram); 429 sShaders.push_back(pr); 409 430 } 410 431 else … … 443 464 444 465 sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos"); 466 467 pr = new ShaderProgram(sCgGiProgram); 468 sShaders.push_back(pr); 445 469 } 446 470 else … … 462 486 sSsaoTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "ssaoTex"); 463 487 sIllumTexCombinedIllumParam = cgGetNamedParameter(sCgCombinedIllumProgram, "illumTex"); 488 489 pr = new ShaderProgram(sCgCombinedIllumProgram); 490 sShaders.push_back(pr); 464 491 } 465 492 else … … 484 511 sFilterOffsetsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterOffs"); 485 512 sFilterWeightsParam = cgGetNamedParameter(sCgCombinedSsaoProgram, "filterWeights"); 513 514 pr = new ShaderProgram(sCgCombinedSsaoProgram); 515 sShaders.push_back(pr); 486 516 } 487 517 else … … 503 533 sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors"); 504 534 sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 535 536 pr = new ShaderProgram(sCgAntiAliasingProgram); 537 sShaders.push_back(pr); 505 538 } 506 539 else … … 538 571 539 572 cgGLSetParameterArray2f(sSamplesShadowParam, 0, NUM_PCF_TABS, (const float *)pcfSamples); 573 574 pr = new ShaderProgram(sCgDeferredShadowProgram); 575 sShaders.push_back(pr); 540 576 } 541 577 else … … 553 589 { 554 590 cgGLLoadProgram(sCgLogLumProgram); 555 sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors"); 591 sColorsTexLogLumParam = cgGetNamedParameter(sCgLogLumProgram, "colors"); 592 593 pr = new ShaderProgram(sCgLogLumProgram); 594 sShaders.push_back(pr); 556 595 } 557 596 else … … 576 615 577 616 sColorsTexToneParam = cgGetNamedParameter(sCgToneProgram, "colors"); 617 618 pr = new ShaderProgram(sCgToneProgram); 619 sShaders.push_back(pr); 578 620 } 579 621 else … … 596 638 sColorsTexDownSampleParam = cgGetNamedParameter(sCgDownSampleProgram, "colors"); 597 639 sDownSampleOffsetParam = cgGetNamedParameter(sCgDownSampleProgram, "downSampleOffs"); 640 641 pr = new ShaderProgram(sCgDownSampleProgram); 642 sShaders.push_back(pr); 598 643 } 599 644 else … … 618 663 // the other one will be written 619 664 620 m FboIndex = 2 -mFboIndex;665 mIllumFboIndex = 2 - mIllumFboIndex; 621 666 622 667 … … 726 771 #endif 727 772 728 GLuint oldTex = m Fbo->GetColorBuffer(2 -mFboIndex)->GetTexture();773 GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 729 774 730 775 glPushAttrib(GL_VIEWPORT_BIT); 731 glViewport(0, 0, m Fbo->GetWidth(),mFbo->GetHeight());776 glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 732 777 733 778 // read the second buffer, write to the first buffer 734 m Fbo->Bind();735 glDrawBuffers(1, mrt + m FboIndex);779 mIllumFbo->Bind(); 780 glDrawBuffers(1, mrt + mIllumFboIndex); 736 781 737 782 … … 850 895 cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 851 896 852 897 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 853 898 glColor3f(1.0f, 1.0f, 1.0f); 854 899 … … 939 984 940 985 glPushAttrib(GL_VIEWPORT_BIT); 941 glViewport(0, 0, m Fbo->GetWidth(),mFbo->GetHeight());986 glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 942 987 943 988 // read the second buffer, write to the first buffer 944 m Fbo->Bind();945 946 glDrawBuffers(2, mrt + m FboIndex);947 948 GLuint oldSsaoTex = m Fbo->GetColorBuffer(2 -mFboIndex)->GetTexture();949 GLuint oldIllumTex = m Fbo->GetColorBuffer(2 -mFboIndex + 1)->GetTexture();989 mIllumFbo->Bind(); 990 991 glDrawBuffers(2, mrt + mIllumFboIndex); 992 993 GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 994 GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 950 995 951 996 cgGLBindProgram(sCgGiProgram); … … 1024 1069 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1025 1070 1026 GLuint ssaoTex = m Fbo->GetColorBuffer(mFboIndex)->GetTexture();1027 GLuint illumTex = m Fbo->GetColorBuffer(mFboIndex + 1)->GetTexture();1071 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1072 GLuint illumTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture(); 1028 1073 1029 1074 … … 1084 1129 GLuint positionsTex = fbo->GetColorBuffer(2)->GetTexture(); 1085 1130 1086 GLuint ssaoTex = m Fbo->GetColorBuffer(mFboIndex)->GetTexture();1131 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1087 1132 1088 1133 // overwrite old color texture -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3016 r3019 19 19 class DirectionalLight; 20 20 21 22 class ShaderProgram 23 { 24 public: 25 26 ShaderProgram(CGprogram program): mProgram(program) {} 27 28 ~ShaderProgram() { cgDestroyProgram(mProgram); } 29 30 CGprogram mProgram; 31 }; 32 33 34 typedef std::vector<ShaderProgram *> ShaderContainer; 35 typedef std::vector<FrameBufferObject *> FBOContainer; 21 36 22 37 /** This class implements a deferred shading algorithm that takes … … 108 123 109 124 int mSamplingMethod; 110 int mFboIndex;111 125 112 126 int mShadingMethod; … … 114 128 bool mRegenerateSamples; 115 129 116 // the main fbo we are working with 117 FrameBufferObject *mFbo; 130 int mIllumFboIndex; 131 // the fbo for indirect illumination (ssao + color bleeding) 132 FrameBufferObject *mIllumFbo; 118 133 119 134 FrameBufferObject *mDownSampleFbo; 135 136 FBOContainer mFBOs; 137 138 static ShaderContainer sShaders; 120 139 }; 121 140 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r2982 r3019 29 29 CLEAR_CONTAINER(mTrafos); 30 30 CLEAR_CONTAINER(mShapes); 31 CLEAR_CONTAINER(mLODs); 31 32 } 32 33 … … 73 74 str.read(reinterpret_cast<char *>(&numShapes), sizeof(int)); 74 75 75 76 76 LODLevel *lodLevel = new LODLevel(dist); 77 77 … … 93 93 } 94 94 95 mLODs.push_back(lodLevel); 95 96 sceneGeom->AddLODLevel(lodLevel); 96 97 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
r2981 r3019 9 9 #include "common.h" 10 10 11 12 #define _CRTDBG_MAP_ALLOC 11 13 12 14 class igzstream; … … 60 62 ShapeContainer mShapes; 61 63 64 LODContainer mLODs; 62 65 63 66 //////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r3011 r3019 160 160 DEL_PTR(mFbo); 161 161 DEL_PTR(mShadowCam); 162 163 DEL_PTR(lightPoly); 164 DEL_PTR(polyhedron); 162 165 } 163 166 … … 649 652 glDisable(GL_DEPTH_TEST); 650 653 651 //glLineWidth(2);652 654 Polyhedron *hpoly = CreatePolyhedron(projView, mSceneBox); 653 655 DrawPoly(hpoly, Vector3(1, 1, 1)); 654 655 656 DEL_PTR(hpoly); 656 657 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3018 r3019 1 1 // chcdemo.cpp : Defines the entry point for the console application. 2 2 // 3 #include "glInterface.h" 3 4 #ifdef _CRT_SET 5 #define _CRTDBG_MAP_ALLOC 6 #include <stdlib.h> 7 #include <crtdbg.h> 8 #endif 9 10 #include "common.h" 11 12 #ifdef _CRT_SET 13 // redefine new operator 14 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 15 #define new DEBUG_NEW 16 #endif 17 18 4 19 #include <math.h> 5 20 #include <time.h> 6 #include "common.h" 21 #include "glInterface.h" 22 23 #include <Cg/cg.h> 24 #include <Cg/cgGL.h> 25 26 7 27 #include "RenderTraverser.h" 8 28 #include "SceneEntity.h" … … 40 60 #include "EntityMerger.h" 41 61 42 #include <Cg/cg.h>43 #include <Cg/cgGL.h>44 45 46 62 using namespace std; 47 63 using namespace CHCDemoEngine; … … 59 75 /// the renderable scene geometry 60 76 SceneEntityContainer sceneEntities; 61 SceneEntityContainer sceneEntities2;62 77 63 78 // traverses and renders the hierarchy … … 255 270 inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; } 256 271 inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; } 257 272 // initialise the frame buffer objects 258 273 void InitFBO(); 259 274 … … 309 324 int main(int argc, char* argv[]) 310 325 { 326 #ifdef _CRT_SET 327 328 //Now just call this function at the start of your program and if you're 329 //compiling in debug mode (F5), any leaks will be displayed in the Output 330 //window when the program shuts down. If you're not in debug mode this will 331 //be ignored. Use it as you will! 332 //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 333 334 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 335 _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 336 _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 337 #endif 338 339 cout << "=== reading environment file ===" << endl << endl; 340 311 341 int returnCode = 0; 312 342 … … 317 347 cout << "=== reading environment file ===" << endl << endl; 318 348 319 string envFileName = "default.env";349 const string envFileName = "default.env"; 320 350 if (!env.Read(envFileName)) 321 351 { … … 347 377 //env.GetStringParam(string("modelPath"), model_path); 348 378 //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples); 349 350 379 351 380 cout << "assumedVisibleFrames: " << assumedVisibleFrames << endl; … … 395 424 SceneEntity::SetUseLODs(useLODs); 396 425 397 398 426 if (!useFullScreen) 399 427 { … … 420 448 InitGLstate(); 421 449 422 423 450 glEnable(GL_MULTISAMPLE_ARB); 424 451 glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); … … 432 459 433 460 const string filename = string(model_path + "city.dem"); 461 434 462 435 463 if (loader->Load(filename, sceneEntities)) … … 441 469 exit(0); 442 470 } 471 443 472 444 473 const string bvh_filename = string(model_path + "city.bvh"); … … 452 481 exit(0); 453 482 } 454 455 483 456 484 // set far plane based on scene extent … … 468 496 469 497 Matrix4x4 transl = TranslationMatrix(cubeCenter); 470 471 498 472 499 SceneEntityContainer dummy; … … 474 501 string skyDomeStr(model_path + "sky.dem"); 475 502 476 if (loader->Load(skyDomeStr, dummy))477 cout << "successfully loaded " << dummy.size() << " scene entities" << endl;503 if (loader->Load(skyDomeStr, sceneEntities)) 504 cout << "successfully loaded " << sceneEntities.size() << " scene entities" << endl; 478 505 else 479 506 { … … 484 511 } 485 512 486 skyDome = dummy[0];513 skyDome = sceneEntities.back(); 487 514 488 515 … … 506 533 // clean up 507 534 CleanUp(); 508 535 509 536 return 0; 510 537 } … … 572 599 cgGLLoadProgram(RenderState::sCgMrtFragmentProgram); 573 600 574 sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragment TexProgram, "eyePos");601 sEyePosParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "eyePos"); 575 602 } 576 603 else … … 613 640 glGenTextures(1, &fontTex); 614 641 glBindTexture(GL_TEXTURE_2D, fontTex); 642 615 643 if (!myfont.Create("data/fonts/verdana.glf", fontTex)) 616 644 return false; … … 1747 1775 DEL_PTR(ssaoShader); 1748 1776 1777 DEL_PTR(light); 1778 DEL_PTR(visCamera); 1779 1780 DEL_PTR(preetham); 1781 1749 1782 if (sCgMrtVertexProgram) 1750 1783 cgDestroyProgram(sCgMrtVertexProgram); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.cpp
r2784 r3019 276 276 } 277 277 278 char *279 strdup(char *a)280 {281 if (a) {282 char *s = new char[strlen(a)+1];283 strcpy(s, a);284 return s;285 } else286 return NULL;287 }288 278 289 279 bool -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
r2980 r3019 32 32 class Vector3; 33 33 class Geometry; 34 34 struct LODLevel; 35 35 36 36 … … 445 445 446 446 447 char * 448 GetAbsPath(char *path); 449 450 char * 451 strdup(char *a); 447 char *GetAbsPath(char *path); 448 452 449 453 450 std::string … … 495 492 typedef std::vector<LODLevel *> LODLevelContainer; 496 493 typedef std::vector<Polygon3 *> PolygonContainer; 494 typedef std::vector<LODLevel *> LODContainer; 497 495 498 496 typedef std::vector<Vector3> VertexArray; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg
r3017 r3019 85 85 for (int i = 0; i < NUM_SAMPLES; i ++) 86 86 { 87 float2 offset = samples[i];87 const float2 offset = samples[i]; 88 88 89 89 #if 1 … … 104 104 //-- reconstruct world space position from sample 105 105 106 const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 106 //const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 107 const float4 sample = tex2D(colors, texcoord); 107 108 108 109 const float eyeSpaceDepth = sample.w; 109 //float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr));110 110 float3 rotView = Interpol(texcoord, bl, br, tl, tr); 111 111 112 const float3 sample _position= - rotView * eyeSpaceDepth;113 const float3 sample _color= sample.xyz;112 const float3 samplePos = - rotView * eyeSpaceDepth; 113 const float3 sampleCol = sample.xyz; 114 114 115 115 // distance between current position and sample position controls AO intensity. 116 116 117 float3 vector_to_sample = sample_position- centerPosition.xyz;118 const float length_to_sample = length(vector_to_sample);119 120 float3 direction_to_sample = vector_to_sample / length_to_sample;117 float3 dirSample = samplePos - centerPosition.xyz; 118 const float magSample = length(dirSample); 119 // normalize 120 dirSample /= magSample; 121 121 122 122 // use angle between current normal and direction to sample controls AO intensity. 123 float cos _angle = max(dot(direction_to_sample, currentNormal), 0);124 125 const float denom = (DISTANCE_SCALE + length_to_sample * length_to_sample);126 127 const float ssao_intensity = SAMPLE_INTENSITY / denom;128 const float illum_intensity = ILLUM_INTENSITY /denom;123 float cosAngle = max(dot(dirSample, currentNormal), 0); 124 125 const float denom = (DISTANCE_SCALE + magSample * magSample); 126 127 float2 intensity = float2(SAMPLE_INTENSITY, ILLUM_INTENSITY); 128 intensity /= denom; 129 129 130 130 // if normal perpenticular to view dir, only the samples approx count half 131 131 #if 1 132 const float view _correction= 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal);133 134 total_ao += cos _angle * ssao_intensity * view_correction;135 total_color += cos _angle * illum_intensity * sample_color * view_correction;132 const float viewCorrect = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, currentNormal); 133 134 total_ao += cosAngle * intensity.x * viewCorrect; 135 total_color += cosAngle * intensity.y * sampleCol * viewCorrect; 136 136 #else 137 total_ao += cos_angle * ssao_intensity;138 total_color += cos_angle * i llum_intensity * sample_color;137 total_ao += cos_angle * intensity.x; 138 total_color += cos_angle * intensity.y * sampleCol; 139 139 #endif 140 140 } … … 143 143 gi.ao = float2(max(0.0f, 1.0f - total_ao), numSamples); 144 144 145 //return saturate(total_color);146 145 return gi; 147 146 } … … 211 210 212 211 // retrieve the sample from the last frame 213 float 4oldSsao = tex2D(oldSsaoTex, tex);214 float 4oldIllum = tex2D(oldIllumTex, tex);212 float3 oldSsao = tex2D(oldSsaoTex, tex); 213 float3 oldIllum = tex2D(oldIllumTex, tex); 215 214 216 215 const float oldDepth = oldSsao.z; … … 218 217 const float depthDif = projDepth - oldDepth; 219 218 220 float oldWeight = clamp(oldSsao.y, 0, temporalCoherence);221 219 // the weights that indicate the state of convergence 220 const float oldWeight = clamp(oldSsao.y, .0f, temporalCoherence); 222 221 float newWeight; 223 222 … … 234 233 newWeight = oldWeight + 1; 235 234 236 OUT.ssao_col.x = (gi.ao + oldSsao.x * oldWeight) / newWeight; 237 OUT.illum_col.xyz = (gi.illum + oldIllum.xyz * oldWeight) / newWeight; 235 float4 tmp = float4(gi.ao.x, gi.illum); 236 float4 oldTmp = float4(oldSsao.x, oldIllum); 237 238 float4 interpol = (tmp + oldTmp * oldWeight) / newWeight; 239 240 OUT.ssao_col.x = interpol.x; 241 OUT.illum_col.xyz = interpol.yzw; 238 242 } 239 243 else … … 261 265 262 266 float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 263 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)).x; 264 float4 illum = tex2Dlod(illumTex, float4(IN.texCoord, 0, 0)); 265 266 OUT.illum_col = (col + illum) * ao; 267 float ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)).x; 268 269 float3 illum = tex2Dlod(illumTex, float4(IN.texCoord, 0, 0)).xyz; 270 271 OUT.illum_col.xyz = (col.xyz + illum) * ao; 272 //OUT.illum_col.xyz = col.xyz * ao; 273 267 274 OUT.illum_col.w = col.w; 268 275 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3017 r3019 48 48 float3 bl, float3 br, float3 tl, float3 tr) 49 49 { 50 const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 50 //const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 51 const float eyeSpaceDepth = tex2D(colors, texcoord).w; 51 52 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 52 53 float3 samplePos = -viewVec * eyeSpaceDepth; … … 94 95 #endif 95 96 // weight with projected coordinate to reach similar kernel size for near and far 96 float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor;97 98 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples;97 const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 98 99 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 99 100 100 101 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); … … 105 106 106 107 float3 dirSample = samplePos - centerPosition; 107 const float lengthSample = length(dirSample);108 109 float3 nDirSample = dirSample / lengthSample;108 const float magSample = length(dirSample); 109 // normalize 110 dirSample /= magSample; 110 111 111 112 // angle between current normal and direction to sample controls AO intensity. 112 const float cosAngle = max(dot( nDirSample, currentNormal), 0.0f);113 const float cosAngle = max(dot(dirSample, currentNormal), 0.0f); 113 114 114 115 // the distance_scale offset is used to avoid singularity that occurs at global illumination when 115 116 // the distance to a sample approaches zero 116 const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthSample * lengthSample);117 const float intensity = SAMPLE_INTENSITY / (DISTANCE_SCALE + magSample * magSample); 117 118 118 119 #if 1
Note: See TracChangeset
for help on using the changeset viewer.