- Timestamp:
- 11/12/08 10:18:15 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3120 r3121 535 535 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 536 536 537 if (mUseTemporalCoherence || mRegenerateSamples) 537 if (//mUseTemporalCoherence || 538 mRegenerateSamples) 538 539 { 539 540 mRegenerateSamples = false; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3120 r3121 57 57 { 58 58 const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 59 //float3 viewVec = normalize(Interpol(texcoord, bl, br, tl, tr));59 60 60 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 61 61 float3 samplePos = -viewVec * eyeSpaceDepth; … … 120 120 reprojected color / depth values as well as a boolean that 121 121 */ 122 inline float 4temporalSmoothing(float4 worldPos,122 inline float3 temporalSmoothing(float4 worldPos, 123 123 float eyeSpaceDepth, 124 float2 ao,125 124 float2 texcoord0, 126 125 float3 oldEyePos, … … 145 144 ) 146 145 { 147 float4 illum_col;148 149 146 // compute position from old frame for dynamic objects + translational portion 150 147 const float3 translatedPos = worldPos.xyz - oldEyePos + diffVec; … … 162 159 // retrieve the sample from the last frame 163 160 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 164 165 161 166 162 #if USE_EYESPACE_DEPTH … … 211 207 } 212 208 #endif 213 const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 209 210 //const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 211 float oldWeight = oldPixel.y; 212 214 213 float newWeight; 215 214 … … 225 224 // increase the weight for convergence 226 225 newWeight = oldWeight + 1.0f; 227 illum_col.x = (ao.x + oldPixel.x * oldWeight) / newWeight;228 226 if (notValid > 1.0f) newWeight = 2.0f; 229 227 } 230 228 else 231 229 { 232 illum_col.x = ao.x; 233 newWeight = .0f; 234 } 235 236 illum_col.y = newWeight; 237 238 #if USE_EYESPACE_DEPTH 239 illum_col.w = eyeSpaceDepth; 240 #else 241 illum_col.w = projectedDepth; 242 #endif 243 //overallDepth = clamp(overallDepth*1e3, 0, 1); 244 illum_col.z = invW; 245 //illum_col.x = overallDepth; 246 247 return illum_col; 230 newWeight = 1.0f; 231 } 232 233 if (oldPixel.y >= temporalCoherence) 234 newWeight = min(temporalCoherence+1, max(oldPixel.y - 70, 50)); 235 236 return float3(oldPixel.x, newWeight, eyeSpaceDepth); 248 237 } 249 238 … … 263 252 float3 tr, 264 253 float3 viewDir 265 //,float2 noiseOffs254 , float2 noiseOffs 266 255 ) 267 256 { … … 282 271 //-- add random noise: reflect around random normal vector (rather slow!) 283 272 284 //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f + noiseOffs, 0, 0)).xy;285 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy;273 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f + noiseOffs, 0, 0)).xy; 274 //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 286 275 const float2 offsetTransformed = myreflect(offset, mynoise); 287 276 #else … … 325 314 return float2(max(0.0f, 1.0f - total_ao), numSamples); 326 315 } 316 327 317 328 318 /** The mrt shader for screen space ambient occlusion … … 354 344 355 345 // reconstruct position from the eye space depth 356 //const float3 viewDir = normalize(IN.view);357 346 const float3 viewDir = IN.view; 358 347 const float eyeSpaceDepth = tex2Dlod(colors, float4(IN.texCoord, 0, 0)).w; 359 348 const float4 eyeSpacePos = float4(-viewDir * eyeSpaceDepth, 1.0f); 360 349 350 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 351 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 352 361 353 362 354 //////////////// … … 367 359 projPos *= invw; 368 360 float scaleFactor = SAMPLE_RADIUS * invw; 369 370 float2 ao = float2(1.0f, 0); 361 362 363 ///////////////// 364 //-- compute temporal reprojection 365 366 float3 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 367 oldTex, oldModelViewProj, temporalCoherence, 368 colors, 369 bl, br, tl, tr, 370 projPos.xyz, 371 invw, 372 noiseTex, 373 samples, 374 scaleFactor, 375 oldbl, oldbr, oldtl, oldtr, 376 diffVec); 377 378 const float oldSsao = temporalVals.x; 379 const float newWeight = temporalVals.y; 380 381 float2 noiseOffs = float2(newWeight / 256.0f, (newWeight - 256.0f) / 192.0f); 382 383 float2 ao; 371 384 // note: this should be done with the stencil buffer 372 385 if (eyeSpaceDepth < 1e10f) 373 386 { 374 387 ao = ssao(IN, colors, noiseTex, samples, normal, 375 eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir));//, noiseOffs); 376 } 377 378 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 379 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 380 381 382 ///////////////// 383 //-- compute temporal reprojection 384 385 OUT.illum_col = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, ao, IN.texCoord, oldEyePos, 386 oldTex, oldModelViewProj, temporalCoherence, 387 colors, 388 bl, br, tl, tr, 389 projPos.xyz, 390 invw, 391 noiseTex, 392 samples, 393 scaleFactor, 394 oldbl, oldbr, oldtl, oldtr, 395 diffVec); 388 eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), noiseOffs); 389 } 390 else 391 { 392 ao = float2(1.0f, 0); 393 } 394 395 396 OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 397 OUT.illum_col.y = newWeight; 398 OUT.illum_col.z = invw; 399 OUT.illum_col.w = temporalVals.z; 396 400 397 401 return OUT;
Note: See TracChangeset
for help on using the changeset viewer.