Changeset 2893


Ignore:
Timestamp:
09/02/08 00:56:48 (16 years ago)
Author:
mattausch
Message:

shadowing partly working

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

Legend:

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

    r2891 r2893  
    8686void Camera::GetModelViewMatrix(Matrix4x4 &mat) 
    8787{ 
    88         glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mat.x); 
     88        mat = mViewOrientation; 
     89 
     90        Vector3 pos = mViewOrientation * -mPosition; 
     91         
     92        mat.x[3][0] = pos.x; 
     93        mat.x[3][1] = pos.y; 
     94        mat.x[3][2] = pos.z; 
     95 
     96        //glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mat.x); 
    8997} 
    9098 
     
    154162void Camera::SetupCameraView() 
    155163{ 
    156         Matrix4x4 tview = mViewOrientation; 
    157  
    158         Vector3 pos = -mPosition; 
    159         pos = tview * pos; 
    160  
    161164        Matrix4x4 viewOrientation = mViewOrientation; 
     165 
     166        Vector3 pos = mViewOrientation * -mPosition; 
    162167 
    163168        viewOrientation.x[3][0] = pos.x; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp

    r2892 r2893  
    4646 
    4747static CGparameter sShadowMatrixParam; 
    48  
    49  
    50  
    51  
    52 DeferredShader::DeferredShader(int w, int h): 
    53 mWidth(w), mHeight(h) 
     48static CGparameter sMaxDepthParam; 
     49 
     50 
     51 
     52DeferredShader::DeferredShader(int w, int h, float scaleFactor): 
     53mWidth(w), mHeight(h), mScaleFactor(scaleFactor) 
    5454{ 
    5555        //mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
     
    124124                sNormalsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "normals");  
    125125                sShadowMapParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMap");   
    126  
     126                sMaxDepthParam = cgGetNamedParameter(sCgDeferredShadowProgram, "maxDepth"); 
    127127                sShadowMatrixParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMatrix"); 
    128128        } 
     
    184184        glDisable(GL_TEXTURE_2D); 
    185185        glDisable(GL_LIGHTING); 
     186        glDepthMask(GL_FALSE); 
     187         
    186188 
    187189        glPushAttrib(GL_VIEWPORT_BIT); 
     
    203205 
    204206        glEnable(GL_LIGHTING); 
    205         glDisable(GL_TEXTURE_2D); 
     207        glEnable(GL_TEXTURE_2D); 
     208        glDepthMask(GL_TRUE); 
    206209         
    207210        glMatrixMode(GL_PROJECTION); 
     
    332335        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    333336        GLuint shadowMap = shadowMapping->mFbo->GetDepthTex(); 
    334  
     337/* 
    335338        static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f, 
    336339                                                                0.0f, 0.5f, 0.0f, 0.0f, 
    337340                                                                0.0f, 0.0f, 0.5f, 0.0f, 
    338341                                                                0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] 
     342*/ 
     343         
     344static 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] 
    339348 
    340349        Matrix4x4 inverseView = matViewing; 
     
    345354        //cout << "matview:\n" << matViewing << endl; 
    346355        //cout << "proj:\n" <<  shadowMapping->mLightProjectionMatrix << endl; 
    347         //cout << "view:\n" <<  shadowMapping->mLightViewMatrix << endl; 
     356        cout << "view:\n" <<  shadowMapping->mLightViewMatrix << endl; 
    348357 
    349358        // compute combined matrix that transforms pixels into light texture space 
     
    353362                                                         inverseView; 
    354363*/ 
    355         Matrix4x4 shadowMatrix = //inverseView *  
    356                                                          lightProjView *  
    357                                                          biasMatrix; 
    358 /* 
    359 Matrix4x4 shadowMatrix = biasMatrix *  
    360                                                          lightProjView;  
     364        //Matrix4x4 shadowMatrix = //inverseView * lightProjView * biasMatrix;* 
     365        Matrix4x4 shadowMatrix = lightProjView*biasMatrix;  
    361366                                                         //inverseView; 
    362 */ 
    363367                                                         cout << "combined:\n" <<  shadowMatrix << endl; 
    364368 
     
    384388        cgGLSetTextureParameter(sShadowMapParam, shadowMap); 
    385389        cgGLEnableTextureParameter(sShadowMapParam); 
     390 
     391        cgGLSetParameter1f(sMaxDepthParam, mScaleFactor); 
    386392 
    387393        cgGLSetMatrixParameterfc(sShadowMatrixParam, (const float *)shadowMatrix.x); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h

    r2892 r2893  
    2424        /** constructor for a deferred shader taking the requested output image size 
    2525        */ 
    26         DeferredShader(int w, int h); 
     26        DeferredShader(int w, int h, float maxDepth); 
    2727 
    2828        ~DeferredShader(); 
     
    5757        int mHeight; 
    5858 
    59         //FrameBufferObject *mFbo; 
     59        float mScaleFactor; 
    6060}; 
    6161 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2892 r2893  
    124124        mLight = light; 
    125125 
    126         const float xlen = Magnitude(mSceneBox.Diagonal());// * 0.5f); 
    127         const float ylen = Magnitude(mSceneBox.Diagonal());// * 0.5f); 
     126        const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
     127        const float ylen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    128128         
    129129        mShadowCam->SetDirection(light->GetDirection()); 
     
    131131        // set position so that we can see the whole scene 
    132132        Vector3 pos = mSceneBox.Center(); 
    133         pos.z = mSceneBox.Max().z; 
     133 
     134        pos -= light->GetDirection() * Magnitude(mSceneBox.Diagonal() * 0.5f); 
     135        //pos.z = mSceneBox.Max().z; 
    134136        //mShadowCam->SetPosition(pos - Magnitude(mSceneBox.Diagonal() * light->GetDirection())); 
    135137        mShadowCam->SetPosition(pos); 
     
    148150        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    149151 
    150         glPolygonOffset(1.0f, 40.0f); 
     152        glPolygonOffset(1.0f, 2000.0f); 
    151153        glEnable(GL_POLYGON_OFFSET_FILL); 
    152154 
     
    158160        glLoadIdentity(); 
    159161         
    160         glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, 100);//Magnitude(mSceneBox.Diagonal()));  
     162        glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal()));  
    161163         
    162164 
     
    267269void ShadowMapping::Render(RenderTraverser *traverser, Camera *cam) 
    268270{ 
     271#if 0 
    269272        Matrix4x4 cam_inverse_modelview; 
    270273 
     
    391394        glDisable(GL_LIGHTING); 
    392395        glDisable(GL_ALPHA_TEST); 
     396#endif 
    393397} 
    394398 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp

    r2891 r2893  
    527527        cgGLSetParameter1f(sMaxDepthParam, mScaleFactor); 
    528528         
     529 
    529530        if (mUseTemporalCoherence) 
    530531        { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2892 r2893  
    443443        sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 
    444444 
    445         light = new Light(Vector3(0, 0, -1), RgbaColor(1, 1, 1, 1)); 
    446  
    447         shadowMapping = new ShadowMapping(bvh->GetBox(), 512); 
     445        Vector3 lightDir = Normalize(Vector3(0, 1, -1)); 
     446        light = new Light(lightDir, RgbaColor(1, 1, 1, 1)); 
     447 
     448        shadowMapping = new ShadowMapping(bvh->GetBox(), 4096); 
    448449         
    449450        // frame time is restarted every frame 
     
    962963        glEnableClientState(GL_NORMAL_ARRAY); 
    963964 
    964  
     965         
    965966        // reset depth pass and render visible objects 
    966967        if (renderType == RenderState::DEPTH_PASS)  
     
    969970                RenderVisibleObjects(); 
    970971        } 
    971          
     972 
    972973 
    973974        /////////////// 
    974975        //-- render sky 
    975976 
     977        // q: should we render sky after deferred shading? (would conveniently solves some issues) 
     978        // (e.g, skys without shadows) 
     979 
    976980        RenderSky(); 
    977  
    978         state.Reset(); 
    979  
    980         glDisableClientState(GL_VERTEX_ARRAY); 
    981         glDisableClientState(GL_NORMAL_ARRAY); 
     981         
    982982 
    983983 
     
    997997                else 
    998998                { 
    999                         if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight); 
     999                        if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight, myfar / 10.0f); 
    10001000                         
    10011001                        //deferredShader->Render(fbo); 
     
    10031003                } 
    10041004        } 
    1005          
    1006          
     1005 
     1006 
     1007        state.SetRenderType(RenderState::FIXED); 
     1008        state.Reset(); 
     1009 
     1010 
     1011        glDisableClientState(GL_VERTEX_ARRAY); 
     1012        glDisableClientState(GL_NORMAL_ARRAY); 
     1013 
     1014 
     1015 
    10071016        /////////// 
    10081017 
    1009         state.SetRenderType(RenderState::FIXED); 
    10101018 
    10111019        if (showAlgorithmTime) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2892 r2893  
    8080                                  uniform sampler2D normals,                
    8181                                  uniform sampler2D shadowMap, 
    82                                   uniform float4x4 shadowMatrix 
     82                                  uniform float4x4 shadowMatrix, 
     83                                  uniform float maxDepth 
    8384                                  ) 
    8485{ 
     
    8990        float4 position = tex2D(positions, IN.texCoord.xy); 
    9091 
    91         float4 lightSpacePos = mul(shadowMatrix, position); 
    92  
    93         float shadowDepth = tex2D(shadowMap, IN.texCoord.xy); 
    9492 
    9593        // an ambient color term 
     
    9997        float4 col = shade(IN, color, position, normal, amb); 
    10098         
     99        position *= maxDepth; 
     100        position.w = 1.0f; 
     101         
     102        float4 lightSpacePos = mul(shadowMatrix, position); 
     103 
     104        float shadowDepth = tex2D(shadowMap, lightSpacePos.xy); 
     105 
    101106        OUT.color = col; 
    102107         
    103         if (lightSpacePos.z / lightSpacePos.w < shadowDepth) 
     108        // hack: prevent shadowing the sky 
     109        if ((amb < 0.9) &&       
     110                (lightSpacePos.z / lightSpacePos.w > shadowDepth)) 
    104111        { 
    105112                OUT.color *= 0.1f; 
    106113        } 
    107114         
    108         //OUT.color = float4(lightSpacePos.z / lightSpacePos.w); 
     115        //OUT.color = lightSpacePos;//float4(lightSpacePos.z / lightSpacePos.w); 
    109116        //OUT.color = float4(shadowDepth); 
    110117        OUT.color.w = color.w; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2892 r2893  
    7171                float2 texcoord = IN.texCoord.xy + offsetTransformed * AREA_SIZE * w; 
    7272 
     73                //if ((texcoord.x <= 1.0f) || (texcoord.x >= 0.0f) || (texcoord.y <= 1.0f) || (texcoord.y >= 0.0f)) 
     74                 
    7375                // sample downsampled texture in order to speed up texture accesses 
    7476                float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, 1)).xyz; 
Note: See TracChangeset for help on using the changeset viewer.