- Timestamp:
- 09/02/08 00:56:48 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2891 r2893 86 86 void Camera::GetModelViewMatrix(Matrix4x4 &mat) 87 87 { 88 glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mat.x); 88 mat = mViewOrientation; 89 90 Vector3 pos = mViewOrientation * -mPosition; 91 92 mat.x[3][0] = pos.x; 93 mat.x[3][1] = pos.y; 94 mat.x[3][2] = pos.z; 95 96 //glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mat.x); 89 97 } 90 98 … … 154 162 void Camera::SetupCameraView() 155 163 { 156 Matrix4x4 tview = mViewOrientation;157 158 Vector3 pos = -mPosition;159 pos = tview * pos;160 161 164 Matrix4x4 viewOrientation = mViewOrientation; 165 166 Vector3 pos = mViewOrientation * -mPosition; 162 167 163 168 viewOrientation.x[3][0] = pos.x; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp
r2892 r2893 46 46 47 47 static CGparameter sShadowMatrixParam; 48 49 50 51 52 DeferredShader::DeferredShader(int w, int h ):53 mWidth(w), mHeight(h) 48 static CGparameter sMaxDepthParam; 49 50 51 52 DeferredShader::DeferredShader(int w, int h, float scaleFactor): 53 mWidth(w), mHeight(h), mScaleFactor(scaleFactor) 54 54 { 55 55 //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); … … 124 124 sNormalsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "normals"); 125 125 sShadowMapParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMap"); 126 126 sMaxDepthParam = cgGetNamedParameter(sCgDeferredShadowProgram, "maxDepth"); 127 127 sShadowMatrixParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMatrix"); 128 128 } … … 184 184 glDisable(GL_TEXTURE_2D); 185 185 glDisable(GL_LIGHTING); 186 glDepthMask(GL_FALSE); 187 186 188 187 189 glPushAttrib(GL_VIEWPORT_BIT); … … 203 205 204 206 glEnable(GL_LIGHTING); 205 glDisable(GL_TEXTURE_2D); 207 glEnable(GL_TEXTURE_2D); 208 glDepthMask(GL_TRUE); 206 209 207 210 glMatrixMode(GL_PROJECTION); … … 332 335 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 333 336 GLuint shadowMap = shadowMapping->mFbo->GetDepthTex(); 334 337 /* 335 338 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f, 336 339 0.0f, 0.5f, 0.0f, 0.0f, 337 340 0.0f, 0.0f, 0.5f, 0.0f, 338 341 0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] 342 */ 343 344 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 345 0.0f, 0.5f, 0.0f, 0.5f, 346 0.0f, 0.0f, 0.5f, 0.5f, 347 0.0f, 0.0f, 0.0f, 1.0f); //bias from [-1, 1] to [0, 1] 339 348 340 349 Matrix4x4 inverseView = matViewing; … … 345 354 //cout << "matview:\n" << matViewing << endl; 346 355 //cout << "proj:\n" << shadowMapping->mLightProjectionMatrix << endl; 347 //cout << "view:\n" << shadowMapping->mLightViewMatrix << endl;356 cout << "view:\n" << shadowMapping->mLightViewMatrix << endl; 348 357 349 358 // compute combined matrix that transforms pixels into light texture space … … 353 362 inverseView; 354 363 */ 355 Matrix4x4 shadowMatrix = //inverseView * 356 lightProjView * 357 biasMatrix; 358 /* 359 Matrix4x4 shadowMatrix = biasMatrix * 360 lightProjView; 364 //Matrix4x4 shadowMatrix = //inverseView * lightProjView * biasMatrix;* 365 Matrix4x4 shadowMatrix = lightProjView*biasMatrix; 361 366 //inverseView; 362 */363 367 cout << "combined:\n" << shadowMatrix << endl; 364 368 … … 384 388 cgGLSetTextureParameter(sShadowMapParam, shadowMap); 385 389 cgGLEnableTextureParameter(sShadowMapParam); 390 391 cgGLSetParameter1f(sMaxDepthParam, mScaleFactor); 386 392 387 393 cgGLSetMatrixParameterfc(sShadowMatrixParam, (const float *)shadowMatrix.x); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h
r2892 r2893 24 24 /** constructor for a deferred shader taking the requested output image size 25 25 */ 26 DeferredShader(int w, int h );26 DeferredShader(int w, int h, float maxDepth); 27 27 28 28 ~DeferredShader(); … … 57 57 int mHeight; 58 58 59 //FrameBufferObject *mFbo;59 float mScaleFactor; 60 60 }; 61 61 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2892 r2893 124 124 mLight = light; 125 125 126 const float xlen = Magnitude(mSceneBox.Diagonal() );//* 0.5f);127 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); 128 128 129 129 mShadowCam->SetDirection(light->GetDirection()); … … 131 131 // set position so that we can see the whole scene 132 132 Vector3 pos = mSceneBox.Center(); 133 pos.z = mSceneBox.Max().z; 133 134 pos -= light->GetDirection() * Magnitude(mSceneBox.Diagonal() * 0.5f); 135 //pos.z = mSceneBox.Max().z; 134 136 //mShadowCam->SetPosition(pos - Magnitude(mSceneBox.Diagonal() * light->GetDirection())); 135 137 mShadowCam->SetPosition(pos); … … 148 150 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 149 151 150 glPolygonOffset(1.0f, 40.0f);152 glPolygonOffset(1.0f, 2000.0f); 151 153 glEnable(GL_POLYGON_OFFSET_FILL); 152 154 … … 158 160 glLoadIdentity(); 159 161 160 glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, 100);//Magnitude(mSceneBox.Diagonal()));162 glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal())); 161 163 162 164 … … 267 269 void ShadowMapping::Render(RenderTraverser *traverser, Camera *cam) 268 270 { 271 #if 0 269 272 Matrix4x4 cam_inverse_modelview; 270 273 … … 391 394 glDisable(GL_LIGHTING); 392 395 glDisable(GL_ALPHA_TEST); 396 #endif 393 397 } 394 398 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp
r2891 r2893 527 527 cgGLSetParameter1f(sMaxDepthParam, mScaleFactor); 528 528 529 529 530 if (mUseTemporalCoherence) 530 531 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2892 r2893 443 443 sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 444 444 445 light = new Light(Vector3(0, 0, -1), RgbaColor(1, 1, 1, 1)); 446 447 shadowMapping = new ShadowMapping(bvh->GetBox(), 512); 445 Vector3 lightDir = Normalize(Vector3(0, 1, -1)); 446 light = new Light(lightDir, RgbaColor(1, 1, 1, 1)); 447 448 shadowMapping = new ShadowMapping(bvh->GetBox(), 4096); 448 449 449 450 // frame time is restarted every frame … … 962 963 glEnableClientState(GL_NORMAL_ARRAY); 963 964 964 965 965 966 // reset depth pass and render visible objects 966 967 if (renderType == RenderState::DEPTH_PASS) … … 969 970 RenderVisibleObjects(); 970 971 } 971 972 972 973 973 974 /////////////// 974 975 //-- render sky 975 976 977 // q: should we render sky after deferred shading? (would conveniently solves some issues) 978 // (e.g, skys without shadows) 979 976 980 RenderSky(); 977 978 state.Reset(); 979 980 glDisableClientState(GL_VERTEX_ARRAY); 981 glDisableClientState(GL_NORMAL_ARRAY); 981 982 982 983 983 … … 997 997 else 998 998 { 999 if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight );999 if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight, myfar / 10.0f); 1000 1000 1001 1001 //deferredShader->Render(fbo); … … 1003 1003 } 1004 1004 } 1005 1006 1005 1006 1007 state.SetRenderType(RenderState::FIXED); 1008 state.Reset(); 1009 1010 1011 glDisableClientState(GL_VERTEX_ARRAY); 1012 glDisableClientState(GL_NORMAL_ARRAY); 1013 1014 1015 1007 1016 /////////// 1008 1017 1009 state.SetRenderType(RenderState::FIXED);1010 1018 1011 1019 if (showAlgorithmTime) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2892 r2893 80 80 uniform sampler2D normals, 81 81 uniform sampler2D shadowMap, 82 uniform float4x4 shadowMatrix 82 uniform float4x4 shadowMatrix, 83 uniform float maxDepth 83 84 ) 84 85 { … … 89 90 float4 position = tex2D(positions, IN.texCoord.xy); 90 91 91 float4 lightSpacePos = mul(shadowMatrix, position);92 93 float shadowDepth = tex2D(shadowMap, IN.texCoord.xy);94 92 95 93 // an ambient color term … … 99 97 float4 col = shade(IN, color, position, normal, amb); 100 98 99 position *= maxDepth; 100 position.w = 1.0f; 101 102 float4 lightSpacePos = mul(shadowMatrix, position); 103 104 float shadowDepth = tex2D(shadowMap, lightSpacePos.xy); 105 101 106 OUT.color = col; 102 107 103 if (lightSpacePos.z / lightSpacePos.w < shadowDepth) 108 // hack: prevent shadowing the sky 109 if ((amb < 0.9) && 110 (lightSpacePos.z / lightSpacePos.w > shadowDepth)) 104 111 { 105 112 OUT.color *= 0.1f; 106 113 } 107 114 108 //OUT.color = float4(lightSpacePos.z / lightSpacePos.w);115 //OUT.color = lightSpacePos;//float4(lightSpacePos.z / lightSpacePos.w); 109 116 //OUT.color = float4(shadowDepth); 110 117 OUT.color.w = color.w; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r2892 r2893 71 71 float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 72 72 73 //if ((texcoord.x <= 1.0f) || (texcoord.x >= 0.0f) || (texcoord.y <= 1.0f) || (texcoord.y >= 0.0f)) 74 73 75 // sample downsampled texture in order to speed up texture accesses 74 76 float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz;
Note: See TracChangeset
for help on using the changeset viewer.