Changeset 2968
- Timestamp:
- 09/24/08 11:08:13 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
r2967 r2968 97 97 static CGparameter sLightDirParam; 98 98 static CGparameter sLightDirShadowParam; 99 100 99 static CGparameter sImageKeyParam; 100 static CGparameter sWhiteLumParam; 101 101 102 102 //#define USE_3D_SSAO … … 285 285 sColorsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "colors"); 286 286 sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 287 287 288 sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 288 289 } … … 407 408 408 409 sImageKeyParam = cgGetNamedParameter(sCgAntiAliasingProgram, "imageKey"); 410 sWhiteLumParam = cgGetNamedParameter(sCgAntiAliasingProgram, "whiteLum"); 409 411 410 412 sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors"); … … 438 440 sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture"); 439 441 sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 442 440 443 sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 441 444 … … 667 670 void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo) 668 671 { 669 const float imageKey = ToneMapper().CalcImageKey(fbo->GetColorBuffer(colorBufferIdx)); 670 671 GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 672 ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 673 674 // we assume that we have a floating point rgba texture 675 float *pixels = (float *)colorBuffer->ReadTexture(); 676 677 const int w = colorBuffer->GetHeight(); 678 const int h = colorBuffer->GetWidth(); 679 680 const float imageKey = ToneMapper().CalcImageKey(pixels, w, h); 681 const float whiteLum = 0.5f * ToneMapper().CalcMaxLuminance(pixels, w, h); 682 683 delete [] pixels; 684 685 GLuint colorsTex = colorBuffer->GetTexture(); 672 686 GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 673 687 … … 684 698 685 699 cgGLSetParameter1f(sImageKeyParam, imageKey); 700 cgGLSetParameter1f(sWhiteLumParam, whiteLum); 701 686 702 687 703 glColor3f(1.0f, 1.0f, 1.0f); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Light.h
r2954 r2968 16 16 public: 17 17 18 DirectionalLight(const Vector3 &dir, const RgbaColor &col): mColor(col) { mDirection = Normalize(dir); } 18 DirectionalLight(const Vector3 &dir, const RgbaColor &amb, const RgbaColor &dif): 19 mAmbient(amb), mDiffuse(dif) { mDirection = Normalize(dir); } 20 21 void SetDirection(const Vector3 &dir) { mDirection = dir; } 22 23 void SetDiffuseColor(const RgbaColor &dif) { mDiffuse = dif; } 24 25 void SetAmbientColor(const RgbaColor &amb) { mAmbient = amb; } 19 26 20 27 Vector3 GetDirection() const { return mDirection; } 21 void SetDirection(const Vector3 &dir) { mDirection = dir; } 22 23 RgbaColor GetColor() const { return mColor; } 28 RgbaColor GetDiffuseColor() const { return mDiffuse; } 29 RgbaColor GetAmbientColor() const { return mAmbient; } 24 30 25 31 … … 27 33 28 34 Vector3 mDirection; 29 RgbaColor mColor; 35 36 RgbaColor mDiffuse; 37 RgbaColor mAmbient; 30 38 }; 31 39 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
r2960 r2968 89 89 bool mAlphaTestEnabled; 90 90 bool mCullFaceEnabled; 91 /// the ass ciated texture91 /// the associated texture 92 92 Texture *mTexture; 93 93 }; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r2967 r2968 284 284 // downscale ambient color 285 285 //ambient *= 5e-5f; 286 ambient *= 2e-5f;286 //ambient *= 2e-3f; 287 287 288 288 // simulate the sun intensity by modulating the ambient term. 289 289 //ambient *= (1.0f - 0.9f * DotProd(sunDir, Vector3::UNIT_Z())); 290 ambient += Vector3(0.2f);290 //ambient += Vector3(0.2f); 291 291 292 292 Vector3 num; … … 321 321 322 322 // Calculate final sun diffuse color. 323 diffuse = color * 1.7e-4f;324 //diffuse = color;325 326 cout << "diffuse: " << Magnitude(diffuse) << " ambient: " << Magnitude(ambient) << endl;327 } 323 //diffuse = color * 2e-3f; 324 diffuse = color; 325 326 //cout << "diffuse: " << Magnitude(diffuse) << " ambient: " << Magnitude(ambient) << endl; 327 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.cpp
r2967 r2968 15 15 16 16 17 float ToneMapper::CalcImageKey( ColorBufferObject *colorBuffer) const17 float ToneMapper::CalcImageKey(float *pixels, int w, int h) const 18 18 { 19 19 float totalLum = .0f; 20 20 21 // we assume that we have a floating point rgba texture 22 float *pixels = (float *)colorBuffer->ReadTexture(); 21 int size = w * h * 4; 23 22 24 const int w = colorBuffer->GetHeight(); 25 const int h = colorBuffer->GetWidth(); 23 // get avg log luminance 24 for (int i = 0; i < size; i += 4) 25 { 26 float r = pixels[i + 0]; 27 float g = pixels[i + 1]; 28 float b = pixels[i + 2]; 26 29 27 // Get full scene luminance 28 for (int i = 0; i < h; ++ i) 30 float pixLum = 0.2125f * r + 0.7154f * g + 0.0721f * b; 31 32 totalLum += log(pixLum + 1e-6f); 33 } 34 35 const float key = exp(totalLum / (float)(w * h)); 36 37 static float previousKey = key; 38 const float factor = 1.0f; 39 40 const float imageKey = key;// * factor + previousKey * (1.0f - factor); 41 previousKey = imageKey; 42 43 cout << "key: " << key << endl; 44 45 return imageKey; 46 } 47 48 49 float ToneMapper::CalcMaxLuminance(float *pixels, int w, int h) const 50 { 51 float maxLum = 1e-6f; 52 53 int size = w * h * 4; 54 55 for (int i = 0; i < size; i += 4) 56 { 57 float r = pixels[i + 0]; 58 float g = pixels[i + 1]; 59 float b = pixels[i + 2]; 60 61 float pixLum = 0.2125f * r + 0.7154f * g + 0.0721f * b; 62 63 if (pixLum > maxLum) 64 maxLum = pixLum; 65 } 66 67 /* for (int i = 0; i < h; ++ i) 29 68 { 30 69 for (int j = 0; j < w; ++ j) … … 36 75 float b = pixels[4 * idx + 2]; 37 76 38 float pixLum = 0.2125f * r + 0.7154f * g + 0.0721f * b; 39 40 totalLum += log(pixLum + 1e-6f); 77 if (pixLum > maxLum) 78 maxLum = pixLum; 41 79 } 42 80 } 43 44 //cout << "totalLum: " << totalLum << endl; 45 46 const float key = exp(totalLum / (float)(w * h)); 47 48 static float previousKey = key; 49 50 //float delta = imageKey - mPreviousImageKey; 51 // Constaint change for temporal coherence 52 //const float maxChange = 5-e2f; 53 //Clamp(delta, -maxChange, maxChange); 54 55 const float factor = 1.0f; 56 57 const float imageKey = key;// * factor + previousKey * (1.0f - factor); 58 previousKey = imageKey; 59 60 cout << "key: " << key << endl; 61 62 delete [] pixels; 63 64 return imageKey; 81 */ 82 return maxLum; 65 83 } 66 84 85 67 86 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ToneMapper.h
r2966 r2968 7 7 { 8 8 9 class ColorBufferObject;10 9 11 10 /** Class representing a tone mapping algorithm … … 18 17 /** Caculates average log lumincance. 19 18 */ 20 float CalcImageKey(ColorBufferObject *colorBuffer) const; 19 float CalcImageKey(float *pixels, int w, int h) const; 20 21 float CalcMaxLuminance(float *pixels, int w, int h) const; 21 22 }; 22 23 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2967 r2968 377 377 378 378 // create a new light 379 light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1) );379 light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1), RgbaColor(1, 1, 1, 1)); 380 380 381 381 … … 576 576 sMaxDepthParamTex = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "maxDepth"); 577 577 RenderState::sTexParam = cgGetNamedParameter(RenderState::sCgMrtFragmentTexProgram, "tex"); 578 578 579 579 cgGLSetParameter1f(sMaxDepthParamTex, MAX_DEPTH_CONST / farDist); 580 580 } … … 595 595 596 596 sMaxDepthParam = cgGetNamedParameter(RenderState::sCgMrtFragmentProgram, "maxDepth"); 597 597 598 cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist); 598 599 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r2967 r2968 35 35 //-- tone mapping 36 36 37 //#define MIDDLE_GRAY 0.5f 37 38 //#define MIDDLE_GRAY 0.72f 38 //#define MIDDLE_GRAY 0.36f 39 #define MIDDLE_GRAY 0.18f 39 #define MIDDLE_GRAY 0.36f 40 //#define MIDDLE_GRAY 0.18f 41 //#define MIDDLE_GRAY 0.18f 40 42 41 43 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg
r2967 r2968 21 21 22 22 23 float3 ToneMap( const float imageKey, float3 color)23 float3 ToneMap(float imageKey, float whiteLum, float3 color) 24 24 { 25 25 float3 outCol; … … 29 29 const float lum = MIDDLE_GRAY * pixLum / imageKey; 30 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);*/ 31 // map to range and calc burnout 32 const float burnedLum = lum * (1.0f + lum / whiteLum * whiteLum) / (1.0f + lum); 37 33 38 outCol = color * scaledLum;34 outCol = color * burnedLum / pixLum; 39 35 //vColor.rgb += 0.6f * vBloom; 40 36 … … 42 38 } 43 39 40 44 41 float4 main(v2p IN, 45 42 uniform sampler2D colors, 46 43 uniform sampler2D normals, 47 uniform float imageKey 44 uniform float imageKey, 45 uniform float whiteLum 48 46 ): COLOR 49 47 { … … 115 113 116 114 //return float4(w); 117 col.xyz = ToneMap(imageKey, col.xyz);115 col.xyz = ToneMap(imageKey, whiteLum, col.xyz); 118 116 119 117 return col; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2967 r2968 37 37 float3 lightDir) 38 38 { 39 /*40 float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f);41 float3 light2 = normalize(lightDir2.xyz);42 float diffuseLight2 = saturate(dot(normal, light2));43 */44 39 // diffuse intensity 45 40 const float angle = saturate(dot(normal, lightDir)); … … 51 46 const float4 ambient = glstate.light[0].ambient; 52 47 53 return (emmisive < 0.95) ? (ambient + diffuse) * color : color;48 float4 outColor; 54 49 55 //return (saturate(((ambient + diffuse))) * (1.0f - emmisive) + emmisive) * color; 50 if (emmisive > 1.5) outColor = color; 51 //else if (emmisive > 0.95) outColor = color * lightDiffuse; 52 else 53 outColor = (ambient + diffuse) * color; 54 55 return outColor; 56 56 //return saturate((((ambient + diffuse)) * (1.0f - emmisive) + emmisive) * color); 57 57 } … … 82 82 83 83 OUT.color = col; 84 //OUT.color = float4(100.0, 1, 1, 0); 84 85 OUT.color.w = color.w; 85 86 … … 123 124 } 124 125 125 total_d /= (float)NUM_ SAMPLES;126 total_d /= (float)NUM_PCF_TABS; 126 127 127 128 return total_d; … … 182 183 183 184 // base lighting 184 OUT.color = (emmisive < 0.95) ? (ambient + diffuse) * color :color;185 OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 185 186 186 187 // also write out depth component -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg
r2967 r2968 24 24 float3 normal: TEXCOORD2; 25 25 float4 mypos: TEXCOORD3; 26 float4 color2: TEXCOORD4; 26 27 }; 27 28 28 29 29 … … 34 34 float4 norm: COLOR2; 35 35 }; 36 36 37 37 38 // fragment input … … 46 47 float3 normal: TEXCOORD2; 47 48 float4 mypos: TEXCOORD3; 49 float4 color2: TEXCOORD4; 48 50 }; 49 51 //-------------------------------------------------------------------------------------- … … 92 94 OUT.color = float4(hcol, 1.0); 93 95 94 //OUT.color.rgb *= 1e-2f;96 //OUT.color.rgb *= 2e-3f; 95 97 //OUT.color.rgb *= 2e-5f; 96 98 97 //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);99 OUT.color2 = OUT.color; 98 100 OUT.worldPos = mul(ModelView, IN.position); 99 101 … … 109 111 pixel pix; 110 112 111 pix.col = IN.color ;113 pix.col = IN.color2; 112 114 pix.pos = IN.worldPos * 1e20;// * maxDepth; 113 115 114 116 pix.norm.xyz = IN.normal; 115 117 116 // hack: squeeze some information about theambient term into the target117 pix.norm.w = 1;118 // hack: squeeze some information about an ambient term into the target 119 pix.norm.w = 2; 118 120 pix.pos.w = IN.mypos.w; 119 121
Note: See TracChangeset
for help on using the changeset viewer.