Ignore:
Timestamp:
09/02/08 15:29:20 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2894 r2895  
    3434#include "FrameBufferObject.h" 
    3535#include "SsaoShader.h" 
    36 #include "DeferredShader.h" 
    3736#include "ShadowMapping.h" 
    3837#include "Light.h" 
     
    9594static int winHeight = 768; 
    9695 
    97 //static int winWidth = 512; 
    98 //static int winHeight = 512; 
    99  
    10096 
    10197static float winAspectRatio = 1.0f; 
     
    172168bool useLODs = true; 
    173169 
    174 int samplingMethod = SsaoShader::POISSON; 
     170SsaoShader::SAMPLING_METHOD samplingMethod = SsaoShader::POISSON; 
     171SsaoShader::SHADING_METHOD shadingMethod = SsaoShader::DEFAULT; 
     172 
     173bool showShadowMap = false; 
     174bool shadowChanged = true; 
    175175 
    176176static Matrix4x4 matProjectionView = IdentityMatrix(); 
     
    179179ShadowMap *shadowMap = NULL; 
    180180Light *light = NULL; 
     181 
    181182 
    182183// function forward declarations 
     
    225226 
    226227SsaoShader *ssaoShader = NULL; 
    227 DeferredShader *deferredShader = NULL; 
    228228 
    229229static GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; 
     
    431431        InitCg(); 
    432432 
    433         DeferredShader::Init(sCgContext); 
    434433        SsaoShader::Init(sCgContext); 
    435434 
     
    442441        sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
    443442 
    444         Vector3 lightDir = Normalize(Vector3(0, 1, -1)); 
     443        //Vector3 lightDir = Normalize(Vector3(0, 1, -1)); 
     444        Vector3 lightDir = Normalize(-Vector3(0.8f, -1.0f, 0.7f)); 
     445         
    445446        light = new Light(lightDir, RgbaColor(1, 1, 1, 1)); 
    446447 
    447         const float shadowSize = 4096; 
    448         shadowMap = new ShadowMap(shadowSize, bvh->GetBox(), camera); 
    449          
     448 
    450449        // frame time is restarted every frame 
    451450        frameTimer.Start(); 
     
    867866        } 
    868867         
     868        if (showShadowMap && !shadowMap) 
     869        { 
     870                const float shadowSize = 4096; 
     871                shadowMap = new ShadowMap(shadowSize, bvh->GetBox(), camera); 
     872        } 
     873 
    869874        // render without shading 
    870875        switch (renderType) 
     
    897902         
    898903                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    899  
    900904                glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    901905 
     
    904908        case RenderState::DEFERRED: 
    905909 
    906                 shadowMap->ComputeShadowMap(light, traverser); 
     910                // change CHC state (must be done for each change of camera) 
     911                BvhNode::SetCurrentState(1); 
     912 
     913                if (showShadowMap && shadowChanged) 
     914                { 
     915                        shadowChanged = false; 
     916 
     917                        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     918                        cgGLDisableProfile(RenderState::sCgVertexProfile); 
     919 
     920                        state.SetRenderType(RenderState::DEPTH_PASS); 
     921 
     922                        // the scene is rendered withouth any shading    
     923                        shadowMap->ComputeShadowMap(light, traverser); 
     924 
     925                        // change back state 
     926                        BvhNode::SetCurrentState(0); 
     927 
     928                        glEnable(GL_LIGHTING); 
     929                        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     930                } 
    907931 
    908932                if (!fbo) InitFBO(); 
     933 
    909934 
    910935                // multisampling does not work with deferred shading 
     
    9891014                cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    9901015 
    991                 if (useSsao) 
    992                 { 
    993                         if (!ssaoShader) ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
    994                         ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor); 
    995  
    996                 } 
    997                 else 
    998                 { 
    999                         if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight, myfar / 10.0f); 
    1000                          
    1001                         deferredShader->Render(fbo, shadowMap); 
    1002                 } 
     1016                if (!ssaoShader) ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
     1017                 
     1018                ssaoShader->SetShadingMethod(shadingMethod); 
     1019                ssaoShader->SetSamplingMethod(samplingMethod); 
     1020                ssaoShader->SetUseTemporalCoherence(useTemporalCoherence); 
     1021 
     1022                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
     1023                ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor, sm); 
    10031024        } 
    10041025 
     
    11181139                        samplingMethod = SsaoShader::GAUSS; 
    11191140 
    1120                 ssaoShader->SetSamplingMethod(samplingMethod); 
    1121  
     1141                break; 
     1142        case 'Y': 
     1143        case 'y': 
     1144                showShadowMap = !showShadowMap; 
    11221145                break; 
    11231146        case 'g': 
    1124         case 'G': 
    1125                 useGlobIllum = !useGlobIllum; 
    1126                 ssaoShader->SetUseGlobIllum(useGlobIllum); 
    1127                 break; 
    11281147        case 't': 
    11291148        case 'T': 
    11301149                useTemporalCoherence = !useTemporalCoherence; 
    1131                 ssaoShader->SetUseTemporalCoherence(useTemporalCoherence); 
    11321150                break; 
    11331151        case 'o': 
     
    12621280                break; 
    12631281        case GLUT_KEY_F8: 
    1264                 useSsao = !useSsao; 
     1282                shadingMethod = (SsaoShader::SHADING_METHOD)((shadingMethod + 1) % 3); 
     1283                 
    12651284                break; 
    12661285        case GLUT_KEY_F9: 
     
    15621581        DEL_PTR(fbo); 
    15631582        DEL_PTR(ssaoShader); 
    1564         DEL_PTR(deferredShader); 
    15651583 
    15661584        if (sCgMrtVertexProgram) 
     
    17661784} 
    17671785 
    1768  
     1786// render visible object from depth pass 
    17691787void RenderVisibleObjects() 
    17701788{ 
Note: See TracChangeset for help on using the changeset viewer.