- Timestamp:
- 12/02/08 17:06:08 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3203 r3204 105 105 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 106 106 107 // the ssao value in the old frame 108 const float ssao = oldPixel.x; 109 107 110 #if USE_EYESPACE_DEPTH 108 111 … … 129 132 #endif 130 133 131 float newWeight; 134 const float xOffs = 1.0f / 1024.0f; 135 const float yOffs = 1.0f / 768.0f; 136 const float eps = 1e-6f; 137 138 // the weight of the old value 139 float w; 140 141 ////////////// 142 //-- reuse old value only if it was still valid in the old frame 132 143 133 144 if (1 134 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f)135 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f)145 && (oldTexCoords.x + eps >= xOffs) && (oldTexCoords.x <= 1.0f - xOffs + eps) 146 && (oldTexCoords.y + eps >= yOffs) && (oldTexCoords.y <= 1.0f - yOffs + eps) 136 147 && (depthDif <= MIN_DEPTH_DIFF) 137 148 ) 138 149 { 139 // increase the weight for convergence140 newWeight =oldPixel.y;150 // pixel valid => retrieve the convergence weight 151 w = 10.0f;//oldPixel.y; 141 152 } 142 153 else 143 154 { 144 newWeight= 0.0f;145 } 146 147 return float2( oldPixel.x, newWeight);155 w = 0.0f; 156 } 157 158 return float2(ssao, w); 148 159 } 149 160 … … 168 179 ) 169 180 { 170 // Check in a circular area around the current position.171 // Shoot vectors to the positions there, and check the angle to these positions.172 // Summing up these angles gives an estimation of the occlusion at the current position.173 174 181 float total_ao = .0f; 175 182 float numSamples = .0f; … … 198 205 const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 199 206 // the normal of the current sample 200 //const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz);201 207 const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 202 208 … … 218 224 cosAngle *= step(0.0f, dot(dirSample, normal)); 219 225 220 // the distance_scale offset is used to avoid singularity that occurs at global illumination when221 // the distance to a sample approaches zero222 //const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);223 226 const float aoContrib = SAMPLE_INTENSITY / sqrLen; 224 227 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; … … 248 251 This version of the ssao shader uses the dotproduct between 249 252 pixel-to-sample direction and sample normal as weight. 253 254 The algorithm works like the following: 255 1) Check in a circular area around the current position. 256 2) Shoot vectors to the positions there, and check the angle to these positions. 257 3) Summing up these angles gives an estimation of the occlusion at the current position. 250 258 */ 251 259 float3 ssao(fragment IN, … … 264 272 ) 265 273 { 266 // Check in a circular area around the current position.267 // Shoot vectors to the positions there, and check the angle to these positions.268 // Summing up these angles gives an estimation of the occlusion at the current position.269 270 274 float total_ao = .0f; 271 275 float validSamples = .0f; … … 278 282 #if 1 279 283 //////////////////// 280 //-- add random noise: reflect around random normal vector (rather slow!) 284 //-- add random noise: reflect around random normal vector 285 //-- (slows down the computation for some reason!) 281 286 282 287 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; … … 286 291 #endif 287 292 // weight with projected coordinate to reach similar kernel size for near and far 288 //const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor + jitter;289 293 const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 290 294 … … 321 325 // hack: the distance measure can fail in some cases => choose something different 322 326 const float tooFarAway = step(1.0f, lengthToSample); 323 validSamples += (1.0f - tooFarAway) * sampleColor.x; 327 validSamples = max(validSamples, (1.0f - tooFarAway) * sampleColor.x); 328 324 329 //validSamples += sampleColor.x; 325 330 … … 327 332 328 333 //if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break; 329 if ((validSamples < 1.0f) && (numSamples >= 8)) break;334 //if ((validSamples < 1.0f) && (numSamples >= 8)) break; 330 335 } 331 336 … … 400 405 401 406 // cull background note: this should be done with the stencil buffer 402 //if (SqrLen(diffVec < 1e6f) && (eyeSpaceDepth < 1e10f))403 407 if (eyeSpaceDepth < 1e10f) 404 408 { … … 412 416 413 417 const float squaredLen = SqrLen(diffVec); 414 415 if ( (ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD))416 {418 /* 419 if (ao.y > 4.0f) oldWeight = 0; 420 else if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 417 421 oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 418 } 419 422 */ 420 423 const float newWeight = ao.z; 421 424 422 425 // blend between old and new samples (and avoid division by zero) 423 426 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, (newWeight + oldWeight)); 424 OUT.illum_col.y = clamp(newWeight + oldWeight, .0f, temporalCoherence); 427 OUT.illum_col.y = oldWeight;//clamp(newWeight + oldWeight, .0f, temporalCoherence); 428 425 429 OUT.illum_col.z = SqrLen(diffVec); 426 430 OUT.illum_col.w = eyeSpaceDepth;
Note: See TracChangeset
for help on using the changeset viewer.