Changeset 3103 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders
- Timestamp:
- 11/06/08 10:41:02 (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/globillum.cg
r3094 r3103 104 104 //-- reconstruct world space position from sample 105 105 106 //const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0));107 const float4 sample = tex2D(colors, texcoord);106 const float4 sample = tex2Dlod(colors, float4(texcoord, 0, 0)); 107 //const float4 sample = tex2D(colors, texcoord); 108 108 109 109 const float eyeSpaceDepth = sample.w; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3101 r3103 4 4 // Screen Spaced Ambient Occlusion shader 5 5 // based on shader of Alexander Kusternig 6 7 8 #define USE_EYE_SPACE_DEPTH 19 10 6 11 7 struct fragment … … 82 78 ) 83 79 { 84 const float2 mynoise = tex2D (noiseTex, texcoord0).xy;80 const float2 mynoise = tex2Dlod(noiseTex, texcoord0).xy; 85 81 86 82 const float2 offsetTransformed = myreflect(offset, mynoise); … … 151 147 //else trafo = inverseModelTrafo * oldModelViewProj; 152 148 153 float3 dummyPt = worldPos.xyz - oldEyePos;149 float3 translatedPt = worldPos.xyz - oldEyePos; 154 150 155 151 // reproject into old frame and calculate texture position of sample in old frame 156 float4 backProjPos = mul(oldModelViewProj, float4( dummyPt, 1.0f));152 float4 backProjPos = mul(oldModelViewProj, float4(translatedPt, 1.0f)); 157 153 backProjPos /= backProjPos.w; 158 154 // fit from unit cube into 0 .. 1 … … 169 165 170 166 const float invlen = 1.0f / length(viewVec); 171 const float projectedEyeSpaceDepth = length( dummyPt) * invlen;167 const float projectedEyeSpaceDepth = length(translatedPt) * invlen; 172 168 173 169 const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth); 170 //const float depthDif = abs(oldEyeSpaceDepth - projectedEyeSpaceDepth) / projectedEyeSpaceDepth; 174 171 175 172 float notValid = 0.5f; 176 173 174 /* 177 175 for (int i = 0; i < NUM_SAMPLES; ++ i) 178 176 { … … 191 189 if (sampleDif >= 5e-2f) ++ notValid; 192 190 } 191 */ 193 192 194 193 // the number of valid samples in this frame … … 202 201 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 203 202 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 204 && ( abs(depthDif)<= MIN_DEPTH_DIFF)203 && (depthDif <= MIN_DEPTH_DIFF) 205 204 // if visibility changed in the surrounding area we have to recompute 206 205 //&& (oldNumSamples > 0.8f * newNumSamples) … … 259 258 //-- add random noise: reflect around random normal vector (rather slow!) 260 259 261 float2 mynoise = tex2D (noiseTex, IN.texCoord).xy;260 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 262 261 const float2 offsetTransformed = myreflect(offset, mynoise); 263 262 #else … … 275 274 276 275 float3 dirSample = samplePos - centerPosition; 277 const float lengthToSample = length(dirSample);276 const float lengthToSample = max(length(dirSample), 1e-6f); 278 277 279 278 dirSample /= lengthToSample; // normalize 280 279 281 280 // angle between current normal and direction to sample controls AO intensity. 282 constfloat cosAngle = max(dot(dirSample, normal), .0f);283 281 float cosAngle = max(dot(dirSample, normal), .0f); 282 284 283 // the distance_scale offset is used to avoid singularity that occurs at global illumination when 285 284 // the distance to a sample approaches zero … … 291 290 // => compensate for this (on the other hand, projected sampling area could be larger!) 292 291 293 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * dot(viewDir, normal);292 const float viewCorrection = 1.0f + VIEW_CORRECTION_SCALE * max(dot(viewDir, normal), 0.0f); 294 293 total_ao += cosAngle * aoContrib * viewCorrection; 295 294 #else … … 352 351 oldbl, oldbr, oldtl, oldtr); 353 352 353 //OUT.illum_col.xyz = normal * 0.5f + 0.5f; 354 354 return OUT; 355 355 } 356 357 358 float Filter(float2 texCoord,359 uniform sampler2D ssaoTex,360 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],361 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES])362 {363 float average = .0f;364 float w = .0f;365 366 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)367 {368 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x;369 w += filterWeights[i];370 }371 372 average *= 1.0f / (float)w;373 374 return average;375 }376 377 378 pixel combine(fragment IN,379 uniform sampler2D colors,380 uniform sampler2D ssaoTex,381 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],382 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]383 )384 {385 pixel OUT;386 387 float4 col = tex2Dlod(colors, float4(IN.texCoord, 0, 0));388 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));389 390 if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);391 392 OUT.illum_col = col * ao.x;393 //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);394 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);395 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);396 OUT.illum_col.w = col.w;397 398 return OUT;399 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3017 r3103 91 91 { 92 92 color = tex2D(colors, downSampleOffs[i]); 93 94 93 const float intensity = dot(cols[i].rgb, w); 95 94 … … 146 145 147 146 // obtain new image key from highest mipmap level 148 float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, 99)).w;147 float logLumScaled = tex2Dlod(colors, float4(.5f, .5f, 0, MAX_LOD_LEVEL)).w; 149 148 float logLum = logLumScaled * LOGLUM_RANGE + MINLOGLUM; 150 149 … … 153 152 // adjust to middle gray 154 153 const float lum = middleGrey * pixLum / newImageKey; 155 156 154 // map to range and calc burnout 157 155 const float scaleLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); … … 170 168 171 169 pixel OUT; 172 170 173 171 const float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 174 175 172 OUT.col = color; 176 173 … … 187 184 float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 188 185 189 if (oldLogLum > 1e-5f) // too bright 186 // exponential smoothing of tone mapping over time 187 if (oldLogLum > 1e-5f) // loglum from last frame too bright 190 188 OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f); 191 189 else
Note: See TracChangeset
for help on using the changeset viewer.