Changeset 2892


Ignore:
Timestamp:
09/01/08 18:33:14 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
12 edited

Legend:

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

    r2888 r2892  
    1010winHeight=768 
    1111camPosition=483.398f 242.364f 186.078f 
    12 camDirection=0 1 0 
    13 //camDirection=1 0 0 
     12camDirection=1 0 0 
    1413useFullScreen=0 
    1514useLODs=1 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.cpp

    r2879 r2892  
    22#include "FrameBufferObject.h" 
    33#include "RenderState.h" 
     4#include "ShadowMapping.h" 
    45 
    56 
     
    2829 
    2930static CGprogram sCgDeferredProgram; 
     31static CGprogram sCgDeferredShadowProgram; 
    3032static CGprogram sCgAntiAliasingProgram; 
    3133 
     
    3739static CGparameter sColorsTexAntiAliasingParam; 
    3840static CGparameter sNormalsTexAntiAliasingParam; 
     41 
     42static CGparameter sShadowMapParam; 
     43static CGparameter sPositionsTexShadowParam;   
     44static CGparameter sColorsTexShadowParam;   
     45static CGparameter sNormalsTexShadowParam; 
     46 
     47static CGparameter sShadowMatrixParam; 
     48 
     49 
    3950 
    4051 
     
    96107                cerr << "antialiasing program failed to load" << endl; 
    97108 
     109        sCgDeferredShadowProgram =  
     110                cgCreateProgramFromFile(context,  
     111                                                                CG_SOURCE, 
     112                                                                "src/shaders/deferred.cg",  
     113                                                                RenderState::sCgFragmentProfile, 
     114                                                                "main_shadow", 
     115                                                                NULL); 
     116 
     117        if (sCgDeferredShadowProgram != NULL) 
     118        { 
     119                cgGLLoadProgram(sCgDeferredShadowProgram); 
     120 
     121                // we need size of texture for scaling 
     122                sPositionsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "positions");   
     123                sColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "colors");   
     124                sNormalsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "normals");  
     125                sShadowMapParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMap");   
     126 
     127                sShadowMatrixParam = cgGetNamedParameter(sCgDeferredShadowProgram, "shadowMatrix"); 
     128        } 
     129        else 
     130                cerr << "deferred program failed to load" << endl; 
    98131 
    99132        PrintGLerror("init"); 
     
    103136void DeferredShader::Render(FrameBufferObject *fbo) 
    104137{ 
     138        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     139 
     140        glDisable(GL_ALPHA_TEST); 
     141        glDisable(GL_TEXTURE_2D); 
     142        glDisable(GL_LIGHTING); 
     143 
     144        glPushAttrib(GL_VIEWPORT_BIT); 
     145        glViewport(0, 0, mWidth, mHeight); 
     146 
     147        glMatrixMode(GL_PROJECTION); 
     148        glPushMatrix(); 
     149        glLoadIdentity(); 
     150 
     151        glMatrixMode(GL_MODELVIEW); 
     152        glPushMatrix(); 
     153        glLoadIdentity(); 
     154 
     155        const float offs = 0.5f; 
     156        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     157 
     158 
    105159        FirstPass(fbo); 
    106160        AntiAliasing(fbo); 
     161 
     162        glEnable(GL_LIGHTING); 
     163        glDisable(GL_TEXTURE_2D); 
     164         
     165        glMatrixMode(GL_PROJECTION); 
     166        glPopMatrix(); 
     167 
     168        glMatrixMode(GL_MODELVIEW); 
     169        glPopMatrix(); 
     170 
     171        glPopAttrib(); 
     172 
     173        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     174} 
     175 
     176 
     177void DeferredShader::Render(FrameBufferObject *fbo,  
     178                                                        const Matrix4x4 &matViewing,  
     179                                                        ShadowMapping *shadowMapping) 
     180{ 
     181        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     182 
     183        glDisable(GL_ALPHA_TEST); 
     184        glDisable(GL_TEXTURE_2D); 
     185        glDisable(GL_LIGHTING); 
     186 
     187        glPushAttrib(GL_VIEWPORT_BIT); 
     188        glViewport(0, 0, mWidth, mHeight); 
     189 
     190        glMatrixMode(GL_PROJECTION); 
     191        glPushMatrix(); 
     192        glLoadIdentity(); 
     193 
     194        glMatrixMode(GL_MODELVIEW); 
     195        glPushMatrix(); 
     196        glLoadIdentity(); 
     197 
     198        const float offs = 0.5f; 
     199        glOrtho(-offs, offs, -offs, offs, 0, 1); 
     200 
     201        FirstPassShadow(fbo, matViewing, shadowMapping); 
     202        AntiAliasing(fbo); 
     203 
     204        glEnable(GL_LIGHTING); 
     205        glDisable(GL_TEXTURE_2D); 
     206         
     207        glMatrixMode(GL_PROJECTION); 
     208        glPopMatrix(); 
     209 
     210        glMatrixMode(GL_MODELVIEW); 
     211        glPopMatrix(); 
     212 
     213        glPopAttrib(); 
     214 
     215        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    107216} 
    108217 
     
    117226        glDrawBuffers(1, mymrt + 3); 
    118227 
    119  
    120         glPushAttrib(GL_VIEWPORT_BIT); 
    121         glViewport(0, 0, mWidth, mHeight); 
    122  
    123         glDisable(GL_ALPHA_TEST); 
    124         glDisable(GL_TEXTURE_2D); 
    125         glDisable(GL_LIGHTING); 
    126          
    127         glMatrixMode(GL_PROJECTION); 
    128         glPushMatrix(); 
    129         glLoadIdentity(); 
    130  
    131         glMatrixMode(GL_MODELVIEW); 
    132         glPushMatrix(); 
    133         glLoadIdentity(); 
    134  
    135         const float offs = 0.5f; 
    136          
    137         glOrtho(-offs, offs, -offs, offs, 0, 1); 
    138228        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    139229 
    140230        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    141  
    142231        cgGLBindProgram(sCgDeferredProgram); 
    143232 
     
    170259        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    171260         
    172         glEnable(GL_LIGHTING); 
    173         glDisable(GL_TEXTURE_2D); 
    174          
    175         glMatrixMode(GL_PROJECTION); 
    176         glPopMatrix(); 
    177  
    178         glMatrixMode(GL_MODELVIEW); 
    179         glPopMatrix(); 
    180  
    181         glPopAttrib(); 
    182  
    183261        FrameBufferObject::Release(); 
    184262 
     
    207285        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
    208286 
    209         glPushAttrib(GL_VIEWPORT_BIT); 
    210         glViewport(0, 0, mWidth, mHeight); 
    211  
    212         glDisable(GL_ALPHA_TEST); 
    213         glDisable(GL_TEXTURE_2D); 
    214         glDisable(GL_LIGHTING); 
    215          
    216         glMatrixMode(GL_PROJECTION); 
    217         glPushMatrix(); 
    218         glLoadIdentity(); 
    219  
    220         glMatrixMode(GL_MODELVIEW); 
    221         glPushMatrix(); 
    222         glLoadIdentity(); 
    223  
    224         const float offs = 0.5f; 
    225          
    226         glOrtho(-offs, offs, -offs, offs, 0, 1); 
     287         
    227288        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    228289 
     
    258319 
    259320        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
    260          
    261         glEnable(GL_LIGHTING); 
    262         glDisable(GL_TEXTURE_2D); 
    263          
    264         glMatrixMode(GL_PROJECTION); 
    265         glPopMatrix(); 
    266  
    267         glMatrixMode(GL_MODELVIEW); 
    268         glPopMatrix(); 
    269  
    270         glPopAttrib(); 
     321 
     322        PrintGLerror("antialiasing"); 
     323} 
     324 
     325 
     326void DeferredShader::FirstPassShadow(FrameBufferObject *fbo,  
     327                                                                         const Matrix4x4 &matViewing,  
     328                                                                         ShadowMapping *shadowMapping) 
     329{ 
     330        GLuint colorsTex = fbo->GetColorBuffer(0)->GetTexture(); 
     331        GLuint positionsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     332        GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     333        GLuint shadowMap = shadowMapping->mFbo->GetDepthTex(); 
     334 
     335        static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f, 
     336                                                                0.0f, 0.5f, 0.0f, 0.0f, 
     337                                                                0.0f, 0.0f, 0.5f, 0.0f, 
     338                                                                0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] 
     339 
     340        Matrix4x4 inverseView = matViewing; 
     341        inverseView.Invert(); 
     342 
     343        Matrix4x4 lightProjView = shadowMapping->mLightViewMatrix * shadowMapping->mLightProjectionMatrix; 
     344 
     345        //cout << "matview:\n" << matViewing << endl; 
     346        //cout << "proj:\n" <<  shadowMapping->mLightProjectionMatrix << endl; 
     347        //cout << "view:\n" <<  shadowMapping->mLightViewMatrix << endl; 
     348 
     349        // compute combined matrix that transforms pixels into light texture space 
     350        /*Matrix4x4 shadowMatrix = biasMatrix *  
     351                                                         shadowMapping->mLightProjectionMatrix *  
     352                                                         shadowMapping->mLightViewMatrix * 
     353                                                         inverseView; 
     354*/ 
     355        Matrix4x4 shadowMatrix = //inverseView *  
     356                                                         lightProjView *  
     357                                                         biasMatrix; 
     358/* 
     359Matrix4x4 shadowMatrix = biasMatrix *  
     360                                                         lightProjView;  
     361                                                         //inverseView; 
     362*/ 
     363                                                         cout << "combined:\n" <<  shadowMatrix << endl; 
     364 
     365        fbo->Bind(); 
     366        glDrawBuffers(1, mymrt + 3); 
     367 
     368         
     369        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     370 
     371        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     372 
     373        cgGLBindProgram(sCgDeferredShadowProgram); 
     374 
     375        cgGLSetTextureParameter(sColorsTexShadowParam, colorsTex); 
     376        cgGLEnableTextureParameter(sColorsTexShadowParam); 
     377 
     378        cgGLSetTextureParameter(sPositionsTexShadowParam, positionsTex); 
     379        cgGLEnableTextureParameter(sPositionsTexShadowParam); 
     380 
     381        cgGLSetTextureParameter(sNormalsTexShadowParam, normalsTex); 
     382        cgGLEnableTextureParameter(sNormalsTexShadowParam); 
     383         
     384        cgGLSetTextureParameter(sShadowMapParam, shadowMap); 
     385        cgGLEnableTextureParameter(sShadowMapParam); 
     386 
     387        cgGLSetMatrixParameterfc(sShadowMatrixParam, (const float *)shadowMatrix.x); 
     388 
     389        glColor3f(1.0f, 1.0f, 1.0f); 
     390         
     391        glBegin(GL_QUADS); 
     392 
     393        float offs2 = 0.5f; 
     394 
     395        glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); 
     396        glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f); 
     397        glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f); 
     398        glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f); 
     399 
     400        glEnd(); 
     401 
     402        cgGLDisableTextureParameter(sColorsTexShadowParam); 
     403        cgGLDisableTextureParameter(sPositionsTexShadowParam); 
     404        cgGLDisableTextureParameter(sNormalsTexShadowParam); 
     405        cgGLDisableTextureParameter(sShadowMapParam); 
     406 
     407        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     408         
     409        FrameBufferObject::Release(); 
    271410 
    272411        PrintGLerror("deferred shading"); 
     
    274413 
    275414 
     415 
    276416} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredShader.h

    r2879 r2892  
    1212 
    1313class FrameBufferObject; 
     14class ShadowMapping; 
     15class Matrix4x4; 
    1416 
    1517 
     
    3638 
    3739 
     40        void Render(FrameBufferObject *fbo,  
     41                        const Matrix4x4 &matViewing,  
     42                                ShadowMapping *shadowMapping); 
     43 
    3844protected: 
    3945 
    4046        void FirstPass(FrameBufferObject *fbo); 
     47        void FirstPassShadow(FrameBufferObject *fbo,  
     48                                                 const Matrix4x4 &matViewing,  
     49                                                 ShadowMapping *shadowMapping); 
     50 
    4151        void AntiAliasing(FrameBufferObject *fbo); 
     52 
     53 
     54        ////////////////// 
    4255 
    4356        int mWidth; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RndGauss.h

    r2886 r2892  
    4343    xf = 1e-20f; 
    4444  assert( xf <= 1.0f); 
    45   assert( (input.yy >= 0.f) && (input.yy <= 1.0f)); 
     45  assert( (input.y >= 0.f) && (input.y <= 1.0f)); 
    4646 
    4747  // Here we have to use natural logarithm function ! 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r2889 r2892  
    166166        glPushMatrix(); 
    167167 
    168  
    169168        glOrtho(+xlen, -xlen, ylen, -ylen, 0.0f, mSceneBox.Size().z);  
    170169 
     
    188187 
    189188        GrabDepthBuffer(mDepth, fbo->GetDepthTex()); 
    190         ExportDepthBuffer(mDepth); PrintGLerror("grab"); 
     189        //ExportDepthBuffer(mDepth); PrintGLerror("grab"); 
    191190 
    192191        DEL_PTR(fbo); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2891 r2892  
    9393ShadowMapping::~ShadowMapping() 
    9494{ 
    95         if (sCgShadowProgram) 
    96                 cgDestroyProgram(sCgShadowProgram); 
    97  
     95        //if (sCgShadowProgram) cgDestroyProgram(sCgShadowProgram); 
    9896        DEL_PTR(mFbo); 
    9997} 
     
    126124        mLight = light; 
    127125 
    128         const float xlen = Magnitude(mSceneBox.Diagonal() * 0.5f); 
    129         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); 
    130128         
    131129        mShadowCam->SetDirection(light->GetDirection()); 
     
    138136 
    139137        mFbo->Bind(); 
    140  
     138         
    141139        glDrawBuffers(1, mrt); 
    142140 
     
    150148        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    151149 
    152         glPolygonOffset(1.0f, 4000.0f); 
    153         //glEnable(GL_POLYGON_OFFSET_FILL); 
     150        glPolygonOffset(1.0f, 40.0f); 
     151        glEnable(GL_POLYGON_OFFSET_FILL); 
    154152 
    155153        glShadeModel(GL_FLAT); 
     
    158156        glMatrixMode(GL_PROJECTION); 
    159157        glPushMatrix(); 
    160  
    161         glOrtho(+xlen, -xlen, ylen, -ylen, 0.0f, Magnitude(mSceneBox.Diagonal()));  
     158        glLoadIdentity(); 
     159         
     160        glOrtho(+xlen, -xlen, +ylen, -ylen, 0.0f, 100);//Magnitude(mSceneBox.Diagonal()));  
     161         
    162162 
    163163        glMatrixMode(GL_MODELVIEW); 
    164164        glPushMatrix(); 
    165165 
     166        glLoadIdentity(); 
     167 
     168 
    166169        mShadowCam->SetupCameraView(); 
    167  
    168         mShadowCam->GetModelViewMatrix(mShadowMatrix); 
     170        mShadowCam->GetModelViewMatrix(mLightViewMatrix); 
     171 
     172        mShadowCam->GetProjectionMatrix(mLightProjectionMatrix); 
     173        //glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mLightProjectionMatrix.x); 
    169174 
    170175        traverser->RenderScene(); 
    171176         
    172177        glDisable(GL_POLYGON_OFFSET_FILL); 
    173  
     178        glMatrixMode(GL_MODELVIEW); 
    174179        glPopMatrix(); 
    175180 
     
    184189        ExportDepthBuffer(data, mSize); 
    185190 
    186         delete [] data;*/ 
     191        delete [] data; 
     192*/ 
     193        PrintGLerror("shadow map"); 
    187194 
    188195        FrameBufferObject::Release(); 
     
    270277                                                                0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1] 
    271278 
    272         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     279        /*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    273280 
    274281        // update the camera, so that the user can have a free look 
     
    280287         
    281288        cam->SetupCameraView(); 
    282  
     289*/ 
    283290        // store the inverse of the resulting modelview matrix for the shadow computation 
    284291        glGetFloatv(GL_MODELVIEW_MATRIX, (float *)cam_inverse_modelview.x); 
     
    287294        // bind shadow map 
    288295        glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, mFbo->GetDepthTex()); 
    289  
    290         //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); 
    291         //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); 
    292  
    293         PrintGLerror("texture"); 
    294296         
    295297        // compute a matrix that transforms from camera eye space to light clip space 
     
    300302 
    301303        glLoadMatrixf((float *)biasMatrix.x); 
    302         glMultMatrixf((float *)mShadowMatrix.x); 
     304        glMultMatrixf((float *)mLightViewMatrix.x); 
    303305         
    304306        // multiply the light's (bias * crop * proj * modelview) by the inverse camera modelview 
     
    308310        RgbaColor white(1, 1, 1, 0); 
    309311        RgbaColor dark(0.2, 0.2, 0.2, 0); 
     312 
     313        glDisable(GL_LIGHTING); 
     314 
     315        /*glDisable(GL_LIGHT0); 
     316        glDisable(GL_LIGHT1); 
    310317 
    311318        //Use dim light to represent shadowed areas 
     
    315322        //glLightfv(GL_LIGHT1, GL_SPECULAR, black); 
    316323        glEnable(GL_LIGHT1); 
    317         glEnable(GL_LIGHTING); 
    318  
    319          
     324        glEnable(GL_LIGHTING);*/ 
     325 
     326        PrintGLerror("firstpass"); 
     327 
    320328        // finally, draw the scene  
    321329        traverser->RenderScene(); 
    322330 
    323          
     331 
     332        glEnable(GL_LIGHTING); 
     333 
    324334 
    325335        //3rd pass 
    326336        //Draw with bright light 
    327         glLightfv(GL_LIGHT1, GL_DIFFUSE, (float *)&white.r); 
    328         glLightfv(GL_LIGHT1, GL_SPECULAR, (float *)&white.r); 
    329  
    330         Matrix4x4 textureMatrix;// = biasMatrix * mLightProjectionMatrix * mLightViewMatrix; 
     337        //glLightfv(GL_LIGHT1, GL_DIFFUSE, (float *)&white.r); 
     338        //glLightfv(GL_LIGHT1, GL_SPECULAR, (float *)&white.r); 
     339 
     340        Matrix4x4 textureMatrix = biasMatrix * mLightProjectionMatrix * mLightViewMatrix; 
     341 
     342        Matrix4x4 texMatT = Transpose(textureMatrix); 
    331343 
    332344        //Set up texture coordinate generation. 
    333345        glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    334         //glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0)); 
     346        glTexGenfv(GL_S, GL_EYE_PLANE, texMatT.x[0]); 
    335347        glEnable(GL_TEXTURE_GEN_S); 
    336348 
    337349        glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    338         //glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1)); 
     350        glTexGenfv(GL_T, GL_EYE_PLANE, texMatT.x[1]); 
    339351        glEnable(GL_TEXTURE_GEN_T); 
    340352 
    341353        glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    342         //glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2)); 
     354        glTexGenfv(GL_R, GL_EYE_PLANE, texMatT.x[2]); 
    343355        glEnable(GL_TEXTURE_GEN_R); 
    344356 
    345357        glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); 
    346         //glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3)); 
     358        glTexGenfv(GL_Q, GL_EYE_PLANE, texMatT.x[3]); 
    347359        glEnable(GL_TEXTURE_GEN_Q); 
    348360 
     
    363375        glAlphaFunc(GL_GEQUAL, 0.99f); 
    364376        glEnable(GL_ALPHA_TEST); 
     377 
     378        PrintGLerror("texture"); 
    365379 
    366380        traverser->RenderScene(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2891 r2892  
    4242        void ComputeShadowMap(Light *light, RenderTraverser *traverser); 
    4343 
    44 protected: 
     44//protected: 
    4545 
    4646        FrameBufferObject *mFbo; 
     
    5252        Camera *mShadowCam; 
    5353 
    54         Matrix4x4 mShadowMatrix; 
     54        Matrix4x4 mLightViewMatrix; 
     55        Matrix4x4 mLightProjectionMatrix; 
    5556 
    5657        Light *mLight; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2891 r2892  
    9494static int winWidth = 1024; 
    9595static int winHeight = 768; 
     96 
     97//static int winWidth = 512; 
     98//static int winHeight = 512; 
     99 
     100 
    96101static float winAspectRatio = 1.0f; 
    97102 
     
    107112static int texHeight = 768; 
    108113 
    109 //static int texWidth = 512; 
    110 //static int texHeight = 384; 
    111  
    112 //static int texWidth = 2048; 
    113 //static int texHeight = 2048; 
    114114 
    115115int renderedObjects = 0; 
     
    175175 
    176176static Matrix4x4 matProjectionView = IdentityMatrix(); 
     177static Matrix4x4 matViewing = IdentityMatrix(); 
    177178 
    178179ShadowMapping *shadowMapping = NULL; 
     
    434435        ShadowMapping::Init(sCgContext); 
    435436 
    436         //deferredShader = new DeferredShader(texWidth, texHeight); 
    437         //ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
    438  
    439437 
    440438        // initialize the render traverser 
     
    448446 
    449447        shadowMapping = new ShadowMapping(bvh->GetBox(), 512); 
    450         shadowMapping->ComputeShadowMap(light, traverser); 
    451  
     448         
    452449        // frame time is restarted every frame 
    453450        frameTimer.Start(); 
     
    795792        camera->SetupCameraView(); 
    796793 
    797         // set lights 
    798         GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f}; 
    799         glLightfv(GL_LIGHT0, GL_POSITION, position); 
    800  
    801         GLfloat position1[] = {-0.5f, 0.5f, 0.4f, 0.0f}; 
    802         glLightfv(GL_LIGHT1, GL_POSITION, position1); 
    803  
    804          
     794                 
    805795        ///////////////// 
    806796 
    807         Matrix4x4 matViewing, matProjection; 
     797        Matrix4x4 matProjection; 
    808798 
    809799        camera->GetModelViewMatrix(matViewing); 
     
    876866        } 
    877867         
    878          
    879         //shadowMapping->ComputeShadowMap(light, traverser); 
    880  
    881  
    882  
    883868        // render without shading 
    884869        switch (renderType) 
     
    918903        case RenderState::DEFERRED: 
    919904 
     905                shadowMapping->ComputeShadowMap(light, traverser); 
     906 
    920907                if (!fbo) InitFBO(); 
    921908 
     
    958945        SetupEyeView(); 
    959946 
    960         // actually render the scene geometry using one of the specified algorithms 
     947        // set up lights 
     948        GLfloat position[] = {0.8f, -1.0f, 0.7f, 0.0f}; 
     949        glLightfv(GL_LIGHT0, GL_POSITION, position); 
     950 
     951        GLfloat position1[] = {-0.5f, 0.5f, 0.4f, 0.0f}; 
     952        glLightfv(GL_LIGHT1, GL_POSITION, position1); 
     953 
     954        // actually render the scene geometry using the specified algorithm 
    961955        traverser->RenderScene(); 
    962  
    963956 
    964957 
     
    999992                { 
    1000993                        if (!ssaoShader) ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 
    1001                         //DEL_PTR(deferredShader); 
    1002994                        ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor); 
    1003995 
     
    1006998                { 
    1007999                        if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight); 
    1008                         //DEL_PTR(ssaoShader); 
    1009                         deferredShader->Render(fbo); 
     1000                         
     1001                        //deferredShader->Render(fbo); 
     1002                        deferredShader->Render(fbo, matViewing, shadowMapping); 
    10101003                } 
    10111004        } 
    1012         else 
    1013         { 
    1014                 /*DEL_PTR(fbo); 
    1015                 DEL_PTR(ssaoShader); 
    1016                 DEL_PTR(deferredShader); 
    1017                 */ 
    1018         } 
     1005         
    10191006         
    10201007        /////////// 
     
    14981485        const float offs = box.Size().x * 0.3f; 
    14991486         
    1500         //Vector3 vizpos = Vector3(box.Min().x, box.Min().y + box.Size().y * 0.5f, box.Min().z + box.Size().z * 50); 
    15011487        Vector3 vizpos = Vector3(box.Min().x, box.Min().y  - box.Size().y * 0.35f, box.Min().z + box.Size().z * 50); 
    15021488         
    15031489        visCamera->SetPosition(vizpos); 
    15041490        visCamera->ResetPitchAndYaw(); 
    1505         //visCamera->Pitch(M_PI); 
    1506  
     1491         
    15071492        glPushAttrib(GL_VIEWPORT_BIT); 
    15081493        glViewport(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth / 3, winHeight / 3); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r2891 r2892  
    99#define SAMPLE_INTENSITY 0.28f 
    1010 
     11//#define AREA_SIZE 50e-1f 
    1112#define AREA_SIZE 5e-1f 
    12 //#define AREA_SIZE 3e-1f 
    1313 
    1414#define VIEW_CORRECTION_SCALE 0.0f 
    1515//#define VIEW_CORRECTION_SCALE 0.1f 
    1616 
     17//#define DISTANCE_SCALE 1e-6f 
    1718#define DISTANCE_SCALE 1e-6f 
    1819 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2887 r2892  
    4949                   uniform sampler2D colors, 
    5050                   uniform sampler2D positions, 
    51                    uniform sampler2D normals 
     51                   uniform sampler2D normals     
    5252                   ) 
    5353{ 
     
    7272        return OUT; 
    7373} 
     74 
     75/** The mrt shader for standard rendering 
     76*/ 
     77pixel main_shadow(fragment IN,  
     78                                  uniform sampler2D colors, 
     79                                  uniform sampler2D positions, 
     80                                  uniform sampler2D normals,                
     81                                  uniform sampler2D shadowMap, 
     82                                  uniform float4x4 shadowMatrix 
     83                                  ) 
     84{ 
     85        pixel OUT; 
     86 
     87        float4 norm = tex2D(normals, IN.texCoord.xy); 
     88        float4 color = tex2Dlod(colors, float4(IN.texCoord.xy, 0, 0)); 
     89        float4 position = tex2D(positions, IN.texCoord.xy); 
     90 
     91        float4 lightSpacePos = mul(shadowMatrix, position); 
     92 
     93        float shadowDepth = tex2D(shadowMap, IN.texCoord.xy); 
     94 
     95        // an ambient color term 
     96        float amb = norm.w; 
     97 
     98        float3 normal = normalize(norm.xyz); 
     99        float4 col = shade(IN, color, position, normal, amb); 
     100         
     101        OUT.color = col; 
     102         
     103        if (lightSpacePos.z / lightSpacePos.w < shadowDepth) 
     104        { 
     105                OUT.color *= 0.1f; 
     106        } 
     107         
     108        //OUT.color = float4(lightSpacePos.z / lightSpacePos.w); 
     109        //OUT.color = float4(shadowDepth); 
     110        OUT.color.w = color.w; 
     111 
     112        return OUT; 
     113} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2891 r2892  
    1313        float3 view: COLOR0; 
    1414}; 
    15  
    1615 
    1716 
     
    6766        for (int i = 0; i < NUM_SAMPLES; i ++)  
    6867        { 
    69                 //float2 offset = samples[i]; 
    70                 float3 offset = float3(samples[i], 0); 
     68                float2 offset = samples[i]; 
     69                //float3 offset = float3(samples[i], 0); 
    7170 
    7271                //sample noisetex; r stores costheta, g stores sintheta 
    73                 //float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 
    74                 float3 mynoise = float3(tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy, 0); 
    75  
    76                 // rotation 
    77                 float2 offsetTransformed = reflect(offset, mynoise); 
     72                float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 
     73                //float3 mynoise = float3(tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy, 0); 
     74 
     75                // reflect sampling using the noise texture 
     76                float2 offsetTransformed = myreflect(offset, mynoise); 
    7877 
    7978                // weight with projected coordinate to reach similar kernel size for near and far 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2891 r2892  
    5656        for (int i = 0; i < NUM_SAMPLES; ++ i)  
    5757        { 
    58                 //const float2 offset = samples[i]; 
    59                 const float3 offset = float3(samples[i], 0); 
     58                const float2 offset = samples[i]; 
     59                //const float3 offset = float3(samples[i], 0); 
    6060 
    6161                //////////////////// 
     
    6363 
    6464                //const float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
    65                 //float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 
    66                 float3 mynoise = float3(tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy,0); 
     65                float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy; 
     66                //float3 mynoise = float3(tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy,0); 
    6767 
    68                 const float2 offsetTransformed = reflect(offset, mynoise); 
     68                const float2 offsetTransformed = myreflect(offset, mynoise); 
    6969 
    7070                // weight with projected coordinate to reach similar kernel size for near and far 
Note: See TracChangeset for help on using the changeset viewer.