- Timestamp:
- 05/19/09 19:17:41 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3371 r3372 53 53 54 54 // get position exactly between texel centers 55 float2 center = (floor(texCoord * res) + float2(.5f)) * texCoord; 56 //center.x = (floor(texCoord.x * res.x - .5f) + 1.0f) / res.x; 57 //center.y = (floor(texCoord.y * res.y - .5f) + 1.0f) / res.y; 58 //center.y = (floor(texCoord.y * res.y) + .5f) * yOffs; 59 60 /*texelCenterConv.x = tex2Dlod(tex, float4(center + float2( xoffs, yoffs), 0, 0)).y; 61 texelCenterConv.y = tex2Dlod(tex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 62 texelCenterConv.z = tex2Dlod(tex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 63 texelCenterConv.w = tex2Dlod(tex, float4(center + float2(-xoffs, yoffs), 0, 0)).y; 64 65 const float m1 = min(texelCenterConv.x, texelCenterConv.y); 66 const float m2 = min(texelCenterConv.z, texelCenterConv.w); 67 68 const float convergence = min(m1, m2);*/ 69 55 float2 center = (floor(texCoord * res) + float2(.5f)) * invRes; 56 70 57 //const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y; 71 58 const float convergence = tex2Dlod(tex, float4(texCoord, 0, 0)).y; … … 133 120 134 121 if (1 135 && (oldTexCoords.x > 0) && (oldTexCoords.x < 1.0f)136 && (oldTexCoords.y > 0) && (oldTexCoords.y < 1.0f)122 && (oldTexCoords.x > .0f) && (oldTexCoords.x < 1.0f) 123 && (oldTexCoords.y > .0f) && (oldTexCoords.y < 1.0f) 137 124 && (depthDif <= MIN_DEPTH_DIFF) 138 125 ) 139 126 { 140 // pixel valid => retrieve the convergence weight 141 /*float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 142 float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y; 143 float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y; 144 float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y; 145 146 w = min(min(w1, w2), min(w3, w4));*/ 127 #if 0 128 idx = floor(oldPixel.z); 129 #else 130 131 // nearest neighbour 132 float2 center; 133 center.x = (floor(oldTexCoords.x * 1024) + .5f) / 1024; 134 center.y = (floor(oldTexCoords.y * 768) + .5f) / 768; 147 135 148 //w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f)); 149 w = oldPixel.y; 150 idx = floor(oldPixel.z); 151 //idx = oldPixel.z; 136 const float4 oldPixelExact = tex2Dlod(oldTex, float4(center, .0f, .0f)); 137 idx = oldPixelExact.z; 138 #endif 139 140 w = oldPixel.y; 152 141 } 153 142 else … … 487 476 float2 offset; 488 477 489 const float2 ssaoOffset = tex2Dlod(samples, float4(( 0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy;478 const float2 ssaoOffset = tex2Dlod(samples, float4((.5f + i + floor(oldIdx)) / NUM_PRECOMPUTED_SAMPLES, .5f, .0f, .0f)).xy; 490 479 //const float2 ssaoOffset = dummySamples[i]; 491 480 … … 494 483 //-- (affects performance for some reason!) 495 484 496 if ( 1)//!USE_OPTIMIZATION ||497 //(convergence < SSAO_CONVERGENCE_THRESHOLD))485 if (!USE_OPTIMIZATION || 486 (convergence < SSAO_CONVERGENCE_THRESHOLD)) 498 487 { 499 488 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; … … 521 510 float3 dirSample = samplePos - centerPosition; 522 511 523 const float minDist = 1e-6f;524 512 const float eps = 1e-3f; 525 513 … … 527 515 const float sampleWeight = 1.0f / max(lengthToSample, eps); 528 516 529 dirSample /= max(length(dirSample), minDist); // normalize517 dirSample /= max(length(dirSample), eps); // normalize 530 518 531 519 // angle between current normal and direction to sample controls AO intensity. … … 540 528 541 529 542 //#ifdef PERFORMANCE_TEST 543 #if 1 530 #ifdef PERFORMANCE_TEST 544 531 // check if the samples have been valid in the last frame 545 532 // only mark sample as invalid if in the last / current frame … … 552 539 const float distanceDiff = abs(oldDistance - lengthToSample); 553 540 554 float pixelValid = (oldSamplePos.x > 1e14f) ? 100.0f : .0f; 555 556 if ((cosAngle >= 0) && (pixelValid < 90.0f))// || (cosAngle2 >= 0)) 557 { 558 pixelValid = (distanceDiff > 1e-3f) ? 100.0f : .0f; 559 //pixelValid = (distanceDiff > 1e-3f) ? 5.0f : .0f; 541 float pixelValid = .0f; 542 543 if ((texcoord.x > .0f) && (texcoord.x < 1.0f) && (texcoord.y > .0f) && (texcoord.y < 1.0f)) 544 { 545 if ((oldSamplePos.x > 1e14f))// || ((cosAngle >= 0) && (distanceDiff > 1e-3f))) 546 { 547 pixelValid = 100.0f; 548 } 549 else if ((cosAngle >= 0) && (distanceDiff > 1e-3f)) 550 { 551 pixelValid = 5.0f; 552 } 560 553 } 561 554 … … 742 735 743 736 oldWeight = min(oldWeight, factor * NUM_SAMPLES); 737 744 738 if (newIdx >= factor * NUM_SAMPLES) 745 739 {
Note: See TracChangeset
for help on using the changeset viewer.