Changeset 3214


Ignore:
Timestamp:
12/08/08 18:48:21 (15 years ago)
Author:
mattausch
Message:

worked on lense flare

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  
    260260        // nodes are tested using the subnodes from 3 levels below 
    261261        mMaxDepthForTestingChildren = 3; 
    262         //mMaxDepthForTestingChildren = 4; 
    263  
    264262        // the ratio of area between node and subnodes where  
    265263        // testing the subnodes as proxy is still considered feasable 
     
    268266 
    269267        mVboId = -1; 
    270  
     268        // bound the maximal depth of the dynamic branch 
    271269        mMaxDepthForDynamicBranch = 10; 
    272270} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r3213 r3214  
    5959                        if (dist < minDist) 
    6060                        { 
    61                                 cout << "minDist: " << dist << endl; 
     61                                //cout << "minDist: " << dist << endl; 
    6262                                minDist = dist; 
    6363                        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3213 r3214  
    7979static float ssaoFilterWeights[NUM_SSAO_FILTER_SAMPLES]; 
    8080 
    81 static Texture *sHaloTex[4]; 
     81static Texture *sHaloTex[5]; 
    8282 
    8383int DeferredRenderer::colorBufferIdx = 0; 
     
    300300static void PrepareLenseFlare() 
    301301{ 
    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) 
    305305        { 
    306306                sHaloTex[i] = new Texture(model_path + textures[i]); 
    307307 
    308                 sHaloTex[i]->SetBoundaryModeS(Texture::CLAMP); 
    309                 sHaloTex[i]->SetBoundaryModeT(Texture::CLAMP); 
     308                sHaloTex[i]->SetBoundaryModeS(Texture::BORDER); 
     309                sHaloTex[i]->SetBoundaryModeT(Texture::BORDER); 
    310310 
    311311                sHaloTex[i]->Create(); 
     
    501501        string lenseFlareParams[] =  
    502502                {"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); 
    506506 
    507507 
     
    555555                                                          bool useToneMapping, 
    556556                                                          bool useAntiAliasing, 
     557                                                          bool lightSourceVisible, 
    557558                                                          ShadowMap *shadowMap 
    558559                                                          ) 
     
    567568        if (mShadingMethod != 0) 
    568569        { 
    569                 // downsample fbo buffers 
    570                 PrepareSsao(fbo); 
     570                PrepareSsao(fbo); // downsample fbo buffers 
    571571        } 
    572572 
     
    584584                CombineIllum(fbo); 
    585585                break; 
    586         default: // DEFAULT 
     586        default: 
    587587                // do nothing: standard deferred shading 
    588588                break; 
     
    598598 
    599599 
    600         LenseFlare(fbo, light); 
     600        if (lightSourceVisible) 
     601                LenseFlare(fbo, light); 
    601602 
    602603        // multisampling is difficult / costly with deferred shading 
     
    12771278        // the sun is a large distance in the reverse light direction 
    12781279        // => extrapolate light pos 
    1279          
    12801280        const Vector3 lightPos = light->GetDirection() * -1e3f; 
    12811281 
    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)) 
    12881293                return; 
    1289  
     1294*/ 
    12901295        // vector to light from screen center in texture space 
    12911296        Vector3 vectorToLight = projLightPos - Vector3(0.5f); 
     
    12951300        vectorToLight /= distanceToLight; 
    12961301 
    1297         cout << "dist " << distanceToLight << " v " << vectorToLight << endl; 
     1302        //cout << "dist " << distanceToLight << " v " << vectorToLight << endl; 
    12981303 
    12991304 
     
    13101315        sCgLenseFlareProgram->SetTexture(i ++, sHaloTex[2]->GetId()); 
    13111316        sCgLenseFlareProgram->SetTexture(i ++, sHaloTex[3]->GetId()); 
     1317        sCgLenseFlareProgram->SetTexture(i ++, sHaloTex[4]->GetId()); 
    13121318        sCgLenseFlareProgram->SetValue2f(i ++, vectorToLight.x, vectorToLight.y); 
    13131319        sCgLenseFlareProgram->SetValue1f(i ++, distanceToLight); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3213 r3214  
    4242                                bool useToneMapping, 
    4343                                bool useAntiAliasing, 
     44                                bool isLightSourceVisible, 
    4445                                ShadowMap *shadowMap = NULL 
    4546                                ); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp

    r3021 r3214  
    242242 
    243243                float dist = plane.Distance(center); 
    244                 //cout << "dist: " << dist<< endl; 
    245                 if (dist > 0)  
    246                         return false; 
     244                 
     245                if (dist > 0) return false; 
    247246        } 
    248247        return true; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3153 r3214  
    8686 
    8787 
    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  
    10188/** A special technique for occlusion queries. This material 
    10289        has color write, depth write, and lighting turned off 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp

    r2865 r3214  
    6464 
    6565 
     66static 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 
    6680void Texture::Create() 
    6781{ 
     
    7589        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4); 
    7690 
    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)); 
    8293 
    8394        if (mUseMipMap) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.h

    r3212 r3214  
    1919        enum {FORMAT_INVALID, FORMAT_RGB, FORMAT_RGBA}; 
    2020        // texture uv modes 
    21         enum {CLAMP, REPEAT}; 
     21        enum {CLAMP, REPEAT, BORDER}; 
    2222 
    2323 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3212 r3214  
    7171/// the renderable scene geometry 
    7272SceneEntityContainer sceneEntities; 
     73/// the dynamic objects in the scene 
    7374SceneEntityContainer dynamicObjects; 
    7475// traverses and renders the hierarchy 
     
    251252SceneEntity *buddha = NULL; 
    252253SceneEntity *skyDome = NULL; 
     254SceneEntity *sunBox = NULL; 
     255 
     256GLuint sunQuery = 0; 
    253257 
    254258 
     
    271275/// render the objects found visible in the depth pass 
    272276void RenderVisibleObjects(); 
     277 
     278bool TestSunVisible(); 
    273279 
    274280void Begin2D(); 
     
    565571 
    566572        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); 
    567594 
    568595 
     
    11331160         
    11341161 
     1162        bool sunVisible = TestSunVisible(); 
     1163 
     1164 
    11351165        /////////////// 
    11361166        //-- render sky 
     
    11701200 
    11711201                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
    1172                 deferredShader->Render(fbo, ssaoTempCohFactor, light, useHDR, useAntiAliasing, sm); 
     1202                deferredShader->Render(fbo, ssaoTempCohFactor, light, useHDR, useAntiAliasing, sunVisible, sm); 
    11731203        } 
    11741204 
     
    22172247        motionPath = new MotionPath(vertices); 
    22182248} 
     2249 
     2250 
     2251bool 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  
    5252#define WHITE_LUMINANCE 3e4f 
    5353 
     54#define TONE_MAPPING_EXPONENTIAL_FACTOR 1e-1f 
     55 
    5456 
    5557/////////////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/lenseFlare.cg

    r3213 r3214  
    77 
    88 
     9inline 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 
     21inline 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 
    927 
    1028float4 LenseFlare(fragment IN,  
     
    1432                                  uniform sampler2D flareTex3, 
    1533                                  uniform sampler2D flareTex4, 
     34                                  uniform sampler2D flareTex5, 
    1635                                  uniform float2 vectorToLight, // vector to current light position 
    1736                                  uniform float distanceToLight // distance to current light position 
     
    2140        const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0)); 
    2241         
    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; 
    2643 
    27         const float2 newTexCoords = (IN.texCoords - center) / scale + center - newPos; 
     44        float4 flare[8]; 
    2845 
    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); 
    3051 
    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); 
    3254 
    33         result.w = color.w; 
     55        flare[7] = ComputeColor(flareTex2, IN.texCoords, vectorToLight, distanceToLight, 1.0f * scale, -1.0f); 
    3456 
    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; 
    3962 
    4063        return result; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r3198 r3214  
    139139        //-- exponential smoothing of the tone mapping over time 
    140140 
    141         const float expFactor = 1e-2f; 
    142          
    143141        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); 
    145143        else 
    146144                OUT.col.w = logLumScaled; 
Note: See TracChangeset for help on using the changeset viewer.