Changeset 3215


Ignore:
Timestamp:
12/08/08 23:13:38 (15 years ago)
Author:
mattausch
Message:

worked on lense flare, cleaned up code a little bit

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r3212 r3215  
    1212# triangles per bvh leaf (influences hierarchy depth vs. occlusion power) 
    1313trianglesPerVirtualLeaf=300 
    14  
     14# max depth for searching for nodes for tight bounds 
    1515maxDepthForTestingChildren=3 
    1616 
     
    3434#camDirection=1 0 0 
    3535 
    36 #camPosition=468.025 267.591 182.478 
    37 #camDirection=0.937282 0.348573 -0 
    38  
    39 # bad view point (culling bug!) 
    40 camPosition=469.381 267.293 184.778 
    41 camDirection=0.142006 0.645885 -0.750111 
    42  
    43 #camPosition=458.412 255.767 182.632 
    44 #camDirection=0.891691 0.42723 0.149535 
    45  
    46 #camPosition=740.137 487.855 188.506 
    47 #camDirection=0.669256 0.727829 0.149535 
    48  
    49 #camPosition=492.678 249.827 187.232 
    50 #camDirection=-0.651041 -0.693292 -0.309017 
     36camPosition=468.025 267.591 182.478 
     37camDirection=0.937282 0.348573 -0 
    5138 
    5239#lightDirection=-0.8f 1.0f -0.7f 
     
    5744# window options 
    5845 
    59 //winWidth=800 
    60 //winHeight=600 
     46#winWidth=800 
     47#winHeight=600 
    6148 
    6249winWidth=1024 
     
    8370useAA=1 
    8471 
     72# show lense flare 
     73useLenseFlare=1 
     74 
    8575# use ssao / color bleeding 
    8676useAdvancedShading=1 
     
    8979turbitity=3.0f 
    9080 
    91 #second bad view point 
    92 //camPosition=465.626 248.788 184.978 
    93 //camDirection=0.0592959 0.998021 0.0209425 
    94  
    9581ssaoKernelRadius=8e-1f 
    9682 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3214 r3215  
    328328mSortSamples(true), 
    329329mKernelRadius(1e-8f), 
    330 mSampleIntensity(0.2f) 
     330mSampleIntensity(0.2f), 
     331mSunVisiblePixels(0) 
    331332{ 
    332333        /////////// 
     
    393394        glDeleteTextures(1, &noiseTex1D); 
    394395} 
    395  
    396  
    397 void DeferredRenderer::SetUseTemporalCoherence(bool temporal) 
    398 { 
    399         mUseTemporalCoherence = temporal; 
    400 } 
    401  
    402396 
    403397 
     
    501495        string lenseFlareParams[] =  
    502496                {"colorsTex", "flareTex1", "flareTex2", "flareTex3", "flareTex4",  
    503                  "flareTex5", "vectorToLight", "distanceToLight"}; 
    504  
    505         sCgLenseFlareProgram->AddParameters(lenseFlareParams, 0, 8); 
     497                 "flareTex5", "vectorToLight", "distanceToLight", "sunVisiblePixels"}; 
     498 
     499        sCgLenseFlareProgram->AddParameters(lenseFlareParams, 0, 9); 
    506500 
    507501 
     
    555549                                                          bool useToneMapping, 
    556550                                                          bool useAntiAliasing, 
    557                                                           bool lightSourceVisible, 
    558551                                                          ShadowMap *shadowMap 
    559552                                                          ) 
     
    597590        } 
    598591 
    599  
    600         if (lightSourceVisible) 
    601                 LenseFlare(fbo, light); 
     592        /// compute lense flare 
     593        LenseFlare(fbo, light); 
    602594 
    603595        // multisampling is difficult / costly with deferred shading 
     
    989981 
    990982 
    991 void DeferredRenderer::SetSamplingMethod(SAMPLING_METHOD s)  
    992 {  
    993         if (s != mSamplingMethod) 
    994         { 
    995                 mSamplingMethod = s;  
    996                 mRegenerateSamples = true; 
    997         } 
    998 } 
    999  
    1000  
    1001 void DeferredRenderer::SetShadingMethod(SHADING_METHOD s) 
    1002 { 
    1003         if (s != mShadingMethod) 
    1004         { 
    1005                 mShadingMethod = s;  
    1006                 mRegenerateSamples = true; 
    1007         } 
    1008 } 
    1009  
    1010  
    1011 #if TODO 
    1012  
    1013 void DeferredRenderer::SetNumSamples(int numSamples) 
    1014 { 
    1015         mNumSamples = numSamples; 
    1016 } 
    1017  
    1018 #endif 
    1019  
    1020  
    1021 void DeferredRenderer::SetSampleIntensity(float sampleIntensity) 
    1022 { 
    1023         mSampleIntensity = sampleIntensity; 
    1024 } 
    1025  
    1026  
    1027 void DeferredRenderer::SetKernelRadius(float kernelRadius) 
    1028 { 
    1029         mKernelRadius = kernelRadius; 
    1030 } 
    1031  
    1032  
    1033983void DeferredRenderer::ComputeToneParameters(FrameBufferObject *fbo,  
    1034984                                                                                         DirectionalLight *light, 
     
    12731223 
    12741224void DeferredRenderer::LenseFlare(FrameBufferObject *fbo, 
    1275                                                                   DirectionalLight *light 
     1225                                                                  DirectionalLight *light                                                        
    12761226                                                                  ) 
    12771227{ 
     1228        // light source not visible 
     1229        if (!mSunVisiblePixels) return; 
     1230 
    12781231        // the sun is a large distance in the reverse light direction 
    12791232        // => extrapolate light pos 
     
    12851238        projLightPos = projLightPos * 0.5f + Vector3(0.5f); 
    12861239 
    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)) 
    1293                 return; 
    1294 */ 
    12951240        // vector to light from screen center in texture space 
    12961241        Vector3 vectorToLight = projLightPos - Vector3(0.5f); 
     
    13181263        sCgLenseFlareProgram->SetValue2f(i ++, vectorToLight.x, vectorToLight.y); 
    13191264        sCgLenseFlareProgram->SetValue1f(i ++, distanceToLight); 
     1265        sCgLenseFlareProgram->SetValue1f(i ++, (float)mSunVisiblePixels); 
    13201266 
    13211267        DrawQuad(sCgLenseFlareProgram); 
     
    13251271 
    13261272 
     1273 
     1274void DeferredRenderer::SetUseTemporalCoherence(bool temporal) 
     1275{ 
     1276        mUseTemporalCoherence = temporal; 
     1277} 
     1278 
     1279 
     1280void DeferredRenderer::SetSamplingMethod(SAMPLING_METHOD s)  
     1281{  
     1282        if (s != mSamplingMethod) 
     1283        { 
     1284                mSamplingMethod = s;  
     1285                mRegenerateSamples = true; 
     1286        } 
     1287} 
     1288 
     1289 
     1290void DeferredRenderer::SetShadingMethod(SHADING_METHOD s) 
     1291{ 
     1292        if (s != mShadingMethod) 
     1293        { 
     1294                mShadingMethod = s;  
     1295                mRegenerateSamples = true; 
     1296        } 
     1297} 
     1298 
     1299 
     1300#if TODO 
     1301 
     1302void DeferredRenderer::SetNumSamples(int numSamples) 
     1303{ 
     1304        mNumSamples = numSamples; 
     1305} 
     1306 
     1307#endif 
     1308 
     1309 
     1310void DeferredRenderer::SetSampleIntensity(float sampleIntensity) 
     1311{ 
     1312        mSampleIntensity = sampleIntensity; 
     1313} 
     1314 
     1315 
     1316void DeferredRenderer::SetKernelRadius(float kernelRadius) 
     1317{ 
     1318        mKernelRadius = kernelRadius; 
     1319} 
     1320 
     1321 
     1322void DeferredRenderer::SetSortSamples(bool sortSamples)  
     1323{ 
     1324        mSortSamples = sortSamples;  
     1325} 
     1326 
     1327 
     1328void DeferredRenderer::SetSunVisiblePixels(int pixels)  
     1329{ 
     1330        mSunVisiblePixels = pixels; 
     1331} 
     1332 
     1333 
     1334 
    13271335} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3214 r3215  
    4242                                bool useToneMapping, 
    4343                                bool useAntiAliasing, 
    44                                 bool isLightSourceVisible, 
    4544                                ShadowMap *shadowMap = NULL 
    4645                                ); 
     
    5049 
    5150        enum SAMPLING_METHOD {SAMPLING_POISSON, SAMPLING_QUADRATIC, SAMPLING_DEFAULT}; 
     51         
    5252        enum SHADING_METHOD {DEFAULT, SSAO, GI}; 
     53 
    5354        /** Set the samplig method for the indirect illumination 
    5455        */ 
     
    5859        void SetShadingMethod(SHADING_METHOD s); 
    5960 
    60         void SetSortSamples(bool sortSamples) { mSortSamples = sortSamples; } 
     61        void SetSortSamples(bool sortSamples); 
    6162 
    6263        void SetSampleIntensity(float sampleIntensity); 
    6364 
    6465        void SetKernelRadius(float kernelRadius); 
     66        /** Sets the number of visible pixels of the sun 
     67        */ 
     68        void SetSunVisiblePixels(int visiblePixels); 
    6569 
    6670 
     
    125129        //////////// 
    126130 
     131        /// deferred shading output image width 
    127132        int mWidth; 
     133        /// deferred shading output image height 
    128134        int mHeight; 
    129135 
     
    139145 
    140146        int mIllumFboIndex; 
    141         // the fbo for indirect illumination (ssao + color bleeding) 
     147        /// the fbo for indirect illumination (ssao + color bleeding) 
    142148        FrameBufferObject *mIllumFbo; 
    143149 
     
    161167        float mKernelRadius; 
    162168        float mSampleIntensity; 
     169 
     170        int mSunVisiblePixels; 
    163171}; 
    164172 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3154 r3215  
    449449} 
    450450 
    451 } 
     451 
     452 
     453Material *ResourceManager::CreateMaterial() 
     454{ 
     455        Material *mat = new Material(); 
     456        mMaterials.push_back(mat); 
     457 
     458        return mat; 
     459} 
     460 
     461} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h

    r3127 r3215  
    5050        */ 
    5151        static void DelSingleton(); 
    52         /** Adds a scene entity to be handled by the resource mananger. 
     52        /** Adds a scene entity to the resource mananger, which from now on is handled by the manager. 
    5353        */ 
    5454        void AddSceneEntity(SceneEntity *ent); 
    55         /** Adds a scene entity to be handled by the resource mananger. 
     55        /** Creates a new transform. 
    5656        */ 
    5757        Transform3 *CreateTransform(const Matrix4x4 &m); 
     58        /** Creates a new default material that is handled by the manager. 
     59        */ 
     60        Material *CreateMaterial(); 
    5861 
    59  
     62        /// giant hack: set this to true if the geometry to load has tangent data for normal mapping 
    6063        bool mUseNormalMapping; 
    6164 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3214 r3215  
    217217bool useHDR = true; 
    218218bool useAntiAliasing = true; 
     219bool useLenseFlare = true; 
    219220 
    220221PerfTimer frameTimer, algTimer; 
     
    276277void RenderVisibleObjects(); 
    277278 
    278 bool TestSunVisible(); 
     279int TestSunVisible(); 
    279280 
    280281void Begin2D(); 
     
    391392                env.GetBoolParam(string("useHDR"), useHDR); 
    392393                env.GetBoolParam(string("useAA"), useAntiAliasing); 
     394                env.GetBoolParam(string("useLenseFlare"), useLenseFlare); 
    393395                env.GetBoolParam(string("useAdvancedShading"), useAdvancedShading); 
    394396 
     
    418420                cout << "render method: " << renderMethod << endl; 
    419421                cout << "use antialiasing: " << useAntiAliasing << endl; 
     422                cout << "use lense flare: " << useLenseFlare << endl; 
    420423                cout << "use advanced shading: " << useAdvancedShading << endl; 
    421424                cout << "turbitity: " << turbitity << endl; 
     
    584587 
    585588        // toto clean up material 
    586         Material *mat = new Material(); 
     589        Material *mat = resourceManager->CreateMaterial(); 
    587590 
    588591        mat->GetTechnique(0)->SetDepthWriteEnabled(false); 
     
    591594        sunBox = conv.ConvertBox(sbox, mat, trafo); 
    592595         
     596        resourceManager->AddSceneEntity(sunBox); 
     597 
     598        /// create single occlusion query that handles sun visibility 
    593599        glGenQueriesARB(1, &sunQuery); 
    594600 
     
    11581164                RenderVisibleObjects(); 
    11591165        } 
    1160          
    1161  
    1162         bool sunVisible = TestSunVisible(); 
     1166 
     1167        const bool useDeferred =  
     1168                ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)); 
     1169 
     1170        // if no lense flare => just set sun to invisible 
     1171        int sunVisiblePixels = useLenseFlare  &&  useDeferred ? TestSunVisible() : 0; 
    11631172 
    11641173 
     
    11721181 
    11731182 
    1174         if ((renderMethod == RENDER_DEFERRED) || 
    1175                 (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 
     1183        if (useDeferred) 
    11761184        { 
    11771185                FrameBufferObject::Release(); 
     
    11921200                        shadingMethod = DeferredRenderer::DEFAULT; 
    11931201 
     1202                deferredShader->SetSunVisiblePixels(sunVisiblePixels); 
    11941203                deferredShader->SetShadingMethod(shadingMethod); 
    11951204                deferredShader->SetSamplingMethod(samplingMethod); 
     
    12001209 
    12011210                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
    1202                 deferredShader->Render(fbo, ssaoTempCohFactor, light, useHDR, useAntiAliasing, sunVisible, sm); 
     1211                deferredShader->Render(fbo, ssaoTempCohFactor, light, useHDR, useAntiAliasing, sm); 
    12031212        } 
    12041213 
     
    14001409                useAntiAliasing = !useAntiAliasing; 
    14011410                break; 
    1402         /*case '?': 
    1403                 sortSamples = !sortSamples; 
    1404                 break; 
    1405         */ 
     1411        case 'c': 
     1412        case 'C': 
     1413                useLenseFlare = !useLenseFlare; 
     1414                break; 
    14061415        default: 
    14071416                return; 
     
    22482257} 
    22492258 
    2250  
    2251 bool TestSunVisible() 
     2259/** This function returns the number of visible pixels of a 
     2260        bounding box representing the sun. 
     2261*/ 
     2262int TestSunVisible() 
    22522263{ 
    22532264        // assume sun is at a far away point along the light vector 
     
    22672278        glGetQueryObjectuivARB(sunQuery, GL_QUERY_RESULT_ARB, &sampleCount); 
    22682279 
    2269         return (sampleCount > 0); 
    2270 } 
     2280        return sampleCount; 
     2281} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/lenseFlare.cg

    r3214 r3215  
    3434                                  uniform sampler2D flareTex5, 
    3535                                  uniform float2 vectorToLight, // vector to current light position 
    36                                   uniform float distanceToLight // distance to current light position 
     36                                  uniform float distanceToLight, // distance to current light position 
     37                                  uniform float sunVisiblePixels 
    3738                                  ): COLOR 
    3839{ 
     
    5859 
    5960        //result.xyz = float3(0); 
     61        sunVisiblePixels = clamp(sunVisiblePixels, .0f, 100.0f) * 0.01f; 
     62 
    6063        for (int i = 0; i < 8; ++ i) 
    61                 result.xyz += flare[i].xyz; 
     64                result.xyz += flare[i].xyz * sunVisiblePixels; 
    6265 
    6366        return result; 
Note: See TracChangeset for help on using the changeset viewer.