Changeset 3313 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 02/16/09 17:08:51 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
r3311 r3313 114 114 } 115 115 116 /** In between step that only filters in one direction 117 */ 118 pixel FilterSsaoFullRes(fragment IN, 119 uniform sampler2D colorsTex, 120 uniform sampler2D ssaoTex, 121 uniform float3 bl, 122 uniform float3 br, 123 uniform float3 tl, 124 uniform float3 tr, 125 uniform float2 res 126 ) 127 { 128 pixel OUT; 129 130 const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w; 131 132 OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 133 // just take unfiltered convergence in current pixel 134 const float convergence = OUT.illum_col.y; 135 136 // filter reaches size 1 pixel when sample size reaches threshold 137 // afterwards we do not use the filter anymore 138 139 float2 xyStep = float2(1.0f / res.x, 0); 140 141 // filter up to a certain convergance value and leave out background (sky) by checking depth 142 if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) 143 { 144 // the filtered ssao value 145 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 146 } 147 148 return OUT; 149 } 116 150 117 151 /** In between step that only filters in one direction … … 151 185 } 152 186 153 154 /** In between step that only filters in one direction155 */156 pixel FilterSsaoFullRes(fragment IN,157 uniform sampler2D colorsTex,158 uniform sampler2D ssaoTex,159 uniform float3 bl,160 uniform float3 br,161 uniform float3 tl,162 uniform float3 tr,163 uniform float2 res164 )165 {166 pixel OUT;167 168 const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w;169 170 OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));171 // just take unfiltered convergence in current pixel172 const float convergence = OUT.illum_col.y;173 174 // filter reaches size 1 pixel when sample size reaches threshold175 // afterwards we do not use the filter anymore176 177 const float2 xyStep = float2(1.0f / res.x, 0);178 179 // filter up to a certain convergance value and leave out background (sky) by checking depth180 if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD))181 {182 // the filtered ssao value183 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);184 }185 186 return OUT;187 }188 189 190 187 /** Function combining image and indirect illumination buffer using a 191 188 depth and convergence aware discontinuity filter. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3311 r3313 263 263 264 264 // check if the pixel belonged to a dyanmic object in the last frame 265 const bool newDynamic = false;//(squaredLen > DYNAMIC_OBJECTS_THRESHOLD);266 const bool oldDynamic = false;//(oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);265 const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 266 const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 267 267 268 268 // actually 0 means pixel is valid 269 269 const float pixelIsValid = 0.0f; 270 270 // means that we only use slight temporal coherence over some frames 271 // so that there isno noticeable drag271 // so that there si no noticeable drag 272 272 const float pixelCouldBeValid = 2.0f; 273 273 // this pixel information has to be discarded in order to not create artifacts 274 274 const float pixelIsNotValid = 100.0f; 275 275 276 // check if the pixel was outside of the frame buffer 277 if ((oldTexCoords.x <= 0) || (oldTexCoords.x >= 1.0f) || 278 (oldTexCoords.y <= 0) || (oldTexCoords.y >= 1.0f) 276 const float xOffs = 0;// 0.5f / 1024.0f; 277 const float yOffs = 0;// 0.5f / 768.0f; 278 279 if ((oldTexCoords.x < xOffs) || (oldTexCoords.x > (1.0f - xOffs)) || 280 (oldTexCoords.y < yOffs) || (oldTexCoords.y > (1.0f - yOffs)) 279 281 ) 280 282 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3311 r3313 48 48 weight of the pixel in the new frame. 49 49 */ 50 inline float 3temporalSmoothing(float4 worldPos,50 inline float2 temporalSmoothing(float4 worldPos, 51 51 float eyeSpaceDepth, 52 52 float2 texcoord0, … … 96 96 // the weight of the accumulated samples from the previous frames 97 97 float w; 98 float idx;99 98 100 99 ////////////// … … 109 108 // pixel valid => retrieve the convergence weight 110 109 w = oldPixel.y; 111 idx = oldPixel.z;112 110 } 113 111 else 114 112 { 115 w = .0f; 116 idx = .0f; 117 } 118 119 return float3(ssao, w, idx); 113 w = 0.0f; 114 } 115 116 return float2(ssao, w); 120 117 } 121 118 … … 145 142 float validSamples = .0f; 146 143 147 148 for (int i = 0; i < NUM_PRECOMPUTED_SAMPLES; ++ i) 144 for (int i = 0; i < NUM_SAMPLES; ++ i) 149 145 { 150 146 const float2 offset = samples[i]; … … 224 220 sampler2D colors, 225 221 sampler2D noiseTex, 226 sampler2D samples,222 float2 samples[NUM_SAMPLES], 227 223 float3 normal, 228 224 float3 centerPosition, … … 235 231 float convergence, 236 232 float sampleIntensity, 237 bool isMovingObject, 238 float idx 233 bool isMovingObject 239 234 ) 240 235 { … … 242 237 float validSamples = .0f; 243 238 float numSamples = .0f; 244 239 245 240 for (int i = 0; i < NUM_SAMPLES; ++ i) 246 241 { … … 251 246 //-- (affects performance for some reason!) 252 247 253 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;254 255 248 if (convergence < SSAO_CONVERGENCE_THRESHOLD) 256 249 { 257 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord .x * 4.0f + idx * 0.01f, IN.texCoord.y* 4.0f, 0, 0)).xy;250 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 258 251 //offset = myreflect(samples[i], mynoise); 259 //offset = myrotate(samples[i], mynoise.x); 260 261 offset = myrotate(ssaoOffset, mynoise.x); 252 offset = myrotate(samples[i], mynoise.x); 262 253 } 263 254 else 264 255 { 265 offset = ssaoOffset; 266 //offset = samples[i]; 256 offset = samples[i]; 267 257 } 268 258 … … 304 294 // we check if the sample could have been near enough to the current pixel 305 295 // to have any influence in the current or last frame 306 //const float tooFarAway = step(0.5f, lengthToSample - changeFactor);296 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 307 297 //validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 308 298 validSamples = max(validSamples, pixelValid); … … 313 303 if (numSamples >= MIN_SAMPLES) 314 304 { 305 //break; 315 306 // if the pixel belongs to a static object and all the samples stay valid in the current frame 316 307 if (!isMovingObject && (validSamples < 1.0f)) break; 317 // if the pixel belongs to a dynamic object but the #accumulated samples 318 // for this pixel is sufficiently high(=> there was no discontinuity recently)308 // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 309 // (=> there was no discontinuity recently) 319 310 else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 320 311 } … … 344 335 uniform sampler2D normals, 345 336 uniform sampler2D noiseTex, 346 uniform sampler2D samples,337 uniform float2 samples[NUM_SAMPLES], 347 338 uniform sampler2D oldTex, 348 339 uniform float4x4 modelViewProj, … … 391 382 //-- compute temporal reprojection 392 383 393 float 3temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,384 float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 394 385 oldTex, oldModelViewProj, 395 386 colors, … … 402 393 const float oldSsao = temporalVals.x; 403 394 float oldWeight = temporalVals.y; 404 405 float idx = (int)temporalVals.z; 406 407 if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0; 408 395 409 396 float3 ao; 410 397 … … 412 399 if (eyeSpaceDepth < DEPTH_THRESHOLD) 413 400 { 414 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 415 scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, 416 sampleIntensity, isMovingObject, idx); 401 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 417 402 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 418 403 } … … 429 414 // the weight equals the number of sampled shot in this pass 430 415 const float newWeight = ao.z; 431 432 idx += newWeight;433 416 434 417 // completely reset the ao in this pixel … … 437 420 const float partlyResetThres = 1.0f; 438 421 439 // hack: just update static geometry 440 if (!isMovingObject) 422 if (1)//!isMovingObject) 441 423 { 442 424 if (ao.y > completelyResetThres) 443 425 { 444 oldWeight = .0f; 445 idx = .0f; 426 oldWeight = .0f; 446 427 } 447 428 else if (ao.y > partlyResetThres) 448 429 { 449 430 oldWeight = min(oldWeight, 4.0f * newWeight); 431 //oldWeight = .0f; 450 432 } 451 433 } 452 453 434 454 435 ////////// 455 436 //-- blend ao between old and new samples (and avoid division by zero) 456 437 457 OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 438 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 439 458 440 OUT.illum_col.x /= (newWeight + oldWeight); 459 441 460 442 // the new weight for the next frame 461 443 const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 462 444 463 445 OUT.illum_col.y = combinedWeight; 464 446 // can be used to check if this pixel belongs to a moving object 465 //OUT.illum_col.z = SqrLen(diffVec); 466 OUT.illum_col.z = idx; 447 OUT.illum_col.z = SqrLen(diffVec); 467 448 OUT.illum_col.w = eyeSpaceDepth; 468 449
Note: See TracChangeset
for help on using the changeset viewer.