Changeset 3227 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 12/22/08 10:56:58 (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
r3213 r3227 45 45 return rpt; 46 46 } 47 48 49 50 51 inline float2 myrotate(float2 pt, float angle) 52 { 53 float2 rpt; 54 55 rpt.x = pt.x * cos(angle) - pt.y * sin(angle); 56 rpt.y = pt.y * cos(angle) + pt.x * sin(angle); 57 58 //normalize(rpt); 59 return rpt; 60 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3226 r3227 229 229 230 230 // compute position from old frame for dynamic objects + translational portion 231 const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 231 //const float3 translatedPos = difVec - oldEyePos + worldPos.xyz; 232 const float3 translatedPos = - oldEyePos + worldPos.xyz; 232 233 233 234 … … 275 276 pixelValid = pixelNotValid; 276 277 } 277 else if ( 278 else if (!((oldEyeSpaceDepth > 1e10f) || (projectedEyeSpaceDepth > 1e10f)) && 278 279 // check if changed from dynamic to not dynamic object 279 ( oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) ||280 ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 280 281 // check if we have a dynamic object and is a depth discontinuity 281 ((oldDynamic || newDynamic) && (depthDif <= MIN_DEPTH_DIFF))) 282 ( 283 //(oldDynamic || newDynamic) && 284 (depthDif > MIN_DEPTH_DIFF)))) 282 285 { 283 286 pixelValid = pixelCouldBeValid; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3226 r3227 1 1 #include "../shaderenv.h" 2 2 #include "common.h" 3 3 4 4 //////////////////// … … 28 28 } 29 29 30 31 inline float SqrLen(float3 v)32 {33 return v.x * v.x + v.y * v.y + v.z * v.z;34 }35 36 37 inline float2 myreflect(float2 pt, float2 n)38 {39 // distance to plane40 float d = dot(n, pt);41 // reflect around plane42 float2 rpt = pt - d * 2.0f * n;43 44 return rpt;45 }46 47 48 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)49 {50 float3 x1 = lerp(bl, tl, w.y);51 float3 x2 = lerp(br, tr, w.y);52 float3 v = lerp(x1, x2, w.x);53 54 return v;55 }56 30 57 31 … … 225 199 total_ao /= numSamples; 226 200 227 #if 0201 #if 1 228 202 // if surface normal perpenticular to view dir, approx. half of the samples will not count 229 203 // => compensate for this (on the other hand, projected sampling area could be larger!) 230 204 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 231 total_ao *=viewCorrection;205 total_ao += cosAngle * aoContrib * viewCorrection; 232 206 233 207 #endif 234 208 235 //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 236 return float3(total_ao, validSamples, numSamples); 209 return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples); 237 210 } 238 211 … … 261 234 float newWeight, 262 235 float sampleIntensity, 263 bool isMovingObject, 264 sampler2D normalTex 236 bool isMovingObject 265 237 ) 266 238 { … … 273 245 const float2 offset = samples[i]; 274 246 275 #if 1 247 float2 offsetTransformed; 248 276 249 //////////////////// 277 250 //-- add random noise: reflect around random normal vector 278 //-- ( slows down the computationfor some reason!)251 //-- (affects performance for some reason!) 279 252 280 253 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 281 const float2 offsetTransformed = myreflect(offset, mynoise);282 #else 283 const float2 offsetTransformed = offset;284 #endif 254 //float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord, 0, 0)).xy; 255 //offsetTransformed = myreflect(offset, mynoise); 256 offsetTransformed = myrotate(offset, mynoise.x); 257 285 258 // weight with projected coordinate to reach similar kernel size for near and far 286 259 const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; … … 290 263 291 264 292 // the normal of the current sample293 //const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz;294 // angle between current normal and direction to sample controls AO intensity.295 //float cosAngle2 = .5f + dot(sampleNormal, -normal) * 0.5f;296 297 265 //////////////// 298 266 //-- compute contribution of sample using the direction and angle … … 300 268 float3 dirSample = samplePos - centerPosition; 301 269 302 const float sqrLen = max(SqrLen(dirSample), 1e-2f); 303 const float lengthToSample = sqrt(sqrLen); 270 //const float sqrLen = max(SqrLen(dirSample), 1e-2f); 271 //const float lengthToSample = sqrt(sqrLen); 272 const float lengthToSample = max(length(dirSample), 1e-2f); 304 273 305 274 dirSample /= lengthToSample; // normalize 306 275 307 276 // angle between current normal and direction to sample controls AO intensity. 308 const float cosAngle = max(dot(dirSample, normal), .0f); 309 const float aoContrib = sampleIntensity / sqrLen; 277 float cosAngle = dot(dirSample, normal); 278 279 //const float aoContrib = sampleIntensity / sqrLen; 280 const float aoContrib = sampleIntensity / lengthToSample; 310 281 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; 311 282 312 //total_ao += cosAngle2 * cosAngle * aoContrib; 313 total_ao += cosAngle * aoContrib; 283 total_ao += max(cosAngle, 0) * aoContrib; 314 284 315 285 ++ numSamples; … … 324 294 // to have any influence in the current or last frame 325 295 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 326 validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid );327 328 #if 1//#ifdef U//USE_GTX296 validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 297 298 #ifdef USE_GTX 329 299 // we can bail out early and use a minimal #samples) 330 300 // if some conditions are met as long as the hardware supports it … … 351 321 352 322 return float3(total_ao, validSamples, numSamples); 353 //return float3(max(0.0f, 1.0f - total_ao), validSamples, numSamples);354 323 } 355 324 … … 426 395 if (eyeSpaceDepth < 1e10f) 427 396 { 428 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject , normals);397 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 429 398 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 430 399 } … … 460 429 } 461 430 431 ////////// 432 //-- blend ao between old and new samples (and avoid division by zero) 433 434 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 435 436 OUT.illum_col.x /= (newWeight + oldWeight); 437 462 438 // the new weight for the next frame 463 439 const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 464 465 466 //////////467 //-- blend ao between old and new samples (and avoid division by zero)468 469 //OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, newWeight + oldWeight);470 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / (newWeight + oldWeight);471 440 472 441 OUT.illum_col.y = combinedWeight;
Note: See TracChangeset
for help on using the changeset viewer.