Changeset 3105 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 11/06/08 15:14:49 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3104 r3105 394 394 //const float filterWidth = 10.0f; 395 395 const float filterWidth = 5.0f; 396 //const float filterWidth = 60.0f; 396 397 397 398 //const float xoffs = filterWidth / mDownSampleFbo->GetWidth(); 398 399 //const float yoffs = filterWidth / mDownSampleFbo->GetHeight(); 399 const float xoffs = (float)filterWidth / 1024.0f;400 const float yoffs = (float)filterWidth / 768.0f;400 const float xoffs = (float)filterWidth / mWidth; 401 const float yoffs = (float)filterWidth / mHeight; 401 402 402 403 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) … … 543 544 sCgSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix); 544 545 545 Vector3 de = mOldEyePos - mEyePos; 546 //Vector3 de = mOldEyePos - mEyePos; 547 Vector3 de; 548 de.x = mOldEyePos.x - mEyePos.x; 549 de.y = mOldEyePos.y - mEyePos.y; 550 de.z = mOldEyePos.z - mEyePos.z; 546 551 //Vector3 de = mEyePos - mOldEyePos; 547 552 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3103 r3105 175 175 bool descendKeyPressed = false; 176 176 bool ascendKeyPressed = false; 177 bool leftStrafeKeyPressed = false; 178 bool rightStrafeKeyPressed = false; 179 177 180 bool altKeyPressed = false; 178 181 … … 844 847 845 848 849 void KeyStrafe(float shift) 850 { 851 Vector3 viewDir = camera->GetDirection(); 852 Vector3 pos = camera->GetPosition(); 853 854 // the 90 degree rotated view vector 855 // z zero so we don't move in the vertical 856 Vector3 rVec(viewDir[0], viewDir[1], 0); 857 858 Matrix4x4 rot = RotationZMatrix(M_PI * 0.5f); 859 rVec = rot * rVec; 860 pos += rVec * shift; 861 862 camera->SetPosition(pos); 863 } 864 865 846 866 /** Initialize the deferred rendering pass. 847 867 */ … … 899 919 if (descendKeyPressed) 900 920 KeyVerticalMotion(-KeyShift()); 921 if (leftStrafeKeyPressed) 922 KeyStrafe(KeyShift()); 923 if (rightStrafeKeyPressed) 924 KeyStrafe(-KeyShift()); 925 901 926 902 927 // place view on ground … … 1218 1243 downKeyPressed = true; 1219 1244 break; 1245 case 'j': 1246 case 'J': 1247 leftStrafeKeyPressed = true; 1248 break; 1249 case 'k': 1250 case 'K': 1251 rightStrafeKeyPressed = true; 1252 break; 1220 1253 case 'r': 1221 1254 case 'R': … … 1297 1330 ascendKeyPressed = false; 1298 1331 break; 1299 1332 case 'j': 1333 case 'J': 1334 leftStrafeKeyPressed = false; 1335 break; 1336 case 'k': 1337 case 'K': 1338 rightStrafeKeyPressed = false; 1339 break; 1300 1340 default: 1301 1341 return; … … 1505 1545 1506 1546 1507 // strafe 1547 /** strafe 1548 */ 1508 1549 void MiddleMotion(int x, int y) 1509 1550 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3103 r3105 43 43 #define MAX_LOD_LEVEL 10 44 44 45 //#define MIN_DEPTH_DIFF 1e-2f46 #define MIN_DEPTH_DIFF 0.1f45 #define MIN_DEPTH_DIFF 1e-3f 46 //#define MIN_DEPTH_DIFF 1e-3f 47 47 #define PRECISION_SCALE 1e-1f 48 48 … … 55 55 #define NUM_DOWNSAMPLES 9 56 56 57 #define NUM_SSAO_FILTERSAMPLES 28 57 //#define NUM_SSAO_FILTERSAMPLES 28 58 #define NUM_SSAO_FILTERSAMPLES 40 58 59 59 60 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3104 r3105 4 4 // Screen Spaced Ambient Occlusion shader 5 5 // based on shader of Alexander Kusternig 6 7 #define USE_EYESPACE_DEPTH 0 8 9 6 10 7 11 struct fragment … … 118 122 float2 texcoord0, 119 123 float3 oldEyePos, 120 sampler2D oldTex,121 float4x4 oldModelViewProj,122 float temporalCoherence,123 float2 samples[NUM_SAMPLES],124 sampler2D colors,125 sampler2D noiseTex,124 uniform sampler2D oldTex, 125 uniform float4x4 oldModelViewProj, 126 uniform float temporalCoherence, 127 uniform float2 samples[NUM_SAMPLES], 128 uniform sampler2D colors, 129 uniform sampler2D noiseTex, 126 130 float scaleFactor, 127 float3 bl, 128 float3 br, 129 float3 tl, 130 float3 tr, 131 float3 oldbl, 132 float3 oldbr, 133 float3 oldtl, 134 float3 oldtr 131 uniform float3 bl, 132 uniform float3 br, 133 uniform float3 tl, 134 uniform float3 tr, 135 uniform float3 oldbl, 136 uniform float3 oldbr, 137 uniform float3 oldtl, 138 uniform float3 oldtr, 139 float invW 135 140 //,const uniform float4x4 inverseModelTrafo 136 141 //, float id … … 147 152 //else trafo = inverseModelTrafo * oldModelViewProj; 148 153 149 float3 translatedPt = worldPos.xyz - oldEyePos; 154 //float3 translatedPt = float3(worldPos.xy - oldEyePos.xy, worldPos.z + oldEyePos.z); 155 //float3 translatedPt = float3(worldPos.x - oldEyePos.x, worldPos.y - oldEyePos.y, worldPos.z - oldEyePos.z); 156 const float3 translatedPt = worldPos.xyz - oldEyePos; 150 157 151 158 // reproject into old frame and calculate texture position of sample in old frame … … 158 165 // retrieve the sample from the last frame 159 166 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 167 168 #if USE_EYESPACE_DEPTH 160 169 // calculate eye space position of sample in old frame 161 170 const float oldEyeSpaceDepth = oldPixel.w; … … 163 172 // vector from eye pos to old sample 164 173 const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 165 166 174 const float invlen = 1.0f / length(viewVec); 167 175 const float projectedEyeSpaceDepth = length(translatedPt) * invlen; … … 169 177 const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 170 178 //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth) / projectedEyeSpaceDepth; 171 179 #else 180 // calculate eye space position of sample in old frame 181 const float oldDepth = oldPixel.w; 182 183 float3 projectedPos = worldPos.xyz * invW; 184 const float projectedDepth = worldPos.z; 185 186 // vector from eye pos to old sample 187 const float depthDif = abs(projectedDepth - oldDepth); 188 //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth) / projectedEyeSpaceDepth; 189 #endif 190 172 191 float notValid = 0.5f; 173 192 … … 219 238 220 239 illum_col.y = newWeight; 240 241 #if USE_EYESPACE_DEPTH 221 242 illum_col.w = eyeSpaceDepth; 243 #else 244 illum_col.w = projectedDepth; 245 illum_col.z = invW; 246 #endif 247 222 248 //illum_col.y = depthDif; 223 249 … … 337 363 338 364 float4 projPos = mul(modelViewProj, eyeSpacePos); 339 float w = SAMPLE_RADIUS / projPos.w; 365 const float w = 1 / projPos.w; 366 float scaleFactor = SAMPLE_RADIUS * w; 340 367 341 368 const float2 ao = ssao(IN, colors, noiseTex, samples, normal, 342 eyeSpacePos.xyz, w, bl, br, tl, tr, normalize(viewDir));369 eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir)); 343 370 344 371 … … 349 376 oldTex, oldModelViewProj, temporalCoherence, 350 377 samples, colors, noiseTex, w, bl, br, tl, tr, 351 oldbl, oldbr, oldtl, oldtr );378 oldbl, oldbr, oldtl, oldtr, scaleFactor); 352 379 353 380 //OUT.illum_col.xyz = normal * 0.5f + 0.5f; … … 358 385 uniform sampler2D ssaoTex, 359 386 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 360 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 387 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 388 float scale) 361 389 { 362 390 float average = .0f; … … 365 393 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 366 394 { 367 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] , 0, 0)).x;395 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 368 396 w += filterWeights[i]; 369 397 } … … 384 412 pixel OUT; 385 413 386 float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));414 const float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 387 415 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 388 416 389 //if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 390 391 //OUT.illum_col = col * ao.x; 417 if ((ao.y < 10.0f) && (col.w < 1e10f)) 418 ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z); 419 420 OUT.illum_col = col * ao.x; 392 421 //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 393 422 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);
Note: See TracChangeset
for help on using the changeset viewer.