- Timestamp:
- 09/23/08 18:02:33 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2966 r2967 35 35 static CGprogram sCgCombinedIllumProgram = NULL; 36 36 37 37 38 /////////////////////////////////////// 38 39 … … 98 99 99 100 static CGparameter sImageKeyParam; 100 static CGparameter sImageKeyShadowParam;101 101 102 102 //#define USE_3D_SSAO … … 286 286 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 287 287 sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 288 289 sImageKeyParam = cgGetNamedParameter(sCgDeferredProgram, "imageKey");290 288 } 291 289 else … … 408 406 cgGLLoadProgram(sCgAntiAliasingProgram); 409 407 408 sImageKeyParam = cgGetNamedParameter(sCgAntiAliasingProgram, "imageKey"); 409 410 410 sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors"); 411 411 sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); … … 440 440 sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 441 441 442 sImageKeyShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "imageKey");443 442 444 443 PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f); … … 668 667 void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo) 669 668 { 669 const float imageKey = ToneMapper().CalcImageKey(fbo->GetColorBuffer(colorBufferIdx)); 670 670 671 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 671 672 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); … … 681 682 cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 682 683 cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 684 685 cgGLSetParameter1f(sImageKeyParam, imageKey); 683 686 684 687 glColor3f(1.0f, 1.0f, 1.0f); … … 708 711 void DeferredRenderer::FirstPass(FrameBufferObject *fbo, DirectionalLight *light) 709 712 { 710 const float imageKey = ToneMapper().CalcImageKey(fbo->GetColorBuffer(0));711 712 713 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 713 714 GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); … … 737 738 cgGLSetParameter3f(sLightDirParam, lightDir.x, lightDir.y, lightDir.z); 738 739 739 cgGLSetParameter1f(sImageKeyParam, imageKey);740 740 741 741 glColor3f(1.0f, 1.0f, 1.0f); … … 978 978 ShadowMap *shadowMap) 979 979 { 980 const float imageKey = ToneMapper().CalcImageKey(fbo->GetColorBuffer(0));981 982 980 GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 983 981 … … 1024 1022 cgGLSetParameter3f(sLightDirShadowParam, lightDir.x, lightDir.y, lightDir.z); 1025 1023 1026 // the average log luminance for tone mapping1027 cgGLSetParameter1f(sImageKeyShadowParam, imageKey);1028 1024 1029 1025 glColor3f(1.0f, 1.0f, 1.0f); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r2961 r2967 272 272 ComputeFactors(sunDir, zenithColor, ABCDE, sun_theta); 273 273 274 ambient = zenithColor;275 276 274 Vector3 zenith_XYZ; 277 275 278 zenith_XYZ.x = ( ambient.x / ambient.y) * ambient.z;279 zenith_XYZ.y = ambient.z;280 zenith_XYZ.z = ((1.0f - ambient.x - ambient.y) / ambient.y) * ambient.z;276 zenith_XYZ.x = (zenithColor.x / zenithColor.y) * zenithColor.z; 277 zenith_XYZ.y = zenithColor.z; 278 zenith_XYZ.z = ((1.0f - zenithColor.x - zenithColor.y) / zenithColor.y) * zenithColor.z; 281 279 282 280 ambient.x = 3.240479f * zenith_XYZ.x - 1.537150f * zenith_XYZ.y - 0.498535f * zenith_XYZ.z; … … 285 283 286 284 // downscale ambient color 287 ambient *= 5e-5f; 285 //ambient *= 5e-5f; 286 ambient *= 2e-5f; 288 287 289 288 // simulate the sun intensity by modulating the ambient term. 290 ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z()));289 //ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z())); 291 290 ambient += Vector3(0.2f); 292 291 … … 304 303 305 304 306 Vector3 xyY = (num / den) * zenithColor;305 Vector3 xyY = zenithColor * num / den; 307 306 308 307 Vector3 XYZ; … … 312 311 XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z; 313 312 313 314 ///////////// 315 //-- transform to rgb 314 316 315 317 Vector3 color; … … 319 321 320 322 // Calculate final sun diffuse color. 321 diffuse = color * 0.00017f; 322 } 323 diffuse = color * 1.7e-4f; 324 //diffuse = color; 325 326 cout << "diffuse: " << Magnitude(diffuse) << " ambient: " << Magnitude(ambient) << endl; 327 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp
r2966 r2967 1 1 #include "ToneMapper.h" 2 2 #include "FrameBufferObject.h" 3 4 5 using namespace std; 3 6 4 7 … … 14 17 float ToneMapper::CalcImageKey(ColorBufferObject *colorBuffer) const 15 18 { 16 float totalLum = 0;19 float totalLum = .0f; 17 20 18 21 // we assume that we have a floating point rgba texture … … 35 38 float pixLum = 0.2125f * r + 0.7154f * g + 0.0721f * b; 36 39 37 totalLum += log(pixLum + 1e- 3f);40 totalLum += log(pixLum + 1e-6f); 38 41 } 39 42 } 40 43 41 const float key = exp(totalLum) / (float)(w * h); 44 //cout << "totalLum: " << totalLum << endl; 45 46 const float key = exp(totalLum / (float)(w * h)); 42 47 43 48 static float previousKey = key; … … 48 53 //Clamp(delta, -maxChange, maxChange); 49 54 50 const float factor = 0.5f;55 const float factor = 1.0f; 51 56 52 const float imageKey = key * factor + previousKey * (1.0f - factor);57 const float imageKey = key;// * factor + previousKey * (1.0f - factor); 53 58 previousKey = imageKey; 54 59 60 cout << "key: " << key << endl; 61 55 62 delete [] pixels; 56 63 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2965 r2967 828 828 Vector3 sunDiffuse; 829 829 830 Vector3 h;831 832 h.x = lightDir.x;833 h.y = lightDir.z;834 h.z = lightDir.y;835 836 837 830 preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse); 838 831 … … 844 837 ambient[2] = sunAmbient.z; 845 838 846 sunDiffuse /= maxComponent;839 //sunDiffuse /= maxComponent; 847 840 848 841 diffuse[0] = sunDiffuse.x; … … 1575 1568 lightDir = roty * lightDir; 1576 1569 lightDir = rotx * lightDir; 1570 1571 // normalize to avoid accumulating errors 1572 lightDir.Normalize(); 1577 1573 1578 1574 light->SetDirection(lightDir); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2966 r2967 35 35 //-- tone mapping 36 36 37 //#define MIDDLE_GRAY 0.72f 37 38 //#define MIDDLE_GRAY 0.36f 38 39 #define MIDDLE_GRAY 0.18f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r2891 r2967 1 #include "../shaderenv.h" 2 1 3 struct v2p 2 4 { … … 18 20 19 21 22 23 float3 ToneMap(const float imageKey, float3 color) 24 { 25 float3 outCol; 26 const float pixLum = 0.2125f * color.x + 0.7154f * color.y + 0.0721f * color.z; 27 28 // adjust to middle gray 29 const float lum = MIDDLE_GRAY * pixLum / imageKey; 30 31 // map to range 32 const float scaledLum = lum / (1.0f + lum); 33 34 /*outCol *= MIDDLE_GRAY / (vLum + 1e-3f); 35 outCol *= (1.0f + vColor / LUM_WHITE); 36 outCol /= (1.0f + vColor);*/ 37 38 outCol = color * scaledLum; 39 //vColor.rgb += 0.6f * vBloom; 40 41 return outCol; 42 } 43 20 44 float4 main(v2p IN, 21 45 uniform sampler2D colors, 22 uniform sampler2D normals 46 uniform sampler2D normals, 47 uniform float imageKey 23 48 ): COLOR 24 49 { … … 86 111 float4 sc = tex2Dlod(colors, float4(IN.c.xy, 0, 0)); 87 112 88 return(s0 + s1 + s2 + s3 + sc) * 0.2f;113 float4 col = (s0 + s1 + s2 + s3 + sc) * 0.2f; 89 114 //return (s0 + s1 + s2 + s3) * 0.25f; 115 90 116 //return float4(w); 117 col.xyz = ToneMap(imageKey, col.xyz); 118 119 return col; 91 120 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2966 r2967 15 15 float4 color: COLOR0; 16 16 }; 17 18 19 20 float3 ToneMap(const float imageKey, float3 color)21 {22 float3 outCol;23 const float pixLum = 0.2125f * color.x + 0.7154f * color.y + 0.0721f * color.z;24 25 // adjust to middle gray26 const float lum = MIDDLE_GRAY * pixLum / imageKey;27 28 // map to range29 const float scaledLum = lum / (1.0f + lum);30 31 /*outCol *= MIDDLE_GRAY / (vLum + 1e-3f);32 outCol *= (1.0f + vColor / LUM_WHITE);33 outCol /= (1.0f + vColor);*/34 35 outCol = color / scaledLum;36 //vColor.rgb += 0.6f * vBloom;37 38 return outCol;39 }40 17 41 18 … … 74 51 const float4 ambient = glstate.light[0].ambient; 75 52 53 return (emmisive < 0.95) ? (ambient + diffuse) * color : color; 54 76 55 //return (saturate(((ambient + diffuse))) * (1.0f - emmisive) + emmisive) * color; 77 return saturate((((ambient + diffuse)) * (1.0f - emmisive) + emmisive) * color);56 //return saturate((((ambient + diffuse)) * (1.0f - emmisive) + emmisive) * color); 78 57 } 79 58 … … 86 65 uniform sampler2D positions, 87 66 uniform sampler2D normals, 88 uniform float3 lightDir, 89 uniform float imageKey 67 uniform float3 lightDir 90 68 ) 91 69 { … … 161 139 uniform sampler2D noiseTexture, 162 140 uniform float2 samples[NUM_PCF_TABS], 163 uniform float3 lightDir, 164 uniform float imageKey 141 uniform float3 lightDir 165 142 ) 166 143 { … … 207 184 OUT.color = (emmisive < 0.95) ? (ambient + diffuse) * color : color; 208 185 209 OUT.color.xyz = ToneMap(imageKey, OUT.color.xyz);210 211 186 // also write out depth component 212 187 OUT.color.w = color.w; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
r2964 r2967 92 92 OUT.color = float4(hcol, 1.0); 93 93 94 OUT.color.rgb *= 5e-5f; 94 //OUT.color.rgb *= 1e-2f; 95 //OUT.color.rgb *= 2e-5f; 95 96 96 97 //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);
Note: See TracChangeset
for help on using the changeset viewer.