Changeset 3105 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 11/06/08 15:14:49 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.