- Timestamp:
- 11/10/08 18:43:06 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3114 r3115 66 66 67 67 inline float ComputeDifference(float2 offset, 68 uniformsampler2D oldTex,69 const uniformfloat4x4 oldModelViewProj,70 uniformsampler2D colors,71 uniformsampler2D noiseTex,72 uniformfloat scaleFactor,73 uniformfloat3 bl,74 uniformfloat3 br,75 uniformfloat3 tl,76 uniformfloat3 tr,68 sampler2D oldTex, 69 float4x4 oldModelViewProj, 70 sampler2D colors, 71 sampler2D noiseTex, 72 float scaleFactor, 73 float3 bl, 74 float3 br, 75 float3 tl, 76 float3 tr, 77 77 float2 texcoord0, 78 78 float3 oldEyePos, 79 uniformfloat3 oldbl,80 uniformfloat3 oldbr,81 uniformfloat3 oldtl,82 uniformfloat3 oldtr,79 float3 oldbl, 80 float3 oldbr, 81 float3 oldtl, 82 float3 oldtr, 83 83 float eyeSpaceDepth 84 84 ) 85 85 { 86 const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy;86 const float2 mynoise = tex2Dlod(noiseTex, float4(texcoord0, 0, 0)).xy; 87 87 88 88 const float2 offsetTransformed = myreflect(offset, mynoise); … … 93 93 const float3 viewVec = Interpol(texCoord, bl, br, tl, tr); 94 94 const float3 samplePos = -viewVec * sampleEyeSpaceDepth; 95 96 95 const float3 translatedPos = samplePos - oldEyePos; 96 97 97 // reproject into old frame and calculate projected depth 98 98 float4 projPos = mul(oldModelViewProj, float4(translatedPos, 1.0f)); 99 99 projPos /= projPos.w; 100 101 100 // fit from unit cube into 0 .. 1 102 101 const float2 oldTexCoords = projPos.xy * 0.5f + 0.5f; … … 105 104 106 105 const float oldEyeSpaceDepth = oldPixel.w; 106 107 // projected linear depth 107 108 const float3 oldViewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 108 109 109 const float invlen = 1.0f / length(oldViewVec); 110 const float projectedEyeSpaceDepth = length(translatedPos) * invlen;111 112 float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 113 0 : abs(oldEyeSpaceDepth -projectedEyeSpaceDepth);110 const float projectedEyeSpaceDepth = invlen * length(translatedPos); 111 112 float depthDif = (abs(eyeSpaceDepth - sampleEyeSpaceDepth) > 5.0f) ? 0 : 113 abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 114 114 115 115 return depthDif; … … 117 117 118 118 119 /** This shader computes the reprojection and stores reprojected color / depth values120 as well as a boolean that119 /** This shader computes the reprojection and stores 120 reprojected color / depth values as well as a boolean that 121 121 */ 122 122 inline float4 temporalSmoothing(float4 worldPos, … … 148 148 149 149 // compute position from old frame for dynamic objects + translational portion 150 const float3 translatedP t= worldPos.xyz - oldEyePos + diffVec;150 const float3 translatedPos = worldPos.xyz - oldEyePos + diffVec; 151 151 152 152 … … 155 155 156 156 // note: the old model view matrix only holds the view orientation part 157 float4 backProjPos = mul(oldModelViewProj, float4(translatedP t, 1.0f));157 float4 backProjPos = mul(oldModelViewProj, float4(translatedPos, 1.0f)); 158 158 backProjPos /= backProjPos.w; 159 159 … … 172 172 const float3 viewVec = Interpol(oldTexCoords, oldbl, oldbr, oldtl, oldtr); 173 173 const float invLen = 1.0f / length(viewVec); 174 const float projectedEyeSpaceDepth = invLen * length(translatedPt); 175 176 //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 174 const float projectedEyeSpaceDepth = invLen * length(translatedPos); 175 177 176 const float depthDif = abs(1.0f - oldEyeSpaceDepth / projectedEyeSpaceDepth); 178 //const float depthDif = abs(projectedEyeSpaceDepth - oldEyeSpaceDepth ) / projectedEyeSpaceDepth;179 177 180 178 #else … … 182 180 const float oldDepth = oldPixel.w; 183 181 const float projectedDepth = projPos.z; 184 //const float projectedDepth = invW * worldPos.z;185 186 182 // vector from eye pos to old sample 187 183 const float depthDif = abs(projectedDepth - oldDepth); … … 189 185 190 186 float notValid = 0.5f; 191 192 /* 193 for (int i = 0; i < NUM_SAMPLES; ++ i) 187 //float overallDepth = 0; 188 const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 189 190 if (squaredLen < 1e-8f) // object not dynamic 194 191 { 195 float sampleDif = ComputeDifference(samples[i], 196 oldTex, 197 oldModelViewProj, 198 colors, 199 noiseTex, 200 scaleFactor, 201 bl, br, tl, tr, 202 texcoord0, 203 oldEyePos, 204 oldbl, oldbr, oldtl, oldtr, 205 eyeSpaceDepth); 206 207 if (sampleDif >= 5e-2f) ++ notValid; 208 } 209 */ 192 for (int i = 0; i < NUM_SAMPLES; ++ i) 193 { 194 float sampleDif = ComputeDifference(samples[i], 195 oldTex, 196 oldModelViewProj, 197 colors, 198 noiseTex, 199 scaleFactor, 200 bl, br, tl, tr, 201 texcoord0, 202 oldEyePos, 203 oldbl, oldbr, oldtl, oldtr, 204 eyeSpaceDepth 205 ); 206 //overallDepth += sampleDif; 207 208 if (sampleDif >= MIN_DEPTH_DIFF) ++ notValid; 209 } 210 } 211 210 212 211 213 // the number of valid samples in this frame … … 243 245 illum_col.w = projectedDepth; 244 246 #endif 245 247 //overallDepth = clamp(overallDepth*1e3, 0, 1); 246 248 illum_col.z = invW; 247 //illum_col.x = length(diffVec*50.0f);249 //illum_col.x = overallDepth; 248 250 249 251 return illum_col; … … 370 372 // note: this should be done with the stencil buffer 371 373 if (eyeSpaceDepth < 1e10f) 374 { 372 375 ao = ssao(IN, colors, noiseTex, samples, normal, 373 376 eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir)); 374 377 } 375 378 376 379 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; … … 409 412 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 410 413 { 411 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale , 0, 0)).x;414 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x; 412 415 w += filterWeights[i]; 413 416 } … … 434 437 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z); 435 438 436 //OUT.illum_col = col * ao.x;439 OUT.illum_col = col * ao.x; 437 440 //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w); 438 441 //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 439 OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w);442 //OUT.illum_col = float4(ao.x, 0, 0, col.w); 440 443 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 441 444 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);
Note: See TracChangeset
for help on using the changeset viewer.