Changeset 3128
- Timestamp:
- 11/16/08 03:46:19 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
r3102 r3128 364 364 if (hasMaterial) 365 365 { 366 SimpleVec ambient, diffuse, black;366 SimpleVec ambient, diffuse, spec, emm; 367 367 368 368 ambient.x = ambient.y = ambient.z = 0.2f; 369 369 diffuse.x = diffuse.y = diffuse.z = 1.0f; 370 black.x = black.y = black.z = .0f; 370 spec.x = spec.y = spec.z = .0f; 371 emm = spec; 371 372 372 373 // only write rgb part of the material 373 374 str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 374 375 str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 375 str.write(reinterpret_cast<char *>(& black), sizeof(SimpleVec));376 str.write(reinterpret_cast<char *>(& black), sizeof(SimpleVec));376 str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec)); 377 str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec)); 377 378 } 378 379 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp
r3127 r3128 140 140 //-- texture 141 141 142 int texId = -1; 143 //int texId = 0; 142 //int texId = -1; 143 int texId = 0; 144 144 145 str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 146 //str.write(reinterpret_cast<char *>(&texId2), sizeof(int)); 145 147 146 148 bool alphaTestEnabled = false; … … 158 160 if (hasMaterial) 159 161 { 160 SimpleVec ambient, diffuse, black;162 SimpleVec ambient, diffuse, spec, emm; 161 163 162 164 ambient.x = ambient.y = ambient.z = 0.2f; 163 165 diffuse.x = diffuse.y = diffuse.z = 1.0f; 164 black.x = black.y = black.z = .0f; 166 spec.x = spec.y = spec.z = .0f; 167 emm = spec; 165 168 166 169 // only write rgb part of the material 167 170 str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 168 171 str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 169 str.write(reinterpret_cast<char *>(& black), sizeof(SimpleVec));170 str.write(reinterpret_cast<char *>(& black), sizeof(SimpleVec));172 str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec)); 173 str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec)); 171 174 } 172 175 } … … 184 187 //-- write textures 185 188 186 //int textureCount = 1;187 int textureCount = 0;189 int textureCount = 1; 190 //int textureCount = 0; 188 191 189 192 ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); … … 192 195 { 193 196 // hack 194 const string texName("wood.jpg"); 197 const string texName("fischi_u1_v1.png"); 198 //const string texName("wood.jpg"); 195 199 196 200 int texnameSize = (int)texName.length() + 1; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3123 r3128 57 57 static ShaderProgram *sCgToneProgram = NULL; 58 58 static ShaderProgram *sCgDownSampleProgram = NULL; 59 60 ShaderContainer DeferredRenderer::sShaders; 59 static ShaderProgram *sCgSmoothSsaoProgram = NULL; 60 61 61 62 62 static GLuint noiseTex = 0; 63 63 64 64 65 // ssao random spherical samples … … 322 323 sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi"); 323 324 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"); 327 327 sCgDownSampleProgram = sm->CreateFragmentProgram("tonemap", "DownSample", "downSample"); 328 328 sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum"); 329 sCgSmoothSsaoProgram = sm->CreateFragmentProgram("combineSsao", "smoothSsao", "smoothSsao"); 329 330 330 331 … … 385 386 386 387 sCgLogLumProgram->AddParameter("colors", 0); 387 388 389 //////////////// 390 391 string smoothSsaoParams[] = {"normalsTex", "ssaoTex", "filterOffs", "filterWeights"}; 392 sCgSmoothSsaoProgram->AddParameters(smoothSsaoParams, 0, 4); 388 393 389 394 … … 461 466 case SSAO: 462 467 ComputeSsao(fbo, tempCohFactor); 468 SmoothSsao(fbo); 463 469 CombineSsao(fbo); 464 470 break; … … 536 542 sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 537 543 538 if (mUseTemporalCoherence || mRegenerateSamples) 544 //if (mUseTemporalCoherence || mRegenerateSamples) 545 if (mRegenerateSamples) 539 546 { 540 547 mRegenerateSamples = false; … … 740 747 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 741 748 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 742 GLuint ssaoTex = mIllumFbo->GetColorBuffer( mIllumFboIndex)->GetTexture();749 GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 743 750 744 751 // overwrite old color texture … … 1034 1041 glPushAttrib(GL_VIEWPORT_BIT); 1035 1042 glViewport(0, 0, mWidth, mHeight); 1036 // revert to old far plane 1043 1044 // revert to old far and near plane 1037 1045 mCamera->SetFar(oldFar); 1038 1046 mCamera->SetNear(oldNear); … … 1040 1048 1041 1049 1050 void DeferredRenderer::SmoothSsao(FrameBufferObject *fbo) 1051 { 1052 mIllumFbo->Bind(); 1053 1054 GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 1055 GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 1056 1057 // overwrite old ssao texture 1058 glDrawBuffers(1, mrt + 2 - mIllumFboIndex); 1059 1060 glPushAttrib(GL_VIEWPORT_BIT); 1061 glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 1062 1063 int i = 0; 1064 sCgSmoothSsaoProgram->SetTexture(i ++, normalsTex); 1065 sCgSmoothSsaoProgram->SetTexture(i ++, ssaoTex); 1066 1067 sCgSmoothSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES); 1068 sCgSmoothSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 1069 1070 DrawQuad(sCgSmoothSsaoProgram); 1071 1072 glPopAttrib(); 1073 1074 PrintGLerror("combine ssao"); 1075 } 1076 1077 1042 1078 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3111 r3128 83 83 void CombineSsao(FrameBufferObject *fbo); 84 84 void CombineIllum(FrameBufferObject *fbo); 85 void SmoothSsao(FrameBufferObject *fbo); 85 86 86 87 void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3127 r3128 52 52 CLEAR_CONTAINER(mTrafos); 53 53 CLEAR_CONTAINER(mShapes); 54 //CLEAR_CONTAINER(mLODs);55 54 } 56 55 … … 71 70 72 71 if (!hasTrafo) 73 { 74 // identity 75 trafo = new Transform3(); 72 { 73 trafo = new Transform3(); // identity 76 74 } 77 75 else … … 79 77 Matrix4x4 m; 80 78 str.read(reinterpret_cast<char *>(m.x), sizeof(Matrix4x4)); 81 82 79 trafo = new Transform3(m); 83 80 } … … 290 287 static ShaderProgram *sDefaultVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultVertexMrt"); 291 288 292 static ShaderProgram *sNormalMappingVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingVertexMrt"); 293 static ShaderProgram *sNormalMappingFragmentProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingFragmentMrt"); 289 //static ShaderProgram *sNormalMappingVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingVertexMrt"); 290 //static ShaderProgram *sNormalMappingFragmentProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingFragmentMrt"); 291 294 292 295 293 Technique *deferred = new Technique(*tech); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp
r3126 r3128 86 86 fragmentProgMrtTex = CreateFragmentProgram("mrt", "fragtex", "defaultFragmentTexMrt"); 87 87 88 88 89 // provide the current view matrix: 89 90 // this is an automatic parameter that is updated each frame … … 98 99 vertexProgMrt->AddParameter("oldModelMatrix", 2); 99 100 100 101 // add a texture parameter102 //fragmentProgMrtTex->AddParameter("tex", 1);103 101 104 102 … … 125 123 treeAnimProgMrt->AddParameter("oldTimer", 5); 126 124 125 126 //ShaderProgram *normalMappingVertexMrt, *normalMappingFragmentMrt; 127 128 //normalMappingVertexMrt = CreateFragmentProgram("normalMapping", "vtx", "normalMappingVertexMrt"); 129 //normalMappingFragmentMrt = CreateFragmentProgram("normalMapping", "frag", "normalMappingFragmentMrt"); 130 131 127 132 cout << "cg initialization successful" << endl; 128 133 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3127 r3128 471 471 //-- load some dynamic stuff 472 472 473 resourceManager->mUseNormalMapping = true; 474 //resourceManager->mUseNormalMapping = false; 475 476 LoadModel("fisch.dem", dynamicObjects); 477 473 //resourceManager->mUseNormalMapping = true; 478 474 resourceManager->mUseNormalMapping = false; 479 //LoadModel("hbuddha.dem", dynamicObjects); 475 476 //LoadModel("fisch.dem", dynamicObjects); 477 LoadModel("hbuddha.dem", dynamicObjects); 478 479 resourceManager->mUseNormalMapping = false; 480 480 481 buddha = dynamicObjects.back(); 481 482 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3123 r3128 6 6 //-- ssao + gi parameters 7 7 8 //#define NUM_SAMPLES 89 #define NUM_SAMPLES 168 #define NUM_SAMPLES 8 9 //#define NUM_SAMPLES 16 10 10 11 11 // for quadratic falloff 12 12 //#define SAMPLE_INTENSITY 0.1f 13 //#define SAMPLE_INTENSITY 0.07f14 #define SAMPLE_INTENSITY 0.015f13 #define SAMPLE_INTENSITY 0.07f 14 //#define SAMPLE_INTENSITY 0.015f 15 15 16 16 #define SAMPLE_RADIUS 8e-1f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
r3126 r3128 63 63 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 64 64 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 65 float scale) 65 float scale, 66 int index) 66 67 { 67 68 float average = .0f; … … 86 87 87 88 //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 88 89 89 depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 90 90 normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); … … 93 93 //w = filterWeights[i] * depthFactor; 94 94 95 average += aoSample .x* w;95 average += aoSample[index] * w; 96 96 total_w += w; 97 97 } … … 119 119 if (col.w < 1e10f) 120 120 { 121 //const static float scaleFactor = 10.0f; 122 const static float scaleFactor = 50.0f; 121 //const static float scaleFactor = 50.0f; 122 const static float scaleFactor = 10.0f; 123 const static float adaptFactor = 10.0f; 123 124 124 125 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 125 126 //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 126 127 //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 127 ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f);128 } 129 130 OUT.illum_col = col* ao.x;128 ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z / (adaptFactor + ao.y), 0); 129 } 130 131 OUT.illum_col.xyz = col.xyz * ao.x; 131 132 //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 132 133 //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); … … 135 136 return OUT; 136 137 } 138 139 float DiscontinuityFilter2(float2 texCoord, 140 float4 ao, 141 uniform sampler2D ssaoTex, 142 uniform sampler2D normalsTex, 143 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 144 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 145 float scale, 146 int index) 147 { 148 float average = .0f; 149 float total_w = .0f; 150 151 const float eyeSpaceDepth = ao.w; 152 const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 153 154 float4 aoSample; 155 float3 sampleNorm; 156 float w; 157 float4 offs; 158 float depthFactor; 159 float normalFactor; 160 161 for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 162 { 163 offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 164 aoSample = tex2Dlod(ssaoTex, offs); 165 166 sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 167 168 //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 169 depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 170 normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); 171 172 w = filterWeights[i] * normalFactor * depthFactor; 173 //w = filterWeights[i] * depthFactor; 174 175 average += aoSample.y * w; 176 total_w += w; 177 } 178 179 average *= 1.0f / max(total_w, 1e-6f); 180 181 return average; 182 } 183 184 pixel smoothSsao(fragment IN, 185 uniform sampler2D ssaoTex, 186 uniform sampler2D normalsTex, 187 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 188 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 189 ) 190 { 191 pixel OUT; 192 193 float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 194 195 //const static float scaleFactor = 10.0f; 196 const static float scaleFactor = 10.0f; 197 198 ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1); 199 200 OUT.illum_col = ao; 201 202 return OUT; 203 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
r3125 r3128 236 236 // newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 237 237 //if (newWeight >= 2000) newWeight = 1000; 238 //newWeight -= step(2000.0f, newWeight) * 1000.0f; 238 239 239 240 return float3(oldPixel.x, newWeight, eyeSpaceDepth); … … 380 381 381 382 const float oldSsao = temporalVals.x; 382 const float newWeight = temporalVals.y;383 384 //float2 noiseOffs = float2( newWeight / 139.0f, newWeight/ 141.0f);383 const float newWeight = clamp(temporalVals.y, .0f, temporalCoherence); 384 385 //float2 noiseOffs = float2(temporalVals.y / 139.0f, temporalVals.y / 141.0f); 385 386 float2 noiseOffs = float2(.0f); 386 387 … … 399 400 400 401 OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 401 OUT.illum_col.y = newWeight;402 OUT.illum_col.y = temporalVals.y; 402 403 OUT.illum_col.z = invw; 403 404 OUT.illum_col.w = temporalVals.z;
Note: See TracChangeset
for help on using the changeset viewer.