- Timestamp:
- 11/30/08 20:41:23 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3197 r3198 122 122 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 123 123 { 124 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0);124 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, .0f, .0f); 125 125 126 126 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); … … 128 128 129 129 // check spatial discontinuity 130 // using the depth from the color texture is not 100% correct as depth was 130 131 // note: using the depth from the color texture is not 100% correct as depth was 131 132 // not scaled with the interpolated view vector depth yet ... 132 133 samplePos = ReconstructSamplePos(colorsTex, sampleTexCoord.xy, bl, br, tl, tr); … … 134 135 135 136 len = min(SqrLen(centerPos - samplePos), 1e2f); 136 137 137 spatialFactor = 1.0f / max(len, 1e-3f); 138 138 139 139 //normalFactor = max(step(.0f, dot(sampleNorm, centerNormal)), 1e-2f); 140 //normalFactor = max(dot(sampleNorm, samplePos), 1e-3f);141 140 convergenceFactor = aoSample.y + 1.0f; 142 //convergenceFactor = max(step(0.5f + NUM_SAMPLES, aoSample.y), 1e-2f); 143 //convergenceFactor = aoSample.y; 144 141 145 142 // combine the weights 146 143 w = convergenceFactor * convergenceFactor * spatialFactor;// * normalFactor; 147 //w = spatialFactor * normalFactor; 148 144 149 145 average += aoSample.x * w; 150 146 total_w += w; … … 178 174 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 179 175 180 float4 dummy; 181 //const float xoffs = .5f / 1024.0f; const float yoffs = .5f / 768.0f; 182 const float xoffs = 1.0f / 1024.0f; const float yoffs = 1.0f / 768.0f; 183 184 dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, yoffs), 0, 0)).w; 185 dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, -yoffs), 0, 0)).w; 186 dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, yoffs), 0, 0)).w; 187 dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-yoffs, -yoffs), 0, 0)).w; 188 189 /*dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).y; 190 dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).y; 191 dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).y; 192 dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).y; 193 */ 194 const float convergence = min(min(dummy.x, dummy.y), min(dummy.z, dummy.w)); 195 //const float convergence = max(max(dummy.x, dummy.y), max(dummy.z, dummy.w)); 176 // get the minimum convergence by exactly sampling the 4 surrounding 177 // texels in the old texture, otherwise flickering because convergence 178 // will be interpolated when upsampling and filter size does not match! 179 float4 texelCenterConv; 180 const float w = 512.0f; const float h = 384.0f; 181 const float xoffs = .5f / w; const float yoffs = .5f / h; 182 183 // get position exactly between old texel centers 184 float2 center; 185 center.x = float(floor(IN.texCoord.x * w - .5f) + 1.0f) / w; 186 center.y = float(floor(IN.texCoord.y * h - .5f) + 1.0f) / h; 187 188 texelCenterConv.x = tex2Dlod(ssaoTex, float4(center + float2(xoffs, yoffs), 0, 0)).y; 189 texelCenterConv.y = tex2Dlod(ssaoTex, float4(center + float2(xoffs, -yoffs), 0, 0)).y; 190 texelCenterConv.z = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, yoffs), 0, 0)).y; 191 texelCenterConv.w = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 192 193 const float m1 = min(texelCenterConv.x, texelCenterConv.y); 194 const float m2 = min(texelCenterConv.z, texelCenterConv.w); 195 196 const float convergence = min(m1, m2); 196 197 //const float convergence = ao.y; 197 198 … … 201 202 // filter up to a certain convergance value and leave out background (sky) by checking depth 202 203 if ((convergence < thres) && (col.w < 1e10f)) 203 //if (col.w < 1e10f)204 204 { 205 //const float eyeSpaceDepth = col.w; const float distanceScaleWeight = 2.0f;206 //const float distanceScale = distanceScaleWeight / (eyeSpaceDepth + distanceScaleWeight);207 205 const float distanceScale = 1.0f; 208 206 209 207 const float convergenceWeight = thres / (SSAO_FILTER_WIDTH - 1.0f); 210 208 const float convergenceScale = convergenceWeight / (convergence + convergenceWeight); 211 212 209 const float scale = SSAO_FILTER_WIDTH * convergenceScale * distanceScale; 213 210 214 211 // the filtered ssao value 215 //ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr);212 ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr); 216 213 } 217 214 … … 221 218 OUT.illum_col.xyz = col.xyz; 222 219 223 //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-3f, 0, 1), 1); 224 //const float mydummy = ao.w * 1e-3f; 225 OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 220 //OUT.illum_col.xyz = float3(ao.x, ao.x, step(thres, convergence)); 221 //OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 226 222 //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-3f, 0, 1), 1); 227 223 //OUT.illum_col.xyz = float3(0, 1.0f - step(0.5f + NUM_SAMPLES, convergence), 1); … … 230 226 return OUT; 231 227 } 228 229 230 231 /** Function combining image and indirect illumination buffer using a 232 depth and normal aware discontinuity filter. 233 */ 234 pixel SmoothSsao(fragment IN, 235 uniform sampler2D ssaoTex) 236 { 237 pixel OUT; 238 239 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 240 241 float4 dummy; 242 const float xoffs = .5f / 1024.0f; const float yoffs = .5f / 768.0f; 243 244 // get positions exactly between old texel centers 245 dummy.x = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(xoffs, 0), 0, 0)).y; 246 dummy.y = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, -yoffs), 0, 0)).y; 247 dummy.z = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(-xoffs, 0), 0, 0)).y; 248 dummy.w = tex2Dlod(ssaoTex, float4(IN.texCoord + float2(0, yoffs), 0, 0)).y; 249 250 const float m1 = min(dummy.x, dummy.y); 251 const float m2 = min(dummy.z, dummy.w); 252 253 ao.y = min(ao.y, min(m1, m2)); 254 255 return OUT; 256 }
Note: See TracChangeset
for help on using the changeset viewer.