Changeset 2894


Ignore:
Timestamp:
09/02/08 09:07:45 (16 years ago)
Author:
mattausch
Message:

shadow mapping almost working (but ulgy!!)

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
8 edited

Legend:

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

    r2888 r2894  
    637637void Bvh::RecomputeBounds() 
    638638{ 
    639         // clear old list 
    640         mTestNodes.clear(); 
    641  
    642639        // collect all nodes 
    643640        BvhNodeContainer nodes; 
     
    662659 
    663660        // recreate indices used for indirect mode rendering 
    664         if (mIndices) 
    665                 CreateIndices(); 
     661        if (mIndices) CreateIndices(); 
    666662} 
    667663 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2825 r2894  
    6565        */ 
    6666        virtual ~BvhNode(); 
    67         /** Returns unique id for this node. 
    68         */ 
    69         //inline int GetId() {return mId;} 
    7067        /** Depth of this node in the tree. 
    7168        */ 
     
    167164 
    168165        ///////// 
    169         // used for view frustum culling 
     166        //-- used for view frustum culling 
    170167 
    171168        int mPlaneMask; 
     
    619616 
    620617        //////////////////////// 
    621  
     618         
     619        /// the bounding box of the bvh 
     620        AxisAlignedBox3 mBox; 
    622621        /// the root of the hierarchy 
    623622        BvhNode *mRoot; 
     
    627626        size_t mGeometrySize; 
    628627 
    629  
    630         //////////////// 
    631  
    632628        /// the current camera 
    633629        Camera *mCamera; 
     630 
     631 
     632        //////////////// 
     633        //-- tigher bounds termination criteria 
     634 
     635        /** maximal depth from which children are fetched for  
     636                testing instead of the current node 
     637        */ 
     638        int mMaxDepthForTestingChildren; 
     639        /// threshold for computing tighter bounds 
     640        float mAreaRatioThreshold; 
     641         
     642         
     643        //////////////// 
     644        //-- statistics 
     645 
     646        BvhStats mBvhStats; 
     647        /// the overall number of nodes 
     648        int mNumNodes; 
     649        /// the number of "virtual" (=actually used) nodes 
     650        int mNumVirtualNodes; 
     651 
     652 
     653        //////////// 
     654        //-- rendering stuff 
     655 
     656        /// these proxy nodes are tested instead of the current node 
     657        BvhNodeContainer mTestNodes; 
     658        /// the indices used for vbo index buffering 
     659        unsigned int *mTestIndices; 
     660        /// a pointer to the end of the indices array 
     661        int mCurrentIndicesPtr; 
     662        /// the vbo id 
     663        unsigned int mVboId; 
    634664        /// a vertex array used if working with indexed arrays (without vbo) 
    635665        Vector3 *mVertices; 
    636666        /// indices used for draw array rendering 
    637667        unsigned int *mIndices; 
    638  
    639         /** maximal depth from which children are fetched for  
    640                 testing instead of the current node 
    641         */ 
    642         int mMaxDepthForTestingChildren; 
    643  
    644         float mAreaRatioThreshold; 
    645  
    646  
    647         BvhStats mBvhStats; 
    648  
    649         BvhNodeContainer mTestNodes; 
    650          
    651         unsigned int *mTestIndices; 
    652         /// a pointer to the end of the indices array 
    653         int mCurrentIndicesPtr; 
    654  
    655         int mNumNodes; 
    656  
    657         /// the bounding box 
    658         AxisAlignedBox3 mBox; 
    659  
    660         int mNumVirtualNodes; 
    661  
    662         ////////////// 
    663  
    664         unsigned int mVboId; 
    665668}; 
    666669 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp

    r2893 r2894  
    176176 
    177177void DeferredShader::Render(FrameBufferObject *fbo,  
    178                                                         const Matrix4x4 &matViewing,  
    179                                                         ShadowMapping *shadowMapping) 
     178                                                        ShadowMap *shadowMap) 
    180179{ 
    181180        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     
    201200        glOrtho(-offs, offs, -offs, offs, 0, 1); 
    202201 
    203         FirstPassShadow(fbo, matViewing, shadowMapping); 
     202        FirstPassShadow(fbo, shadowMap); 
    204203        AntiAliasing(fbo); 
    205204 
     
    328327 
    329328void DeferredShader::FirstPassShadow(FrameBufferObject *fbo,  
    330                                                                          const Matrix4x4 &matViewing,  
    331                                                                          ShadowMapping *shadowMapping) 
     329                                                                         ShadowMap *shadowMap) 
    332330{ 
    333331        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    334332        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    335333        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    336         GLuint shadowMap = shadowMapping->mFbo->GetDepthTex(); 
    337 /* 
    338         static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f, 
    339                                                                 0.0f, 0.5f, 0.0f, 0.0f, 
    340                                                                 0.0f, 0.0f, 0.5f, 0.0f, 
    341                                                                 0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] 
    342 */ 
    343          
    344 static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 
    345                                                                 0.0f, 0.5f, 0.0f, 0.5f, 
    346                                                                 0.0f, 0.0f, 0.5f, 0.5f, 
    347                                                                 0.0f, 0.0f, 0.0f, 1.0f); //bias from [-1, 1] to [0, 1] 
    348  
    349         Matrix4x4 inverseView = matViewing; 
    350         inverseView.Invert(); 
    351  
    352         Matrix4x4 lightProjView = shadowMapping->mLightViewMatrix * shadowMapping->mLightProjectionMatrix; 
    353  
    354         //cout << "matview:\n" << matViewing << endl; 
    355         //cout << "proj:\n" <<  shadowMapping->mLightProjectionMatrix << endl; 
    356         cout << "view:\n" <<  shadowMapping->mLightViewMatrix << endl; 
    357  
    358         // compute combined matrix that transforms pixels into light texture space 
    359         /*Matrix4x4 shadowMatrix = biasMatrix *  
    360                                                          shadowMapping->mLightProjectionMatrix *  
    361                                                          shadowMapping->mLightViewMatrix * 
    362                                                          inverseView; 
    363 */ 
    364         //Matrix4x4 shadowMatrix = //inverseView * lightProjView * biasMatrix;* 
    365         Matrix4x4 shadowMatrix = lightProjView*biasMatrix;  
    366                                                          //inverseView; 
    367                                                          cout << "combined:\n" <<  shadowMatrix << endl; 
     334        GLuint shadowTex = shadowMap->GetShadowTexture(); 
     335 
     336        Matrix4x4 shadowMatrix; 
     337        shadowMap->GetTextureMatrix(shadowMatrix); 
    368338 
    369339        fbo->Bind(); 
     
    386356        cgGLEnableTextureParameter(sNormalsTexShadowParam); 
    387357         
    388         cgGLSetTextureParameter(sShadowMapParam, shadowMap); 
     358        cgGLSetTextureParameter(sShadowMapParam, shadowTex); 
    389359        cgGLEnableTextureParameter(sShadowMapParam); 
    390360 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h

    r2893 r2894  
    1212 
    1313class FrameBufferObject; 
    14 class ShadowMapping; 
     14class ShadowMap; 
    1515class Matrix4x4; 
    1616 
     
    3737        static void Init(CGcontext context); 
    3838 
     39        void Render(FrameBufferObject *fbo, ShadowMap *shadowMap); 
    3940 
    40         void Render(FrameBufferObject *fbo,  
    41                         const Matrix4x4 &matViewing,  
    42                                 ShadowMapping *shadowMapping); 
    4341 
    4442protected: 
    4543 
    4644        void FirstPass(FrameBufferObject *fbo); 
    47         void FirstPassShadow(FrameBufferObject *fbo,  
    48                                                  const Matrix4x4 &matViewing,  
    49                                                  ShadowMapping *shadowMapping); 
     45 
     46        void FirstPassShadow(FrameBufferObject *fbo, ShadowMap *shadowMap); 
    5047 
    5148        void AntiAliasing(FrameBufferObject *fbo); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2893 r2894  
    7979 
    8080 
    81 ShadowMapping::ShadowMapping(const AxisAlignedBox3 &sceneBox, int size): 
    82 mSceneBox(sceneBox), mSize(size) 
     81ShadowMap::ShadowMap(int size, const AxisAlignedBox3 &sceneBox, Camera *cam): 
     82mSceneBox(sceneBox), mSize(size), mCamera(cam) 
    8383{ 
    8484        mFbo = new FrameBufferObject(size, size, FrameBufferObject::DEPTH_32, true); 
     
    9191 
    9292 
    93 ShadowMapping::~ShadowMapping() 
    94 { 
    95         //if (sCgShadowProgram) cgDestroyProgram(sCgShadowProgram); 
     93ShadowMap::~ShadowMap() 
     94{ 
    9695        DEL_PTR(mFbo); 
    9796} 
    9897 
    9998 
    100 void ShadowMapping::Init(CGcontext context) 
    101 {/* 
    102         sCgShadowProgram =  
    103                 cgCreateProgramFromFile(context,  
    104                                                                 CG_SOURCE, 
    105                                                                 "src/shaders/shadow.cg",  
    106                                                                 RenderState::sCgFragmentProfile, 
    107                                                                 "main", 
    108                                                                 NULL); 
    109  
    110         if (sCgShadowProgram != NULL) 
    111         { 
    112                 cgGLLoadProgram(sCgShadowProgram); 
    113                 sShadowParam = cgGetNamedParameter(sCgShadowProgram, "shadowMap"); 
    114         } 
    115         else 
    116                 cerr << "shadow program failed to load" << endl; 
    117 */ 
    118         PrintGLerror("init"); 
    119 } 
    120  
    121  
    122 void ShadowMapping::ComputeShadowMap(Light *light, RenderTraverser *traverser) 
     99 
     100void ShadowMap::ComputeShadowMap(Light *light, RenderTraverser *traverser) 
    123101{ 
    124102        mLight = light; 
     
    133111 
    134112        pos -= light->GetDirection() * Magnitude(mSceneBox.Diagonal() * 0.5f); 
    135         //pos.z = mSceneBox.Max().z; 
    136         //mShadowCam->SetPosition(pos - Magnitude(mSceneBox.Diagonal() * light->GetDirection())); 
    137113        mShadowCam->SetPosition(pos); 
    138114 
     
    160136        glLoadIdentity(); 
    161137         
     138        // setup projection 
    162139        glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal()));  
    163140         
     
    168145        glLoadIdentity(); 
    169146 
    170  
     147        // setup shadow camera 
    171148        mShadowCam->SetupCameraView(); 
    172         mShadowCam->GetModelViewMatrix(mLightViewMatrix); 
    173  
    174         mShadowCam->GetProjectionMatrix(mLightProjectionMatrix); 
    175         //glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mLightProjectionMatrix.x); 
     149 
     150        ////////////// 
     151        //-- compute texture matrix 
     152 
     153        Matrix4x4 lightView, lightProj; 
     154 
     155        mShadowCam->GetModelViewMatrix(lightView); 
     156        mShadowCam->GetProjectionMatrix(lightProj); 
     157 
     158        static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 
     159                                                                0.0f, 0.5f, 0.0f, 0.5f, 
     160                                                                0.0f, 0.0f, 0.5f, 0.5f, 
     161                                                                0.0f, 0.0f, 0.0f, 1.0f); //bias from [-1, 1] to [0, 1] 
     162 
     163        Matrix4x4 lightProjView = lightView * lightProj; 
     164        mTextureMatrix = lightProjView * biasMatrix;  
     165 
     166 
     167        ///////////// 
     168        //-- render scene into shadow map 
    176169 
    177170        traverser->RenderScene(); 
     
    192185 
    193186        delete [] data; 
    194 */ 
     187        */ 
    195188        PrintGLerror("shadow map"); 
    196189 
     
    198191} 
    199192 
    200 /* 
    201 void ShadowMapping::Render(RenderTraverser *traverser, Camera *cam) 
    202 { 
    203         Matrix4x4 cam_proj; 
    204         Matrix4x4 cam_inverse_modelview; 
    205  
    206         const float bias[16] =  
    207         {0.5f, 0.0f, 0.0f, 0.0f,  
    208         0.0f, 0.5f, 0.0f, 0.0f, 
    209         0.0f, 0.0f, 0.5f, 0.0f, 
    210         0.5f, 0.5f, 0.5f, 1.0f  }; 
    211  
    212  
    213         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    214  
    215         // update the camera, so that the user can have a free look 
    216         glMatrixMode(GL_MODELVIEW); 
    217         glLoadIdentity(); 
    218          
    219         glMatrixMode(GL_PROJECTION); 
    220         glLoadIdentity(); 
    221          
    222         cam->SetupCameraView(); 
    223  
    224         // store the inverse of the resulting modelview matrix for the shadow computation 
    225         glGetFloatv(GL_MODELVIEW_MATRIX, (float *)cam_inverse_modelview.x); 
    226         cam_inverse_modelview.Invert(); 
    227  
    228         // bind shadow map 
    229         glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, mFbo->GetDepthTex()); 
    230  
    231         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); 
    232         //glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_COMPARE_MODE, GL_NONE); 
    233  
    234         PrintGLerror("texture"); 
    235  
    236         //float light_m[16]; 
    237          
    238         // compute a matrix that transforms from camera eye space to light clip space 
    239         // and pass it to the shader through the OpenGL texture matrices, since we 
    240         // don't use them now 
    241         glEnable(GL_TEXTURE_2D); 
    242         glMatrixMode(GL_TEXTURE); 
    243  
    244         glLoadMatrixf(bias); 
    245         glMultMatrixf((float *)mShadowMatrix.x); 
    246          
    247         // multiply the light's (bias * crop * proj * modelview) by the inverse camera modelview 
    248         // so that we can transform a pixel as seen from the camera 
    249         glMultMatrixf((float *)cam_inverse_modelview.x); 
    250          
    251                  
    252         cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    253         cgGLBindProgram(sCgShadowProgram); 
    254          
    255         cgGLSetTextureParameter(sShadowParam, mFbo->GetDepthTex()); 
    256         cgGLEnableTextureParameter(sShadowParam); 
    257          
    258         // finally, draw the scene  
    259         traverser->RenderScene(); 
    260  
    261         cgGLDisableTextureParameter(sShadowParam); 
    262  
    263         PrintGLerror("shadow"); 
    264 } 
    265 */ 
    266  
    267  
    268 //Called to draw scene 
    269 void ShadowMapping::Render(RenderTraverser *traverser, Camera *cam) 
    270 { 
    271 #if 0 
    272         Matrix4x4 cam_inverse_modelview; 
    273  
    274         //Calculate texture matrix for projection 
    275         //This matrix takes us from eye space to the light's clip space 
    276         //It is postmultiplied by the inverse of the current view matrix when specifying texgen 
    277         static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f, 
    278                                                                 0.0f, 0.5f, 0.0f, 0.0f, 
    279                                                                 0.0f, 0.0f, 0.5f, 0.0f, 
    280                                                                 0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] 
    281  
    282         /*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    283  
    284         // update the camera, so that the user can have a free look 
    285         glMatrixMode(GL_MODELVIEW); 
    286         glLoadIdentity(); 
    287          
    288         glMatrixMode(GL_PROJECTION); 
    289         glLoadIdentity(); 
    290          
    291         cam->SetupCameraView(); 
    292 */ 
    293         // store the inverse of the resulting modelview matrix for the shadow computation 
    294         glGetFloatv(GL_MODELVIEW_MATRIX, (float *)cam_inverse_modelview.x); 
    295         cam_inverse_modelview.Invert(); 
    296  
    297         // bind shadow map 
    298         glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, mFbo->GetDepthTex()); 
    299          
    300         // compute a matrix that transforms from camera eye space to light clip space 
    301         // and pass it to the shader through the OpenGL texture matrices, since we 
    302         // don't use them now 
    303         glEnable(GL_TEXTURE_2D); 
    304         glMatrixMode(GL_TEXTURE); 
    305  
    306         glLoadMatrixf((float *)biasMatrix.x); 
    307         glMultMatrixf((float *)mLightViewMatrix.x); 
    308          
    309         // multiply the light's (bias * crop * proj * modelview) by the inverse camera modelview 
    310         // so that we can transform a pixel as seen from the camera 
    311         glMultMatrixf((float *)cam_inverse_modelview.x); 
    312  
    313         RgbaColor white(1, 1, 1, 0); 
    314         RgbaColor dark(0.2, 0.2, 0.2, 0); 
    315  
    316         glDisable(GL_LIGHTING); 
    317  
    318         /*glDisable(GL_LIGHT0); 
    319         glDisable(GL_LIGHT1); 
    320  
    321         //Use dim light to represent shadowed areas 
    322         glLightfv(GL_LIGHT1, GL_POSITION, mLight->GetDirection()); 
    323         glLightfv(GL_LIGHT1, GL_AMBIENT, (float *)&dark.r); 
    324         glLightfv(GL_LIGHT1, GL_DIFFUSE, (float *)&white.r); 
    325         //glLightfv(GL_LIGHT1, GL_SPECULAR, black); 
    326         glEnable(GL_LIGHT1); 
    327         glEnable(GL_LIGHTING);*/ 
    328  
    329         PrintGLerror("firstpass"); 
    330  
    331         // finally, draw the scene  
    332         traverser->RenderScene(); 
    333  
    334  
    335         glEnable(GL_LIGHTING); 
    336  
    337  
    338         //3rd pass 
    339         //Draw with bright light 
    340         //glLightfv(GL_LIGHT1, GL_DIFFUSE, (float *)&white.r); 
    341         //glLightfv(GL_LIGHT1, GL_SPECULAR, (float *)&white.r); 
    342  
    343         Matrix4x4 textureMatrix = biasMatrix * mLightProjectionMatrix * mLightViewMatrix; 
    344  
    345         Matrix4x4 texMatT = Transpose(textureMatrix); 
    346  
    347         //Set up texture coordinate generation. 
    348         glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    349         glTexGenfv(GL_S, GL_EYE_PLANE, texMatT.x[0]); 
    350         glEnable(GL_TEXTURE_GEN_S); 
    351  
    352         glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    353         glTexGenfv(GL_T, GL_EYE_PLANE, texMatT.x[1]); 
    354         glEnable(GL_TEXTURE_GEN_T); 
    355  
    356         glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    357         glTexGenfv(GL_R, GL_EYE_PLANE, texMatT.x[2]); 
    358         glEnable(GL_TEXTURE_GEN_R); 
    359  
    360         glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    361         glTexGenfv(GL_Q, GL_EYE_PLANE, texMatT.x[3]); 
    362         glEnable(GL_TEXTURE_GEN_Q); 
    363  
    364         //Bind & enable shadow map texture 
    365         glBindTexture(GL_TEXTURE_2D, mFbo->GetDepthTex()); 
    366         glEnable(GL_TEXTURE_2D); 
    367  
    368         //Enable shadow comparison 
    369         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE); 
    370  
    371         //Shadow comparison should be true (ie not in shadow) if r<=texture 
    372         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL); 
    373  
    374         //Shadow comparison should generate an INTENSITY result 
    375         glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY); 
    376  
    377         //Set alpha test to discard false comparisons 
    378         glAlphaFunc(GL_GEQUAL, 0.99f); 
    379         glEnable(GL_ALPHA_TEST); 
    380  
    381         PrintGLerror("texture"); 
    382  
    383         traverser->RenderScene(); 
    384  
    385         //Disable textures and texgen 
    386         glDisable(GL_TEXTURE_2D); 
    387  
    388         glDisable(GL_TEXTURE_GEN_S); 
    389         glDisable(GL_TEXTURE_GEN_T); 
    390         glDisable(GL_TEXTURE_GEN_R); 
    391         glDisable(GL_TEXTURE_GEN_Q); 
    392  
    393         //Restore other states 
    394         glDisable(GL_LIGHTING); 
    395         glDisable(GL_ALPHA_TEST); 
    396 #endif 
     193 
     194void ShadowMap::GetTextureMatrix(Matrix4x4 &m) const 
     195{ 
     196        m = mTextureMatrix; 
     197} 
     198 
     199  
     200unsigned int ShadowMap::GetShadowTexture() const 
     201{ 
     202        return mFbo->GetDepthTex(); 
    397203} 
    398204 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2892 r2894  
    1 #ifndef _ShadowMapping_H__ 
    2 #define _ShadowMapping_H__ 
     1#ifndef _ShadowMap_H__ 
     2#define _ShadowMap_H__ 
    33 
    44#include "common.h" 
     
    2020class Light; 
    2121 
    22 /** This class implements a shadow mapping algorithm 
     22/** This class implements a the computation of single shadow map 
    2323*/ 
    24 class ShadowMapping 
     24class ShadowMap 
    2525{ 
     26 
    2627public: 
    27         /** constructor for a deferred shader taking the requested shadow size 
     28        /** Constructor taking the scene boundig box and the current camera.  
     29                The shadow map has resolution size * size. 
    2830        */ 
    29         ShadowMapping(const AxisAlignedBox3 &sceneBox, int size); 
     31        ShadowMap(int size, const AxisAlignedBox3 &sceneBox, Camera *cam); 
    3032 
    31         ~ShadowMapping(); 
    32         /** Renders the shadowed scene 
     33        ~ShadowMap(); 
     34        /** Computes the shadow map 
    3335        */ 
    34         void Render(RenderTraverser *traverser, Camera *cam); 
    35         /** Initialises shadow mapping and loads the required shaders: 
    36                 This function has to be called only once. 
     36        void ComputeShadowMap(Light *light, RenderTraverser *traverser); 
     37        /** Returns computed shadow texture. 
    3738        */ 
    38         static void Init(CGcontext context); 
     39        unsigned int GetShadowTexture() const; 
     40        /** Returns computed texture matrix. It must be applied on the 
     41                the world space positions.  
     42                 
     43                The texture     matrix can be directly applied if the world space position 
     44                is available (deferred shading), otherwise it must be multiplied with  
     45                the inverse model matrix. 
     46        */ 
     47        void GetTextureMatrix(Matrix4x4 &m) const; 
    3948 
    40 //protected: 
    4149 
    42         void ComputeShadowMap(Light *light, RenderTraverser *traverser); 
     50protected: 
    4351 
    44 //protected: 
    45  
     52        /// the scene bounding box 
     53        AxisAlignedBox3 mSceneBox; 
     54        /// fbo storing the shadow texture 
    4655        FrameBufferObject *mFbo; 
    47  
     56        /// size of the shadow map 
    4857        int mSize; 
    4958 
    50         AxisAlignedBox3 mSceneBox; 
    51  
    5259        Camera *mShadowCam; 
    53  
    54         Matrix4x4 mLightViewMatrix; 
    55         Matrix4x4 mLightProjectionMatrix; 
    56  
     60        /// the texture matrix 
     61        Matrix4x4 mTextureMatrix; 
     62        /// the used light 
    5763        Light *mLight; 
     64        /// the scene camera 
     65        Camera *mCamera; 
    5866}; 
    5967 
    6068} // namespace  
    61 #endif // _DeferredShader_H__ 
     69#endif // _ShadowMapping_H__ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp

    r2893 r2894  
    533533                cgGLSetParameter1f(sExpFactorParam, expFactor); 
    534534 
    535  
    536535                // q: should we generate new samples or only rotate the old ones? 
    537536                // in the first case, the sample patterns look nicer, but the kernel 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2893 r2894  
    175175 
    176176static Matrix4x4 matProjectionView = IdentityMatrix(); 
    177 static Matrix4x4 matViewing = IdentityMatrix(); 
    178  
    179 ShadowMapping *shadowMapping = NULL; 
     177 
     178 
     179ShadowMap *shadowMap = NULL; 
    180180Light *light = NULL; 
    181181 
     
    433433        DeferredShader::Init(sCgContext); 
    434434        SsaoShader::Init(sCgContext); 
    435         ShadowMapping::Init(sCgContext); 
    436435 
    437436 
     
    446445        light = new Light(lightDir, RgbaColor(1, 1, 1, 1)); 
    447446 
    448         shadowMapping = new ShadowMapping(bvh->GetBox(), 4096); 
     447        const float shadowSize = 4096; 
     448        shadowMap = new ShadowMap(shadowSize, bvh->GetBox(), camera); 
    449449         
    450450        // frame time is restarted every frame 
     
    796796        ///////////////// 
    797797 
    798         Matrix4x4 matProjection; 
     798        Matrix4x4 matViewing, matProjection; 
    799799 
    800800        camera->GetModelViewMatrix(matViewing); 
     
    904904        case RenderState::DEFERRED: 
    905905 
    906                 shadowMapping->ComputeShadowMap(light, traverser); 
     906                shadowMap->ComputeShadowMap(light, traverser); 
    907907 
    908908                if (!fbo) InitFBO(); 
     
    975975        //-- render sky 
    976976 
    977         // q: should we render sky after deferred shading? (would conveniently solves some issues) 
    978         // (e.g, skys without shadows) 
     977        // q: should we render sky after deferred shading?  
     978        // this would conveniently solves some issues (e.g, skys without shadows) 
    979979 
    980980        RenderSky(); 
     
    999999                        if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight, myfar / 10.0f); 
    10001000                         
    1001                         //deferredShader->Render(fbo); 
    1002                         deferredShader->Render(fbo, matViewing, shadowMapping); 
     1001                        deferredShader->Render(fbo, shadowMap); 
    10031002                } 
    10041003        } 
Note: See TracChangeset for help on using the changeset viewer.