Changeset 2900


Ignore:
Timestamp:
09/03/08 22:40:35 (16 years ago)
Author:
mattausch
Message:

changed to real 3d samples which are then projected to texture space

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
7 edited

Legend:

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

    r2898 r2900  
    807807                                > 
    808808                        </File> 
     809                        <File 
     810                                RelativePath=".\src\shaders\ssao2.cg" 
     811                                > 
     812                        </File> 
    809813                </Filter> 
    810814                <File 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r2899 r2900  
    4242 
    4343static CGparameter sOldModelViewProjMatrixParam; 
     44static CGparameter sModelViewProjMatrixParam; 
    4445static CGparameter sMaxDepthParam; 
    4546static CGparameter sSamplesParam;  
     
    9697 
    9798// ssao random spherical samples 
    98 static Sample2 samples[NUM_SAMPLES]; 
     99static Sample2 samples2[NUM_SAMPLES]; 
     100static Sample2 samples3[NUM_SAMPLES]; 
    99101 
    100102static int colorBufferIdx = 0; 
     
    117119static void GenerateSamples(int sampling) 
    118120{ 
     121        static SphericalSampleGenerator gauss(NUM_SAMPLES, 0.5f); 
     122        gauss.Generate((float *)samples3); 
     123/* 
    119124        switch (sampling) 
    120125        { 
     
    122127                { 
    123128                        static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 
    124                         poisson.Generate((Sample2 *)samples); 
     129                        poisson.Generate((float *)samples2); 
    125130                } 
    126131                break; 
     
    128133                { 
    129134                        //static GaussianSampleGenerator gauss(NUM_SAMPLES, 0.5f); 
    130                         //gauss.Generate((Sample2 *)samples); 
     135                        //gauss.Generate((float *)samples2); 
    131136 
    132137                        static SphericalSampleGenerator gauss(NUM_SAMPLES, 0.5f); 
    133                         gauss.Generate((Sample2 *)samples); 
     138                        gauss.Generate((float *)samples3); 
    134139                } 
    135140                break; 
    136141        default: 
    137142                break; 
    138         } 
     143        }*/ 
    139144} 
    140145 
     
    145150        float *randomNormals = new float[w * h * 3]; 
    146151 
     152        static HaltonSequence halton; 
     153        float r[2]; 
     154 
    147155        for (int i = 0; i < w * h * 3; i += 3) 
    148156        { 
    149157                // create random samples on a circle 
    150                 const float rx = RandomValue(0, 1); 
     158                halton.GetNext(2, r); 
     159 
     160                /* 
    151161                const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    152162 
    153                 //randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
    154                 //randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
    155163                randomNormals[i + 0] = cos(theta); 
    156164                randomNormals[i + 1] = sin(theta); 
    157                 randomNormals[i + 2] = 0; 
     165                randomNormals[i + 2] = 0;*/ 
     166 
     167                const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 
     168                const float phi = 2.0f * M_PI * r[1]; 
     169 
     170                randomNormals[i + 0] = sin(theta) * cos(phi); 
     171                randomNormals[i + 1] = sin(theta) * sin(phi); 
     172                randomNormals[i + 2] = cos(theta); 
    158173        } 
    159174 
     
    197212        //-- the flip-flop fbos 
    198213 
    199         /*mNewFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    200          
    201         mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    202         mNewFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    203          
    204  
    205         /////////////////////// 
    206  
    207         mOldFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    208          
    209         mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 
    210         mOldFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false);*/ 
    211          
    212214        mFbo = new FrameBufferObject(w, h, FrameBufferObject::DEPTH_NONE); 
    213215 
     
    269271                cgCreateProgramFromFile(context,  
    270272                                                                CG_SOURCE, 
    271                                                                 "src/shaders/ssao.cg",  
     273                                                                //"src/shaders/ssao.cg",  
     274                                                                "src/shaders/ssao2.cg",  
    272275                                                                RenderState::sCgFragmentProfile, 
    273276                                                                "main", 
     
    285288                 
    286289                sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 
     290                sModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "mymodelViewProj"); 
    287291                sMaxDepthParam = cgGetNamedParameter(sCgSsaoProgram, "maxDepth"); 
    288292                sTemporalCoherenceParam = cgGetNamedParameter(sCgSsaoProgram, "temporalCoherence"); 
     
    416420void DeferredRenderer::Render(FrameBufferObject *fbo,  
    417421                                                          const Matrix4x4 &oldProjViewMatrix, 
     422                                                          const Matrix4x4 &projViewMatrix, 
    418423                                                          float expFactor, 
    419424                                                          ShadowMap *shadowMap) 
     
    457462        { 
    458463        case SSAO: 
    459                 ComputeSsao(fbo, expFactor, oldProjViewMatrix); 
     464                ComputeSsao(fbo, expFactor, oldProjViewMatrix, projViewMatrix); 
    460465                CombineSsao(fbo); 
    461466                break; 
     
    487492 
    488493void DeferredRenderer::ComputeSsao(FrameBufferObject *fbo,  
    489                                                          float expFactor, 
    490                                                          const Matrix4x4 &oldProjViewMatrix 
    491                                                          ) 
    492 { 
     494                                                                   float expFactor, 
     495                                                                   const Matrix4x4 &oldProjViewMatrix, 
     496                                                                   const Matrix4x4 &projViewMatrix 
     497                                                                   ) 
     498{ 
     499        static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 
     500                                                                0.0f, 0.5f, 0.0f, 0.5f, 
     501                                                                0.0f, 0.0f, 0.5f, 0.5f, 
     502                                                                0.0f, 0.0f, 0.0f, 1.0f); //bias from [-1, 1] to [0, 1] 
     503 
     504        Matrix4x4 m = projViewMatrix * biasMatrix;  
     505 
    493506        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 
     507        cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 
    494508 
    495509        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
     
    547561                // needs longer to converge 
    548562                GenerateSamples(mSamplingMethod);  
    549                 cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples); 
     563 
     564                //cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples2); 
     565                cgGLSetParameterArray3f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples3); 
    550566        } 
    551567 
     
    772788                // needs longer to converge 
    773789                GenerateSamples(mSamplingMethod);  
    774                 cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples); 
     790                cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples2); 
    775791        } 
    776792 
     
    865881{ 
    866882        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
    867         //GLuint ssaoTex = mNewFbo->GetColorBuffer(0)->GetTexture(); 
    868883        GLuint ssaoTex = mFbo->GetColorBuffer(mFboIndex)->GetTexture(); 
    869884 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r2897 r2900  
    3838                a smoothing factor for temporal coherence 
    3939        */ 
    40         void Render(FrameBufferObject *fbo, const Matrix4x4 &oldProjViewMatrix, float expFactor, ShadowMap *shadowMap = NULL); 
     40        void Render(FrameBufferObject *fbo,  
     41                        const Matrix4x4 &oldProjViewMatrix,  
     42                                const Matrix4x4 &projViewMatrix,  
     43                                float expFactor,  
     44                                ShadowMap *shadowMap = NULL); 
    4145 
    4246        /** Initialises the deferred shader and loads the required shaders: 
     
    5862protected: 
    5963 
    60         void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix); 
     64        void ComputeSsao(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix, const Matrix4x4 &projViewMatrix); 
    6165 
    6266        void ComputeGlobIllum(FrameBufferObject *fbo, float expFactor, const Matrix4x4 &oldProjViewMatrix); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp

    r2899 r2900  
    1717 
    1818 
    19 void PoissonDiscSampleGenerator::Generate(Sample2 *samples) const 
     19void PoissonDiscSampleGenerator::Generate(float *samples) const 
    2020{ 
    2121        // this is a hacky poisson sampling generator which does random dart-throwing 
     
    3535 
    3636        //cout << "minDist before= " << minDist << endl; 
     37        Sample2 *s = (Sample2 *)samples; 
    3738 
    3839        for (int i = 0; i < mNumSamples; ++ i) 
     
    6162                        { 
    6263                                const float dist =  
    63                                         sqrt((samples[j].x - rx) * (samples[j].x - rx) + 
    64                                              (samples[j].y - ry) * (samples[j].y - ry)); 
     64                                        sqrt((s[j].x - rx) * (s[j].x - rx) + 
     65                                             (s[j].y - ry) * (s[j].y - ry)); 
    6566                         
    6667                                if (dist < minDist) 
     
    7071                        if (sampleValid) 
    7172                        { 
    72                                 samples[i].x = rx; 
    73                                 samples[i].y = ry; 
     73                                s[i].x = rx; 
     74                                s[i].y = ry; 
    7475                                break; 
    7576                        } 
     
    9596 
    9697 
    97 void GaussianSampleGenerator::Generate(Sample2 *samples) const 
     98void GaussianSampleGenerator::Generate(float *samples) const 
    9899{ 
    99100        static HaltonSequence halton; 
     
    101102 
    102103        const float sigma = mRadius; 
     104 
     105        Sample2 *s = (Sample2 *)samples; 
    103106 
    104107        const float p0 = 1.0f / (sigma * sqrt(2.0f * M_PI)); 
     
    112115                float exp_y = -(r[1] * r[1]) / (2.0f * sigma * sigma); 
    113116 
    114                 samples[i].x = p0 * pow(M_E, exp_x); 
    115                 samples[i].y = p1 * pow(M_E, exp_y); 
     117                s[i].x = p0 * pow(M_E, exp_x); 
     118                s[i].y = p1 * pow(M_E, exp_y); 
    116119        } 
    117120 
     
    125128 
    126129 
    127  
    128  
    129 void SphericalSampleGenerator::Generate(Sample2 *samples) const 
     130void SphericalSampleGenerator::Generate(float *samples) const 
    130131{ 
    131132        static HaltonSequence halton; 
    132133        float r[2]; 
     134 
     135        Sample3 *s = (Sample3 *)samples; 
    133136 
    134137        for (int i = 0; i < mNumSamples; ++ i) 
     
    137140 
    138141                // create stratified samples over sphere 
    139                 const float rx = r[0]; 
    140                 const float ry = r[1]; 
     142                const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 
     143                const float phi = 2.0f * M_PI * r[1]; 
    141144 
    142                 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    143                 const float phi = 2.0f * M_PI * ry; 
    144  
    145                 float x = sin(theta) * cos(phi); 
    146                 float y = sin(theta) * sin(phi); 
    147                 float z = cos(theta); 
    148  
    149                 // project to disc 
    150                 samples[i].x = x / z; 
    151                 samples[i].y = y / z; 
     145                s[i].x = sin(theta) * cos(phi); 
     146                s[i].y = sin(theta) * sin(phi); 
     147                s[i].z = cos(theta); 
    152148        } 
    153149} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.h

    r2899 r2900  
    1616 
    1717 
     18struct Sample3 
     19{ 
     20        Sample3() {} 
     21        Sample3(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} 
     22 
     23        float x;  
     24        float y; 
     25        float z; 
     26}; 
     27 
     28/** Class generating random samples on a disc or a sphere, respectively. 
     29*/ 
    1830class SampleGenerator 
    1931{ 
     
    2234        SampleGenerator(int numSamples, float radius); 
    2335 
    24         virtual void Generate(Sample2 *samples) const = 0; 
     36        virtual void Generate(float *samples) const = 0; 
    2537 
    2638protected: 
     
    3951        PoissonDiscSampleGenerator(int numSamples, float radius); 
    4052 
    41         virtual void Generate(Sample2 *samples) const; 
     53        virtual void Generate(float *samples) const; 
    4254}; 
    4355 
     
    4961        GaussianSampleGenerator(int numSamples, float radius); 
    5062 
    51         virtual void Generate(Sample2 *samples) const; 
     63        virtual void Generate(float *samples) const; 
    5264}; 
    5365 
     
    5971        SphericalSampleGenerator(int numSamples, float radius); 
    6072 
    61         virtual void Generate(Sample2 *samples) const; 
     73        virtual void Generate(float *samples) const; 
    6274}; 
    6375 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2899 r2900  
    10321032 
    10331033                ShadowMap *sm = showShadowMap ? shadowMap : NULL; 
    1034                 ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor, sm); 
     1034                ssaoShader->Render(fbo, oldViewProjMatrix, matProjectionView, ssaoExpFactor, sm); 
    10351035        } 
    10361036 
     
    13001300                break; 
    13011301        case GLUT_KEY_F8: 
    1302                 shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 3); 
     1302                //shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 3); 
     1303                shadingMethod = (DeferredRenderer::SHADING_METHOD)((shadingMethod + 1) % 2); 
    13031304                 
    13041305                break; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r2899 r2900  
    77// rule of thumb: approx 1 / NUM_SAMPLES 
    88//#define SAMPLE_INTENSITY 0.14f 
    9 #define SAMPLE_INTENSITY 0.28f 
    10 //#define SAMPLE_INTENSITY 1.0f 
     9//#define SAMPLE_INTENSITY 0.28f 
     10#define SAMPLE_INTENSITY 0.32f 
    1111 
    12 //#define AREA_SIZE 20e-1f 
    13 #define AREA_SIZE 5e-1f 
     12//#define AREA_SIZE 18e-1f 
     13#define AREA_SIZE 8e-1f 
     14//#define AREA_SIZE 5e-1f 
    1415 
    1516#define VIEW_CORRECTION_SCALE 0.0f 
Note: See TracChangeset for help on using the changeset viewer.