Changeset 2928 for GTP/trunk/App/Demos
- Timestamp:
- 09/10/08 17:35:26 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r2911 r2928 816 816 </File> 817 817 <File 818 RelativePath=".\src\shaders\shadow.cg"819 >820 </File>821 <File822 818 RelativePath=".\src\shaders\ssao.cg" 823 819 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2927 r2928 12 12 13 13 // our coordinate system has the positive z axis pointing up 14 static Vector3 baseDir = Vector3(0, 1, 0);14 static const Vector3 baseDir = -Vector3::UNIT_Y(); 15 15 16 16 … … 49 49 50 50 51 void Camera::Precompute(const Vector3 &dir ection)52 { 53 Vector3 up = Vector3 (0, 0, 1);54 Vector3 right = Normalize(CrossProd( up, direction));55 up = Normalize(CrossProd( direction, right));56 57 mBaseOrientation = Matrix4x4(right, up, direction);51 void Camera::Precompute(const Vector3 &dir) 52 { 53 Vector3 up = Vector3::UNIT_Z(); 54 Vector3 right = Normalize(CrossProd(dir, up)); 55 up = Normalize(CrossProd(right, dir)); 56 57 mBaseOrientation = Matrix4x4(right, up, -dir); 58 58 mViewOrientation = mBaseOrientation; 59 59 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2903 r2928 22 22 static CGprogram sCgAntiAliasingProgram = NULL; 23 23 static CGprogram sCgDeferredShadowProgram = NULL; 24 static CGprogram sCgShadowDebugProgram = NULL; 24 25 25 26 static CGparameter sColorsTexCombineParam; … … 29 30 static CGparameter sPositionsTexDeferredParam; 30 31 static CGparameter sNormalsTexDeferredParam; 32 33 static CGparameter sShadowMapDebugParam; 34 static CGparameter sShadowMatrixDebugParam; 35 static CGparameter sColorsTexDebugParam; 31 36 32 37 … … 431 436 else 432 437 cerr << "deferred program failed to load" << endl; 438 439 sCgShadowDebugProgram = 440 cgCreateProgramFromFile(context, 441 CG_SOURCE, 442 "src/shaders/deferred.cg", 443 RenderState::sCgFragmentProfile, 444 "main_shadow_debug", 445 NULL); 446 447 if (sCgShadowDebugProgram != NULL) 448 { 449 cgGLLoadProgram(sCgShadowDebugProgram); 450 451 // we need size of texture for scaling 452 sShadowMapDebugParam = cgGetNamedParameter(sCgShadowDebugProgram, "shadowMap"); 453 sShadowMatrixDebugParam = cgGetNamedParameter(sCgShadowDebugProgram, "shadowMatrix"); 454 sColorsTexDebugParam = cgGetNamedParameter(sCgShadowDebugProgram, "colorTex"); 455 } 456 else 457 cerr << "shadow debug program failed to load" << endl; 458 433 459 PrintGLerror("init"); 434 460 } … … 471 497 glLoadIdentity(); 472 498 473 if (shadowMap) 474 FirstPassShadow(fbo, shadowMap); 499 if (shadowMap && (mShadingMethod == GI)) 500 { 501 ShadowDebug(fbo, shadowMap); 502 } 475 503 else 476 FirstPass(fbo); 477 478 switch (mShadingMethod) 479 { 480 case SSAO: 481 ComputeSsao(fbo, tempCohFactor, oldProjViewMatrix, projViewMatrix); 482 CombineSsao(fbo); 483 break; 484 case GI: 485 ComputeGlobIllum(fbo, tempCohFactor, oldProjViewMatrix); 486 CombineIllum(fbo); 487 break; 488 default: // DEFAULT 489 // do nothing: standard deferred shading 490 break; 491 } 492 493 AntiAliasing(fbo); 494 504 { 505 if (shadowMap) 506 FirstPassShadow(fbo, shadowMap); 507 else 508 FirstPass(fbo); 509 510 switch (mShadingMethod) 511 { 512 case SSAO: 513 ComputeSsao(fbo, tempCohFactor, oldProjViewMatrix, projViewMatrix); 514 CombineSsao(fbo); 515 break; 516 case GI: 517 ComputeGlobIllum(fbo, tempCohFactor, oldProjViewMatrix); 518 CombineIllum(fbo); 519 break; 520 default: // DEFAULT 521 // do nothing: standard deferred shading 522 break; 523 } 524 525 AntiAliasing(fbo); 526 } 495 527 glEnable(GL_LIGHTING); 496 528 glDisable(GL_TEXTURE_2D); … … 735 767 PrintGLerror("deferred shading"); 736 768 } 769 737 770 738 771 … … 952 985 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 953 986 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 954 GLuint shadowTex = shadowMap->Get ShadowTexture();987 GLuint shadowTex = shadowMap->GetDepthTexture(); 955 988 956 989 Matrix4x4 shadowMatrix; … … 1008 1041 1009 1042 1043 void DeferredRenderer::ShadowDebug(FrameBufferObject *fbo, ShadowMap *shadowMap) 1044 { 1045 GLuint colorsTex = shadowMap->GetShadowColorTexture(); 1046 GLuint shadowTex = shadowMap->GetDepthTexture(); 1047 1048 1049 Matrix4x4 shadowMatrix; 1050 shadowMap->GetTextureMatrix(shadowMatrix); 1051 1052 //glMatrixMode(GL_PROJECTION);glLoadIdentity(); 1053 //glViewport(0, 0, shadowMap->GetSize(), shadowMap->GetSize()); 1054 1055 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1056 1057 cgGLBindProgram(sCgShadowDebugProgram); 1058 1059 cgGLSetTextureParameter(sShadowMapDebugParam, shadowTex); 1060 cgGLSetTextureParameter(sColorsTexDebugParam, colorsTex); 1061 1062 cgGLEnableTextureParameter(sShadowMapDebugParam); 1063 1064 cgGLSetMatrixParameterfc(sShadowMatrixDebugParam, (const float *)shadowMatrix.x); 1065 1066 glColor3f(1.0f, 1.0f, 1.0f); 1067 1068 glBegin(GL_QUADS); 1069 1070 float offs2 = 0.5f; 1071 1072 glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); 1073 glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f); 1074 glTexCoord2f(1, 1); glVertex3f( offs2, offs2, -0.5f); 1075 glTexCoord2f(0, 1); glVertex3f(-offs2, offs2, -0.5f); 1076 1077 glEnd(); 1078 1079 cgGLDisableTextureParameter(sColorsTexDebugParam); 1080 cgGLDisableTextureParameter(sShadowMapDebugParam); 1081 1082 PrintGLerror("shadows debug"); 1083 } 1084 1085 1010 1086 void DeferredRenderer::SetSamplingMethod(SAMPLING_METHOD s) 1011 1087 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r2901 r2928 62 62 protected: 63 63 64 void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix, const Matrix4x4 &projViewMatrix); 64 void ComputeSsao(FrameBufferObject *fbo, 65 float tempCohFactor, 66 const Matrix4x4 &oldProjViewMatrix, 67 const Matrix4x4 &projViewMatrix); 65 68 66 69 void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix); … … 78 81 */ 79 82 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 83 84 85 void ShadowDebug(FrameBufferObject *fbo, ShadowMap *shadowMap); 80 86 81 87 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2925 r2928 111 111 // the diffuse color buffer 112 112 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 113 114 mShadowCam = new Camera(mSceneBox.Size().x * 0.5f, mSceneBox.Size().y * 0.5f); 113 //mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 114 115 mShadowCam = new Camera(mSize, mSize);//mSceneBox.Size().x * 0.5f, mSceneBox.Size().y * 0.5f); 115 116 mShadowCam->SetOrtho(true); 116 117 } … … 204 205 ) 205 206 { 207 //return IdentityMatrix(); 208 206 209 AxisAlignedBox3 bounds_ls = GetExtremalPoints(lightSpace, body); 207 //return IdentityMatrix();208 210 209 211 /////////////// … … 212 214 213 215 //const float n = 1e6f; 214 const float n = ComputeN(bounds_ls); 216 //const float n = 1e1f; 217 const float n = ComputeN(bounds_ls) * 100; 215 218 216 219 cout << "n: " << n << endl; … … 228 231 229 232 // the new projection center 230 Vector3 projCenter = startPt + Vector3::UNIT_Z() * n * 1000;233 Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 231 234 232 235 cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; … … 245 248 246 249 247 //////// 250 ////////// 248 251 //-- now apply these values to construct the perspective lispsm matrix 249 252 … … 518 521 //mCamera->GetModelViewMatrix(camView); 519 522 520 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0. 1f);523 pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 521 524 mShadowCam->SetPosition(pos); 522 525 … … 530 533 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 531 534 535 //glEnable(GL_LIGHTING); 536 //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 532 537 glDisable(GL_LIGHTING); 533 538 glDisable(GL_TEXTURE_2D); … … 597 602 598 603 glPopAttrib(); 604 605 606 glEnable(GL_LIGHTING); 607 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 608 599 609 #if 0 600 610 float *data = new float[mSize * mSize]; … … 617 627 618 628 619 unsigned int ShadowMap::Get ShadowTexture() const629 unsigned int ShadowMap::GetDepthTexture() const 620 630 { 621 631 return mFbo->GetDepthTex(); 622 632 } 623 633 624 634 unsigned int ShadowMap::GetShadowColorTexture() const 635 { 636 return mFbo->GetColorBuffer(0)->GetTexture(); 637 638 } 625 639 626 640 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2920 r2928 36 36 */ 37 37 void ComputeShadowMap(RenderTraverser *traverser, const Matrix4x4 &projView); 38 /** Returns computed shadow texture.38 /** Returns computed shadow color texture. 39 39 */ 40 unsigned int GetShadowTexture() const; 40 unsigned int GetShadowColorTexture() const; 41 42 unsigned int GetDepthTexture() const; 43 41 44 /** Returns computed texture matrix. It must be applied on the 42 45 the world space positions. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2927 r2928 914 914 { 915 915 const float shadowSize = 4096; 916 //const float shadowSize = 512; 916 917 shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera); 917 918 } … … 925 926 shadowChanged = false; 926 927 928 #if 0 929 state.SetRenderType(RenderState::DEFERRED); 930 931 fbo->Bind(); 932 933 glPushAttrib(GL_VIEWPORT_BIT); 934 glViewport(0, 0, texWidth, texHeight); 935 936 cgGLEnableProfile(RenderState::sCgFragmentProfile); 937 cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 938 939 cgGLEnableProfile(RenderState::sCgVertexProfile); 940 cgGLBindProgram(sCgMrtVertexProgram); 941 #else 942 927 943 cgGLDisableProfile(RenderState::sCgFragmentProfile); 928 944 cgGLDisableProfile(RenderState::sCgVertexProfile); 929 945 930 946 state.SetRenderType(RenderState::DEPTH_PASS); 931 947 #endif 932 948 // the scene is rendered withouth any shading 933 949 shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView); … … 936 952 BvhNode::SetCurrentState(0); 937 953 938 glEnable(GL_LIGHTING);939 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);940 954 } 941 955 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2911 r2928 153 153 return OUT; 154 154 } 155 156 157 /** The mrt shader for standard rendering 158 */ 159 pixel main_shadow_debug(fragment IN, 160 uniform sampler2D shadowMap, 161 uniform sampler2D colorTex, 162 uniform float4x4 shadowMatrix) 163 { 164 pixel OUT; 165 #if 0 166 // visualize depth 167 OUT.color = tex2Dlod(colorTex, float4(IN.texCoord.xy, 0, 0)); 168 #else 169 float4 col; 170 col = tex2Dlod(shadowMap, float4(IN.texCoord.xy, 0, 0)); 171 OUT.color = float4(col.z / col.w, 0, 0, 1); 172 #endif 173 return OUT; 174 }
Note: See TracChangeset
for help on using the changeset viewer.