Changeset 3214 for GTP/trunk/App/Demos/Vis/FriendlyCulling
- Timestamp:
- 12/08/08 18:48:21 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3203 r3214 260 260 // nodes are tested using the subnodes from 3 levels below 261 261 mMaxDepthForTestingChildren = 3; 262 //mMaxDepthForTestingChildren = 4;263 264 262 // the ratio of area between node and subnodes where 265 263 // testing the subnodes as proxy is still considered feasable … … 268 266 269 267 mVboId = -1; 270 268 // bound the maximal depth of the dynamic branch 271 269 mMaxDepthForDynamicBranch = 10; 272 270 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r3213 r3214 59 59 if (dist < minDist) 60 60 { 61 cout << "minDist: " << dist << endl;61 //cout << "minDist: " << dist << endl; 62 62 minDist = dist; 63 63 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r3213 r3214 79 79 static float ssaoFilterWeights[NUM_SSAO_FILTER_SAMPLES]; 80 80 81 static Texture *sHaloTex[ 4];81 static Texture *sHaloTex[5]; 82 82 83 83 int DeferredRenderer::colorBufferIdx = 0; … … 300 300 static void PrepareLenseFlare() 301 301 { 302 string textures[] = {" lens1.jpg", "lens2.jpg", "lens3.jpg", "lens4.jpg"};303 304 for (int i = 0; i < 4; ++ i)302 string textures[] = {"flare4.tga", "lens2.jpg", "lens3.jpg", "lens4.jpg", "lens1.jpg"}; 303 304 for (int i = 0; i < 5; ++ i) 305 305 { 306 306 sHaloTex[i] = new Texture(model_path + textures[i]); 307 307 308 sHaloTex[i]->SetBoundaryModeS(Texture:: CLAMP);309 sHaloTex[i]->SetBoundaryModeT(Texture:: CLAMP);308 sHaloTex[i]->SetBoundaryModeS(Texture::BORDER); 309 sHaloTex[i]->SetBoundaryModeT(Texture::BORDER); 310 310 311 311 sHaloTex[i]->Create(); … … 501 501 string lenseFlareParams[] = 502 502 {"colorsTex", "flareTex1", "flareTex2", "flareTex3", "flareTex4", 503 " vectorToLight", "distanceToLight"};504 505 sCgLenseFlareProgram->AddParameters(lenseFlareParams, 0, 7);503 "flareTex5", "vectorToLight", "distanceToLight"}; 504 505 sCgLenseFlareProgram->AddParameters(lenseFlareParams, 0, 8); 506 506 507 507 … … 555 555 bool useToneMapping, 556 556 bool useAntiAliasing, 557 bool lightSourceVisible, 557 558 ShadowMap *shadowMap 558 559 ) … … 567 568 if (mShadingMethod != 0) 568 569 { 569 // downsample fbo buffers 570 PrepareSsao(fbo); 570 PrepareSsao(fbo); // downsample fbo buffers 571 571 } 572 572 … … 584 584 CombineIllum(fbo); 585 585 break; 586 default: // DEFAULT586 default: 587 587 // do nothing: standard deferred shading 588 588 break; … … 598 598 599 599 600 LenseFlare(fbo, light); 600 if (lightSourceVisible) 601 LenseFlare(fbo, light); 601 602 602 603 // multisampling is difficult / costly with deferred shading … … 1277 1278 // the sun is a large distance in the reverse light direction 1278 1279 // => extrapolate light pos 1279 1280 1280 const Vector3 lightPos = light->GetDirection() * -1e3f; 1281 1281 1282 Vector3 projLightPos = mProjViewMatrix * lightPos * 0.5f + Vector3(0.5f); 1283 cout << "lightPos " << projLightPos << endl; 1284 1285 // check if light is visible in the image 1286 if ((projLightPos.x < -0.2f) || (projLightPos.y < -0.2f) || 1287 (projLightPos.x >= 1.2f) || (projLightPos.y >= 1.2f)) 1282 float w; 1283 Vector3 projLightPos = mProjViewMatrix.Transform(w, lightPos, 1.0f); 1284 projLightPos /= w; 1285 projLightPos = projLightPos * 0.5f + Vector3(0.5f); 1286 1287 //Vector3 dummy = mProjViewMatrix * lightPos; 1288 1289 // check if light out of image range 1290 /*if ((projLightPos.x < -0.2f) || (projLightPos.y < -0.2f) || 1291 (projLightPos.x >= 1.2f) || (projLightPos.y >= 1.2f) || 1292 (w < .0f)) 1288 1293 return; 1289 1294 */ 1290 1295 // vector to light from screen center in texture space 1291 1296 Vector3 vectorToLight = projLightPos - Vector3(0.5f); … … 1295 1300 vectorToLight /= distanceToLight; 1296 1301 1297 cout << "dist " << distanceToLight << " v " << vectorToLight << endl;1302 //cout << "dist " << distanceToLight << " v " << vectorToLight << endl; 1298 1303 1299 1304 … … 1310 1315 sCgLenseFlareProgram->SetTexture(i ++, sHaloTex[2]->GetId()); 1311 1316 sCgLenseFlareProgram->SetTexture(i ++, sHaloTex[3]->GetId()); 1317 sCgLenseFlareProgram->SetTexture(i ++, sHaloTex[4]->GetId()); 1312 1318 sCgLenseFlareProgram->SetValue2f(i ++, vectorToLight.x, vectorToLight.y); 1313 1319 sCgLenseFlareProgram->SetValue1f(i ++, distanceToLight); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
r3213 r3214 42 42 bool useToneMapping, 43 43 bool useAntiAliasing, 44 bool isLightSourceVisible, 44 45 ShadowMap *shadowMap = NULL 45 46 ); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp
r3021 r3214 242 242 243 243 float dist = plane.Distance(center); 244 //cout << "dist: " << dist<< endl; 245 if (dist > 0) 246 return false; 244 245 if (dist > 0) return false; 247 246 } 248 247 return true; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3153 r3214 86 86 87 87 88 static Technique GetDummyTechnique()89 {90 Technique tech;91 tech.Init();92 93 tech.SetColorWriteEnabled(true);94 tech.SetLightingEnabled(true);95 tech.SetDepthWriteEnabled(false);96 //tech.SetCullFaceEnabled(false);97 98 return tech;99 }100 101 88 /** A special technique for occlusion queries. This material 102 89 has color write, depth write, and lighting turned off -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp
r2865 r3214 64 64 65 65 66 static int GetGlWrapMode(int mode) 67 { 68 switch (mode) 69 { 70 case Texture::REPEAT: return GL_REPEAT; 71 case Texture::CLAMP: return GL_CLAMP_TO_EDGE; 72 case Texture::BORDER: return GL_CLAMP_TO_BORDER; 73 default: return GL_CLAMP_TO_EDGE; 74 } 75 76 return GL_CLAMP_TO_EDGE; 77 } 78 79 66 80 void Texture::Create() 67 81 { … … 75 89 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4); 76 90 77 int glWrapModeS = (mBoundaryModeS == REPEAT) ? GL_REPEAT : GL_CLAMP_TO_EDGE; 78 int glWrapModeT = (mBoundaryModeT == REPEAT) ? GL_REPEAT : GL_CLAMP_TO_EDGE; 79 80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glWrapModeS); 81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glWrapModeT); 91 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrapMode(mBoundaryModeS)); 92 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrapMode(mBoundaryModeT)); 82 93 83 94 if (mUseMipMap) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.h
r3212 r3214 19 19 enum {FORMAT_INVALID, FORMAT_RGB, FORMAT_RGBA}; 20 20 // texture uv modes 21 enum {CLAMP, REPEAT };21 enum {CLAMP, REPEAT, BORDER}; 22 22 23 23 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3212 r3214 71 71 /// the renderable scene geometry 72 72 SceneEntityContainer sceneEntities; 73 /// the dynamic objects in the scene 73 74 SceneEntityContainer dynamicObjects; 74 75 // traverses and renders the hierarchy … … 251 252 SceneEntity *buddha = NULL; 252 253 SceneEntity *skyDome = NULL; 254 SceneEntity *sunBox = NULL; 255 256 GLuint sunQuery = 0; 253 257 254 258 … … 271 275 /// render the objects found visible in the depth pass 272 276 void RenderVisibleObjects(); 277 278 bool TestSunVisible(); 273 279 274 280 void Begin2D(); … … 565 571 566 572 CreateAnimation(); 573 574 ////////////////////////// 575 //-- a bounding box representing the sun position 576 //-- in order to test sun visibility 577 Transform3 *trafo = resourceManager->CreateTransform(IdentityMatrix()); 578 579 // make it slightly bigger to simulate sun diameter 580 const float size = 25.0f; 581 AxisAlignedBox3 sbox(Vector3(-size), Vector3(size)); 582 583 SceneEntityConverter conv; 584 585 // toto clean up material 586 Material *mat = new Material(); 587 588 mat->GetTechnique(0)->SetDepthWriteEnabled(false); 589 mat->GetTechnique(0)->SetColorWriteEnabled(false); 590 591 sunBox = conv.ConvertBox(sbox, mat, trafo); 592 593 glGenQueriesARB(1, &sunQuery); 567 594 568 595 … … 1133 1160 1134 1161 1162 bool sunVisible = TestSunVisible(); 1163 1164 1135 1165 /////////////// 1136 1166 //-- render sky … … 1170 1200 1171 1201 ShadowMap *sm = showShadowMap ? shadowMap : NULL; 1172 deferredShader->Render(fbo, ssaoTempCohFactor, light, useHDR, useAntiAliasing, s m);1202 deferredShader->Render(fbo, ssaoTempCohFactor, light, useHDR, useAntiAliasing, sunVisible, sm); 1173 1203 } 1174 1204 … … 2217 2247 motionPath = new MotionPath(vertices); 2218 2248 } 2249 2250 2251 bool TestSunVisible() 2252 { 2253 // assume sun is at a far away point along the light vector 2254 Vector3 sunPos = light->GetDirection() * -1e3f; 2255 sunPos += camera->GetPosition(); 2256 2257 sunBox->GetTransform()->SetMatrix(TranslationMatrix(sunPos)); 2258 2259 glBeginQueryARB(GL_SAMPLES_PASSED_ARB, sunQuery); 2260 2261 sunBox->Render(&renderState); 2262 2263 glEndQueryARB(GL_SAMPLES_PASSED_ARB); 2264 2265 GLuint sampleCount; 2266 2267 glGetQueryObjectuivARB(sunQuery, GL_QUERY_RESULT_ARB, &sampleCount); 2268 2269 return (sampleCount > 0); 2270 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3212 r3214 52 52 #define WHITE_LUMINANCE 3e4f 53 53 54 #define TONE_MAPPING_EXPONENTIAL_FACTOR 1e-1f 55 54 56 55 57 /////////////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/lenseFlare.cg
r3213 r3214 7 7 8 8 9 inline float2 ComputeTexCoords(float2 tex, float2 v, float dist, float scale, float distScale) 10 { 11 const float2 center = float2(.5f, .5f); 12 const float2 newPos = -v * dist * distScale; 13 //const float2 newPos = v * dist * distScale; 14 15 //return (tex - center - newPos) / scale + newPos + center; 16 return (tex - center) / scale + center + newPos / scale; 17 //return tex / scale - center;// + center + newPos; 18 } 19 20 21 inline float4 ComputeColor(sampler2D tex, float2 texCoords, float2 v, float dist, float scale, float distScale) 22 { 23 const float2 newTexCoords = ComputeTexCoords(texCoords, v, dist, scale, distScale); 24 return tex2Dlod(tex, float4(newTexCoords, 0, 0)); 25 } 26 9 27 10 28 float4 LenseFlare(fragment IN, … … 14 32 uniform sampler2D flareTex3, 15 33 uniform sampler2D flareTex4, 34 uniform sampler2D flareTex5, 16 35 uniform float2 vectorToLight, // vector to current light position 17 36 uniform float distanceToLight // distance to current light position … … 21 40 const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0)); 22 41 23 const float scale = 0.5f; 24 const float center = float2(.5f, .5f); 25 const float2 newPos = vectorToLight * distanceToLight; 42 const float scale = 0.3f; 26 43 27 const float2 newTexCoords = (IN.texCoords - center) / scale + center - newPos;44 float4 flare[8]; 28 45 29 const float4 flare1 = tex2Dlod(flareTex1, float4(newTexCoords, 0, 0)); 46 flare[0] = ComputeColor(flareTex1, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, 1.0f); 47 flare[1] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 0.7f * scale, 1.0f / 3.0f); 48 flare[2] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, 0.25f * scale, 0.7f); 49 flare[3] = ComputeColor(flareTex4, IN.texCoords, vectorToLight, distanceToLight, .7f * scale, -1.0f / 2.0f); 50 flare[4] = ComputeColor(flareTex3, IN.texCoords, vectorToLight, distanceToLight, .4f * scale, -1.0f / 6.0f); 30 51 31 float4 result; 52 flare[5] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .1f * scale, 0.5f); 53 flare[6] = ComputeColor(flareTex5, IN.texCoords, vectorToLight, distanceToLight, .2f * scale, -0.25f); 32 54 33 result.w = color.w;55 flare[7] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, -1.0f); 34 56 35 //const float factor = 0.9f; 36 //result.xyz = lerp(color.xyz, flare1.xyz, factor); 37 //result.xyz = color.xyz * (1.0f - flare1.w) + flare1.xyz * flare1.w; 38 result.xyz = color.xyz + flare1.xyz; 57 float4 result = color; 58 59 //result.xyz = float3(0); 60 for (int i = 0; i < 8; ++ i) 61 result.xyz += flare[i].xyz; 39 62 40 63 return result; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg
r3198 r3214 139 139 //-- exponential smoothing of the tone mapping over time 140 140 141 const float expFactor = 1e-2f;142 143 141 if (oldLogLum > 1e-3f) // check if loglum from last frame too small (=> tm too bright) 144 OUT.col.w = lerp(oldLogLum, logLumScaled, expFactor);142 OUT.col.w = lerp(oldLogLum, logLumScaled, TONE_MAPPING_EXPONENTIAL_FACTOR); 145 143 else 146 144 OUT.col.w = logLumScaled;
Note: See TracChangeset
for help on using the changeset viewer.