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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.