- Timestamp:
- 10/31/08 09:03:25 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3081 r3083 11 11 // for quadratic falloff 12 12 //#define SAMPLE_INTENSITY 0.1f 13 //#define SAMPLE_INTENSITY 0.07f14 #define SAMPLE_INTENSITY 0.03f13 #define SAMPLE_INTENSITY 0.07f 14 //#define SAMPLE_INTENSITY 0.03f 15 15 16 16 #define SAMPLE_RADIUS 8e-1f … … 53 53 #define NUM_SSAO_FILTERSAMPLES 100 54 54 55 #define PRECISION_SCALE 1e-3f 56 57 55 58 #endif // __SHADERENV_H -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3082 r3083 54 54 float3 bl, float3 br, float3 tl, float3 tr) 55 55 { 56 texcoord.x += 1.0f / 1024.0f; texcoord.y += 1.0f / 768.0f; 57 56 58 //const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 57 59 const float eyeSpaceDepth = tex2D(colors, texcoord).w; … … 66 68 as well as a boolean that 67 69 */ 68 pixel TemporalSmoothing(float currentPos, 69 float currentDepth, 70 uniform sampler2D oldTex) 71 { 70 float4 temporalSmoothing(float4 currentProjPos, 71 float4 worldPos, 72 float currentDepth, 73 uniform sampler2D oldTex, 74 const uniform float4x4 oldModelViewProj, 75 uniform float temporalCoherence, 76 uniform float2 ao, 77 uniform float2 samples[NUM_SAMPLES], 78 uniform sampler2D colors, 79 uniform sampler2D noiseTexture, 80 uniform float scaleFactor, 81 uniform float3 bl, 82 uniform float3 br, 83 uniform float3 tl, 84 uniform float3 tr, 85 float2 texcoord0 86 ) 87 { 88 float4 illum_col; 72 89 73 90 ///////////////// 74 91 //-- compute reprojection for temporal smoothing 75 92 76 77 93 // reproject into old frame and calculate projected depth 78 float4 projPos = mul(oldModelViewProj, worldPos);79 projPos /= projPos.w;94 float4 backProjPos = mul(oldModelViewProj, worldPos); 95 backProjPos /= backProjPos.w; 80 96 81 97 // the current depth projected into the old frame 82 const float projDepth = projPos.z * precisionScale;98 const float backProjDepth = backProjPos.z * PRECISION_SCALE; 83 99 // fit from unit cube into 0 .. 1 84 const float2 tex = projPos.xy * 0.5f + 0.5f;100 const float2 tex = backProjPos.xy * 0.5f + 0.5f; 85 101 // retrieve the sample from the last frame 86 102 float4 oldCol = tex2D(oldTex, tex); 87 103 88 104 const float oldDepth = oldCol.z; 89 //const float depthDif = 1.0f - projDepth / oldDepth; 90 const float depthDif = projDepth - oldDepth; 105 const float depthDif = backProjDepth - oldDepth; 91 106 92 107 //const float oldNumSamples = oldCol.y; 93 108 const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 94 95 109 float newWeight; 110 111 bool isValid = true; 112 113 for (int i = 0; i < NUM_SAMPLES; ++ i) 114 { 115 const float2 offset = samples[i]; 116 117 //////////////////// 118 // add random noise: reflect around random normal vector (warning: slow!) 119 120 float2 mynoise = tex2D(noiseTexture, texcoord0).xy; 121 const float2 offsetTransformed = myreflect(offset, mynoise); 122 123 const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 124 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr); 125 126 // reproject into old frame and calculate projected depth 127 float4 projPos = mul(oldModelViewProj, float4(samplePos, 1.0f)); 128 projPos /= projPos.w; 129 130 // the current depth projected into the old frame 131 const float projDepth = projPos.z * PRECISION_SCALE; 132 // fit from unit cube into 0 .. 1 133 // retrieve the sample from the last frame 134 const float4 oldSample = tex2D(oldTex, projPos.xy * 0.5f + 0.5f); 135 const float dDiff = projDepth - oldSample.z; 136 137 if (abs(dDiff) > 1e-5f) isValid = false; 138 //if (oldSample.y < oldWeight) isValid = false; 139 } 96 140 97 141 // the number of valid samples in this frame … … 101 145 && (tex.x >= 0.0f) && (tex.x < 1.0f) 102 146 && (tex.y >= 0.0f) && (tex.y < 1.0f) 103 && (abs(depthDif) < MIN_DEPTH_DIFF)147 //&& (abs(depthDif) < MIN_DEPTH_DIFF) 104 148 // if visibility changed in the surrounding area we have to recompute 105 149 //&& (oldNumSamples > 0.8f * newNumSamples) 150 && isValid 106 151 ) 107 152 { 108 153 // increase the weight for convergence 109 154 newWeight = oldWeight + 1.0f; 110 OUT.illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight;155 illum_col.x = (ao.x + oldCol.x * oldWeight) / newWeight; 111 156 //if (!(oldNumSamples > ao.y - 1.5f)) newWeight = 0; 112 157 } 113 158 else 114 159 { 115 OUT.illum_col.x = ao.x;160 illum_col.x = ao.x; 116 161 newWeight = .0f; 117 162 } … … 122 167 return illum_col; 123 168 } 124 125 169 126 170 … … 128 172 */ 129 173 float2 ssao(fragment IN, 130 131 132 133 134 135 136 137 138 139 140 141 174 uniform sampler2D colors, 175 uniform sampler2D noiseTexture, 176 uniform float2 samples[NUM_SAMPLES], 177 uniform float3 currentNormal, 178 uniform float3 centerPosition, 179 uniform float scaleFactor, 180 uniform float3 bl, 181 uniform float3 br, 182 uniform float3 tl, 183 uniform float3 tr, 184 uniform float3 viewDir 185 ) 142 186 { 143 187 // Check in a circular area around the current position. … … 209 253 uniform float2 samples[NUM_SAMPLES], 210 254 uniform sampler2D oldTex, 255 const uniform float4x4 modelViewProj, 211 256 const uniform float4x4 oldModelViewProj, 212 const uniform float4x4 modelViewProj,213 257 uniform float temporalCoherence, 214 258 uniform float3 eyePos, … … 234 278 //-- calculcate the current projected posiion (also used for next frame) 235 279 236 float4 currentPos = mul(modelViewProj, worldPos); 237 238 const float w = SAMPLE_RADIUS / currentPos.w; 239 currentPos /= currentPos.w; 240 241 const float precisionScale = 1e-3f; 242 const float currentDepth = currentPos.z * precisionScale; 280 float4 projPos = mul(modelViewProj, worldPos); 281 282 const float w = SAMPLE_RADIUS / projPos.w; 283 projPos /= projPos.w; 284 285 const float currentDepth = projPos.z * PRECISION_SCALE; 243 286 244 287 const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); … … 248 291 //-- compute temporally smoothing 249 292 250 OUT.illum_col = TemporalSmoothing(currentPos, currentDepth, oldTex); 293 OUT.illum_col = temporalSmoothing(projPos, worldPos, currentDepth, oldTex, oldModelViewProj, temporalCoherence, ao, 294 samples, colors, noise, w, bl, br, tl, tr, IN.texCoord); 251 295 252 296 return OUT; … … 287 331 float3 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 288 332 289 if (ao.y < 10.0f)290 ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights);291 292 OUT.illum_col = col * ao.x;293 //OUT.illum_col.xyz = float3(ao.x,1-ao.y*1e-2f, 0);333 //if (ao.y < 10.0f) 334 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 335 336 //OUT.illum_col = col * ao.x; 337 OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 294 338 OUT.illum_col.w = col.w; 295 339
Note: See TracChangeset
for help on using the changeset viewer.