- Timestamp:
- 02/26/09 18:39:04 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3328 r3329 203 203 float2 offset; 204 204 205 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;206 //const float2 ssaoOffset = samples[i];205 const float2 ssaoOffset = 206 tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 207 207 208 208 //////////////////// … … 234 234 float3 dirSample = samplePos - centerPosition; 235 235 236 //const float minDist = 9e-1f;237 const float minDist = 1e-2f;238 239 //const float sqrLen = max(SqrLen(dirSample), minDist);240 //const float lengthToSample = sqrt(sqrLen);241 const float lengthToSample = max(length(dirSample), minDist); 242 243 dirSample /= lengthToSample; // normalize 236 const float minDist = 1e-6f; 237 const float scaleFactor = 1e-3f; 238 239 const float lengthToSample = length(dirSample); 240 const float sampleWeight = 1.0f / (lengthToSample + scaleFactor); 241 242 dirSample /= max(lengthToSample, minDist); // normalize 243 244 244 245 245 // angle between current normal and direction to sample controls AO intensity. 246 float cosAngle = dot(dirSample, normal);246 const float cosAngle = dot(dirSample, normal); 247 247 248 248 // the normal of the current sample 249 //const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 250 const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 251 249 const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 250 252 251 // angle between current normal and direction to sample controls AO intensity. 253 float cosAngle2 = .5f + dot(sampleNormal, -normal) * 0.5f; 254 //float cosAngle2 = dot(-dirSample, sampleNormal); 252 const float cosAngle2 = dot(-dirSample, sampleNormal); 255 253 256 //const float aoContrib = sampleIntensity / sqrLen;257 const float aoContrib = sampleIntensity / lengthToSample;254 dirSample *= minDist; 255 const float aoContrib = sampleIntensity * sampleWeight; 258 256 259 257 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; … … 277 275 278 276 const float partlyResetThres = 1.0f; 277 279 278 if (pixelValid <= partlyResetThres) 280 279 validSamples = max(validSamples, pixelValid * (1.0f - tooFarAway) * step(-0.1f, cosAngle)); … … 326 325 sampler2D colors, 327 326 sampler2D noiseTex, 328 float2 samples[NUM_SAMPLES],327 sampler2D samples, 329 328 float3 normal, 330 329 float3 centerPosition, … … 337 336 float convergence, 338 337 float sampleIntensity, 339 bool isMovingObject 338 bool isMovingObject, 339 float oldIdx 340 340 ) 341 341 { … … 348 348 float2 offset; 349 349 350 const float2 ssaoOffset = 351 tex2Dlod(samples, float4((0.5f + i + oldIdx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 352 350 353 //////////////////// 351 354 //-- add random noise: reflect around random normal vector … … 356 359 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 357 360 //offset = myreflect(samples[i], mynoise); 358 offset = myrotate(samples[i], mynoise.x); 361 //offset = myrotate(samples[i], mynoise.x); 362 offset = myrotate(ssaoOffset, mynoise.x); 359 363 } 360 364 else 361 365 { 362 offset = samples[i]; 363 } 364 366 offset = ssaoOffset; 367 } 368 369 365 370 // weight with projected coordinate to reach similar kernel size for near and far 366 371 const float2 texcoord = IN.texCoord.xy + offset * scaleFactor; … … 375 380 float3 dirSample = samplePos - centerPosition; 376 381 377 //const float minDist = 9e-1f; 378 const float minDist = 1e-2f; 379 380 //const float sqrLen = max(SqrLen(dirSample), minDist); 381 //const float lengthToSample = sqrt(sqrLen); 382 const float lengthToSample = max(length(dirSample), minDist); 383 384 dirSample /= lengthToSample; // normalize 382 const float minDist = 1e-6f; 383 const float scaleFactor = 1e-3f; 384 385 const float lengthToSample = length(dirSample); 386 const float sampleWeight = 1.0f / (lengthToSample + scaleFactor); 387 388 dirSample /= max(length(dirSample), minDist); // normalize 385 389 386 390 // angle between current normal and direction to sample controls AO intensity. 387 float cosAngle = dot(dirSample, normal);391 const float cosAngle = dot(dirSample, normal); 388 392 389 393 //const float aoContrib = sampleIntensity / sqrLen; 390 const float aoContrib = sampleIntensity / lengthToSample;394 const float aoContrib = sampleIntensity * sampleWeight; 391 395 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 392 396 393 total_ao += max(cosAngle, 0) * aoContrib;397 total_ao += max(cosAngle, .0f) * aoContrib; 394 398 395 399 ++ numSamples; … … 427 431 // (=> there was no discontinuity recently) 428 432 //else if (isMovingObject && (convergence > SSAO_CONVERGENCE_THRESHOLD)) break; 429 //else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break;433 else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 430 434 } 431 435 #endif … … 513 517 514 518 float oldWeight = temporalVals.y; 515 float oldIdx = temporal Vals.z;516 519 float oldIdx = temporalCoherence > 1 ? temporalVals.z : 0; 520 517 521 float3 ao; 518 522 … … 520 524 if (eyeSpaceDepth < DEPTH_THRESHOLD) 521 525 { 522 if (0) 523 { 524 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 526 if (1) 527 { 528 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 529 scaleFactor, bl, br, tl, tr, normalize(viewDir), 530 oldWeight, sampleIntensity, isMovingObject, oldIdx); 525 531 } 526 532 else 527 533 { 528 534 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, 529 530 535 bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, 536 isMovingObject, normals, oldIdx); 531 537 } 532 538 }
Note: See TracChangeset
for help on using the changeset viewer.