Changeset 3204 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 12/02/08 17:06:08 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3199 r3204 292 292 293 293 294 295 294 DeferredRenderer::DeferredRenderer(int w, int h, PerspectiveCamera *cam): 296 295 mWidth(w), mHeight(h), … … 306 305 //-- the flip-flop fbos 307 306 308 const int dsw = w / 2; const int dsh = h / 2; 307 //const int dsw = w / 2; const int dsh = h / 2; 308 //const int dsw = 128; const int dsh = 96; 309 const int dsw = 16; const int dsh = 12; 309 310 //const int dsw = w; const int dsh = h; 310 311 … … 325 326 326 327 mDownSampleFbo = new FrameBufferObject(dsw, dsh, FrameBufferObject::DEPTH_NONE); 328 // the downsampled color + depth buffer 327 329 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 328 // downsample buffer for the normal texture329 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);330 // downsample buffer for the normal texture 331 mDownSampleFbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 330 332 331 333 for (int i = 0; i < 2; ++ i) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp
r3193 r3204 176 176 case WRAP_CLAMP_TO_EDGE: 177 177 wrapParam = GL_CLAMP_TO_EDGE; break; 178 case WRAP_CLAMP_TO_BORDER: 179 wrapParam = GL_MIRROR_CLAMP_TO_EDGE_EXT; break; 178 180 } 179 181 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h
r3147 r3204 16 16 17 17 enum FORMAT {RGB_UBYTE, RGBA_UBYTE, RGB_FLOAT_16, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32}; 18 enum WRAP_TYPE {WRAP_REPEAT, WRAP_CLAMP_TO_EDGE };18 enum WRAP_TYPE {WRAP_REPEAT, WRAP_CLAMP_TO_EDGE, WRAP_CLAMP_TO_BORDER}; 19 19 enum FILTER_TYPE {FILTER_NEAREST, FILTER_LINEAR}; 20 20 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3203 r3204 8 8 //#define NUM_SAMPLES 8 9 9 //#define NUM_SAMPLES 16 10 #define NUM_SAMPLES 96 10 #define NUM_SAMPLES 24 11 //#define NUM_SAMPLES 96 11 12 12 13 #define SAMPLE_INTENSITY 0.3f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3203 r3204 125 125 126 126 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 127 sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz;127 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 128 128 129 129 // check spatial discontinuity 130 131 130 // note: using the depth from the color texture is not 100% correct as depth was 132 131 // not scaled with the interpolated view vector depth yet ... … … 137 136 spatialFactor = 1.0f / max(len, 1e-3f); 138 137 139 //normalFactor = max(step(. 0f, dot(sampleNorm, centerNormal)), 1e-2f);138 //normalFactor = max(step(.2f, dot(sampleNorm, centerNormal)), 1e-2f); 140 139 convergenceFactor = aoSample.y + 1.0f; 141 140 … … 172 171 173 172 float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); 174 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));173 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 175 174 176 175 // get the minimum convergence by exactly sampling the 4 surrounding … … 178 177 // will be interpolated when upsampling and filter size does not match! 179 178 float4 texelCenterConv; 180 const float w = 512.0f; const float h = 384.0f; 179 //const float w = 512.0f; const float h = 384.0f; 180 //const float w = 128.0f; const float h = 96.0f; 181 const float w = 16.0f; const float h = 12.0f; 181 182 const float xoffs = .5f / w; const float yoffs = .5f / h; 182 183 183 184 // get position exactly between old texel centers 184 185 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;186 center.x = (floor(IN.texCoord.x * w - .5f) + 1.0f) / w; 187 center.y = (floor(IN.texCoord.y * h - .5f) + 1.0f) / h; 188 //center=IN.texCoord; 189 texelCenterConv.x = tex2Dlod(ssaoTex, float4(center + float2( xoffs, yoffs), 0, 0)).y; 190 texelCenterConv.y = tex2Dlod(ssaoTex, float4(center + float2( xoffs, -yoffs), 0, 0)).y; 191 texelCenterConv.z = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y; 192 texelCenterConv.w = tex2Dlod(ssaoTex, float4(center + float2(-xoffs, yoffs), 0, 0)).y; 192 193 193 194 const float m1 = min(texelCenterConv.x, texelCenterConv.y); … … 196 197 const float minConvergence = min(m1, m2); 197 198 198 const float convergence = step(200.0f, minConvergence) * minConvergence; 199 const float convergence = minConvergence; 200 //const float convergence = 0; 199 201 //const float convergence = ao.y; 200 202 201 // filter reaches size 1 after thres samples 203 // filter reaches size 1 pixel after thres samples: 204 // afterwards we do not use the filter anymore 202 205 const float thres = 500.0f; 203 206 … … 222 225 223 226 //OUT.illum_col.xyz = float3(ao.x, ao.x, step(thres, convergence)); 224 //OUT.illum_col.xyz = float3(ao.x, ao.x, ao.x); 227 OUT.illum_col.xyz = float3(0, convergence, 0); 228 //OUT.illum_col.xyz = float3(abs(center.x - IN.texCoord.x) * 16.0f, abs(center.y - IN.texCoord.y) * 12.0f, 0); 229 225 230 //OUT.illum_col.xyz = float3(0, clamp(1.0f - ao.y * 1e-3f, 0, 1), 1); 226 231 //OUT.illum_col.xyz = float3(0, 1.0f - step(0.5f + NUM_SAMPLES, convergence), 1); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3199 r3204 256 256 const float squaredLen = SqrLen(difVec); 257 257 258 // test if this pixel was notvalid in the old frame259 float validPixel;258 // test if this pixel was valid in the old frame 259 float pixelValid; 260 260 261 261 const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 262 262 const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 263 263 264 if (!(oldDynamic && !newDynamic) && !(!oldDynamic && newDynamic) 265 && !(oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF)) 266 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f) 267 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f) 264 const float xOffs = 1.0f / 1024.0f; 265 const float yOffs = 1.0f / 768.0f; 266 267 // actually 0 means pixel is valid 268 const float pixelIsValid = 0.0f; 269 const float pixelCouldBeValid = 2.0f; 270 const float pixelNotValid = 10.0f; 271 272 const float eps = 1e-6f; 273 274 if (0 275 //&& !(oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF)) 276 //&& (oldTexCoords.x + eps >= xOffs) && (oldTexCoords.x <= (1.0f - xOffs) + eps ) 277 //&& (oldTexCoords.y + eps >= yOffs) && (oldTexCoords.y <= (1.0f - yOffs) + eps ) 278 || (oldTexCoords.x < .0f) || (oldTexCoords.x >= 1.0f) 279 || (oldTexCoords.y < .0f) || (oldTexCoords.y >= 1.0f) 268 280 ) 269 281 { 270 validPixel = 0.0f; 271 } 272 else 282 pixelValid = pixelNotValid; 283 } 284 // check if changed from dynamic to not dynamic object 285 // or there is a depth discontinuity 286 else 287 if ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 288 (oldDynamic && newDynamic && (depthDif <= MIN_DEPTH_DIFF))) 273 289 { 274 validPixel = 10.5f; 275 } 276 277 //return depthDif; 278 return validPixel; 279 } 280 281 290 pixelValid = pixelCouldBeValid; 291 } 292 else 293 { 294 pixelValid = pixelIsValid; 295 } 296 297 return pixelValid; 298 } 299 300 301 /** This function is called during downsampling of the buffers 302 for ssao. 303 */ 282 304 pixel PrepareSsao(fragment IN, 283 305 uniform sampler2D colorsTex, -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3203 r3204 105 105 const float4 oldPixel = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)); 106 106 107 // the ssao value in the old frame 108 const float ssao = oldPixel.x; 109 107 110 #if USE_EYESPACE_DEPTH 108 111 … … 129 132 #endif 130 133 131 float newWeight; 134 const float xOffs = 1.0f / 1024.0f; 135 const float yOffs = 1.0f / 768.0f; 136 const float eps = 1e-6f; 137 138 // the weight of the old value 139 float w; 140 141 ////////////// 142 //-- reuse old value only if it was still valid in the old frame 132 143 133 144 if (1 134 && (oldTexCoords.x >= 0.0f) && (oldTexCoords.x < 1.0f)135 && (oldTexCoords.y >= 0.0f) && (oldTexCoords.y < 1.0f)145 && (oldTexCoords.x + eps >= xOffs) && (oldTexCoords.x <= 1.0f - xOffs + eps) 146 && (oldTexCoords.y + eps >= yOffs) && (oldTexCoords.y <= 1.0f - yOffs + eps) 136 147 && (depthDif <= MIN_DEPTH_DIFF) 137 148 ) 138 149 { 139 // increase the weight for convergence140 newWeight =oldPixel.y;150 // pixel valid => retrieve the convergence weight 151 w = 10.0f;//oldPixel.y; 141 152 } 142 153 else 143 154 { 144 newWeight= 0.0f;145 } 146 147 return float2( oldPixel.x, newWeight);155 w = 0.0f; 156 } 157 158 return float2(ssao, w); 148 159 } 149 160 … … 168 179 ) 169 180 { 170 // Check in a circular area around the current position.171 // Shoot vectors to the positions there, and check the angle to these positions.172 // Summing up these angles gives an estimation of the occlusion at the current position.173 174 181 float total_ao = .0f; 175 182 float numSamples = .0f; … … 198 205 const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 199 206 // the normal of the current sample 200 //const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz);201 207 const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 202 208 … … 218 224 cosAngle *= step(0.0f, dot(dirSample, normal)); 219 225 220 // the distance_scale offset is used to avoid singularity that occurs at global illumination when221 // the distance to a sample approaches zero222 //const float aoContrib = SAMPLE_INTENSITY / (DISTANCE_SCALE + lengthToSample * lengthToSample);223 226 const float aoContrib = SAMPLE_INTENSITY / sqrLen; 224 227 //const float aoContrib = (1.0f > lengthToSample) ? occlusionPower(9e-2f, DISTANCE_SCALE + lengthToSample): .0f; … … 248 251 This version of the ssao shader uses the dotproduct between 249 252 pixel-to-sample direction and sample normal as weight. 253 254 The algorithm works like the following: 255 1) Check in a circular area around the current position. 256 2) Shoot vectors to the positions there, and check the angle to these positions. 257 3) Summing up these angles gives an estimation of the occlusion at the current position. 250 258 */ 251 259 float3 ssao(fragment IN, … … 264 272 ) 265 273 { 266 // Check in a circular area around the current position.267 // Shoot vectors to the positions there, and check the angle to these positions.268 // Summing up these angles gives an estimation of the occlusion at the current position.269 270 274 float total_ao = .0f; 271 275 float validSamples = .0f; … … 278 282 #if 1 279 283 //////////////////// 280 //-- add random noise: reflect around random normal vector (rather slow!) 284 //-- add random noise: reflect around random normal vector 285 //-- (slows down the computation for some reason!) 281 286 282 287 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; … … 286 291 #endif 287 292 // weight with projected coordinate to reach similar kernel size for near and far 288 //const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor + jitter;289 293 const float2 texcoord = IN.texCoord.xy + offsetTransformed * scaleFactor; 290 294 … … 321 325 // hack: the distance measure can fail in some cases => choose something different 322 326 const float tooFarAway = step(1.0f, lengthToSample); 323 validSamples += (1.0f - tooFarAway) * sampleColor.x; 327 validSamples = max(validSamples, (1.0f - tooFarAway) * sampleColor.x); 328 324 329 //validSamples += sampleColor.x; 325 330 … … 327 332 328 333 //if ((validSamples < 1.0f) && (newWeight > 200) && (numSamples >= 8)) break; 329 if ((validSamples < 1.0f) && (numSamples >= 8)) break;334 //if ((validSamples < 1.0f) && (numSamples >= 8)) break; 330 335 } 331 336 … … 400 405 401 406 // cull background note: this should be done with the stencil buffer 402 //if (SqrLen(diffVec < 1e6f) && (eyeSpaceDepth < 1e10f))403 407 if (eyeSpaceDepth < 1e10f) 404 408 { … … 412 416 413 417 const float squaredLen = SqrLen(diffVec); 414 415 if ( (ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD))416 {418 /* 419 if (ao.y > 4.0f) oldWeight = 0; 420 else if ((ao.y > 1.0f) && (squaredLen < DYNAMIC_OBJECTS_THRESHOLD)) 417 421 oldWeight = min(oldWeight, 4.0f * NUM_SAMPLES); 418 } 419 422 */ 420 423 const float newWeight = ao.z; 421 424 422 425 // blend between old and new samples (and avoid division by zero) 423 426 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight) / max(1e-6f, (newWeight + oldWeight)); 424 OUT.illum_col.y = clamp(newWeight + oldWeight, .0f, temporalCoherence); 427 OUT.illum_col.y = oldWeight;//clamp(newWeight + oldWeight, .0f, temporalCoherence); 428 425 429 OUT.illum_col.z = SqrLen(diffVec); 426 430 OUT.illum_col.w = eyeSpaceDepth;
Note: See TracChangeset
for help on using the changeset viewer.