Changeset 2967


Ignore:
Timestamp:
09/23/08 18:02:33 (16 years ago)
Author:
mattausch
Message:
 
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  
    3535static CGprogram sCgCombinedIllumProgram = NULL; 
    3636 
     37 
    3738/////////////////////////////////////// 
    3839 
     
    9899 
    99100static CGparameter sImageKeyParam; 
    100 static CGparameter sImageKeyShadowParam; 
    101101 
    102102//#define USE_3D_SSAO 
     
    286286                sNormalsTexDeferredParam = cgGetNamedParameter(sCgDeferredProgram, "normals"); 
    287287                sLightDirParam = cgGetNamedParameter(sCgDeferredProgram, "lightDir"); 
    288  
    289                 sImageKeyParam = cgGetNamedParameter(sCgDeferredProgram, "imageKey"); 
    290288        } 
    291289        else 
     
    408406                cgGLLoadProgram(sCgAntiAliasingProgram); 
    409407 
     408                sImageKeyParam = cgGetNamedParameter(sCgAntiAliasingProgram, "imageKey"); 
     409 
    410410                sColorsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "colors");   
    411411                sNormalsTexAntiAliasingParam = cgGetNamedParameter(sCgAntiAliasingProgram, "normals"); 
     
    440440                sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 
    441441 
    442                 sImageKeyShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "imageKey"); 
    443442 
    444443                PoissonDiscSampleGenerator2 poisson(NUM_PCF_TABS, 1.0f); 
     
    668667void DeferredRenderer::AntiAliasing(FrameBufferObject *fbo) 
    669668{ 
     669        const float imageKey = ToneMapper().CalcImageKey(fbo->GetColorBuffer(colorBufferIdx)); 
     670 
    670671        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    671672        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     
    681682        cgGLSetTextureParameter(sNormalsTexAntiAliasingParam, normalsTex); 
    682683        cgGLEnableTextureParameter(sNormalsTexAntiAliasingParam); 
     684 
     685        cgGLSetParameter1f(sImageKeyParam, imageKey); 
    683686 
    684687        glColor3f(1.0f, 1.0f, 1.0f); 
     
    708711void DeferredRenderer::FirstPass(FrameBufferObject *fbo, DirectionalLight *light) 
    709712{ 
    710         const float imageKey = ToneMapper().CalcImageKey(fbo->GetColorBuffer(0)); 
    711  
    712713        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    713714        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     
    737738        cgGLSetParameter3f(sLightDirParam, lightDir.x, lightDir.y, lightDir.z); 
    738739 
    739         cgGLSetParameter1f(sImageKeyParam, imageKey); 
    740740 
    741741        glColor3f(1.0f, 1.0f, 1.0f); 
     
    978978                                                                           ShadowMap *shadowMap) 
    979979{ 
    980         const float imageKey = ToneMapper().CalcImageKey(fbo->GetColorBuffer(0)); 
    981  
    982980        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    983981 
     
    10241022        cgGLSetParameter3f(sLightDirShadowParam, lightDir.x, lightDir.y, lightDir.z); 
    10251023 
    1026         // the average log luminance for tone mapping 
    1027         cgGLSetParameter1f(sImageKeyShadowParam, imageKey); 
    10281024 
    10291025        glColor3f(1.0f, 1.0f, 1.0f); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r2961 r2967  
    272272        ComputeFactors(sunDir, zenithColor, ABCDE, sun_theta); 
    273273 
    274         ambient = zenithColor; 
    275  
    276274        Vector3 zenith_XYZ;                                                                                              
    277275 
    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;                                                                 
    281279 
    282280        ambient.x =  3.240479f * zenith_XYZ.x - 1.537150f * zenith_XYZ.y - 0.498535f * zenith_XYZ.z; 
     
    285283 
    286284        // downscale ambient color 
    287         ambient *= 5e-5f; 
     285        //ambient *= 5e-5f; 
     286        ambient *= 2e-5f; 
    288287 
    289288        // 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())); 
    291290        ambient += Vector3(0.2f); 
    292291 
     
    304303 
    305304 
    306         Vector3 xyY = (num / den) * zenithColor;     
     305        Vector3 xyY = zenithColor * num / den;     
    307306 
    308307        Vector3 XYZ;                                                                                              
     
    312311        XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z;                                                                 
    313312 
     313 
     314        ///////////// 
     315        //-- transform to rgb 
    314316 
    315317        Vector3 color;   
     
    319321 
    320322        // 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  
    11#include "ToneMapper.h" 
    22#include "FrameBufferObject.h" 
     3 
     4 
     5using namespace std; 
    36 
    47 
     
    1417float ToneMapper::CalcImageKey(ColorBufferObject *colorBuffer) const 
    1518{ 
    16         float totalLum = 0; 
     19        float totalLum = .0f; 
    1720 
    1821        // we assume that we have a floating point rgba texture 
     
    3538                        float pixLum = 0.2125f * r + 0.7154f * g + 0.0721f * b; 
    3639 
    37                         totalLum += log(pixLum + 1e-3f); 
     40                        totalLum += log(pixLum + 1e-6f); 
    3841                } 
    3942        } 
    4043 
    41         const float key = exp(totalLum) / (float)(w * h); 
     44        //cout << "totalLum: " << totalLum <<  endl; 
     45 
     46        const float key = exp(totalLum / (float)(w * h)); 
    4247 
    4348        static float previousKey = key; 
     
    4853        //Clamp(delta, -maxChange, maxChange); 
    4954 
    50         const float factor = 0.5f; 
     55        const float factor = 1.0f; 
    5156 
    52         const float imageKey = key * factor + previousKey * (1.0f - factor); 
     57        const float imageKey = key;// * factor + previousKey * (1.0f - factor); 
    5358        previousKey = imageKey; 
    5459         
     60        cout << "key: " << key << endl; 
     61 
    5562        delete [] pixels; 
    5663 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2965 r2967  
    828828        Vector3 sunDiffuse; 
    829829 
    830         Vector3 h; 
    831  
    832         h.x = lightDir.x; 
    833         h.y = lightDir.z; 
    834         h.z = lightDir.y; 
    835  
    836  
    837830        preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse); 
    838831 
     
    844837        ambient[2] = sunAmbient.z; 
    845838 
    846         sunDiffuse /= maxComponent; 
     839        //sunDiffuse /= maxComponent; 
    847840 
    848841        diffuse[0] = sunDiffuse.x; 
     
    15751568        lightDir = roty * lightDir; 
    15761569        lightDir = rotx * lightDir; 
     1570 
     1571        // normalize to avoid accumulating errors 
     1572        lightDir.Normalize(); 
    15771573 
    15781574        light->SetDirection(lightDir); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r2966 r2967  
    3535//-- tone mapping 
    3636 
     37//#define MIDDLE_GRAY 0.72f 
    3738//#define MIDDLE_GRAY 0.36f 
    3839#define MIDDLE_GRAY 0.18f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg

    r2891 r2967  
     1#include "../shaderenv.h" 
     2 
    13struct v2p 
    24{ 
     
    1820 
    1921 
     22 
     23float3 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 
    2044float4 main(v2p IN,  
    2145                        uniform sampler2D colors, 
    22                         uniform sampler2D normals 
     46                        uniform sampler2D normals, 
     47                        uniform float imageKey 
    2348                        ): COLOR 
    2449{ 
     
    86111        float4 sc = tex2Dlod(colors, float4(IN.c.xy, 0, 0)); 
    87112 
    88         return (s0 + s1 + s2 + s3 + sc) * 0.2f; 
     113        float4 col = (s0 + s1 + s2 + s3 + sc) * 0.2f; 
    89114        //return (s0 + s1 + s2 + s3) * 0.25f; 
     115 
    90116        //return float4(w); 
     117        col.xyz = ToneMap(imageKey, col.xyz); 
     118 
     119        return col; 
    91120} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2966 r2967  
    1515        float4 color: COLOR0; 
    1616}; 
    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 gray 
    26         const float lum = MIDDLE_GRAY * pixLum / imageKey; 
    27           
    28     // map to range 
    29         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 } 
    4017 
    4118 
     
    7451        const float4 ambient = glstate.light[0].ambient; 
    7552         
     53        return (emmisive < 0.95) ? (ambient + diffuse) * color : color; 
     54 
    7655        //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); 
    7857} 
    7958 
     
    8665                   uniform sampler2D positions, 
    8766                   uniform sampler2D normals, 
    88                    uniform float3 lightDir, 
    89                    uniform float imageKey 
     67                   uniform float3 lightDir 
    9068                   ) 
    9169{ 
     
    161139                                  uniform sampler2D noiseTexture, 
    162140                                  uniform float2 samples[NUM_PCF_TABS], 
    163                                   uniform float3 lightDir, 
    164                                   uniform float imageKey 
     141                                  uniform float3 lightDir 
    165142                                  ) 
    166143{ 
     
    207184        OUT.color = (emmisive < 0.95) ? (ambient + diffuse) * color : color; 
    208185 
    209         OUT.color.xyz = ToneMap(imageKey, OUT.color.xyz); 
    210  
    211186        // also write out depth component 
    212187        OUT.color.w = color.w; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg

    r2964 r2967  
    9292        OUT.color = float4(hcol, 1.0); 
    9393 
    94         OUT.color.rgb *= 5e-5f;  
     94        //OUT.color.rgb *= 1e-2f;  
     95        //OUT.color.rgb *= 2e-5f;  
    9596 
    9697        //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); 
Note: See TracChangeset for help on using the changeset viewer.