Changeset 3313
- Timestamp:
- 02/16/09 17:08:51 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/sibenik.env
r3312 r3313 106 106 ssaoSampleIntensity=0.8f 107 107 # ssao temporal coherence factor 108 tempCohFactor=20 48.0f108 tempCohFactor=2000.0f 109 109 # ssao filter radius 110 110 ssaoFilterRadius=12.0f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3311 r3313 71 71 static GLuint noiseTex2D = 0; 72 72 static GLuint noiseTex1D = 0; 73 static GLuint sampleTex2D = 0; 74 75 76 static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 73 74 77 75 // ssao random spherical samples 78 //static Sample2 samples2[NUM_SAMPLES]; 79 76 static Sample2 samples2[NUM_SAMPLES]; 77 //#define NUM_PRECOMPUTED_SAMPLES 240 78 //static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 80 79 // pcf samples 81 80 static Sample2 pcfSamples[NUM_PCF_TABS]; … … 92 91 /** Helper method that computes the view vectors in the corners of the current view frustum. 93 92 */ 94 static void ComputeViewVectors(PerspectiveCamera *cam, 95 Vector3 &bl, 96 Vector3 &br, 97 Vector3 &tl, 98 Vector3 &tr) 93 static void ComputeViewVectors(PerspectiveCamera *cam, Vector3 &bl, Vector3 &br, Vector3 &tl, Vector3 &tr) 99 94 { 100 95 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; … … 212 207 case DeferredRenderer::SAMPLING_QUADRATIC: 213 208 { 214 QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);215 //static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);209 //static QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f); 210 static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 216 211 g.Generate((float *)samples2); 217 212 } … … 262 257 263 258 cout << "created noise texture" << endl; 264 265 PrintGLerror("noisetexture");266 }267 268 269 static void CreateSampleTex(Sample2 *samples, int numSamples)270 {271 glEnable(GL_TEXTURE_2D);272 glGenTextures(1, &sampleTex2D);273 glBindTexture(GL_TEXTURE_2D, sampleTex2D);274 275 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);276 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);279 280 int w = numSamples;281 int h = 1;282 283 float *tempBuffer = new float[numSamples * 3];284 285 for (int i = 0; i < numSamples; ++ i)286 {287 tempBuffer[i * 3 + 0] = samples[i].x;288 tempBuffer[i * 3 + 1] = samples[i].y;289 tempBuffer[i * 3 + 2] = 0;290 291 }292 293 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, w, h, 0, GL_RGB, GL_FLOAT, (float *)tempBuffer);294 295 glBindTexture(GL_TEXTURE_2D, 0);296 glDisable(GL_TEXTURE_2D);297 298 cout << "created sample texture" << endl;299 300 delete [] tempBuffer;301 259 302 260 PrintGLerror("noisetexture"); … … 469 427 470 428 string ssaoParams[] = 471 429 {"colors", "normals", "oldTex", "noiseTex", "temporalCoherence", 472 430 "samples", "bl", "br", "tl", "tr", 473 431 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 474 432 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"}; 475 476 433 sCgSsaoProgram->AddParameters(ssaoParams, 0, 20); 477 434 … … 783 740 sCgSsaoProgram->SetTexture(i ++, noiseTex2D); 784 741 785 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : .0f); 786 787 if (/*mUseTemporalCoherence || */mRegenerateSamples) 742 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 743 744 static int currentPos = 0; 745 746 if (mUseTemporalCoherence || mRegenerateSamples) 788 747 { 789 748 mRegenerateSamples = false; … … 792 751 // in the first case, the sample patterns look nicer, but the kernel 793 752 // needs longer to converge 794 GenerateSamples(mSamplingMethod); 795 CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 753 //if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES) { 754 currentPos = 0; 755 GenerateSamples(mSamplingMethod); 756 //} 757 796 758 //if (mSortSamples) { SortSamples(); } 797 //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 798 //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES); 799 sCgSsaoProgram->SetTexture(i, sampleTex2D); 800 } 801 802 759 sCgSsaoProgram->SetArray2f(i, (float *)samples2 + currentPos, NUM_SAMPLES); 760 761 currentPos += NUM_SAMPLES; 762 } 763 803 764 ++ i; 804 765 805 766 for (int j = 0; j < 4; ++ j, ++ i) 806 {807 767 sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 808 }809 768 810 769 sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix); … … 815 774 de.y = mOldEyePos.y - mEyePos.y; 816 775 de.z = mOldEyePos.z - mEyePos.z; 817 818 776 819 777 sCgSsaoProgram->SetValue3f(i ++, de.x, de.y, de.z); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
r3311 r3313 51 51 int tries = 0; 52 52 53 cout << "minDist before= " << minDist << endl;53 //cout << "minDist before= " << minDist << endl; 54 54 Sample2 *s = (Sample2 *)samples; 55 55 … … 109 109 } 110 110 111 cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;111 //cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl; 112 112 } 113 113 … … 172 172 173 173 QuadraticDiscSampleGenerator2D::QuadraticDiscSampleGenerator2D(int numSamples, float radius): 174 PoissonDiscSampleGenerator2D(numSamples, radius)175 //RandomSampleGenerator2D(numSamples, radius)174 //PoissonDiscSampleGenerator2D(numSamples, radius) 175 RandomSampleGenerator2D(numSamples, radius) 176 176 {} 177 177 … … 194 194 #else 195 195 196 PoissonDiscSampleGenerator2D::Generate(samples);197 //RandomSampleGenerator2D::Generate(samples);196 //PoissonDiscSampleGenerator2D::Generate(samples); 197 RandomSampleGenerator2D::Generate(samples); 198 198 199 199 Sample2 *s = (Sample2 *)samples; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h
r3311 r3313 78 78 with the distance 79 79 */ 80 class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D81 //class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D80 //class QuadraticDiscSampleGenerator2D: public PoissonDiscSampleGenerator2D 81 class QuadraticDiscSampleGenerator2D: public RandomSampleGenerator2D 82 82 { 83 83 public: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3311 r3313 1211 1211 if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView)) 1212 1212 { 1213 if (!shadowMap) shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera); 1214 if (!shadowTraverser) shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera()); 1213 if (!shadowMap) 1214 shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera); 1215 1216 if (!shadowTraverser) 1217 shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera()); 1218 1215 1219 } 1216 1220 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3312 r3313 5 5 //////////// 6 6 //-- ssao + gi parameters 7 #define NUM_PRECOMPUTED_SAMPLES 2048 7 8 8 //#define NUM_SAMPLES 8 9 9 //#define NUM_SAMPLES 16 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
r3311 r3313 114 114 } 115 115 116 /** In between step that only filters in one direction 117 */ 118 pixel FilterSsaoFullRes(fragment IN, 119 uniform sampler2D colorsTex, 120 uniform sampler2D ssaoTex, 121 uniform float3 bl, 122 uniform float3 br, 123 uniform float3 tl, 124 uniform float3 tr, 125 uniform float2 res 126 ) 127 { 128 pixel OUT; 129 130 const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w; 131 132 OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 133 // just take unfiltered convergence in current pixel 134 const float convergence = OUT.illum_col.y; 135 136 // filter reaches size 1 pixel when sample size reaches threshold 137 // afterwards we do not use the filter anymore 138 139 float2 xyStep = float2(1.0f / res.x, 0); 140 141 // filter up to a certain convergance value and leave out background (sky) by checking depth 142 if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD)) 143 { 144 // the filtered ssao value 145 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence); 146 } 147 148 return OUT; 149 } 116 150 117 151 /** In between step that only filters in one direction … … 151 185 } 152 186 153 154 /** In between step that only filters in one direction155 */156 pixel FilterSsaoFullRes(fragment IN,157 uniform sampler2D colorsTex,158 uniform sampler2D ssaoTex,159 uniform float3 bl,160 uniform float3 br,161 uniform float3 tl,162 uniform float3 tr,163 uniform float2 res164 )165 {166 pixel OUT;167 168 const float depth = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)).w;169 170 OUT.illum_col = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));171 // just take unfiltered convergence in current pixel172 const float convergence = OUT.illum_col.y;173 174 // filter reaches size 1 pixel when sample size reaches threshold175 // afterwards we do not use the filter anymore176 177 const float2 xyStep = float2(1.0f / res.x, 0);178 179 // filter up to a certain convergance value and leave out background (sky) by checking depth180 if ((convergence < SSAO_CONVERGENCE_THRESHOLD) && (depth < DEPTH_THRESHOLD))181 {182 // the filtered ssao value183 OUT.illum_col.x = FilterXY(IN.texCoord, ssaoTex, colorsTex, bl, br, tl, tr, xyStep, convergence);184 }185 186 return OUT;187 }188 189 190 187 /** Function combining image and indirect illumination buffer using a 191 188 depth and convergence aware discontinuity filter. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3311 r3313 263 263 264 264 // check if the pixel belonged to a dyanmic object in the last frame 265 const bool newDynamic = false;//(squaredLen > DYNAMIC_OBJECTS_THRESHOLD);266 const bool oldDynamic = false;//(oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);265 const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 266 const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD); 267 267 268 268 // actually 0 means pixel is valid 269 269 const float pixelIsValid = 0.0f; 270 270 // means that we only use slight temporal coherence over some frames 271 // so that there isno noticeable drag271 // so that there si no noticeable drag 272 272 const float pixelCouldBeValid = 2.0f; 273 273 // this pixel information has to be discarded in order to not create artifacts 274 274 const float pixelIsNotValid = 100.0f; 275 275 276 // check if the pixel was outside of the frame buffer 277 if ((oldTexCoords.x <= 0) || (oldTexCoords.x >= 1.0f) || 278 (oldTexCoords.y <= 0) || (oldTexCoords.y >= 1.0f) 276 const float xOffs = 0;// 0.5f / 1024.0f; 277 const float yOffs = 0;// 0.5f / 768.0f; 278 279 if ((oldTexCoords.x < xOffs) || (oldTexCoords.x > (1.0f - xOffs)) || 280 (oldTexCoords.y < yOffs) || (oldTexCoords.y > (1.0f - yOffs)) 279 281 ) 280 282 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3311 r3313 48 48 weight of the pixel in the new frame. 49 49 */ 50 inline float 3temporalSmoothing(float4 worldPos,50 inline float2 temporalSmoothing(float4 worldPos, 51 51 float eyeSpaceDepth, 52 52 float2 texcoord0, … … 96 96 // the weight of the accumulated samples from the previous frames 97 97 float w; 98 float idx;99 98 100 99 ////////////// … … 109 108 // pixel valid => retrieve the convergence weight 110 109 w = oldPixel.y; 111 idx = oldPixel.z;112 110 } 113 111 else 114 112 { 115 w = .0f; 116 idx = .0f; 117 } 118 119 return float3(ssao, w, idx); 113 w = 0.0f; 114 } 115 116 return float2(ssao, w); 120 117 } 121 118 … … 145 142 float validSamples = .0f; 146 143 147 148 for (int i = 0; i < NUM_PRECOMPUTED_SAMPLES; ++ i) 144 for (int i = 0; i < NUM_SAMPLES; ++ i) 149 145 { 150 146 const float2 offset = samples[i]; … … 224 220 sampler2D colors, 225 221 sampler2D noiseTex, 226 sampler2D samples,222 float2 samples[NUM_SAMPLES], 227 223 float3 normal, 228 224 float3 centerPosition, … … 235 231 float convergence, 236 232 float sampleIntensity, 237 bool isMovingObject, 238 float idx 233 bool isMovingObject 239 234 ) 240 235 { … … 242 237 float validSamples = .0f; 243 238 float numSamples = .0f; 244 239 245 240 for (int i = 0; i < NUM_SAMPLES; ++ i) 246 241 { … … 251 246 //-- (affects performance for some reason!) 252 247 253 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy;254 255 248 if (convergence < SSAO_CONVERGENCE_THRESHOLD) 256 249 { 257 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord .x * 4.0f + idx * 0.01f, IN.texCoord.y* 4.0f, 0, 0)).xy;250 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 258 251 //offset = myreflect(samples[i], mynoise); 259 //offset = myrotate(samples[i], mynoise.x); 260 261 offset = myrotate(ssaoOffset, mynoise.x); 252 offset = myrotate(samples[i], mynoise.x); 262 253 } 263 254 else 264 255 { 265 offset = ssaoOffset; 266 //offset = samples[i]; 256 offset = samples[i]; 267 257 } 268 258 … … 304 294 // we check if the sample could have been near enough to the current pixel 305 295 // to have any influence in the current or last frame 306 //const float tooFarAway = step(0.5f, lengthToSample - changeFactor);296 const float tooFarAway = step(0.5f, lengthToSample - changeFactor); 307 297 //validSamples = max(validSamples, (1.0f - tooFarAway) * pixelValid * step(-0.1f, cosAngle)); 308 298 validSamples = max(validSamples, pixelValid); … … 313 303 if (numSamples >= MIN_SAMPLES) 314 304 { 305 //break; 315 306 // if the pixel belongs to a static object and all the samples stay valid in the current frame 316 307 if (!isMovingObject && (validSamples < 1.0f)) break; 317 // if the pixel belongs to a dynamic object but the #accumulated samples 318 // for this pixel is sufficiently high(=> there was no discontinuity recently)308 // if the pixel belongs to a dynamic object but the #accumulated samples for this pixel is sufficiently high 309 // (=> there was no discontinuity recently) 319 310 else if (isMovingObject && (convergence > NUM_SAMPLES * 5)) break; 320 311 } … … 344 335 uniform sampler2D normals, 345 336 uniform sampler2D noiseTex, 346 uniform sampler2D samples,337 uniform float2 samples[NUM_SAMPLES], 347 338 uniform sampler2D oldTex, 348 339 uniform float4x4 modelViewProj, … … 391 382 //-- compute temporal reprojection 392 383 393 float 3temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,384 float2 temporalVals = temporalSmoothing(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 394 385 oldTex, oldModelViewProj, 395 386 colors, … … 402 393 const float oldSsao = temporalVals.x; 403 394 float oldWeight = temporalVals.y; 404 405 float idx = (int)temporalVals.z; 406 407 if (idx >= NUM_PRECOMPUTED_SAMPLES) idx = 0; 408 395 409 396 float3 ao; 410 397 … … 412 399 if (eyeSpaceDepth < DEPTH_THRESHOLD) 413 400 { 414 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, 415 scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, 416 sampleIntensity, isMovingObject, idx); 401 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 417 402 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 418 403 } … … 429 414 // the weight equals the number of sampled shot in this pass 430 415 const float newWeight = ao.z; 431 432 idx += newWeight;433 416 434 417 // completely reset the ao in this pixel … … 437 420 const float partlyResetThres = 1.0f; 438 421 439 // hack: just update static geometry 440 if (!isMovingObject) 422 if (1)//!isMovingObject) 441 423 { 442 424 if (ao.y > completelyResetThres) 443 425 { 444 oldWeight = .0f; 445 idx = .0f; 426 oldWeight = .0f; 446 427 } 447 428 else if (ao.y > partlyResetThres) 448 429 { 449 430 oldWeight = min(oldWeight, 4.0f * newWeight); 431 //oldWeight = .0f; 450 432 } 451 433 } 452 453 434 454 435 ////////// 455 436 //-- blend ao between old and new samples (and avoid division by zero) 456 437 457 OUT.illum_col.x = ao.x * newWeight + oldSsao * oldWeight; 438 OUT.illum_col.x = (ao.x * newWeight + oldSsao * oldWeight);// / (newWeight + oldWeight);//max(1e-6f, newWeight + oldWeight); 439 458 440 OUT.illum_col.x /= (newWeight + oldWeight); 459 441 460 442 // the new weight for the next frame 461 443 const float combinedWeight = clamp(newWeight + oldWeight, .0f, temporalCoherence); 462 444 463 445 OUT.illum_col.y = combinedWeight; 464 446 // can be used to check if this pixel belongs to a moving object 465 //OUT.illum_col.z = SqrLen(diffVec); 466 OUT.illum_col.z = idx; 447 OUT.illum_col.z = SqrLen(diffVec); 467 448 OUT.illum_col.w = eyeSpaceDepth; 468 449
Note: See TracChangeset
for help on using the changeset viewer.