Changeset 3324 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 02/20/09 19:26:13 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3322 r3324 71 71 static GLuint noiseTex2D = 0; 72 72 static GLuint noiseTex1D = 0; 73 74 73 static GLuint sampleTex2D = 0; 74 75 76 static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 75 77 // ssao random spherical samples 76 static Sample2 samples2[NUM_SAMPLES]; 77 //#define NUM_PRECOMPUTED_SAMPLES 240 78 //static Sample2 samples2[NUM_PRECOMPUTED_SAMPLES]; 78 //static Sample2 samples2[NUM_SAMPLES]; 79 79 80 // pcf samples 80 81 static Sample2 pcfSamples[NUM_PCF_TABS]; … … 212 213 case DeferredRenderer::SAMPLING_QUADRATIC: 213 214 { 214 //staticQuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f);215 QuadraticDiscSampleGenerator2D g(NUM_PRECOMPUTED_SAMPLES, 1.0f); 215 216 //static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f); 216 static QuadraticDiscSampleGenerator2D g(NUM_SAMPLES, 1.0f);217 217 g.Generate((float *)samples2); 218 218 } … … 263 263 264 264 cout << "created noise texture" << endl; 265 266 PrintGLerror("noisetexture"); 267 } 268 269 270 static void CreateSampleTex(Sample2 *samples, int numSamples) 271 { 272 glEnable(GL_TEXTURE_2D); 273 glGenTextures(1, &sampleTex2D); 274 glBindTexture(GL_TEXTURE_2D, sampleTex2D); 275 276 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 279 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 280 281 int w = numSamples; 282 int h = 1; 283 284 float *tempBuffer = new float[numSamples * 3]; 285 286 for (int i = 0; i < numSamples; ++ i) 287 { 288 tempBuffer[i * 3 + 0] = samples[i].x; 289 tempBuffer[i * 3 + 1] = samples[i].y; 290 tempBuffer[i * 3 + 2] = 0; 291 292 } 293 294 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, w, h, 0, GL_RGB, GL_FLOAT, (float *)tempBuffer); 295 296 glBindTexture(GL_TEXTURE_2D, 0); 297 glDisable(GL_TEXTURE_2D); 298 299 cout << "created sample texture" << endl; 300 301 delete [] tempBuffer; 265 302 266 303 PrintGLerror("noisetexture"); … … 439 476 "modelViewProj", "oldModelViewProj", "oldEyePos", "oldbl", "oldbr", 440 477 "oldtl", "oldtr", "attribsTex", "kernelRadius", "sampleIntensity"}; 478 441 479 sCgSsaoProgram->AddParameters(ssaoParams, 0, 20); 442 480 … … 751 789 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 752 790 753 static int currentPos = 0; 754 755 if (mUseTemporalCoherence || mRegenerateSamples) 791 if (/*mUseTemporalCoherence || */mRegenerateSamples) 756 792 { 757 793 mRegenerateSamples = false; … … 760 796 // in the first case, the sample patterns look nicer, but the kernel 761 797 // needs longer to converge 762 //if (currentPos + NUM_SAMPLES >= NUM_PRECOMPUTED_SAMPLES) { 763 currentPos = 0; 764 GenerateSamples(mSamplingMethod); 765 //} 766 798 GenerateSamples(mSamplingMethod); 799 CreateSampleTex(samples2, NUM_PRECOMPUTED_SAMPLES); 767 800 //if (mSortSamples) { SortSamples(); } 768 sCgSsaoProgram->SetArray2f(i, (float *)samples2 + currentPos, NUM_SAMPLES);769 770 currentPos += NUM_SAMPLES;801 //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 802 //sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_PRECOMPUTED_SAMPLES); 803 sCgSsaoProgram->SetTexture(i, sampleTex2D); 771 804 } 772 805 … … 774 807 775 808 for (int j = 0; j < 4; ++ j, ++ i) 809 { 776 810 sCgSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 811 } 777 812 778 813 sCgSsaoProgram->SetMatrix(i ++, mProjViewMatrix); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3323 r3324 5 5 //////////// 6 6 //-- ssao + gi parameters 7 7 #define NUM_PRECOMPUTED_SAMPLES 4096 8 8 //#define NUM_SAMPLES 8 9 9 //#define NUM_SAMPLES 16 10 10 //#define NUM_SAMPLES 24 11 #define NUM_SAMPLES 2411 #define NUM_SAMPLES 48 12 12 13 13 //#define MIN_SAMPLES 48 14 #define MIN_SAMPLES 2414 #define MIN_SAMPLES 8 15 15 16 16 #define DISTANCE_SCALE 1e-2f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3313 r3324 263 263 264 264 // check if the pixel belonged to a dyanmic object in the last frame 265 const bool oldDynamic = (squaredLen > DYNAMIC_OBJECTS_THRESHOLD);266 const bool newDynamic = (oldPixel.z > DYNAMIC_OBJECTS_THRESHOLD);265 const bool oldDynamic = false;(squaredLen > DYNAMIC_OBJECTS_THRESHOLD); 266 const bool newDynamic = false; (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 sino noticeable drag271 // so that there is 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 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)) 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) 281 279 ) 282 280 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3322 r3324 77 77 weight of the pixel in the new frame. 78 78 */ 79 inline float 2Reproject(float4 worldPos,80 81 82 83 84 85 86 87 88 89 90 91 92 93 79 inline float3 Reproject(float4 worldPos, 80 float eyeSpaceDepth, 81 float2 texcoord0, 82 float3 oldEyePos, 83 sampler2D oldTex, 84 float4x4 oldModelViewProj, 85 sampler2D colors, 86 float3 projPos, 87 float invW, 88 float3 oldbl, 89 float3 oldbr, 90 float3 oldtl, 91 float3 oldtr, 92 float3 diffVec 93 ) 94 94 { 95 95 // compute position from old frame for dynamic objects + translational portion … … 125 125 // the weight of the accumulated samples from the previous frames 126 126 float w; 127 128 float idx = oldPixel.z; 127 129 128 130 ////////////// … … 151 153 } 152 154 153 return float 2(ssao, w);155 return float3(ssao, w, idx); 154 156 } 155 157 … … 167 169 sampler2D colors, 168 170 sampler2D noiseTex, 169 float2 samples[NUM_SAMPLES],171 sampler2D samples, 170 172 float3 normal, 171 173 float3 centerPosition, … … 179 181 float sampleIntensity, 180 182 bool isMovingObject, 181 sampler2D normalTex 183 sampler2D normalTex, 184 int idx 182 185 ) 183 186 { … … 190 193 float2 offset; 191 194 195 const float2 ssaoOffset = tex2Dlod(samples, float4((0.5f + i + idx) / NUM_PRECOMPUTED_SAMPLES, 0.5f, .0f, .0f)).xy; 196 197 192 198 //////////////////// 193 199 //-- add random noise: reflect around random normal vector 194 200 //-- (affects performance for some reason!) 195 201 196 if ( 1)//convergence < SSAO_CONVERGENCE_THRESHOLD)202 if (convergence < SSAO_CONVERGENCE_THRESHOLD) 197 203 { 198 204 float2 mynoise = tex2Dlod(noiseTex, float4(IN.texCoord * 4.0f, 0, 0)).xy; 199 205 //offset = myreflect(samples[i], mynoise); 200 offset = myrotate(samples[i], mynoise.x); 206 //offset = myrotate(samples[i], mynoise.x); 207 offset = myrotate(ssaoOffset, mynoise.x); 201 208 } 202 209 else 203 210 { 204 offset = s amples[i];211 offset = ssaoOffset; 205 212 } 206 213 … … 441 448 uniform sampler2D normals, 442 449 uniform sampler2D noiseTex, 443 uniform float2 samples[NUM_SAMPLES],450 uniform sampler2D samples, 444 451 uniform sampler2D oldTex, 445 452 uniform float4x4 modelViewProj, … … 488 495 //-- compute temporal reprojection 489 496 490 float 2temporalVals = Reproject(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos,497 float3 temporalVals = Reproject(eyeSpacePos, eyeSpaceDepth, IN.texCoord, oldEyePos, 491 498 oldTex, oldModelViewProj, 492 499 colors, … … 499 506 const float oldSsao = temporalVals.x; 500 507 float oldWeight = temporalVals.y; 501 508 float oldIdx = temporalVals.z; 509 502 510 float3 ao; 503 511 … … 506 514 { 507 515 //ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject); 508 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals );516 ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), oldWeight, sampleIntensity, isMovingObject, normals, oldIdx); 509 517 //ao = ssao2(IN, colors, noiseTex, samples, normal, eyeSpacePos.xyz, scaleFactor, bl, br, tl, tr, normalize(viewDir), normals, sampleIntensity); 510 518 } … … 552 560 OUT.illum_col.y = combinedWeight; 553 561 // can be used to check if this pixel belongs to a moving object 554 OUT.illum_col.z = SqrLen(diffVec); 562 //OUT.illum_col.z = SqrLen(diffVec); 563 OUT.illum_col.z = oldIdx + newWeight; 555 564 OUT.illum_col.w = eyeSpaceDepth; 556 565
Note: See TracChangeset
for help on using the changeset viewer.