Changeset 3134
- Timestamp:
- 11/18/08 11:28:38 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3123 r3134 30 30 31 31 # initial camera position 32 camPosition=483.398f 242.364f 186.078f32 #camPosition=483.398f 242.364f 186.078f 33 33 # initial camera orientation 34 camDirection=1 0 0 34 #camDirection=1 0 0 35 36 camPosition=468.025 267.591 182.478 37 camDirection=0.937282 0.348573 -0 35 38 36 39 #lightDirection=-0.8f 1.0f -0.7f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3133 r3134 112 112 } 113 113 114 static void ComputeSampleOffsets(float *sampleOffsets, int w, int h) 115 { 116 /* 117 const float xoffs = 0.5f / w; 118 const float yoffs = 0.5f / h; 119 120 sampleOffsets[0] = xoffs; sampleOffsets[1] = yoffs; 121 sampleOffsets[2] = xoffs; sampleOffsets[3] = -yoffs; 122 sampleOffsets[4] = -xoffs; sampleOffsets[5] = -yoffs; 123 sampleOffsets[6] = -xoffs; sampleOffsets[7] = yoffs; 124 */ 125 //const float xoffs = .5f / w; 126 //const float yoffs = .5f / h; 127 128 const float xoffs = 1.0f / w; 129 const float yoffs = 1.0f / h; 130 131 int idx = 0; 132 133 for (int x = -1; x <= 1; ++ x) 134 { 135 for (int y = -1; y <= 1; ++ y) 114 115 static void ComputeSampleOffsets(float *sampleOffsets, 116 int imageW, int imageH, 117 float width, 118 int samples) 119 { 120 const float xoffs = width / (float)imageW; 121 const float yoffs = width / (float)imageH; 122 123 const int numSamples = (int)sqrt((float)samples); 124 const int startSamples = -numSamples / 2; 125 const int endSamples = numSamples + startSamples - 1; 126 //cout << startSamples << " " << endSamples << endl; 127 128 int idx = 0; 129 130 for (int x = startSamples; x <= endSamples; ++ x) 131 { 132 for (int y = startSamples; y <= endSamples; ++ y) 136 133 { 137 sampleOffsets[idx + 0] = x * xoffs; 138 sampleOffsets[idx + 1] = y * yoffs; 139 134 sampleOffsets[idx + 0] = (float)x * xoffs; 135 sampleOffsets[idx + 1] = (float)y * yoffs; 140 136 idx += 2; 141 }142 }143 }144 145 146 static void ComputeSampleOffsets2(float *sampleOffsets, int w, int h, float width, int samples)147 {148 const float xoffs = width / (float)w;149 const float yoffs = width / (float)h;150 151 const int numSamples = (int)sqrt((float)samples);152 153 for (int x = 0; x < numSamples; ++ x)154 {155 for (int y = 0; y < numSamples; ++ y)156 {157 int idx = (y * numSamples + x) * 2;158 sampleOffsets[idx + 0] = ((float)x - 0.5f * numSamples) * xoffs;159 sampleOffsets[idx + 1] = ((float)y - 0.5f * numSamples) * yoffs;160 137 } 161 138 } … … 434 411 //////////////// 435 412 436 string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights" };437 sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 5);413 string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights", "bl", "br", "tl", "tr"}; 414 sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 9); 438 415 439 416 ////////////// … … 464 441 /////////// 465 442 466 #if 0 443 const float filterWidth = 10.0f; 444 445 #if 1 467 446 PoissonDiscSampleGenerator2 poisson(NUM_SSAO_FILTERSAMPLES, 1.0f); 468 447 poisson.Generate((float *)ssaoFilterOffsets); 469 448 470 const float filterWidth = 10.0f;471 449 const float xoffs = (float)filterWidth / mWidth; 472 450 const float yoffs = (float)filterWidth / mHeight; … … 484 462 } 485 463 #else 486 //ComputeSampleOffsets(ssaoFilterOffsets, 1024, 768, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES);487 ComputeSampleOffsets 2(ssaoFilterOffsets, 1024, 768, 5, NUM_SSAO_FILTERSAMPLES);488 464 //ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, sqrt(NUM_SSAO_FILTERSAMPLES), NUM_SSAO_FILTERSAMPLES); 465 ComputeSampleOffsets(ssaoFilterOffsets, mWidth, mHeight, filterWidth, NUM_SSAO_FILTERSAMPLES); 466 //cout<<"ssao filter size: " << NUM_SSAO_FILTERSAMPLES << endl; 489 467 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 490 468 ssaoFilterWeights[i] = 1.0f; … … 829 807 sCgCombineSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 830 808 809 Vector3 bl = mCornersView[0]; 810 Vector3 br = mCornersView[1]; 811 Vector3 tl = mCornersView[2]; 812 Vector3 tr = mCornersView[3]; 813 814 sCgCombineSsaoProgram->SetValue3f(i ++, bl.x, bl.y, bl.z); 815 sCgCombineSsaoProgram->SetValue3f(i ++, br.x, br.y, br.z); 816 sCgCombineSsaoProgram->SetValue3f(i ++, tl.x, tl.y, tl.z); 817 sCgCombineSsaoProgram->SetValue3f(i ++, tr.x, tr.y, tr.z); 818 819 831 820 DrawQuad(sCgCombineSsaoProgram); 832 821 … … 968 957 sCgDownSampleProgram->SetTexture(0, colorsTex); 969 958 959 const float filterWidth = 1.0f; 970 960 float downSampleOffsets[NUM_DOWNSAMPLES * 2]; 971 ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight());972 961 //ComputeSampleOffsets(downSampleOffsets, fbo->GetWidth(), fbo->GetHeight(), filterWidth, NUM_DOWNSAMPLES); 962 973 963 sCgDownSampleProgram->SetArray2f(1, (float *)downSampleOffsets, NUM_DOWNSAMPLES); 974 964 … … 979 969 980 970 glPopAttrib(); 981 982 971 PrintGLerror("downsample"); 983 972 } … … 1019 1008 DrawQuad(sCgDownSampleProgram); 1020 1009 1021 PrintGLerror(" OUTPUT");1010 PrintGLerror("output"); 1022 1011 } 1023 1012 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3128 r3134 1186 1186 { 1187 1187 case 27: 1188 Debug << "camPosition=" << camera->GetPosition().x << " " << camera->GetPosition().y << " " << camera->GetPosition().z << endl; 1189 Debug << "camDirection=" << camera->GetDirection().x << " " << camera->GetDirection().y << " " << camera->GetDirection().z << endl; 1190 1188 1191 CleanUp(); 1189 1192 exit(0); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3133 r3134 58 58 #define NUM_DOWNSAMPLES 9 59 59 60 //#define NUM_SSAO_FILTERSAMPLES 25 60 61 #define NUM_SSAO_FILTERSAMPLES 49 61 //#define NUM_SSAO_FILTERSAMPLES 40 62 //#define NUM_SSAO_FILTERSAMPLES 100 62 //#define NUM_SSAO_FILTERSAMPLES 81 63 63 64 64 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3133 r3134 16 16 17 17 18 float Filter(float2 texCoord, 19 uniform sampler2D ssaoTex, 20 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 21 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 22 { 23 float average = .0f; 24 float w = .0f; 25 26 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 27 { 28 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i], 0, 0)).x; 29 w += filterWeights[i]; 30 } 31 32 average *= 1.0f / (float)w; 33 34 return average; 18 19 20 inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 21 { 22 float3 x1 = lerp(bl, tl, w.y); 23 float3 x2 = lerp(br, tr, w.y); 24 float3 v = lerp(x1, x2, w.x); 25 26 return v; 27 } 28 29 30 // reconstruct world space position 31 inline float3 ReconstructSamplePos(uniform sampler2D tex, 32 float2 texcoord, 33 float3 bl, float3 br, float3 tl, float3 tr) 34 { 35 const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; 36 37 float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 38 float3 samplePos = -viewVec * eyeSpaceDepth; 39 40 return samplePos; 35 41 } 36 42 … … 56 62 } 57 63 64 #define USE_POSITION 58 65 59 66 float DiscontinuityFilter(float2 texCoord, … … 64 71 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 65 72 float scale, 66 int index) 73 float3 bl, 74 float3 br, 75 float3 tl, 76 float3 tr) 67 77 { 68 78 float average = .0f; 69 79 float total_w = .0f; 70 80 81 #ifdef USE_POSITION 82 const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 83 #else 71 84 const float eyeSpaceDepth = ao.w; 85 #endif 86 72 87 const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 73 88 74 89 float4 aoSample; 75 90 float3 sampleNorm; 91 float3 samplePos; 76 92 float w; 77 float4 offs;93 float4 sampleTexCoord; 78 94 float depthFactor; 79 95 float normalFactor; 80 float converg anceFactor;96 float convergenceFactor; 81 97 82 98 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 83 99 { 84 offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 85 aoSample = tex2Dlod(ssaoTex, offs); 86 87 sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 88 89 //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 100 sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 101 aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 102 sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 103 104 #ifdef USE_POSITION 105 samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 106 depthFactor = max(step(1.0f - 5e-1f, 1.0f - length(samplePos - centerPos)), 1e-3f); 107 #else // use depth 90 108 depthFactor = max(step(5e-1f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 109 #endif 91 110 normalFactor = max(step(0.6f, dot(sampleNorm, norm)), 1e-3f); 92 converg anceFactor = max(step(8.5f, aoSample.y), 1e-3f);93 94 //w = filterWeights[i] * normalFactor * depthFactor * converganceFactor;95 w = filterWeights[i];//* normalFactor * converganceFactor;96 //w = filterWeights[i] * depthFactor;97 98 average += aoSample [index]* w;111 convergenceFactor = min(60.0f, aoSample.y) * 0.01f;//max(step(18.5f, aoSample.y), 1e-3f); 112 113 w = filterWeights[i] * normalFactor * depthFactor * convergenceFactor; 114 //w = filterWeights[i] * normalFactor * converganceFactor; 115 //w = filterWeights[i] * normalFactor * depthFactor; 116 117 average += aoSample.x * w; 99 118 total_w += w; 100 119 } … … 112 131 uniform sampler2D offsetTex, 113 132 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 114 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 115 ) 133 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 134 uniform float3 bl, 135 uniform float3 br, 136 uniform float3 tl, 137 uniform float3 tr) 116 138 { 117 139 pixel OUT; … … 132 154 133 155 float border = step(0.001f, b2 134 135 156 //float3 id = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 136 157 */ … … 155 176 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor / (adaptFactor + ao.y), 0); 156 177 157 if (ao.y < 10.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0);178 if (ao.y < 60.5f) ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor, bl, br, tl, tr); 158 179 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1, 0); 159 180 } … … 163 184 OUT.illum_col.xyz = col.xyz * ao.x; 164 185 165 // if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0);166 // else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000);167 // else186 // if (ao.y < 1.5f) OUT.illum_col.xyz = float3(10000, 10000, 0); 187 // else if (ao.y < 3.5f) OUT.illum_col.xyz = float3(10000, 0, 10000); 188 // else 168 189 // if (ao.y < 10.5f) OUT.illum_col.xyz = float3(0, 10000, 0); 169 190 //OUT.illum_col = float4(dummy3, dummy3, dummy3, col.w); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r3104 r3134 291 291 292 292 #endif 293 294 295 float4 Output(fragment IN, uniform sampler2D colors): COLOR 296 { 297 // let bilinear filtering do its work 298 return tex2Dlod(colors, float4(IN.texCoord, 0, 0)); 299 }
Note: See TracChangeset
for help on using the changeset viewer.