Changeset 3213 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 12/08/08 03:01:45 (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/common.h
r3170 r3213 1 /************************************/ 2 /* Common shader functions */ 3 /************************************/ 4 5 /** Interpolate bilinearly between 2 vectors 6 */ 1 7 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 2 8 { … … 9 15 10 16 11 // reconstruct world space position 17 /** reconstruct world space position 18 */ 12 19 inline float3 ReconstructSamplePos(uniform sampler2D tex, 13 20 float2 texcoord, -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/lenseFlare.cg
r3212 r3213 6 6 }; 7 7 8 float4 main(fragment IN, 9 uniform sampler2D colors, 10 uniform sampler2D , 11 ): COLOR 8 9 10 float4 LenseFlare(fragment IN, 11 uniform sampler2D colorsTex, 12 uniform sampler2D flareTex1, 13 uniform sampler2D flareTex2, 14 uniform sampler2D flareTex3, 15 uniform sampler2D flareTex4, 16 uniform float2 vectorToLight, // vector to current light position 17 uniform float distanceToLight // distance to current light position 18 ): COLOR 12 19 { 13 20 // center color 14 const float4 centerColor = tex2Dlod(colors, float4(IN.texCoords, 0, 0)); 15 // center depth 16 const float4 centerDepth = float4(centerColor.w); 21 const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0)); 17 22 18 const float2 lt = IN.texCoords + offsets[0]; 19 const float2 rb = IN.texCoords + offsets[1]; 20 const float2 rt = IN.texCoords + offsets[2]; 21 const float2 lb = IN.texCoords + offsets[3]; 23 const float scale = 0.5f; 24 const float center = float2(.5f, .5f); 25 const float2 newPos = vectorToLight * distanceToLight; 22 26 27 const float2 newTexCoords = (IN.texCoords - center) / scale + center - newPos; 23 28 24 return col; 29 const float4 flare1 = tex2Dlod(flareTex1, float4(newTexCoords, 0, 0)); 30 31 float4 result; 32 33 result.w = color.w; 34 35 //const float factor = 0.9f; 36 //result.xyz = lerp(color.xyz, flare1.xyz, factor); 37 //result.xyz = color.xyz * (1.0f - flare1.w) + flare1.xyz * flare1.w; 38 result.xyz = color.xyz + flare1.xyz; 39 40 return result; 25 41 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3212 r3213 258 258 float3 viewDir, 259 259 float newWeight, 260 float sampleIntensity 260 float sampleIntensity, 261 bool isMovingObject 261 262 ) 262 263 { … … 312 313 313 314 ++ numSamples; 314 315 315 316 // check if the samples have been valid in the last frame 316 // only mark sample as invalid if taking it into account can have influence the ssao: 317 // hence we also check if the sample or the same sample in the previous frame 318 // had any chance to be near the current sample 317 // only mark sample as invalid if in the last / current frame 318 // they possibly have any influence on the ao 319 319 const float changeFactor = sampleColor.y; 320 320 const float pixelValid = sampleColor.x; 321 321 322 // hack: cedistance measure can fail in some cases => choose something different 322 // we check if the sample could have been near enough to the current pixel 323 // to have any influence in the current or last frame 323 324 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 324 325 validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid); 325 //validSamples += sampleColor.x; 326 327 //if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break; 328 //if ((validSamples < 1.0f) && (numSamples >= 8)) break; 329 } 330 326 327 #ifdef USE_GTX 328 // we can bail out early and use a minimal #samples) 329 // if some conditions are met as long as the hardware supports it 330 if (numSamples >= 8) 331 { 332 // if the pixel belongs to a static object and all the samples stay valid in the current frame 333 if (!isMovingObject && (validSamples < 1.0f)) break; 334 // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 335 // (=> there was no discontinuity recently) 336 else if (isMovingObject && (newWeight > NUM_SAMPLES * 5)) break; 337 } 338 #endif 339 340 } 341 342 // scale ao contribution 331 343 total_ao /= numSamples; 332 344 333 return float3( max(0.0f, 1.0f - total_ao), validSamples, numSamples);345 return float3(total_ao, validSamples, numSamples); 334 346 } 335 347 … … 382 394 float scaleFactor = kernelRadius * invw; 383 395 396 const float sqrMoveSpeed = SqrLen(diffVec); 397 const bool isMovingObject = (sqrMoveSpeed > DYNAMIC_OBJECTS_THRESHOLD); 398 384 399 385 400 ///////////////// … … 403 418 if (eyeSpaceDepth < 1e10f) 404 419 { 405 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity );420 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 406 421 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 407 422 } … … 411 426 } 412 427 413 const float squaredLen = SqrLen(diffVec); 414 415 // check if we have to reset pixel because one of the sample points was invalid 416 if (squaredLen < DYNAMIC_OBJECTS_THRESHOLD) 417 { 418 if (ao.y > 4.0f) 419 oldWeight = 0; 420 else if (ao.y > 1.0f) 421 oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 422 } 423 428 429 /////////// 430 //-- check if we have to reset pixel because one of the sample points was invalid 431 //-- only do this if the current pixel does not belong to a moving object 432 433 // the weight equals the number of sampled shot in this pass 424 434 const float newWeight = ao.z; 435 436 const float completelyResetThres = 4.0f; 437 const float partlyResetThres = 1.0f; 438 439 if (!isMovingObject) 440 { 441 if (ao.y > completelyResetThres) 442 oldWeight = .0f; 443 else if (ao.y > partlyResetThres) 444 oldWeight = min(oldWeight, 4.0f * newWeight); 445 } 446 447 // the new weight for the next frame 425 448 const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 426 449 427 428 // blendbetween old and new samples (and avoid division by zero)450 ////////// 451 //-- blend ao between old and new samples (and avoid division by zero) 429 452 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, newWeight + oldWeight); 453 430 454 OUT.illum_col.z = SqrLen(diffVec); 431 455 OUT.illum_col.y = combinedWeight;
Note: See TracChangeset
for help on using the changeset viewer.