Changeset 2860 for GTP/trunk


Ignore:
Timestamp:
08/21/08 20:17:46 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

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

    r2844 r2860  
    4242void Camera::Precompute(const Vector3 &direction)  
    4343{ 
    44         /* 
    45         Vector3 side = CrossProd(Vector3(1, 0, 0), direction); 
    46         Vector3 up = -Normalize(CrossProd(side, direction)); 
    47         Vector3 right = -Normalize(CrossProd(direction, up)); 
    48         */ 
    4944        Vector3 up = Vector3(0, 0, 1); 
    5045        Vector3 right = Normalize(CrossProd(up, direction)); 
     
    5348        mBaseOrientation = Matrix4x4(right, up, direction); 
    5449        mViewOrientation = mBaseOrientation; 
    55  
    56         /*cout << "right: " << right << endl; 
    57         cout << "up:    " << up << endl; 
    58         cout << "dir:   " << direction << endl; 
    59         */ 
    6050} 
    6151 
     
    241231        } 
    242232 
    243         Vector3 h2 = direction;// h2.x = 0;  
     233        Vector3 h2 = direction;  
    244234         
    245235        if (SqrMagnitude(h2) > 0) 
    246236        { 
    247237                h2.Normalize(); 
    248                 mYaw = -acos(DotProd(h2, h1));//Vector3(0, 1, 0))); 
     238                mYaw = -acos(DotProd(h2, h1)); 
    249239        } 
    250240 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.cpp

    r2859 r2860  
    33#include "RenderState.h" 
    44#include "SampleGenerator.h" 
     5#include "Vector3.h" 
     6#include "Camera.h" 
    57 
    68 
    79using namespace std; 
    810 
    9 GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; 
     11static GLenum mymrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; 
    1012 
    1113namespace CHCDemoEngine 
    1214{ 
     15 
     16// number of ssao samples 
     17#define NUM_SAMPLES 16 
     18 
    1319 
    1420static CGprogram sCgSsaoProgram = NULL; 
     
    2531static CGparameter sExpFactorParam; 
    2632 
    27  
    28 #define NUM_SAMPLES 16 
     33static GLuint noiseTex; 
    2934 
    3035// ssao random spherical samples 
     
    5459 
    5560 
    56 SsaoShader::SsaoShader(int w, int h, float expFactor, float scaleFactor): 
    57 mWidth(w), mHeight(h), mExpFactor(expFactor), mScaleFactor(scaleFactor) 
     61SsaoShader::SsaoShader(int w, int h,  
     62                                           Camera *cam, 
     63                                           float expFactor,  
     64                                           float scaleFactor 
     65                                           ): 
     66mWidth(w), mHeight(h),  
     67mCamera(cam), 
     68mExpFactor(expFactor),  
     69mScaleFactor(scaleFactor) 
    5870{} 
    5971 
     
    113125        GLuint normalsTex = fbo->GetColorBuffer(0)->GetTexture(); 
    114126 
     127        GLuint oldTex = fbo2->GetColorBuffer(0)->GetTexture(); 
     128 
    115129        glPushAttrib(GL_VIEWPORT_BIT); 
    116130        glViewport(0, 0, mWidth, mHeight); 
    117131 
    118         glDrawBuffers(1, mrt); 
     132        glDrawBuffers(1, mymrt); 
    119133 
    120134        glDisable(GL_ALPHA_TEST); 
     
    172186 
    173187        // note: slightly larger texture hides ambient occlusion error on border but costs resolution 
    174         //float offs2 = 0.55f; 
    175         float offs2 = 0.5f; 
    176  
    177         glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); 
    178         glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f); 
    179         glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f); 
    180         glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f); 
     188        //const float new_offs = 0.55f; 
     189        const float new_offs = 0.5f; 
     190         
     191        glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-new_offs, -new_offs, -0.5f); 
     192        glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( new_offs, -new_offs, -0.5f); 
     193        glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( new_offs,  new_offs, -0.5f); 
     194        glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-new_offs,  new_offs, -0.5f); 
    181195 
    182196        glEnd(); 
    183197 
    184         cgGLDisableTextureParameter(sColorsTexParamSsao); 
    185         cgGLDisableTextureParameter(sPositionsTexParamSsao); 
    186         cgGLDisableTextureParameter(sNormalsTexParamSsao); 
    187         cgGLDisableTextureParameter(sNoiseTexParamSsao); 
    188         cgGLDisableTextureParameter(sOldTexParamSsao); 
     198        cgGLDisableTextureParameter(sColorsTexParam); 
     199        cgGLDisableTextureParameter(sPositionsTexParam); 
     200        cgGLDisableTextureParameter(sNormalsTexParam); 
     201        cgGLDisableTextureParameter(sNoiseTexParam); 
     202        cgGLDisableTextureParameter(sOldTexParam); 
    189203 
    190204        cgGLDisableProfile(RenderState::sCgFragmentProfile); 
     
    254268 
    255269 
     270void SsaoShader::ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br) 
     271{ 
     272        Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
     273 
     274        mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
     275 
     276#if 1 // matT: debug this!! 
     277         
     278        bl = Normalize(nbl - fbl); 
     279        br = Normalize(nbr - fbr); 
     280        tl = Normalize(ftl - ntl); 
     281        tr = Normalize(ftr - ntr); 
     282 
     283#else // just take camera direction 
     284         
     285        bl = -Normalize(mCamera->GetDirection()); 
     286        br = -Normalize(mCamera->GetDirection()); 
     287        tl = -Normalize(mCamera->GetDirection()); 
     288        tr = -Normalize(mCamera->GetDirection()); 
     289 
     290#endif 
     291 
     292        // normalize to 0 .. 1 
     293        bl = bl * 0.5f + 0.5f; 
     294        br = br * 0.5f + 0.5f; 
     295        tl = tl * 0.5f + 0.5f; 
     296        tr = tr * 0.5f + 0.5f; 
     297} 
     298 
     299 
     300void SsaoShader::CreateNoiseTex2D() 
     301{ 
     302        GLubyte *randomNormals = new GLubyte[mWidth * mHeight * 3]; 
     303 
     304        for (int i = 0; i < mWidth * mHeight * 3; i += 3) 
     305        { 
     306                // create random samples over sphere 
     307                const float rx = RandomValue(0, 1); 
     308                const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
     309 
     310                randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
     311                randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
     312                randomNormals[i + 2] = 0; 
     313        } 
     314 
     315        glEnable(GL_TEXTURE_2D); 
     316        glGenTextures(1, &noiseTex); 
     317        glBindTexture(GL_TEXTURE_2D, noiseTex); 
     318                 
     319        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     320        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     321        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
     322        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
     323 
     324        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
     325 
     326        glBindTexture(GL_TEXTURE_2D, 0); 
     327        glDisable(GL_TEXTURE_2D); 
     328 
     329        delete [] randomNormals; 
     330 
     331        cout << "created noise texture" << endl; 
     332 
     333        PrintGLerror("noisetexture"); 
     334} 
     335 
    256336 
    257337} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SsaoShader.h

    r2859 r2860  
    1212 
    1313class FrameBufferObject; 
     14class Vector3; 
     15class Camera; 
    1416 
    1517 
     
    2123public: 
    2224        /** constructor for a deferred shader taking the requested output image size, 
    23                 the exponential smoothing factor for temporal reprojection. 
    24                  
    25                 The last parameter is a just a scale factor 
    26                 for the scene depth in order to get better floating point precision in the shader 
    27                 This must be reciprocal value of the scale factor used in the mrt shader. 
     25                the current camera, the exponential smoothing factor for temporal reprojection,  
     26                and a scaling factor. 
     27                         
     28                The parameter scaleFactor must be reciprocal value of the  
     29                scale factor used for creating the positions texture. It is used recover the  
     30                exact scene size that was scaled in order to improve floating point precision. 
    2831        */ 
    29         SsaoShader(int w, int h, float expFactor, float scaleFactor); 
     32        SsaoShader(int w, int h, Camera *cam, float expFactor, float scaleFactor); 
    3033        /** The algorithm renders the scene given an fbo. 
    3134                The fbo must have color buffer, position buffer, normal buffer. 
     
    5558        /// this is just a scale factor for the scene depth in order to get better float precision in the shader 
    5659        float mScaleFactor; 
     60 
     61        Camera *mCamera; 
     62 
     63 
     64private: 
     65 
     66        void CreateNoiseTex2D(); 
     67        void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br); 
     68 
    5769}; 
    5870 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2859 r2860  
    668668        // this fbo basicly stores the scene information we get from standard rendering of a frame 
    669669        // we store colors, normals, positions (for the ssao) 
    670         myfbo = new FrameBufferObject(texWidth, texHeight, true, FrameBufferObject::DEPTH_24); 
     670        fbo = new FrameBufferObject(texWidth, texHeight, true, FrameBufferObject::DEPTH_24); 
    671671 
    672672 
    673673        // the diffuse color buffer 
    674         myfbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32,  
    675                                                   ColorBufferObject::WRAP_CLAMP_TO_EDGE,  
    676                                                   ColorBufferObject::FILTER_LINEAR,  
    677                                                   false, false); 
     674        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false, false); 
    678675 
    679676        // the positions buffer 
    680         myfbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32,  
    681                               ColorBufferObject::WRAP_CLAMP_TO_EDGE,  
    682                                                   ColorBufferObject::FILTER_NEAREST,  
    683                                                   false, false); 
     677        fbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 
    684678 
    685679        // the normals buffer 
    686         myfbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE,  
    687                               ColorBufferObject::WRAP_CLAMP_TO_EDGE,  
    688                                                   ColorBufferObject::FILTER_NEAREST,  
    689                                                   false, false); 
    690  
    691          
     680        fbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST, false, false); 
     681 
    692682 
    693683 
Note: See TracChangeset for help on using the changeset viewer.