Changeset 3128


Ignore:
Timestamp:
11/16/08 03:46:19 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp

    r3102 r3128  
    364364        if (hasMaterial) 
    365365        { 
    366                 SimpleVec ambient, diffuse, black; 
     366                SimpleVec ambient, diffuse, spec, emm; 
    367367 
    368368                ambient.x = ambient.y = ambient.z = 0.2f; 
    369369                diffuse.x = diffuse.y = diffuse.z = 1.0f; 
    370                 black.x   = black.y   = black.z   = .0f; 
     370                spec.x   = spec.y   = spec.z   =  .0f; 
     371                emm = spec; 
    371372 
    372373                // only write rgb part of the material 
    373374                str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 
    374375                str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 
    375                 str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
    376                 str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
     376                str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec)); 
     377                str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec)); 
    377378        } 
    378379} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter/VboFormatConverter.cpp

    r3127 r3128  
    140140        //-- texture 
    141141 
    142         int texId = -1; 
    143         //int texId = 0; 
     142        //int texId = -1; 
     143        int texId = 0; 
     144         
    144145        str.write(reinterpret_cast<char *>(&texId), sizeof(int)); 
     146        //str.write(reinterpret_cast<char *>(&texId2), sizeof(int)); 
    145147 
    146148        bool alphaTestEnabled = false; 
     
    158160        if (hasMaterial) 
    159161        { 
    160                 SimpleVec ambient, diffuse, black; 
     162                SimpleVec ambient, diffuse, spec, emm; 
    161163 
    162164                ambient.x = ambient.y = ambient.z = 0.2f; 
    163165                diffuse.x = diffuse.y = diffuse.z = 1.0f; 
    164                 black.x   = black.y   = black.z   = .0f; 
     166                spec.x   = spec.y   = spec.z   =  .0f; 
     167                emm = spec; 
    165168 
    166169                // only write rgb part of the material 
    167170                str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 
    168171                str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 
    169                 str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
    170                 str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
     172                str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec)); 
     173                str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec)); 
    171174        } 
    172175} 
     
    184187        //-- write textures 
    185188 
    186         //int textureCount = 1; 
    187         int textureCount = 0; 
     189        int textureCount = 1; 
     190        //int textureCount = 0; 
    188191 
    189192        ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int)); 
     
    192195        { 
    193196                // hack 
    194                 const string texName("wood.jpg"); 
     197                const string texName("fischi_u1_v1.png"); 
     198                //const string texName("wood.jpg"); 
    195199 
    196200                int texnameSize = (int)texName.length() + 1; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3123 r3128  
    5757static ShaderProgram *sCgToneProgram = NULL; 
    5858static ShaderProgram *sCgDownSampleProgram = NULL; 
    59  
    60 ShaderContainer DeferredRenderer::sShaders; 
     59static ShaderProgram *sCgSmoothSsaoProgram = NULL; 
     60 
    6161 
    6262static GLuint noiseTex = 0; 
     63 
    6364 
    6465// ssao random spherical samples 
     
    322323        sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi"); 
    323324        sCgCombineSsaoProgram = sm->CreateFragmentProgram("combineSsao", "combine", "combineSsao"); 
    324         //sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao"); 
    325325        sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing"); 
    326326        sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap"); 
    327327        sCgDownSampleProgram = sm->CreateFragmentProgram("tonemap", "DownSample", "downSample"); 
    328328        sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum"); 
     329        sCgSmoothSsaoProgram = sm->CreateFragmentProgram("combineSsao", "smoothSsao", "smoothSsao"); 
    329330 
    330331 
     
    385386 
    386387        sCgLogLumProgram->AddParameter("colors", 0); 
    387          
     388 
     389        //////////////// 
     390 
     391        string smoothSsaoParams[] = {"normalsTex", "ssaoTex", "filterOffs", "filterWeights"}; 
     392        sCgSmoothSsaoProgram->AddParameters(smoothSsaoParams, 0, 4); 
    388393         
    389394         
     
    461466        case SSAO: 
    462467                ComputeSsao(fbo, tempCohFactor); 
     468                SmoothSsao(fbo); 
    463469                CombineSsao(fbo); 
    464470                break; 
     
    536542        sCgSsaoProgram->SetValue1f(i ++, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
    537543         
    538         if (mUseTemporalCoherence || mRegenerateSamples) 
     544        //if (mUseTemporalCoherence || mRegenerateSamples) 
     545        if (mRegenerateSamples) 
    539546        { 
    540547                mRegenerateSamples = false; 
     
    740747        GLuint colorsTex = fbo->GetColorBuffer(colorBufferIdx)->GetTexture(); 
    741748        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    742         GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
     749        GLuint ssaoTex = mIllumFbo->GetColorBuffer(2 - mIllumFboIndex)->GetTexture(); 
    743750 
    744751        // overwrite old color texture 
     
    10341041        glPushAttrib(GL_VIEWPORT_BIT); 
    10351042        glViewport(0, 0, mWidth, mHeight); 
    1036         // revert to old far plane 
     1043 
     1044        // revert to old far and near plane 
    10371045        mCamera->SetFar(oldFar); 
    10381046        mCamera->SetNear(oldNear); 
     
    10401048 
    10411049 
     1050void DeferredRenderer::SmoothSsao(FrameBufferObject *fbo) 
     1051{ 
     1052        mIllumFbo->Bind(); 
     1053 
     1054        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
     1055        GLuint ssaoTex = mIllumFbo->GetColorBuffer(mIllumFboIndex)->GetTexture(); 
     1056 
     1057        // overwrite old ssao texture 
     1058        glDrawBuffers(1, mrt + 2 - mIllumFboIndex); 
     1059 
     1060        glPushAttrib(GL_VIEWPORT_BIT); 
     1061        glViewport(0, 0, mIllumFbo->GetWidth(), mIllumFbo->GetHeight()); 
     1062 
     1063        int i = 0; 
     1064        sCgSmoothSsaoProgram->SetTexture(i ++, normalsTex); 
     1065        sCgSmoothSsaoProgram->SetTexture(i ++, ssaoTex); 
     1066 
     1067        sCgSmoothSsaoProgram->SetArray2f(i ++, (float *)ssaoFilterOffsets, NUM_SSAO_FILTERSAMPLES); 
     1068        sCgSmoothSsaoProgram->SetArray1f(i ++, (float *)ssaoFilterWeights, NUM_SSAO_FILTERSAMPLES); 
     1069         
     1070        DrawQuad(sCgSmoothSsaoProgram); 
     1071 
     1072        glPopAttrib(); 
     1073 
     1074        PrintGLerror("combine ssao"); 
     1075} 
     1076 
     1077 
    10421078} // namespace 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3111 r3128  
    8383        void CombineSsao(FrameBufferObject *fbo); 
    8484        void CombineIllum(FrameBufferObject *fbo); 
     85        void SmoothSsao(FrameBufferObject *fbo); 
    8586 
    8687        void AntiAliasing(FrameBufferObject *fbo, DirectionalLight *light); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3127 r3128  
    5252        CLEAR_CONTAINER(mTrafos); 
    5353        CLEAR_CONTAINER(mShapes); 
    54         //CLEAR_CONTAINER(mLODs); 
    5554} 
    5655 
     
    7170 
    7271        if (!hasTrafo) 
    73         { 
    74                 // identity 
    75                 trafo = new Transform3(); 
     72        {        
     73                trafo = new Transform3(); // identity 
    7674        } 
    7775        else 
     
    7977                Matrix4x4 m; 
    8078                str.read(reinterpret_cast<char *>(m.x), sizeof(Matrix4x4)); 
    81                  
    8279                trafo = new Transform3(m); 
    8380        } 
     
    290287        static ShaderProgram *sDefaultVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultVertexMrt"); 
    291288 
    292         static ShaderProgram *sNormalMappingVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingVertexMrt"); 
    293         static ShaderProgram *sNormalMappingFragmentProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingFragmentMrt"); 
     289        //static ShaderProgram *sNormalMappingVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingVertexMrt"); 
     290        //static ShaderProgram *sNormalMappingFragmentProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("normalMappingFragmentMrt"); 
     291 
    294292 
    295293        Technique *deferred = new Technique(*tech); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp

    r3126 r3128  
    8686        fragmentProgMrtTex = CreateFragmentProgram("mrt", "fragtex", "defaultFragmentTexMrt"); 
    8787 
     88 
    8889        // provide the current view matrix: 
    8990        // this is an automatic parameter that is updated each frame 
     
    9899        vertexProgMrt->AddParameter("oldModelMatrix", 2); 
    99100         
    100  
    101         // add a texture parameter 
    102         //fragmentProgMrtTex->AddParameter("tex", 1); 
    103101 
    104102 
     
    125123        treeAnimProgMrt->AddParameter("oldTimer", 5); 
    126124 
     125         
     126        //ShaderProgram *normalMappingVertexMrt, *normalMappingFragmentMrt; 
     127 
     128        //normalMappingVertexMrt = CreateFragmentProgram("normalMapping", "vtx", "normalMappingVertexMrt"); 
     129        //normalMappingFragmentMrt = CreateFragmentProgram("normalMapping", "frag", "normalMappingFragmentMrt"); 
     130 
     131 
    127132        cout << "cg initialization successful" << endl; 
    128133} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3127 r3128  
    471471        //-- load some dynamic stuff 
    472472 
    473         resourceManager->mUseNormalMapping = true; 
    474         //resourceManager->mUseNormalMapping = false; 
    475  
    476         LoadModel("fisch.dem", dynamicObjects); 
    477          
     473        //resourceManager->mUseNormalMapping = true; 
    478474        resourceManager->mUseNormalMapping = false; 
    479         //LoadModel("hbuddha.dem", dynamicObjects); 
     475 
     476        //LoadModel("fisch.dem", dynamicObjects); 
     477        LoadModel("hbuddha.dem", dynamicObjects); 
     478 
     479        resourceManager->mUseNormalMapping = false; 
     480 
    480481        buddha = dynamicObjects.back(); 
    481482         
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3123 r3128  
    66//-- ssao + gi parameters 
    77 
    8 //#define NUM_SAMPLES 8 
    9 #define NUM_SAMPLES 16 
     8#define NUM_SAMPLES 8 
     9//#define NUM_SAMPLES 16 
    1010 
    1111// for quadratic falloff 
    1212//#define SAMPLE_INTENSITY 0.1f 
    13 //#define SAMPLE_INTENSITY 0.07f 
    14 #define SAMPLE_INTENSITY 0.015f 
     13#define SAMPLE_INTENSITY 0.07f 
     14//#define SAMPLE_INTENSITY 0.015f 
    1515 
    1616#define SAMPLE_RADIUS 8e-1f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3126 r3128  
    6363                                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    6464                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    65                                                   float scale) 
     65                                                  float scale, 
     66                                                  int index) 
    6667{ 
    6768        float average = .0f; 
     
    8687 
    8788                //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
    88                  
    8989                depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
    9090                normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); 
     
    9393                //w = filterWeights[i] * depthFactor; 
    9494 
    95                 average += aoSample.x * w; 
     95                average += aoSample[index] * w; 
    9696                total_w += w; 
    9797        } 
     
    119119        if (col.w < 1e10f) 
    120120        { 
    121                 //const static float scaleFactor = 10.0f; 
    122                 const static float scaleFactor = 50.0f; 
     121                //const static float scaleFactor = 50.0f; 
     122                const static float scaleFactor = 10.0f; 
     123                const static float adaptFactor = 10.0f; 
    123124 
    124125                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights); 
    125126                //ao.x = Filter(IN.texCoord, ssaoTex, filterOffs, filterWeights, 1.0f / (1.0f + ao.y)); 
    126127                //ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor / (scaleFactor + ao.y)); 
    127                 ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, 1.0f); 
    128         } 
    129  
    130         OUT.illum_col = col * ao.x; 
     128                ao.x = DiscontinuityFilter(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, adaptFactor * scaleFactor * ao.z  / (adaptFactor + ao.y), 0); 
     129        } 
     130 
     131        OUT.illum_col.xyz = col.xyz * ao.x; 
    131132        //OUT.illum_col = float4(ao.x, ao.x, ao.x, col.w); 
    132133        //OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
     
    135136        return OUT; 
    136137} 
     138 
     139float DiscontinuityFilter2(float2 texCoord, 
     140                                                  float4 ao, 
     141                                                  uniform sampler2D ssaoTex, 
     142                                                  uniform sampler2D normalsTex, 
     143                                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     144                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     145                                                  float scale, 
     146                                                  int index) 
     147{ 
     148        float average = .0f; 
     149        float total_w = .0f; 
     150 
     151        const float eyeSpaceDepth = ao.w; 
     152        const float3 norm = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
     153 
     154        float4 aoSample; 
     155        float3 sampleNorm; 
     156        float w; 
     157        float4 offs; 
     158        float depthFactor; 
     159        float normalFactor; 
     160 
     161        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     162        { 
     163                offs = float4(texCoord + filterOffs[i] * scale, 0, 0); 
     164                aoSample = tex2Dlod(ssaoTex, offs); 
     165                 
     166                sampleNorm = normalize(tex2Dlod(normalsTex, offs).xyz); 
     167 
     168                //depthFactor = clamp(1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w), 1e-3f, 1.0f); 
     169                depthFactor = max(step(5e-2f, 1.0f - abs(1.0f - eyeSpaceDepth / aoSample.w)), 1e-3f); 
     170                normalFactor = max(step(0.5f, dot(sampleNorm, norm)), 1e-3f); 
     171 
     172                w = filterWeights[i] * normalFactor * depthFactor; 
     173                //w = filterWeights[i] * depthFactor; 
     174 
     175                average += aoSample.y * w; 
     176                total_w += w; 
     177        } 
     178 
     179        average *= 1.0f / max(total_w, 1e-6f); 
     180 
     181        return average; 
     182} 
     183 
     184pixel smoothSsao(fragment IN,  
     185                                 uniform sampler2D ssaoTex, 
     186                                 uniform sampler2D normalsTex, 
     187                                 uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     188                                 uniform float filterWeights[NUM_SSAO_FILTERSAMPLES] 
     189                          ) 
     190{ 
     191        pixel OUT; 
     192 
     193        float4 ao = tex2Dlod(ssaoTex, float4(IN.texCoord, 0, 0)); 
     194 
     195        //const static float scaleFactor = 10.0f; 
     196        const static float scaleFactor = 10.0f; 
     197 
     198        ao.y = DiscontinuityFilter2(IN.texCoord, ao, ssaoTex, normalsTex, filterOffs, filterWeights, scaleFactor * ao.z, 1); 
     199         
     200        OUT.illum_col = ao; 
     201 
     202        return OUT; 
     203} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3125 r3128  
    236236        //      newWeight = min(temporalCoherence + 1, max(oldPixel.y - 70, 50)); 
    237237        //if (newWeight >= 2000) newWeight = 1000; 
     238        //newWeight -= step(2000.0f, newWeight) * 1000.0f; 
    238239 
    239240        return float3(oldPixel.x, newWeight, eyeSpaceDepth); 
     
    380381 
    381382        const float oldSsao = temporalVals.x; 
    382         const float newWeight = temporalVals.y; 
    383  
    384         //float2 noiseOffs = float2(newWeight / 139.0f, newWeight / 141.0f); 
     383        const float newWeight = clamp(temporalVals.y, .0f, temporalCoherence); 
     384 
     385        //float2 noiseOffs = float2(temporalVals.y / 139.0f, temporalVals.y / 141.0f); 
    385386        float2 noiseOffs = float2(.0f); 
    386387 
     
    399400 
    400401        OUT.illum_col.x = (ao.x + oldSsao * (newWeight - 1.0f)) / newWeight; 
    401         OUT.illum_col.y = newWeight; 
     402        OUT.illum_col.y = temporalVals.y; 
    402403        OUT.illum_col.z = invw; 
    403404        OUT.illum_col.w = temporalVals.z; 
Note: See TracChangeset for help on using the changeset viewer.