Changeset 3005


Ignore:
Timestamp:
10/05/08 23:13:58 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
8 edited
1 copied

Legend:

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

    r3004 r3005  
    256256        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    257257 
    258         //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
    259258        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, w, h, 0, GL_RGB, GL_FLOAT, randomNormals); 
    260259 
     
    555554                cerr << "tone program failed to load" << endl; 
    556555 
     556 
    557557        sCgDownSampleProgram =  
    558558                cgCreateProgramFromFile(context,  
     
    587587        } 
    588588        else 
    589                 cerr << "intensity program failed to load" << endl; 
     589                cerr << "downsample program failed to load" << endl; 
    590590 
    591591        PrintGLerror("init"); 
     
    610610         
    611611        FrameBufferObject::Release(); 
    612  
    613612        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    614613 
     
    683682                                                                   ) 
    684683{ 
    685 //#ifdef USE_3D_SSAO 
     684#ifdef USE_3D_SSAO 
    686685        // bias from [-1, 1] to [0, 1] 
    687686        static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 
     
    691690 
    692691        Matrix4x4 m = projViewMatrix * biasMatrix;  
    693  
    694692        cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 
    695 //#endif 
     693#else 
     694        cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)projViewMatrix.x); 
     695#endif 
     696 
    696697 
    697698        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 
     
    869870 
    870871        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    871          
    872872        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    873873 
     
    13161316void DeferredRenderer::DownSample(FrameBufferObject *fbo) 
    13171317{ 
     1318        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
     1319        GLuint colorsTex = colorBuffer->GetTexture(); 
     1320         
     1321        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     1322        cgGLBindProgram(sCgDownSampleProgram); 
     1323         
     1324        cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex); 
     1325        cgGLEnableTextureParameter(sColorsTexDownSampleParam); 
     1326 
     1327        mDownSampleFbo->Bind(); 
     1328 
     1329        glDrawBuffers(1, mrt); 
     1330         
     1331        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     1332 
     1333        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     1334        cgGLBindProgram(sCgDownSampleProgram); 
     1335 
    13181336        //glPushAttrib(GL_VIEWPORT_BIT); 
    13191337        glViewport(0, 0, mWidth / 2, mHeight / 2); 
     
    13291347        glPushMatrix(); 
    13301348        glLoadIdentity(); 
    1331  
    1332  
    1333         ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
    1334         GLuint colorsTex = colorBuffer->GetTexture(); 
    1335          
    1336         cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    1337         cgGLBindProgram(sCgDownSampleProgram); 
    1338          
    1339         cgGLSetTextureParameter(sColorsTexDownSampleParam, colorsTex); 
    1340         cgGLEnableTextureParameter(sColorsTexDownSampleParam); 
    1341  
    1342         mDownSampleFbo->Bind(); 
    1343  
    1344         glDrawBuffers(1, mrt); 
    1345          
    1346         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    1347  
    1348         cgGLEnableProfile(RenderState::sCgFragmentProfile); 
    1349         cgGLBindProgram(sCgDownSampleProgram); 
    13501349 
    13511350        const float offs = 0.5f; 
     
    13641363        FrameBufferObject::Release(); 
    13651364 
    1366         //glPopAttrib(); 
    1367         glViewport(0, 0, mWidth, mHeight); 
    1368         PrintGLerror("downsample"); 
    1369  
    13701365        float *data = (float *)mDownSampleFbo->GetColorBuffer(0)->ReadTexture(); 
    13711366        //float *data = (float *)mFbo->GetColorBuffer(colorBufferIdx)->ReadTexture(); 
     
    13781373        glPopMatrix(); 
    13791374 
     1375        //glPopAttrib(); 
     1376        glViewport(0, 0, mWidth, mHeight); 
     1377        PrintGLerror("downsample"); 
     1378 
    13801379        delete [] data; 
    1381          
    1382         PrintGLerror("shadow map"); 
    13831380} 
    13841381 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp

    r2999 r3005  
    8686        mHeight = h; 
    8787 
    88         int myformat = GL_RGBA; 
     88        int components = GL_RGBA; 
    8989 
    9090        switch (format) 
    9191        { 
    92         case BUFFER_UBYTE: 
     92        case RGB_UBYTE:  
     93                mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGB8; 
     94                components = GL_RGB; 
     95                break; 
     96        case RGBA_UBYTE: 
    9397                mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; break; 
    94         case BUFFER_FLOAT_16: 
     98        case RGBA_FLOAT_16: 
    9599                mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA16F_ARB; break; 
    96         case BUFFER_FLOAT_32:  
     100        case RGB_FLOAT_32:  
     101                mGlFormat = GL_FLOAT; mInternalFormat = GL_RGB32F_ARB; 
     102                components = GL_RGB; 
     103                break; 
     104        case RGBA_FLOAT_32:  
    97105                mGlFormat = GL_FLOAT; mInternalFormat = GL_RGBA32F_ARB; break; 
    98         case BUFFER_LUMINANCE_ALPHA:  
    99                 mGlFormat = GL_FLOAT; mInternalFormat = GL_LUMINANCE_ALPHA ; 
    100                 myformat = GL_LUMINANCE_ALPHA; 
    101                 break; 
    102106        default: 
    103107                mGlFormat = GL_UNSIGNED_BYTE; mInternalFormat = GL_RGBA8; 
     
    115119        glGenTextures(1, &mTexId); 
    116120        glBindTexture(GL_TEXTURE_2D, mTexId); 
    117         glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, myformat, mGlFormat, NULL); 
     121        glTexImage2D(GL_TEXTURE_2D, 0, mInternalFormat, w, h, 0, components, mGlFormat, NULL); 
    118122 
    119123        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, mrt[attachment_idx], GL_TEXTURE_2D, mTexId, 0); 
     
    185189        switch (mInternalFormat) 
    186190        { 
     191        case GL_RGB8: 
     192                bytes = 3; break; 
    187193        case GL_RGBA8: 
    188                 bytes = 8; break; 
     194                bytes = 4; break; 
    189195        case GL_RGBA16F_ARB: 
    190196                bytes = 16; break; 
     197        case GL_RGB32F_ARB:  
     198                bytes = 24; break; 
    191199        case GL_RGBA32F_ARB:  
    192200                bytes = 32; break; 
     
    198206        glBindTexture(GL_TEXTURE_2D, mTexId); 
    199207         
    200         GLint width, height; 
     208        /*GLint width, height; 
    201209        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); 
    202210        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); 
    203  
    204         //cout << "w: " << width << "h: " << height << endl; 
    205  
    206         unsigned char *data = new unsigned char[bytes * 4 * width * height]; 
     211        cout << "w: " << width << "h: " << height << endl; 
     212        */ 
     213 
     214        unsigned char *data = new unsigned char[bytes * 4 * mWidth * mHeight]; 
    207215 
    208216        glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, data); 
     
    210218        glBindTexture(GL_TEXTURE_2D, 0); 
    211219        glDisable(GL_TEXTURE_2D); 
    212  
    213         float *d = (float *)data; 
    214220 
    215221        return data; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.h

    r3001 r3005  
    1515public: 
    1616 
    17         enum FORMAT { RGBA_UBYTE, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32}; 
     17        enum FORMAT { RGB_UBYTE, RGBA_UBYTE, RGBA_FLOAT_16, RGB_FLOAT_32, RGBA_FLOAT_32}; 
    1818        enum WRAP_TYPE { WRAP_REPEAT, WRAP_CLAMP_TO_EDGE }; 
    1919        enum FILTER_TYPE { FILTER_NEAREST, FILTER_LINEAR }; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3002 r3005  
    203203DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_QUADRATIC; 
    204204 
    205  
    206 static Matrix4x4 matProjectionView = IdentityMatrix(); 
    207  
    208  
    209205ShadowMap *shadowMap = NULL; 
    210206DirectionalLight *light = NULL; 
     
    287283static CGparameter sBLParamTex; 
    288284 
    289 static Matrix4x4 oldViewProjMatrix; 
    290 static Matrix4x4 oldMatViewing; 
     285static Matrix4x4 viewProjMat = IdentityMatrix(); 
     286static Matrix4x4 oldViewProjMat = IdentityMatrix(); 
    291287 
    292288 
     
    668664        fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
    669665        // the positions buffer 
    670         fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
    671         //fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
     666        //fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
     667        fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, ColorBufferObject::FILTER_NEAREST); 
    672668        // the normals buffer 
    673669        fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST); 
     
    905901{ 
    906902        // store matrix of last frame 
    907         oldViewProjMatrix = matProjectionView; 
    908         camera->GetModelViewMatrix(oldMatViewing); 
     903        oldViewProjMat = viewProjMat; 
    909904 
    910905        glMatrixMode(GL_PROJECTION); 
     
    926921 
    927922        // store matrix for later use 
    928         matProjectionView = matViewing * matProjection; 
     923        viewProjMat = matViewing * matProjection; 
    929924         
    930925        if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 
     
    11701165                // otherwise the temporal coherency is broken 
    11711166                BvhNode::SetCurrentState(1); 
    1172                 shadowMap->RenderShadowView(shadowTraverser, matProjectionView); 
     1167                shadowMap->RenderShadowView(shadowTraverser, viewProjMat); 
    11731168                BvhNode::SetCurrentState(0); 
    11741169        } 
     
    11771172                // actually render the scene geometry using the specified algorithm 
    11781173                traverser->RenderScene(); 
    1179 /* 
    1180 #if 0 
    1181                 SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end(); 
    1182  
    1183                 for (sit = sceneEntities.begin(); sit != sit_end; ++ sit) 
    1184                         renderQueue->Enqueue(*sit); 
    1185 #else 
    1186  
    1187                 SceneEntityContainer::const_iterator sit, sit_end = sceneEntities2.end(); 
    1188  
    1189                 for (sit = sceneEntities2.begin(); sit != sit_end; ++ sit) 
    1190                         renderQueue->Enqueue(*sit); 
    1191 #endif 
    1192 */                       
    1193                 renderQueue->Apply(); 
     1174                //renderQueue->Apply(); 
    11941175        } 
    11951176 
     
    12441225 
    12451226                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
    1246                 ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoTempCohFactor, light, useHDR, sm); 
     1227                ssaoShader->Render(fbo, oldViewProjMat, viewProjMat, ssaoTempCohFactor, light, useHDR, sm); 
    12471228        } 
    12481229 
     
    21732154         
    21742155        // the scene is rendered withouth any shading    
    2175         shadowMap->ComputeShadowMap(shadowTraverser, matProjectionView); 
     2156        shadowMap->ComputeShadowMap(shadowTraverser, viewProjMat); 
    21762157 
    21772158        glEnable(GL_CULL_FACE); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2992 r3005  
    4848        float4 outColor; 
    4949 
    50         if (position.w > 1e19f) outColor = color; 
     50        // hack: prevent shading the sky 
     51        if (position.z > 1e19f) outColor = color; 
    5152        //if (emmisive > 1.5f) outColor = color; 
    5253        else outColor = (ambient + diffuse) * color; 
    5354 
    5455        return outColor; 
    55         //return saturate((((ambient + diffuse)) * (1.0f - emmisive) + emmisive) * color); 
    5656} 
    5757 
     
    188188        // calc diffuse illumination + shadow term 
    189189        //if ((emmisive < 1.5f) // hack: prevent shadowing the sky       
    190         if ( 
    191                 (position.w < 1e19f) 
     190        if ((position.z < 1e19f) 
    192191                && (angle > 1e-3f) // shadow only if diffuse color has some minimum intensity 
    193192                ) 
     
    209208        // base lighting 
    210209        //OUT.color = (emmisive > 1.5f) ? color: (ambient + diffuse) * color; 
    211         OUT.color = (position.w > 1e19f) ? color: (ambient + diffuse) * color; 
     210        OUT.color = (position.z > 1e19f) ? color: (ambient + diffuse) * color; 
    212211 
    213212 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3004 r3005  
    3737struct pixel 
    3838{ 
    39   float4 col: COLOR0; 
    40   //float4 pos: COLOR1; 
    41   float4 pos: COLOR1; 
    42   float4 norm: COLOR2; 
     39        float4 col: COLOR0; 
     40        //float4 pos: COLOR1; 
     41        float3 pos: COLOR1; 
     42        float4 norm: COLOR2; 
    4343}; 
    4444 
     
    113113        pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 
    114114 
     115#if 1 
    115116        // save world position in second render target 
    116         pix.pos = IN.worldPos * maxDepth; 
    117         // store the projected depth 
    118         pix.pos.w = projPos.z; 
     117        pix.pos = IN.worldPos.xyz * maxDepth; 
     118#endif 
    119119 
    120120        return pix; 
     
    150150        pix.col.w = length(eyePos - IN.worldPos.xyz) * maxDepth / magView; 
    151151 
    152         pix.pos = IN.worldPos * maxDepth; 
    153         // store the projected depth 
    154         pix.pos.w = projPos.z; 
     152#if 1 
     153        pix.pos = IN.worldPos.xyz * maxDepth; 
     154#endif 
    155155 
    156156        return pix; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg

    r2982 r3005  
    3131{ 
    3232  float4 col: COLOR0; 
    33   float4 pos: COLOR1; 
     33  float3 pos: COLOR1; 
    3434  float4 norm: COLOR2; 
    3535}; 
     
    112112 
    113113        pix.col = IN.color2; 
    114         pix.pos = 1e20f; 
     114        pix.col.w = 2.0f; 
    115115 
    116116        pix.norm.xyz = IN.normal; 
     117        pix.norm.w = IN.mypos.w; 
     118 
     119        pix.pos = 1e20f; 
    117120         
    118         pix.norm.w = IN.mypos.w; 
    119         pix.pos.w = 1e20f; 
    120          
    121         pix.col.w = 2.0f; 
    122  
    123121        return pix; 
    124122} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3004 r3005  
    170170 
    171171 
    172         // the current world position 
    173         const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
    174  
    175172#if USE_EYE_SPACE_DEPTH 
    176173        /// reconstruct position from the eye space depth 
    177174        float3 viewDir = IN.view; 
    178175        const float eyeDepth = tex2D(colors, IN.texCoord.xy).w; 
    179         float4 centerPosition2; 
    180  
    181         centerPosition2.xyz = eyePos - viewDir * eyeDepth; 
    182         centerPosition2.w = centerPosition.w; 
    183  
    184         const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition2, w, eyePos, bl, br, tl, tr); 
     176 
     177        float4 centerPosition; 
     178        centerPosition.xyz = eyePos - viewDir * eyeDepth; 
     179        centerPosition.w = centerPosition.w; 
     180 
     181        const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 
    185182#else 
    186183 
     184        // the current world position 
     185        const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
     186 
    187187        const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 
    188188 
    189189#endif 
    190190 
    191         // get the current depth 
     191        ///////////////// 
     192        //-- compute temporally smoothing 
     193 
     194        float4 realPos = centerPosition * maxDepth; 
     195        realPos.w = 1.0f; 
     196 
     197        // calulcate the current depth 
    192198        //const float currentDepth = centerPosition.w; 
    193199         
     
    198204         
    199205 
    200         ///////////////// 
    201         //-- compute temporally smoothing 
    202  
    203         float4 realPos = centerPosition * maxDepth; 
    204         realPos.w = 1.0f; 
    205  
    206  
    207206        /////////// 
    208207        //-- reprojection new frame into old one  
     
    210209        // calculate projected depth 
    211210        float4 projPos = mul(oldModelViewProj, realPos); 
    212         projPos /= oldPos.w; 
     211        projPos /= projPos.w; 
    213212 
    214213        // the current depth projected into the old frame 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/tonemap.cg

    r3003 r3005  
    2222float4 DownSample(frag IN, 
    2323                                  uniform sampler2D colors, 
    24                                   float2 downSampleOffs[4]) : COLOR 
     24                                  uniform float2 downSampleOffs[4]): COLOR 
    2525{     
    2626    float4 average = .0f; 
     
    130130        float logLumScaled = logLum * INV_LOGLUM_RANGE - logLumOffset; 
    131131 
    132         if (oldLogLum > 1e-5f) // too hight log lum 
     132        if (oldLogLum > 1e-5f) // too bright 
    133133                OUT.col.w = lerp(oldLogLum, logLumScaled, 0.1f); 
    134134        else 
Note: See TracChangeset for help on using the changeset viewer.