Changeset 3167 for GTP/trunk/App/Demos/Vis
- Timestamp:
- 11/25/08 18:14:48 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3166 r3167 71 71 72 72 73 static float ssaoFilterOffsets[NUM_SSAO_FILTER SAMPLES * 2];74 static float ssaoFilterWeights[NUM_SSAO_FILTER SAMPLES];73 static float ssaoFilterOffsets[NUM_SSAO_FILTER_SAMPLES * 2]; 74 static float ssaoFilterWeights[NUM_SSAO_FILTER_SAMPLES]; 75 75 76 76 … … 445 445 446 446 string prepareSsaoParams[] = 447 {"colorsTex", "oldTex", "oldEyePos", "modelViewProj", "oldModelViewProj", 448 "oldbl", "oldbr", "oldtl", "oldtr", "diffVals"}; 449 450 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 10); 447 {"colorsTex", "normalsTex", "diffVals", "oldTex", 448 "oldEyePos", "modelViewProj", "oldModelViewProj", 449 "oldbl", "oldbr", "oldtl", "oldtr"}; 450 451 sCgPrepareSsaoProgram->AddParameters(prepareSsaoParams, 0, 11); 451 452 452 453 453 454 //////////////// 454 455 455 456 //const float filterWidth = 100.0f; 457 const float filterWidth = 30.0f; 458 //const float filterWidth = 15.0f; 459 460 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 456 const float filterWidth = 1.0f; 457 458 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTER_SAMPLES, 1.0f); 461 459 poisson.Generate((float *)ssaoFilterOffsets); 462 460 … … 464 462 const float yoffs = (float)filterWidth / mHeight; 465 463 466 for (int i = 0; i < NUM_SSAO_FILTER SAMPLES; ++ i)464 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 467 465 { 468 466 float x = ssaoFilterOffsets[2 * i + 0]; … … 516 514 //DownSample(fbo, colorBufferIdx, mDownSampleFbo, 0, sCgScaleDepthProgram); 517 515 PrepareSsao(fbo); 518 DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals519 DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets516 //DownSample(fbo, 1, mDownSampleFbo, 1, sCgDownSampleProgram); // normals 517 //DownSample(fbo, 2, mDownSampleFbo, 2, sCgDownSampleProgram); // offsets 520 518 } 521 519 … … 570 568 571 569 570 571 static inline float SqrMag(const Sample2 &s) 572 { 573 return (s.x * s.x + s.y * s.y); 574 } 575 576 577 static inline float SqrDist(const Sample2 &a, const Sample2 &b) 578 { 579 float x = a.x - b.x; 580 float y = a.y - b.y; 581 582 return x * x + y * y; 583 } 584 585 586 static inline bool lt(const Sample2 &a, const Sample2 &b) 587 { 588 return SqrMag(a) < SqrMag(b); 589 } 590 591 592 void DeferredRenderer::SortSamples() 593 { 594 //for (int i = 0; i < NUM_SAMPLES; ++ i)cout << SqrDist(samples2[i-1], samples2[i]) << "|"; 595 float dist = 0; 596 for (int i = 1; i < NUM_SAMPLES; ++ i) 597 dist += SqrDist(samples2[i-1], samples2[i]); 598 //cout << samples2[i].x << " " << samples2[i].y 599 600 //cout << "\nbefore: " << dist << endl; 601 602 //sort(samples2, samples2 + sizeof(samples2) / sizeof(Sample2), lt2); 603 604 605 static Sample2 tempSamples[NUM_SAMPLES]; 606 static bool checked[NUM_SAMPLES]; 607 608 for (int i = 0; i < NUM_SAMPLES; ++ i) 609 checked[i] = false; 610 611 Sample2 currentSample; 612 currentSample.x = 0; currentSample.y = 0; 613 int ns = 0; // the next sample index 614 615 for (int i = 0; i < NUM_SAMPLES; ++ i) 616 { 617 float minLen = 1e20f; 618 619 for (int j = 0; j < NUM_SAMPLES; ++ j) 620 { 621 if (checked[j]) continue; 622 623 Sample2 s = samples2[j]; 624 const float len = SqrDist(s, currentSample); 625 626 if (len < minLen) 627 { 628 minLen = len; 629 ns = j; 630 } 631 } 632 633 tempSamples[i] = samples2[ns]; 634 currentSample = samples2[ns]; 635 checked[ns] = true; 636 } 637 638 for (int i = 0; i < NUM_SAMPLES; ++ i) 639 samples2[i] = tempSamples[i]; 640 641 dist = 0; 642 for (int i = 1; i < NUM_SAMPLES; ++ i) 643 dist += SqrDist(samples2[i-1], samples2[i]); 644 //cout << samples2[i].x << " " << samples2[i].y << " " << SqrDist(samples2[i-1], samples2[i]) << "|"; 645 646 //cout << "after: " << dist << endl; 647 } 648 649 572 650 void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo, 573 651 float tempCohFactor) … … 616 694 // needs longer to converge 617 695 GenerateSamples(mSamplingMethod); 696 697 SortSamples(); 618 698 sCgSsaoProgram->SetArray2f(i, (float *)samples2, NUM_SAMPLES); 619 699 } … … 821 901 sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 822 902 823 sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER SAMPLES);824 sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER SAMPLES);903 sCgCombineSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTER_SAMPLES); 904 sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTER_SAMPLES); 825 905 826 906 sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix); … … 957 1037 void DeferredRenderer::PrepareSsao(FrameBufferObject *fbo) 958 1038 { 959 GLuint colorsTex, diffVals, oldTex;1039 GLuint colorsTex, normalsTex, diffVals, oldTex; 960 1040 961 1041 colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 962 //normalsTex = fbo->GetColorBuffer(1)->GetTexture();1042 normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 963 1043 diffVals = fbo->GetColorBuffer(2)->GetTexture(); 964 1044 //diffVals = mDownSampleFbo->GetColorBuffer(2)->GetTexture(); … … 970 1050 971 1051 sCgPrepareSsaoProgram->SetTexture(i ++, colorsTex); 972 //sCgSsaoProgram->SetTexture(i ++, normalsTex); 1052 sCgPrepareSsaoProgram->SetTexture(i ++, normalsTex); 1053 sCgPrepareSsaoProgram->SetTexture(i ++, diffVals); 973 1054 sCgPrepareSsaoProgram->SetTexture(i ++, oldTex); 974 1055 … … 986 1067 sCgPrepareSsaoProgram->SetValue3f(i, mOldCornersView[j].x, mOldCornersView[j].y, mOldCornersView[j].z); 987 1068 988 sCgPrepareSsaoProgram->SetTexture(i ++, diffVals);989 990 991 1069 glPushAttrib(GL_VIEWPORT_BIT); 992 1070 glViewport(0, 0, mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); … … 994 1072 mDownSampleFbo->Bind(); 995 1073 996 glDrawBuffers( 1, mrt + 0);1074 glDrawBuffers(3, mrt + 0); 997 1075 998 1076 DrawQuad(sCgPrepareSsaoProgram); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3155 r3167 109 109 void PrepareSsao(FrameBufferObject *fbo); 110 110 111 void SortSamples(); 111 112 112 113 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3155 r3167 587 587 //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 588 588 // buffer holding the difference vector to the old frame 589 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_ 32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);589 fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR); 590 590 // another color buffer 591 591 fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3166 r3167 6 6 //-- ssao + gi parameters 7 7 8 //#define NUM_SAMPLES 89 #define NUM_SAMPLES 248 #define NUM_SAMPLES 8 9 //#define NUM_SAMPLES 24 10 10 11 11 // for quadratic falloff 12 12 //#define SAMPLE_INTENSITY 0.2f 13 //#define SAMPLE_INTENSITY 0.07f14 #define SAMPLE_INTENSITY 0.01f13 #define SAMPLE_INTENSITY 0.07f 14 //#define SAMPLE_INTENSITY 0.01f 15 15 16 16 //#define SAMPLE_INTENSITY 0.075f … … 27 27 28 28 #define VIEW_CORRECTION_SCALE 1.0f 29 30 //#define NUM_SSAO_FILTERSAMPLES 80 31 #define NUM_SSAO_FILTER_SAMPLES 16 32 #define NUM_SSAO_FILTER_WIDTH 10.0f 33 #define SSAO_CONVERGENCE_WEIGHT 25.0f 29 34 30 35 … … 60 65 #define NUM_DOWNSAMPLES 9 61 66 62 //#define NUM_SSAO_FILTERSAMPLES 2563 //#define NUM_SSAO_FILTERSAMPLES 5064 //#define NUM_SSAO_FILTERSAMPLES 8065 #define NUM_SSAO_FILTERSAMPLES 8066 67 67 68 68 #define DYNAMIC_OBJECTS_THRESHOLD 1e-8f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r3154 r3167 91 91 92 92 93 //float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f;94 float4 col = (s0 + s1 + s2 + s3) * 0.25f;93 float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 94 //float4 col = (s0 + s1 + s2 + s3) * 0.25f; 95 95 //float4 col = float4(ne.x, ne.x, ne.x, 0); 96 96 //float4 col = float4(de.x, de.x, de.x, 0); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3164 r3167 30 30 uniform sampler2D normalsTex, 31 31 uniform sampler2D colorsTex, 32 uniform float2 filterOffs[NUM_SSAO_FILTER SAMPLES],33 uniform float filterWeights[NUM_SSAO_FILTER SAMPLES],32 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 33 uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 34 34 float scale 35 35 ) … … 40 40 const float eyeSpaceDepth = color.w; 41 41 42 const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 43 //const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 42 const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 44 43 45 44 float4 aoSample; … … 53 52 float sampleDepth; 54 53 55 for (int i = 0; i < NUM_SSAO_FILTER SAMPLES; ++ i)54 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 56 55 { 57 56 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 58 57 59 58 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 60 sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 61 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 59 sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 62 60 63 61 // check depth discontinuity … … 96 94 uniform sampler2D normalsTex, 97 95 uniform sampler2D colorsTex, 98 uniform float2 filterOffs[NUM_SSAO_FILTER SAMPLES],96 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 99 97 float scale, 100 98 float3 bl, … … 107 105 108 106 const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 109 const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 110 //const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 107 const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 111 108 112 109 float4 aoSample; … … 118 115 float normalFactor; 119 116 float convergenceFactor; 120 float sampleDepth;121 122 for (int i = 0; i < NUM_SSAO_FILTER SAMPLES; ++ i)117 float len; 118 119 for (int i = 0; i < NUM_SSAO_FILTER_SAMPLES; ++ i) 123 120 { 124 121 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 125 122 126 123 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 127 sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 128 //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 124 sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 129 125 130 126 // check spatial discontinuity 131 127 samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 132 float len = SqrLen(centerPos - samplePos);128 len = min(SqrLen(centerPos - samplePos), 1e2f); 133 129 134 130 spatialFactor = 1.0f / max(len, 1e-3f); … … 159 155 uniform sampler2D ssaoTex, 160 156 uniform sampler2D normalsTex, 161 uniform float2 filterOffs[NUM_SSAO_FILTER SAMPLES],162 uniform float filterWeights[NUM_SSAO_FILTER SAMPLES],157 uniform float2 filterOffs[NUM_SSAO_FILTER_SAMPLES], 158 uniform float filterWeights[NUM_SSAO_FILTER_SAMPLES], 163 159 uniform float4x4 modelViewProj, 164 160 uniform float3 bl, … … 180 176 */ 181 177 178 // filter up to a certain convergance value and leave out background (sky) by checking depth 182 179 if ((ao.y < 100.0f) && (col.w < 1e10f)) 183 180 //if (col.w < 1e10f) … … 189 186 190 187 const float convergence = ao.y; 191 const float adaptWeight = 5.0f;192 const float convergenceScale = adaptWeight / (convergence + adaptWeight);193 194 const float scale = convergenceScale * distanceScale;195 196 188 const float adaptWeight = 25.0f; 189 const float convergenceScale = SSAO_CONVERGENCE_WEIGHT / (convergence + SSAO_CONVERGENCE_WEIGHT); 190 191 const float scale = NUM_SSAO_FILTER_WIDTH * convergenceScale * distanceScale; 192 193 // the filtered ssao value 197 194 ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, scale, bl, br, tl, tr); 198 195 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3164 r3167 14 14 { 15 15 float4 color: COLOR0; 16 float3 normal: COLOR1; 17 float3 diffVal: COLOR2; 16 18 }; 17 19 … … 230 232 valid in the current frame 231 233 */ 232 inline float PixelValid(sampler2D diffVals, 233 sampler2D oldTex, 234 inline float PixelValid(sampler2D oldTex, 234 235 float4 color, 236 float3 diffVec, 235 237 float2 texCoord, 236 238 float3 viewDir, … … 248 250 const float4 worldPos = float4(-viewDir * eyeSpaceDepth, 1.0f); 249 251 250 float3 diffVec = tex2Dlod(diffVals, float4(texCoord, 0, 0)).xyz;251 252 252 253 … … 308 309 309 310 310 float4PrepareSsao(fragment IN,311 pixel PrepareSsao(fragment IN, 311 312 uniform sampler2D colorsTex, 313 uniform sampler2D normalsTex, 314 uniform sampler2D diffVals, 312 315 uniform sampler2D oldTex, 313 316 uniform float4x4 modelViewProj, … … 317 320 uniform float3 oldtl, 318 321 uniform float3 oldtr, 319 uniform float3 oldEyePos, 320 uniform sampler2D diffVals 321 ): COLOR 322 uniform float3 oldEyePos 323 ) 322 324 { 323 //const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 325 pixel pix; 326 327 const float3 normal = normalize(tex2Dlod(normalsTex, float4(IN.texCoord, 0 ,0)).xyz); 328 const float3 difVec = tex2Dlod(diffVals, float4(IN.texCoord, 0 ,0)).xyz; 329 324 330 const float3 viewDir = IN.view; 325 331 float4 color = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0)); … … 330 336 331 337 // do reprojection and filter out the pixels that are not save 332 float pValid = PixelValid( diffVals,338 float pValid = PixelValid( 333 339 oldTex, 334 340 color, 341 difVec.xyz, 335 342 IN.texCoord, 336 343 viewDir, … … 341 348 ); 342 349 343 color.x = pValid; 344 return color; 350 pix.color = color; 351 pix.color.x = pValid; 352 353 pix.normal = normal; 354 pix.diffVal = difVec; 355 356 return pix; 345 357 } 346 358 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3161 r3167 213 213 const float3 samplePos = ReconstructSamplePos(sampleColor.w, texcoord, bl, br, tl, tr); 214 214 // the normal of the current sample 215 const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 215 //const float3 sampleNormal = normalize(tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz); 216 const float3 sampleNormal = tex2Dlod(normalTex, float4(texcoord, 0, 0)).xyz; 216 217 217 218 … … 357 358 pixel OUT; 358 359 359 const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 360 //const float3 normal = normalize(tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz); 361 const float3 normal = tex2Dlod(normals, float4(IN.texCoord, 0 ,0)).xyz; 360 362 361 363 // reconstruct position from the eye space depth -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao3d.cg
r3017 r3167 127 127 128 128 // the ambient term 129 const float amb = norm.w; 130 129 //const float amb = norm.w; 131 130 // expand normal 132 131 float3 normal = normalize(norm.xyz); 133 134 132 /// the current view direction 135 133 float3 viewDir;// = normalize(IN.view);
Note: See TracChangeset
for help on using the changeset viewer.