Changeset 3326 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Timestamp:
- 02/23/09 18:33:26 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3325 r3326 268 268 269 269 270 static void UpdateSampleTex(Sample2 *samples, int numSamples) 271 { 272 glEnable(GL_TEXTURE_2D); 273 glBindTexture(GL_TEXTURE_2D, sampleTex2D); 274 275 const int w = numSamples; const int h = 1; 276 277 float *tempBuffer = new float[numSamples * 3]; 278 279 for (int i = 0; i < numSamples; ++ i) 280 { 281 tempBuffer[i * 3 + 0] = samples[i].x; 282 tempBuffer[i * 3 + 1] = samples[i].y; 283 tempBuffer[i * 3 + 2] = 0; 284 285 } 286 287 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_FLOAT, (float *)tempBuffer); 288 289 glBindTexture(GL_TEXTURE_2D, 0); 290 glDisable(GL_TEXTURE_2D); 291 292 cout << "updated sample texture" << endl; 293 294 delete [] tempBuffer; 295 296 PrintGLerror("noisetexture"); 297 } 298 299 270 300 static void CreateSampleTex(Sample2 *samples, int numSamples) 271 301 { … … 279 309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 280 310 281 int w = numSamples; 282 int h = 1; 311 const int w = numSamples; const int h = 1; 283 312 284 313 float *tempBuffer = new float[numSamples * 3]; … … 506 535 507 536 string combineSsaoParams[] = 508 //{"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence"};509 537 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"}; 510 538 511 //sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 13);512 539 sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9); 513 540 … … 517 544 string filterSsaoParams[] = 518 545 {"colorsTex", "ssaoTex", "bl", "br", "tl", "tr", "res", "maxConvergence", "spatialWeight"}; 519 520 546 sCgFilterSsaoProgram->AddParameters(filterSsaoParams, 0, 9); 521 547 … … 549 575 550 576 string prepareSsaoParams[] = 551 {"colorsTex", "normalsTex", "diffVals", "oldTex", "oldTex2",577 {"colorsTex", "normalsTex", "diffVals", "oldTex", 552 578 "oldEyePos", "modelViewProj", "oldModelViewProj", 553 "oldbl", "oldbr", "oldtl", "oldtr"}; 554 579 "oldbl", "oldbr", "oldtl", "oldtr", "myTex"}; 555 580 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 12); 556 581 … … 673 698 // if it hasn't been done yet => just output the latest buffer 674 699 if (!mUseAntiAliasing || !displayAfterAA) 700 { 675 701 Output(fbo); 702 } 676 703 677 704 glEnable(GL_LIGHTING); … … 801 828 // needs longer to converge 802 829 GenerateSamples(mSamplingMethod); 803 CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 830 831 if (!sampleTex2D) 832 { 833 CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 834 } 835 else 836 { 837 UpdateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 838 } 839 804 840 //if (mSortSamples) { SortSamples(); } 805 841 //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); … … 936 972 // read the second buffer, write to the first buffer 937 973 mIllumFbo->Bind(); 938 939 974 glDrawBuffers(2, mrt + mIllumFboIndex); 940 975 976 // bind the old buffers for temporal coherence 941 977 GLuint oldSsaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 942 978 GLuint oldIllumTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); … … 1012 1048 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1013 1049 1014 //mIllumFbo->Bind();1015 //glDrawBuffers(1, mrt + mIllumFboIndex + 1);1016 1050 mTempFbo->Bind(); 1017 1051 glDrawBuffers(1, mrt); … … 1040 1074 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 1041 1075 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1042 //GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex + 1)->GetTexture();1043 1076 GLuint ssaoTex = mTempFbo->GetColorBuffer(0)->GetTexture(); 1044 1077 … … 1173 1206 // flip flop between illumination buffers 1174 1207 GLuint oldTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 1175 GLuint oldTex2= mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture();1208 GLuint myTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex + 1)->GetTexture(); 1176 1209 1177 1210 int i = 0; … … 1181 1214 sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 1182 1215 sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 1183 sCgPrepareSsaoProgram->SetTexture(i ++, oldTex2);1184 1216 1185 1217 Vector3 de; … … 1193 1225 sCgPrepareSsaoProgram->SetMatrix(i ++, mOldProjViewMatrix); 1194 1226 1227 1195 1228 for (int j = 0; j < 4; ++ j, ++ i) 1196 1229 { 1197 1230 sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 1198 1231 } 1232 1233 sCgPrepareSsaoProgram->SetTexture(i ++, myTex); 1199 1234 1200 1235 glPushAttrib(GL_VIEWPORT_BIT); … … 1244 1279 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 1245 1280 GLuint colorsTex = colorBuffer->GetTexture(); 1246 //FrameBufferObject::Release();1281 1247 1282 1248 1283 FlipFbos(fbo); … … 1272 1307 DrawQuad(sCgDownSampleProgram); 1273 1308 1274 PrintGLerror(" output");1309 PrintGLerror("Output"); 1275 1310 } 1276 1311 … … 1279 1314 { 1280 1315 for (int i = 0; i < 4; ++ i) 1316 { 1281 1317 mOldCornersView[i] = mCornersView[i]; 1318 } 1282 1319 1283 1320 mOldProjViewMatrix = mProjViewMatrix; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
r3114 r3326 153 153 */ 154 154 void Render(RenderState *state, SceneEntity *parent); 155 155 /** Adds a new technique to the material 156 */ 156 157 void AddTechnique(Technique *t); 157 158 /** Returns the default technique (usually the first) 159 */ 158 160 Technique *GetDefaultTechnique() const; 159 161 160 162 Technique *GetTechnique(int i) const; 161 163 /** Returns the number of techniques associated with this material 164 */ 162 165 int GetNumTechniques() const; 163 164 166 165 167 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3325 r3326 61 61 #define NUM_DOF_TABS 16 62 62 63 #define USE_GTX63 //#define USE_GTX 64 64 65 65 #define SSAO_FILTER_RADIUS 5 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
r3323 r3326 192 192 { 193 193 // the filtered ssao value 194 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);194 //OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight); 195 195 } 196 196 … … 223 223 const float convergence = ao.y; 224 224 225 const float2 xyStep = float2( 0, 1.0f / res.y);225 const float2 xyStep = float2(.0f, 1.0f / res.y); 226 226 227 227 // filter reaches size 1 pixel when sample size reaches threshold … … 232 232 { 233 233 // the filtered ssao value 234 ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight);234 //ao.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence, maxConvergence, spatialWeight); 235 235 } 236 236 … … 249 249 } 250 250 251 //OUT.illum_col.xyz = float3(col.w * 5e-3f, 0, 0); 252 OUT.illum_col.xyz = ao.xyz; 253 251 254 OUT.illum_col.w = col.w; 252 255 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3325 r3326 15 15 float4 color: COLOR0; 16 16 float3 normal: COLOR1; 17 float3 diffVal: COLOR2;17 //float3 diffVal: COLOR2; 18 18 }; 19 19 … … 37 37 float4 outColor; 38 38 39 // hack: prevent shadingthe sky39 // hack: prevent to shade the sky 40 40 if (color.w > DEPTH_THRESHOLD) 41 41 { … … 171 171 lightSpacePos /= lightSpacePos.w; 172 172 173 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex); 173 float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, 174 lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex); 174 175 diffuse *= shadowTerm; 175 176 } … … 209 210 */ 210 211 inline float2 PixelValid(sampler2D oldTex, 211 sampler2D oldTex2,212 212 float4 color, 213 213 float3 difVec, … … 220 220 float3 oldbr, 221 221 float3 oldtl, 222 float3 oldtr 222 float3 oldtr, 223 sampler2D myTex 223 224 ) 224 225 { … … 249 250 250 251 // fit from unit cube into 0 .. 1 251 const float2 oldTexCoords = backProjPos.xy * 0.5f + 0.5f;252 //const float2 oldTexCoords = texCoord;252 const float2 oldTexCoords = backProjPos.xy * .5f + .5f; 253 253 254 // retrieve the sample from the last frame 254 const float4 oldPixel = tex2Dlod( oldTex, float4(oldTexCoords, .0f, .0f));255 const float 4 oldPixel2 = tex2Dlod(oldTex2, float4(oldTexCoords, .0f, .0f));255 const float4 oldPixel = tex2Dlod(myTex, float4(oldTexCoords, .0f, .0f)); 256 const float oldDiff = tex2Dlod(oldTex, float4(oldTexCoords, .0f, .0f)).x; 256 257 257 258 // calculate eye space position of sample in old frame … … 266 267 const float squaredLen = SqrLen(difVec); 267 268 269 268 270 // test if this pixel was valid in the old frame 269 271 float isPixelValid; 270 272 271 273 // check if the pixel belonged to a dynamic object in the last frame 272 const bool newDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 273 const bool oldDynamic = (oldPixel2.x > DYNAMIC_OBJECTS_THRESHOLD); 274 const bool newDynamic = (squaredLen > 100000);//DYNAMIC_OBJECTS_THRESHOLD); 275 const bool oldDynamic = (oldDiff > 1000000);//DYNAMIC_OBJECTS_THRESHOLD); 276 274 277 275 278 // actually 0 means pixel is valid 276 const float pixelIsValid = 0.0f;279 const float pixelIsValid = .0f; 277 280 // means that we only use slight temporal coherence over some frames 278 281 // so that there is no noticeable drag … … 281 284 const float pixelIsNotValid = 100.0f; 282 285 286 283 287 // check if the pixel was outside of the frame buffer 284 if ((oldTexCoords.x <= 0) || (oldTexCoords.x >= 1.0f) ||285 (oldTexCoords.y <= 0) || (oldTexCoords.y >= 1.0f)288 if ((oldTexCoords.x <= .0f) || (oldTexCoords.x >= 1.0f) || 289 (oldTexCoords.y <= .0f) || (oldTexCoords.y >= 1.0f) 286 290 ) 287 291 { 288 292 isPixelValid = pixelIsNotValid; 289 293 } 290 else if (// check if changed from dynamic to not dynamic object 291 ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 292 ( 293 (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) && 294 // check if we have a dynamic object 295 (oldDynamic || newDynamic) && 296 // and there is a depth discontinuity 297 (depthDif > MIN_DEPTH_DIFF)))) 294 else if ( // check if changed from dynamic to not dynamic object 295 ((oldDynamic && !newDynamic) || (!oldDynamic && newDynamic) || 296 ( 297 (oldEyeSpaceDepth < DEPTH_THRESHOLD) && (projectedEyeSpaceDepth < DEPTH_THRESHOLD) && 298 (oldDynamic || newDynamic) && // check if we have a dynamic object 299 (depthDif > MIN_DEPTH_DIFF)))) // and there is a depth discontinuity 298 300 { 299 isPixelValid = pixelCouldBeValid; 301 isPixelValid = pixelCouldBeValid; 300 302 } 301 303 else … … 303 305 isPixelValid = pixelIsValid; 304 306 } 305 307 308 //isPixelValid = 2e20f; 306 309 return float2(isPixelValid, abs(oldEyeSpaceDepth - projectedEyeSpaceDepth)); 307 310 } … … 312 315 */ 313 316 pixel PrepareSsao(fragment IN, 314 315 316 317 318 uniform sampler2D oldTex2,319 uniform float4x4 modelViewProj,320 uniform float4x4 oldModelViewProj,321 uniform float3 oldbl,322 uniform float3 oldbr,323 uniform float3 oldtl,324 uniform float3 oldtr,325 uniform float3 oldEyePos326 317 uniform sampler2D colorsTex, 318 uniform sampler2D normalsTex, 319 uniform sampler2D diffVals, 320 uniform sampler2D oldTex, 321 uniform float4x4 modelViewProj, 322 uniform float4x4 oldModelViewProj, 323 uniform float3 oldbl, 324 uniform float3 oldbr, 325 uniform float3 oldtl, 326 uniform float3 oldtr, 327 uniform float3 oldEyePos, 328 uniform sampler2D myTex 329 ) 327 330 { 328 331 pixel pix; 329 332 330 float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));333 float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, .0f, .0f)); 331 334 // store scaled view vector so wie don't have to normalize for e.g., ssao 332 335 color.w /= length(IN.view); … … 337 340 338 341 // do reprojection and filter out the pixels that are not save 339 float2 pValid = PixelValid(oldTex,340 oldTex2,341 color,342 difVec.xyz,343 IN.texCoord,344 IN.view,345 oldEyePos,346 modelViewProj,347 oldModelViewProj,348 oldbl, oldbr, oldtl, oldtr349 342 const float2 pValid = PixelValid(oldTex, 343 color, 344 difVec.xyz, 345 IN.texCoord, 346 IN.view, 347 oldEyePos, 348 modelViewProj, 349 oldModelViewProj, 350 oldbl, oldbr, oldtl, oldtr, 351 myTex 352 ); 350 353 351 354 pix.color = color; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3325 r3326 273 273 // to the current pixel or if the angle is small enough 274 274 // to have any influence in the current or last frame 275 #if 1275 #if 0 276 276 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 277 277 … … 281 281 else 282 282 validSamples = max(validSamples, pixelValid); 283 #else284 validSamples = max(validSamples, pixelValid);285 283 #endif 286 284 … … 408 406 // or if the angle is small enough 409 407 // to have any influence in the current or last frame 410 #if 1408 #if 0 411 409 const float partlyResetThres = 1.0f; 412 410 … … 416 414 else 417 415 validSamples = max(validSamples, pixelValid); 418 #else419 validSamples = max(validSamples, pixelValid);420 416 #endif 421 417 … … 523 519 if (eyeSpaceDepth < DEPTH_THRESHOLD) 524 520 { 525 //ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 526 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx); 521 if (0) 522 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 523 else 524 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, 525 bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, 526 isMovingObject, normals, oldIdx); 527 527 } 528 528 else … … 545 545 546 546 // don't check for moving objects, otherwise almost no coherence 547 if (!isMovingObject)547 /*if (!isMovingObject) 548 548 { 549 549 if (ao.y > completelyResetThres) … … 558 558 oldIdx = .0f; 559 559 } 560 } 560 }*/ 561 561 562 562 563 ////////// … … 573 574 OUT.illum_col.w = eyeSpaceDepth; 574 575 575 // can be used to check if this pixel belongs to a moving object576 // this value can be used to check if this pixel belongs to a moving object 576 577 OUT.col.x = SqrLen(diffVec); 577 578 //OUT.illum_col.z = SqrLen(diffVec); 578 579 580 OUT.illum_col.xyz = normal.xyz; 579 581 return OUT; 580 582 }
Note: See TracChangeset
for help on using the changeset viewer.