Ignore:
Timestamp:
09/04/08 15:00:42 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2901 r2903  
    4747static CGparameter sOldTexParam; 
    4848static CGparameter sNoiseTexParam; 
    49 static CGparameter sNoiseMultiplierParam; 
    5049static CGparameter sTemporalCoherenceParam; 
    5150 
     
    6564static CGparameter sOldIllumTexGiParam; 
    6665static CGparameter sNoiseTexGiParam; 
    67 static CGparameter sNoiseMultiplierGiParam; 
    6866static CGparameter sTemporalCoherenceGiParam; 
    6967 
     
    9290static CGparameter sSampleWidthParam; 
    9391 
     92//#define USE_3D_SSAO 
    9493 
    9594 
     
    9796 
    9897// ssao random spherical samples 
     98#ifdef USE_3D_SSAO 
     99 
     100static Sample2 samples3[NUM_SAMPLES]; 
     101 
     102#else 
     103 
    99104static Sample2 samples2[NUM_SAMPLES]; 
    100 static Sample2 samples3[NUM_SAMPLES]; 
     105 
     106#endif 
    101107 
    102108static int colorBufferIdx = 0; 
     
    119125static void GenerateSamples(int sampling) 
    120126{ 
    121         SphericalSampleGenerator gauss(NUM_SAMPLES, 1.0f); 
    122         gauss.Generate((float *)samples3); 
    123          
    124         /* 
     127#ifdef USE_3D_SSAO 
     128 
     129        SphericalSampleGenerator sph(NUM_SAMPLES, 1.0f); 
     130        sph.Generate((float *)samples3); 
     131 
     132#else 
    125133        switch (sampling) 
    126134        { 
    127135        case DeferredRenderer::POISSON: 
    128136                { 
    129                         static PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 
     137                        PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 
    130138                        poisson.Generate((float *)samples2); 
    131139                } 
     
    133141        case DeferredRenderer::GAUSS: 
    134142                { 
    135                         //static GaussianSampleGenerator gauss(NUM_SAMPLES, 0.5f); 
    136                         //gauss.Generate((float *)samples2); 
    137  
    138                         static SphericalSampleGenerator gauss(NUM_SAMPLES, 0.5f); 
    139                         gauss.Generate((float *)samples3); 
     143                        //PoissonDiscSampleGenerator poisson(NUM_SAMPLES, 1.0f); 
     144                        //poisson.Generate((float *)samples2); 
     145 
     146                        PseudoRandomGenerator pseudo(NUM_SAMPLES, 1.0f); 
     147                        pseudo.Generate((float *)samples2); 
    140148                } 
    141149                break; 
    142150        default: 
     151                cout << "should not come here" << endl; 
    143152                break; 
    144         }*/ 
     153        } 
     154#endif 
    145155} 
    146156 
     
    151161        float *randomNormals = new float[w * h * 3]; 
    152162 
    153         //SphericalSampleGenerator gauss(w * h, 1.0f); 
    154         //gauss.Generate(randomNormals); 
    155  
    156163        static HaltonSequence halton; 
    157164        float r[2]; 
     
    159166        for (int i = 0; i < w * h * 3; i += 3) 
    160167        { 
    161                 // create random samples on a circle 
    162                 halton.GetNext(2, r); 
    163  
    164168                 
    165                 //const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    166                 //randomNormals[i + 0] = cos(theta); 
    167                 //randomNormals[i + 1] = sin(theta); 
    168                 //randomNormals[i + 2] = 0; 
     169#ifdef USE_3D_SSAO 
     170                //halton.GetNext(2, r); 
     171                r[0] = RandomValue(0, 1); 
     172                r[1] = RandomValue(0, 1); 
    169173 
    170174                const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 
     
    174178                randomNormals[i + 1] = sin(theta) * sin(phi); 
    175179                randomNormals[i + 2] = cos(theta); 
     180#else 
     181                // create random samples on a circle 
     182                r[0] = RandomValue(0, 1); 
     183                //halton.GetNext(1, r); 
     184 
     185                const float theta = 2.0f * acos(sqrt(1.0f - r[0])); 
     186                 
     187                randomNormals[i + 0] = cos(theta); 
     188                randomNormals[i + 1] = sin(theta); 
     189                randomNormals[i + 2] = 0; 
     190#endif 
    176191        } 
    177192 
     
    274289                cgCreateProgramFromFile(context,  
    275290                                                                CG_SOURCE, 
    276                                                                 //"src/shaders/ssao.cg",  
     291#ifdef USE_3D_SSAO 
    277292                                                                "src/shaders/ssao3d.cg",  
     293 
     294#else 
     295                                                                "src/shaders/ssao.cg",  
     296#endif 
    278297                                                                RenderState::sCgFragmentProfile, 
    279298                                                                "main", 
     
    288307                sNormalsTexParam = cgGetNamedParameter(sCgSsaoProgram, "normals");   
    289308                sNoiseTexParam = cgGetNamedParameter(sCgSsaoProgram, "noiseTexture"); 
    290                 sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier"); 
    291309                 
    292310                sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 
     
    297315                sOldTexParam = cgGetNamedParameter(sCgSsaoProgram, "oldTex");   
    298316                 
    299                 cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(1.0f, 3.0f)); 
    300317                sSamplesParam = cgGetNamedParameter(sCgSsaoProgram, "samples"); 
    301318        } 
     
    320337                sNormalsTexGiParam = cgGetNamedParameter(sCgGiProgram, "normals");   
    321338                sNoiseTexGiParam = cgGetNamedParameter(sCgGiProgram, "noiseTexture"); 
    322                 sNoiseMultiplierGiParam = cgGetNamedParameter(sCgGiProgram, "noiseMultiplier"); 
    323339                 
    324340                sOldModelViewProjMatrixGiParam = cgGetNamedParameter(sCgGiProgram, "oldModelViewProj"); 
     
    330346                sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex");   
    331347                sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex");   
    332  
    333                 cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(1.0f, 3.0f)); 
    334348        } 
    335349        else 
     
    500514                                                                   ) 
    501515{ 
     516#ifdef USE_3D_SSAO 
    502517        static Matrix4x4 biasMatrix(0.5f, 0.0f, 0.0f, 0.5f, 
    503518                                                                0.0f, 0.5f, 0.0f, 0.5f, 
     
    507522        Matrix4x4 m = projViewMatrix * biasMatrix;  
    508523 
     524        cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 
     525#endif 
     526 
    509527        cgGLSetMatrixParameterfc(sOldModelViewProjMatrixParam, (const float *)oldProjViewMatrix.x); 
    510         cgGLSetMatrixParameterfc(sModelViewProjMatrixParam, (const float *)m.x); 
    511528 
    512529        GLuint colorsTex = fbo->GetColorBuffer(3)->GetTexture(); 
     
    558575        { 
    559576                mRegenerateSamples = false; 
    560                 cgGLSetParameter1f(sNoiseMultiplierParam, RandomValue(3.0f, 17.0f)); 
    561577 
    562578                // q: should we generate new samples or only rotate the old ones? 
     
    565581                GenerateSamples(mSamplingMethod);  
    566582 
    567                 //cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples2); 
     583#ifdef USE_3D_SSAO 
    568584                cgGLSetParameterArray3f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples3); 
     585#else 
     586                cgGLSetParameterArray2f(sSamplesParam, 0, NUM_SAMPLES, (const float *)samples2); 
     587#endif 
    569588        } 
    570589 
     
    779798        { 
    780799                mRegenerateSamples = false; 
    781                 cgGLSetParameter1f(sNoiseMultiplierGiParam, RandomValue(3.0f, 17.0f)); 
    782800 
    783801                // q: should we generate new samples or only rotate the old ones? 
     
    785803                // needs longer to converge 
    786804                GenerateSamples(mSamplingMethod);  
     805 
     806#ifdef USE_3D_SSAO 
     807                cgGLSetParameterArray3f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples3); 
     808#else 
    787809                cgGLSetParameterArray2f(sSamplesGiParam, 0, NUM_SAMPLES, (const float *)samples2); 
     810#endif 
    788811        } 
    789812 
Note: See TracChangeset for help on using the changeset viewer.