Changeset 2835 for GTP


Ignore:
Timestamp:
07/14/08 17:20:08 (16 years ago)
Author:
mattausch
Message:

removed ambient occlusion bugs

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
2 edited

Legend:

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

    r2834 r2835  
    241241void InitFBO(); 
    242242 
    243 void GenerateSamples(); 
    244  
    245243void CreateNoiseTex2D(); 
    246244 
     
    273271static CGparameter sOldModelViewProjMatrixParam; 
    274272static CGparameter sMaxDepthParam; 
     273static CGparameter sMaxDepthParamSsao; 
    275274static CGparameter sMaxDepthParamTex; 
    276275 
     
    443442        // create noise texture for ssao 
    444443        CreateNoiseTex2D(); 
    445  
    446444        // init render traverser 
    447445        ResetTraverser(); 
     
    561559                sNoiseMultiplierParam = cgGetNamedParameter(sCgSsaoProgram, "noiseMultiplier"); 
    562560                sOldModelViewProjMatrixParam = cgGetNamedParameter(sCgSsaoProgram, "oldModelViewProj"); 
    563                  
    564                 cgGLDisableTextureParameter(sNoiseTexParamSsao); 
     561                sMaxDepthParamSsao = cgGetNamedParameter(sCgSsaoProgram, "maxDepth"); 
     562 
     563                cgGLSetParameter1f(sMaxDepthParamSsao, myfar / 10.0f); 
    565564 
    566565                sSamplesParamSsao = cgGetNamedParameter(sCgSsaoProgram, "samples"); 
    567566                sOldTexParamSsao = cgGetNamedParameter(sCgSsaoProgram, "oldTex");   
    568567 
    569                 GenerateSamples(); 
    570                 cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); 
     568                GenerateSamples(); cgGLSetParameterArray2f(sSamplesParamSsao, 0, NUM_SAMPLES, (const float *)samples); 
    571569        } 
    572570        else 
     
    649647        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer); 
    650648         
    651         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 
     649        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 
    652650        int samples = 8; 
    653651        //glEnable(GL_MULTISAMPLE_ARB); 
     
    658656        glBindTexture(GL_TEXTURE_2D, colorsTex); 
    659657 
    660         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
    661         glGenerateMipmapEXT(GL_TEXTURE_2D); 
     658        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
     659        //glGenerateMipmapEXT(GL_TEXTURE_2D); 
    662660        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex, 0); 
    663661 
    664662        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    665         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
     663        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    666664 
    667665        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
     
    744742        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer1); 
    745743         
    746         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 
     744        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 
    747745        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer1); 
    748746         
     
    750748        glBindTexture(GL_TEXTURE_2D, colorsTex1); 
    751749 
    752         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
    753         glGenerateMipmapEXT(GL_TEXTURE_2D); 
     750        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
     751        //glGenerateMipmapEXT(GL_TEXTURE_2D); 
    754752        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex1, 0); 
    755753 
    756         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    757         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
     754        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     755        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
    758756 
    759757        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    760758        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
    761759 
     760        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     761        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
     762 
    762763        PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 
    763764 
     
    776777        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorsBuffer2); 
    777778         
    778         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA16F_ARB, texWidth, texHeight); 
     779        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 
    779780        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorsBuffer2); 
    780781         
     
    782783        glBindTexture(GL_TEXTURE_2D, colorsTex2); 
    783784 
    784         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
    785         glGenerateMipmapEXT(GL_TEXTURE_2D); 
     785        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
     786        //glGenerateMipmapEXT(GL_TEXTURE_2D); 
    786787        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorsTex2, 0); 
    787788 
     789        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     790        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
     791 
     792        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     793        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    788794        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    789         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
     795        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    790796 
    791797        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
     
    23192325        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    23202326 
    2321         //glTexImage2D(GL_RGBA, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, randomNormals); 
    2322         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texWidth, texHeight, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
     2327        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
     2328        //gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texWidth, texHeight, GL_RGB, GL_UNSIGNED_BYTE, randomNormals); 
    23232329 
    23242330        glBindTexture(GL_TEXTURE_2D, 0); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2834 r2835  
    77//#define SAMPLE_INTENSITY 0.125f 
    88// rule of thumb: approx 1 / NUM_SAMPLES 
    9 #define SAMPLE_INTENSITY 0.2 //0.0625f 
     9#define SAMPLE_INTENSITY 0.16 //0.0625f 
    1010 
    1111#define AREA_SIZE 5e-1f 
     
    7676 
    7777                //sample noisetex; r stores costheta, g stores sintheta 
    78                 float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
     78                float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
    7979 
    8080                // rotation 
    8181                //float2 offsetTransformed = offset; 
    82                 float2 offsetTransformed = rotate(offset, noise); 
     82                float2 offsetTransformed = rotate(offset, mynoise); 
    8383                //float2 offsetTransformed = reflect(offset, noise); 
    8484 
     
    9595                float cos_angle = dot(direction_to_sample, currentNormal); 
    9696                cos_angle = max(cos_angle, 0.0f); 
    97                 // take quadratic influence to sharpen contrast 
    98                 //cos_angle *= cos_angle; 
    9997 
    10098                // distance between current position and sample position controls AO intensity. 
    101                 //const float maxdist = 2e-1f; 
    102                 //const float maxdist = 5e-1f; 
    10399                const float distanceScale = 1e-6f; 
    104100 
     
    107103 
    108104                // if normal perpenticular to view dir, only half of the samples count 
    109                 float view_correction = (2.0f - dot(currentViewDir, currentNormal)); 
    110                 view_correction *= view_correction; 
     105                float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal)); 
    111106 
    112107                total_ao += cos_angle * distance_intensity * view_correction; 
     
    144139 
    145140                //sample noisetex; r stores costheta, g stores sintheta 
    146                 float2 noise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
     141                float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy * noiseMultiplier).xy * 2.0f - 1.0f; 
    147142 
    148143                // rotation 
    149                 float2 offsetTransformed = rotate(offset, noise); 
     144                float2 offsetTransformed = rotate(offset, mynoise); 
    150145 
    151146                // weight with projected coordinate to reach similar kernel size for near and far 
     
    171166                // if normal perpenticular to view dir, only half of the samples count 
    172167                float view_correction = 1.0f + 0.5f * (1.0f - dot(currentViewDir, currentNormal)); 
    173                 //view_correction *= view_correction; 
    174168 
    175169                total_ao += cos_angle * distance_intensity * view_correction; 
     
    218212                                uniform float noiseMultiplier, 
    219213                                uniform sampler2D oldTex, 
    220                                 const uniform float4x4 oldModelViewProj 
     214                                const uniform float4x4 oldModelViewProj, 
     215                                uniform float maxDepth 
    221216                                ) 
    222217{ 
     
    236231 
    237232        //float ao = ssao(IN, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
    238         float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition); 
     233        float4 new_col = globIllum(IN, colors, positions, noiseTexture, samples, normal.xyz, viewDir, noiseMultiplier, centerPosition);  
    239234        float ao = new_col.w; 
    240235 
     
    244239        //OUT.color = ao; 
    245240        //OUT.color = ao * col;  
    246         float4 dummy = centerPosition / 0.000487676f; 
     241        float4 dummy = centerPosition * maxDepth; 
    247242        dummy.w = 1.0f; 
    248243        float4 oldPos = mul(oldModelViewProj, dummy); 
     
    250245        float newDepth = oldPos.z / oldPos.w; 
    251246  
    252         const float x = 0.05f; 
     247        const float x = 0.1f; 
    253248 
    254249        float2 tex = (oldPos.xy / oldPos.w) * 0.5f + 0.5f; 
     
    257252        float oldDepth = col1.w; 
    258253 
    259         if ((tex.x >= 0) && (tex.x <= 1) && (tex.y >= 0) && (tex.y <= 1) && (abs(newDepth - oldDepth) < 5e-4f)) 
     254        if ((tex.x >= 0.0f) && (tex.x < 1.0f) && (tex.y >= 0.0f) && (tex.y < 1.0f) && (abs(newDepth - oldDepth) < 9e-4f)) 
    260255                OUT.color = attenuated_color * x + col1 * float4(1.0f - x); 
    261         else            OUT.color = attenuated_color;// * x + col1 * float4(1.0f - x); 
     256        else 
     257                OUT.color = attenuated_color; 
    262258 
    263259        //OUT.color = float4(centerPosition.w); 
     
    292288        float4 col1 = tex2D(oldTex, IN.texCoord.xy); 
    293289 
    294         const float x = 0.1f; 
     290        const float x = 0.01f; 
    295291        OUT.color = col * x + col1 * float4(1.0f - x); 
    296292 
Note: See TracChangeset for help on using the changeset viewer.