- Timestamp:
- 11/12/08 01:47:27 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
r3119 r3120 97 97 &tangent.x, &tangent.y, &tangent.z); 98 98 99 vtx.x *= 0.07f; 100 vtx.y *= 0.07f; 101 vtx.z *= 0.07f; 99 const float scale = 0.05f; 100 vtx.x *= scale; 101 vtx.y *= scale; 102 vtx.z *= scale; 102 103 103 104 geom->mVertices[line] = vtx; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3118 r3120 321 321 sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "giFrag"); 322 322 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi"); 323 //sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao");324 sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao");323 sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao"); 324 //sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao"); 325 325 sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing"); 326 326 sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap"); … … 364 364 //////////////// 365 365 366 string combineSsaoParams[] = {"colorsTex", " ssaoTex", "filterOffs", "filterWeights"};367 sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 4);366 string combineSsaoParams[] = {"colorsTex", "normalsTex", "ssaoTex", "filterOffs", "filterWeights"}; 367 sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 5); 368 368 369 369 ////////////// … … 395 395 396 396 //const float filterWidth = 10.0f; 397 const float filterWidth = 5.0f;398 //const float filterWidth = 60.0f;397 //const float filterWidth = 6.0f; 398 const float filterWidth = 20.0f; 399 399 400 400 //const float xoffs = filterWidth / mDownSampleFbo->GetWidth(); … … 408 408 float y = ssaoFilterOffsets[2 * i + 1]; 409 409 410 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f); 411 410 412 ssaoFilterOffsets[2 * i + 0] *= xoffs; 411 413 ssaoFilterOffsets[2 * i + 1] *= yoffs; 412 413 ssaoFilterWeights[i] = GaussianDistribution(x, y, 1.0f);414 414 } 415 415 … … 747 747 int i = 0; 748 748 sCgCombineSsaoProgram->SetTexture(i ++, colorsTex); 749 //sCgCombineSsaoProgram->SetTexture(i ++, normalsTex);749 sCgCombineSsaoProgram->SetTexture(i ++, normalsTex); 750 750 sCgCombineSsaoProgram->SetTexture(i ++, ssaoTex); 751 751 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r3114 r3120 164 164 { 165 165 if (mTransform->IsIdentity()) return mCenter; 166 return mTransform->GetMatrix() * 166 return mTransform->GetMatrix() * mCenter; 167 167 } 168 168 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r3110 r3120 89 89 */ 90 90 int GetNumLODLevels() const { return (int)mLODLevels.size(); } 91 /** Returns center point of this shape. 92 */ 93 Vector3 GetCenter() const {return mCenter; } 91 94 /** Returns transformed center point of this shape. 92 95 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3119 r3120 301 301 void CreateAnimation(); 302 302 303 304 // the new and the old viewProjection matrix of the current camera 303 SceneQuery *GetOrCreateSceneQuery(); 304 305 306 // new view projection matrix of the camera 305 307 static Matrix4x4 viewProjMat = IdentityMatrix(); 308 // the old view projection matrix of the camera 306 309 static Matrix4x4 oldViewProjMat = IdentityMatrix(); 307 310 … … 463 466 //-- load some dynamic stuff 464 467 465 LoadModel("fisch.dem", dynamicObjects);466 //LoadModel("hbuddha.dem", dynamicObjects);468 //LoadModel("fisch.dem", dynamicObjects); 469 LoadModel("hbuddha.dem", dynamicObjects); 467 470 buddha = dynamicObjects.back(); 468 471 … … 482 485 offs.y = RandomValue(.0f, 50.0f); 483 486 484 transl = TranslationMatrix(sceneCenter + offs); 487 Vector3 newPos = sceneCenter + offs; 488 489 transl = TranslationMatrix(newPos); 485 490 Transform3 *transform = resourceManager->CreateTransform(transl); 486 491 … … 912 917 buddha->GetTransform()->SetMatrix(trafo); 913 918 919 /*for (int i = 0; i < 10; ++ i) 920 { 921 SceneEntity *ent = dynamicObjects[i]; 922 Vector3 newPos = ent->GetWorldCenter(); 923 924 if (GetOrCreateSceneQuery()->CalcIntersection(newPos)) 925 { 926 Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter());// + Vector3(0, 0, ent->GetBoundingBox().Size(2) * 0.5f)); 927 ent->GetTransform()->SetMatrix(mat); 928 } 929 }*/ 930 914 931 Matrix4x4 rotMatrix = RotationZMatrix(M_PI * 1e-3f); 915 916 932 dynamicObjects[1]->GetTransform()->MultMatrix(rotMatrix); 933 917 934 918 935 … … 2007 2024 2008 2025 2026 SceneQuery *GetOrCreateSceneQuery() 2027 { 2028 if (!sceneQuery) 2029 sceneQuery = new SceneQuery(bvh->GetBox(), traverser, &renderState); 2030 2031 return sceneQuery; 2032 } 2033 2034 2009 2035 void PlaceViewer(const Vector3 &oldPos) 2010 2036 { 2011 if (!sceneQuery)2012 {2013 sceneQuery = new SceneQuery(bvh->GetBox(), traverser, &renderState);2014 }2015 2016 2037 Vector3 playerPos = camera->GetPosition(); 2017 bool validIntersect = sceneQuery->CalcIntersection(playerPos);2038 bool validIntersect = GetOrCreateSceneQuery()->CalcIntersection(playerPos); 2018 2039 2019 2040 if (validIntersect) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3115 r3120 29 29 //-- reprojection 30 30 31 #define MIN_DEPTH_DIFF 2e-2f 31 //#define MIN_DEPTH_DIFF 2e-2f 32 #define MIN_DEPTH_DIFF 5e-3f 32 33 #define PRECISION_SCALE 1e-1f 33 34 … … 57 58 #define NUM_DOWNSAMPLES 9 58 59 59 //#define NUM_SSAO_FILTERSAMPLES 28 60 #define NUM_SSAO_FILTERSAMPLES 20 60 61 //#define NUM_SSAO_FILTERSAMPLES 40 61 #define NUM_SSAO_FILTERSAMPLES 10062 //#define NUM_SSAO_FILTERSAMPLES 100 62 63 63 64 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3109 r3120 36 36 37 37 38 float Filter(float2 texCoord, 39 uniform sampler2D ssaoTex, 40 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 41 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 42 float scale) 43 { 44 float average = .0f; 45 float w = .0f; 46 47 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 48 { 49 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale, 0, 0)).x; 50 w += filterWeights[i]; 51 } 52 53 average *= 1.0f / (float)w; 54 55 return average; 56 } 57 58 38 59 float BilateralFilter(float2 texCoord, 39 60 float4 ao, … … 41 62 uniform sampler2D normalsTex, 42 63 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 43 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]) 64 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 65 float scale) 44 66 { 45 67 float average = .0f; 46 68 float total_w = .0f; 47 69 48 //const float eyeSpaceDepth = ao.w;70 const float eyeSpaceDepth = ao.w; 49 71 const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 50 72 … … 52 74 float3 sampleNorm; 53 75 float w; 76 float4 offs; 77 float depthFactor; 54 78 55 79 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 56 80 { 57 float4 offs = float4(texCoord + filterOffs[i], 0, 0);81 offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 58 82 aoSample = tex2Dlod(ssaoTex, offs); 59 //aoSample = tex2D(ssaoTex, texCoord + filterOffs[i]); 60 //float sampleEyeSpaceDepth = aoSample.w; 61 //factor = abs(eyeSpaceDepth - sampleEyeSpaceDepth) / eyeSpaceDepth; 83 62 84 sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 85 depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 63 86 //sampleNorm = tex2Dlod(normalsTex, offs).xyz; 64 87 65 w = filterWeights[i] * max(dot(sampleNorm, norm), .0f) ;88 w = filterWeights[i] * max(dot(sampleNorm, norm), .0f) * depthFactor; 66 89 67 average += w * aoSample.x;90 average += aoSample.x * w; 68 91 total_w += w; 69 92 } 70 93 71 average *= 1.0f / max(total_w, 1e- 5f);94 average *= 1.0f / max(total_w, 1e-6f); 72 95 73 96 return average; … … 88 111 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 89 112 90 //if (ao.y < 10.0f) ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 91 //if (ao.y < 10.0f) ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights); 113 if ((ao.y < 60.0f) && (col.w < 1e10f)) 114 { 115 const static float scaleFactor = 10.0f; 92 116 93 //OUT.illum_col = col * ao.x; 94 //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w); 95 OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 117 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 118 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 119 ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 120 //ao.x = BilateralFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 121 } 122 123 OUT.illum_col = col * ao.x; 124 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 96 125 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 97 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);98 126 OUT.illum_col.w = col.w; 99 127 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3119 r3120 189 189 //float overallDepth = 0; 190 190 const float squaredLen = diffVec.x * diffVec.x + diffVec.y * diffVec.y + diffVec.z * diffVec.z; 191 191 #if 1 192 192 if (squaredLen < 1e-8f) // object not dynamic 193 193 { … … 210 210 } 211 211 } 212 212 #endif 213 213 const float oldWeight = clamp(oldPixel.y, .0f, temporalCoherence); 214 214 float newWeight; … … 220 220 // if visibility changed in the surrounding area we have to recompute 221 221 //&& (oldNumSamples > 0.8f * newNumSamples) 222 && (notValid < 1.0f)222 //&& (notValid < 1.0f) 223 223 ) 224 224 { … … 226 226 newWeight = oldWeight + 1.0f; 227 227 illum_col.x = (ao.x + oldPixel.x * oldWeight) / newWeight; 228 //if (notValid > 1.0f) newWeight = 2.0f;228 if (notValid > 1.0f) newWeight = 2.0f; 229 229 } 230 230 else … … 292 292 293 293 //if ((texcoord.x <= 1.0f) && (texcoord.x >= 0.0f) && (texcoord.y <= 1.0f) && (texcoord.y >= 0.0f)) ++ numSamples; 294 294 295 const float3 samplePos = ReconstructSamplePos(colors, texcoord, bl, br, tl, tr); 295 296 … … 378 379 float3 diffVec = tex2Dlod(attribsTex, float4(IN.texCoord, 0, 0)).xyz; 379 380 381 380 382 ///////////////// 381 383 //-- compute temporal reprojection … … 393 395 diffVec); 394 396 395 //OUT.illum_col.xyz = id;396 //OUT.illum_col.xyz = normal * 0.5f + 0.5f;397 397 return OUT; 398 398 } 399 400 401 float Filter(float2 texCoord,402 uniform sampler2D ssaoTex,403 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],404 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES],405 float scale)406 {407 float average = .0f;408 float w = .0f;409 410 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i)411 {412 average += filterWeights[i] * tex2Dlod(ssaoTex, float4(texCoord + filterOffs[i] * scale * 2, 0, 0)).x;413 w += filterWeights[i];414 }415 416 average *= 1.0f / (float)w;417 418 return average;419 }420 421 422 pixel combine(fragment IN,423 uniform sampler2D colorsTex,424 uniform sampler2D ssaoTex,425 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES],426 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES]427 )428 {429 pixel OUT;430 431 const float4 col = tex2Dlod(colorsTex, float4(IN.texCoord, 0, 0));432 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0));433 434 //if ((ao.y < 10.0f) && (col.w < 1e10f))435 // ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y));//ao.z);436 437 OUT.illum_col = col * ao.x;438 //OUT.illum_col = float4(ao.y, ao.y, ao.y, col.w);439 //OUT.illum_col = float4(ao.x, ao.y, ao.z, col.w);440 //OUT.illum_col = float4(ao.x, 0, 0, col.w);441 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1);442 //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0);443 OUT.illum_col.w = col.w;444 445 return OUT;446 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/toto.txt
r3098 r3120 76 76 to compare the depth of the current pixel, but the depth of the 77 77 samples taken for ao 78 79 80 idea for incorporation of dynamic objects: 81 82 store object id with render target 83 for each object we know the trafo 84 when doing the back projection => 85 86 as usual: 87 we have the world space position of the current pixel 88 find pixel from last frame using the old projection view trafo 89 90 but now we first apply the inverse transformation that brought the 91 last pixel to the current pixel and then the old projection view!! 92 93 => now we do the equality comparison as usual 94 95 96 for reducing flickering: 97 98
Note: See TracChangeset
for help on using the changeset viewer.