Changeset 2928


Ignore:
Timestamp:
09/10/08 17:35:26 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
8 edited

Legend:

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

    r2911 r2928  
    816816                        </File> 
    817817                        <File 
    818                                 RelativePath=".\src\shaders\shadow.cg" 
    819                                 > 
    820                         </File> 
    821                         <File 
    822818                                RelativePath=".\src\shaders\ssao.cg" 
    823819                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r2927 r2928  
    1212 
    1313// our coordinate system has the positive z axis pointing up 
    14 static Vector3 baseDir = Vector3(0, 1, 0); 
     14static const Vector3 baseDir = -Vector3::UNIT_Y(); 
    1515 
    1616 
     
    4949 
    5050 
    51 void Camera::Precompute(const Vector3 &direction)  
    52 { 
    53         Vector3 up = Vector3(0, 0, 1); 
    54         Vector3 right = Normalize(CrossProd(up, direction)); 
    55         up = Normalize(CrossProd(direction, right)); 
    56  
    57         mBaseOrientation = Matrix4x4(right, up, direction); 
     51void Camera::Precompute(const Vector3 &dir)  
     52{ 
     53        Vector3 up = Vector3::UNIT_Z(); 
     54        Vector3 right = Normalize(CrossProd(dir, up)); 
     55        up = Normalize(CrossProd(right, dir)); 
     56 
     57        mBaseOrientation = Matrix4x4(right, up, -dir); 
    5858        mViewOrientation = mBaseOrientation; 
    5959} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r2903 r2928  
    2222static CGprogram sCgAntiAliasingProgram = NULL; 
    2323static CGprogram sCgDeferredShadowProgram = NULL; 
     24static CGprogram sCgShadowDebugProgram = NULL; 
    2425 
    2526static CGparameter sColorsTexCombineParam; 
     
    2930static CGparameter sPositionsTexDeferredParam; 
    3031static CGparameter sNormalsTexDeferredParam; 
     32 
     33static CGparameter sShadowMapDebugParam;   
     34static CGparameter sShadowMatrixDebugParam; 
     35static CGparameter sColorsTexDebugParam; 
    3136 
    3237 
     
    431436        else 
    432437                cerr << "deferred program failed to load" << endl; 
     438 
     439        sCgShadowDebugProgram =  
     440                cgCreateProgramFromFile(context,  
     441                                                                CG_SOURCE, 
     442                                                                "src/shaders/deferred.cg",  
     443                                                                RenderState::sCgFragmentProfile, 
     444                                                                "main_shadow_debug", 
     445                                                                NULL); 
     446 
     447        if (sCgShadowDebugProgram != NULL) 
     448        { 
     449                cgGLLoadProgram(sCgShadowDebugProgram); 
     450 
     451                // we need size of texture for scaling 
     452                sShadowMapDebugParam = cgGetNamedParameter(sCgShadowDebugProgram, "shadowMap");   
     453                sShadowMatrixDebugParam = cgGetNamedParameter(sCgShadowDebugProgram, "shadowMatrix"); 
     454                sColorsTexDebugParam = cgGetNamedParameter(sCgShadowDebugProgram, "colorTex");   
     455        } 
     456        else 
     457                cerr << "shadow debug program failed to load" << endl; 
     458 
    433459        PrintGLerror("init"); 
    434460} 
     
    471497        glLoadIdentity(); 
    472498 
    473         if (shadowMap) 
    474                 FirstPassShadow(fbo, shadowMap); 
     499        if (shadowMap && (mShadingMethod == GI)) 
     500        { 
     501                ShadowDebug(fbo, shadowMap); 
     502        } 
    475503        else 
    476                 FirstPass(fbo); 
    477          
    478         switch (mShadingMethod) 
    479         { 
    480         case SSAO: 
    481                 ComputeSsao(fbo, tempCohFactor, oldProjViewMatrix, projViewMatrix); 
    482                 CombineSsao(fbo); 
    483                 break; 
    484         case GI: 
    485                 ComputeGlobIllum(fbo, tempCohFactor, oldProjViewMatrix); 
    486                 CombineIllum(fbo); 
    487                 break; 
    488         default: // DEFAULT 
    489                 // do nothing: standard deferred shading 
    490                 break; 
    491         } 
    492  
    493         AntiAliasing(fbo); 
    494  
     504        { 
     505                if (shadowMap) 
     506                        FirstPassShadow(fbo, shadowMap); 
     507                else 
     508                        FirstPass(fbo); 
     509 
     510                switch (mShadingMethod) 
     511                { 
     512                case SSAO: 
     513                        ComputeSsao(fbo, tempCohFactor, oldProjViewMatrix, projViewMatrix); 
     514                        CombineSsao(fbo); 
     515                        break; 
     516                case GI: 
     517                        ComputeGlobIllum(fbo, tempCohFactor, oldProjViewMatrix); 
     518                        CombineIllum(fbo); 
     519                        break; 
     520                default: // DEFAULT 
     521                        // do nothing: standard deferred shading 
     522                        break; 
     523                } 
     524 
     525                AntiAliasing(fbo); 
     526        } 
    495527        glEnable(GL_LIGHTING); 
    496528        glDisable(GL_TEXTURE_2D); 
     
    735767        PrintGLerror("deferred shading"); 
    736768} 
     769 
    737770 
    738771 
     
    952985        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    953986        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    954         GLuint shadowTex = shadowMap->GetShadowTexture(); 
     987        GLuint shadowTex = shadowMap->GetDepthTexture(); 
    955988 
    956989        Matrix4x4 shadowMatrix; 
     
    10081041 
    10091042 
     1043void DeferredRenderer::ShadowDebug(FrameBufferObject *fbo, ShadowMap *shadowMap) 
     1044{ 
     1045        GLuint colorsTex = shadowMap->GetShadowColorTexture(); 
     1046        GLuint shadowTex = shadowMap->GetDepthTexture(); 
     1047         
     1048 
     1049        Matrix4x4 shadowMatrix; 
     1050        shadowMap->GetTextureMatrix(shadowMatrix); 
     1051 
     1052        //glMatrixMode(GL_PROJECTION);glLoadIdentity(); 
     1053        //glViewport(0, 0, shadowMap->GetSize(), shadowMap->GetSize()); 
     1054 
     1055        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1056 
     1057        cgGLBindProgram(sCgShadowDebugProgram); 
     1058 
     1059        cgGLSetTextureParameter(sShadowMapDebugParam, shadowTex); 
     1060        cgGLSetTextureParameter(sColorsTexDebugParam, colorsTex); 
     1061 
     1062        cgGLEnableTextureParameter(sShadowMapDebugParam); 
     1063 
     1064        cgGLSetMatrixParameterfc(sShadowMatrixDebugParam, (const float *)shadowMatrix.x); 
     1065 
     1066        glColor3f(1.0f, 1.0f, 1.0f); 
     1067         
     1068        glBegin(GL_QUADS); 
     1069 
     1070        float offs2 = 0.5f; 
     1071 
     1072        glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); 
     1073        glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f); 
     1074        glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f); 
     1075        glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f); 
     1076 
     1077        glEnd(); 
     1078 
     1079        cgGLDisableTextureParameter(sColorsTexDebugParam); 
     1080        cgGLDisableTextureParameter(sShadowMapDebugParam); 
     1081 
     1082        PrintGLerror("shadows debug"); 
     1083} 
     1084 
     1085 
    10101086void DeferredRenderer::SetSamplingMethod(SAMPLING_METHOD s)  
    10111087{  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r2901 r2928  
    6262protected: 
    6363 
    64         void ComputeSsao(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix, const Matrix4x4 &projViewMatrix); 
     64        void ComputeSsao(FrameBufferObject *fbo,  
     65                                         float tempCohFactor,  
     66                                         const Matrix4x4 &oldProjViewMatrix,  
     67                                         const Matrix4x4 &projViewMatrix); 
    6568 
    6669        void ComputeGlobIllum(FrameBufferObject *fbo, float tempCohFactor, const Matrix4x4 &oldProjViewMatrix); 
     
    7881        */ 
    7982        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 
     83 
     84 
     85        void ShadowDebug(FrameBufferObject *fbo, ShadowMap *shadowMap); 
    8086 
    8187 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2925 r2928  
    111111        // the diffuse color buffer 
    112112        mFbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    113  
    114         mShadowCam = new Camera(mSceneBox.Size().x * 0.5f, mSceneBox.Size().y * 0.5f); 
     113        //mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
     114 
     115        mShadowCam = new Camera(mSize, mSize);//mSceneBox.Size().x * 0.5f, mSceneBox.Size().y * 0.5f); 
    115116        mShadowCam->SetOrtho(true); 
    116117} 
     
    204205                                                                                 ) 
    205206{ 
     207        //return IdentityMatrix(); 
     208 
    206209        AxisAlignedBox3 bounds_ls = GetExtremalPoints(lightSpace, body); 
    207         //return IdentityMatrix(); 
    208210 
    209211        /////////////// 
     
    212214 
    213215        //const float n = 1e6f; 
    214         const float n = ComputeN(bounds_ls); 
     216        //const float n = 1e1f; 
     217        const float n = ComputeN(bounds_ls) * 100; 
    215218 
    216219        cout << "n: " << n << endl; 
     
    228231 
    229232        // the new projection center 
    230         Vector3 projCenter = startPt + Vector3::UNIT_Z() * n * 1000; 
     233        Vector3 projCenter = startPt + Vector3::UNIT_Z() * n; 
    231234 
    232235        cout <<"start: " << startPt << " " << projCenter << " " << Distance(lightSpace * mCamera->GetPosition(), startPt) << endl; 
     
    245248         
    246249 
    247         //////// 
     250        ////////// 
    248251        //-- now apply these values to construct the perspective lispsm matrix 
    249252 
     
    518521        //mCamera->GetModelViewMatrix(camView); 
    519522 
    520         pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.1f); 
     523        pos -= dir * Magnitude(mSceneBox.Diagonal() * 0.5f); 
    521524        mShadowCam->SetPosition(pos); 
    522525 
     
    530533        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    531534 
     535        //glEnable(GL_LIGHTING); 
     536        //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    532537        glDisable(GL_LIGHTING); 
    533538        glDisable(GL_TEXTURE_2D); 
     
    597602 
    598603        glPopAttrib(); 
     604 
     605         
     606        glEnable(GL_LIGHTING); 
     607        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
     608 
    599609#if 0 
    600610        float *data = new float[mSize * mSize]; 
     
    617627 
    618628  
    619 unsigned int ShadowMap::GetShadowTexture() const 
     629unsigned int ShadowMap::GetDepthTexture() const 
    620630{ 
    621631        return mFbo->GetDepthTex(); 
    622632} 
    623633 
    624  
     634unsigned int ShadowMap::GetShadowColorTexture() const 
     635{ 
     636        return mFbo->GetColorBuffer(0)->GetTexture(); 
     637         
     638} 
    625639 
    626640} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2920 r2928  
    3636        */ 
    3737        void ComputeShadowMap(RenderTraverser *traverser, const Matrix4x4 &projView); 
    38         /** Returns computed shadow texture. 
     38        /** Returns computed shadow color texture. 
    3939        */ 
    40         unsigned int GetShadowTexture() const; 
     40        unsigned int GetShadowColorTexture() const; 
     41         
     42        unsigned int GetDepthTexture() const; 
     43 
    4144        /** Returns computed texture matrix. It must be applied on the 
    4245                the world space positions.  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2927 r2928  
    914914                        { 
    915915                                const float shadowSize = 4096; 
     916                                //const float shadowSize = 512; 
    916917                                shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera); 
    917918                        } 
     
    925926                        shadowChanged = false; 
    926927 
     928#if 0 
     929                        state.SetRenderType(RenderState::DEFERRED); 
     930 
     931                        fbo->Bind(); 
     932 
     933                        glPushAttrib(GL_VIEWPORT_BIT); 
     934                        glViewport(0, 0, texWidth, texHeight); 
     935 
     936                        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     937                        cgGLBindProgram(RenderState::sCgMrtFragmentProgram); 
     938 
     939                        cgGLEnableProfile(RenderState::sCgVertexProfile); 
     940                        cgGLBindProgram(sCgMrtVertexProgram); 
     941#else 
     942 
    927943                        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    928944                        cgGLDisableProfile(RenderState::sCgVertexProfile); 
    929945 
    930946                        state.SetRenderType(RenderState::DEPTH_PASS); 
    931  
     947#endif 
    932948                        // the scene is rendered withouth any shading    
    933949                        shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView); 
     
    936952                        BvhNode::SetCurrentState(0); 
    937953 
    938                         glEnable(GL_LIGHTING); 
    939                         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    940954                } 
    941955 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2911 r2928  
    153153        return OUT; 
    154154} 
     155 
     156 
     157/** The mrt shader for standard rendering 
     158*/ 
     159pixel main_shadow_debug(fragment IN,  
     160                                                uniform sampler2D shadowMap, 
     161                                                uniform sampler2D colorTex, 
     162                                                uniform float4x4 shadowMatrix) 
     163{ 
     164        pixel OUT; 
     165#if 0 
     166        // visualize depth 
     167        OUT.color = tex2Dlod(colorTex, float4(IN.texCoord.xy, 0, 0)); 
     168#else 
     169        float4 col; 
     170        col = tex2Dlod(shadowMap, float4(IN.texCoord.xy, 0, 0)); 
     171        OUT.color = float4(col.z / col.w, 0, 0, 1); 
     172#endif 
     173        return OUT; 
     174} 
Note: See TracChangeset for help on using the changeset viewer.