Changeset 2990


Ignore:
Timestamp:
10/02/08 14:21:10 (16 years ago)
Author:
mattausch
Message:

recovering world pos from eye space depth => better gi performance

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

Legend:

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

    r2988 r2990  
    8989static CGparameter sBRParam; 
    9090static CGparameter sBLParam; 
     91 
     92 
     93static CGparameter sTLGiParam; 
     94static CGparameter sTRGiParam; 
     95static CGparameter sBRGiParam; 
     96static CGparameter sBLGiParam; 
     97 
     98static CGparameter sEyePosGiParam; 
     99 
     100 
    91101 
    92102//////////// 
     
    390400                 
    391401                sOldSsaoTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldSsaoTex");   
    392                 sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex");   
     402                sOldIllumTexGiParam = cgGetNamedParameter(sCgGiProgram, "oldIllumTex");  
     403 
     404                sTLGiParam = cgGetNamedParameter(sCgGiProgram, "tl");  
     405                sTRGiParam = cgGetNamedParameter(sCgGiProgram, "tr");  
     406                sBRGiParam = cgGetNamedParameter(sCgGiProgram, "br");  
     407                sBLGiParam = cgGetNamedParameter(sCgGiProgram, "bl");  
     408 
     409                sEyePosGiParam = cgGetNamedParameter(sCgGiProgram, "eyePos"); 
    393410        } 
    394411        else 
     
    477494                sNoiseTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "noiseTexture"); 
    478495                sSamplesShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "samples"); 
    479  
    480496                sLightDirShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "lightDir"); 
    481  
    482497                sOldColorsTexShadowParam = cgGetNamedParameter(sCgDeferredShadowProgram, "oldColors"); 
    483498 
     
    576591        else 
    577592                FirstPass(fbo, light); 
     593 
     594        glBindTexture(GL_TEXTURE_2D, fbo->GetColorBuffer(colorBufferIdx)->GetTexture()); 
     595        glGenerateMipmapEXT(GL_TEXTURE_2D); 
    578596 
    579597        switch (mShadingMethod) 
     
    921939        cgGLSetParameter1f(sMaxDepthGiParam, mScaleFactor); 
    922940 
     941 
    923942        cgGLSetParameter1f(sTemporalCoherenceGiParam, (mUseTemporalCoherence && !mRegenerateSamples) ? tempCohFactor : 0); 
    924943 
     
    943962        Vector3 tl, tr, bl, br; 
    944963        ComputeViewVectors(tl, tr, bl, br); 
     964         
     965        const Vector3 pos = mCamera->GetPosition() / mScaleFactor; 
     966        cgGLSetParameter3f(sEyePosGiParam, pos.x, pos.y, pos.z); 
     967 
     968        cgGLSetParameter3f(sBLGiParam, bl.x, bl.y, bl.z); 
     969        cgGLSetParameter3f(sBRGiParam, br.x, br.y, br.z); 
     970        cgGLSetParameter3f(sTLGiParam, tl.x, tl.y, tl.z); 
     971        cgGLSetParameter3f(sTRGiParam, tr.x, tr.y, tr.z); 
     972 
    945973 
    946974        glBegin(GL_QUADS); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2989 r2990  
    525525 
    526526 
    527         const float turbitiy = 9.0f; 
     527        const float turbitiy = 5.0f; 
    528528        preetham = new SkyPreetham(turbitiy, skyDome); 
    529529 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2988 r2990  
    8282         
    8383        OUT.color = col; 
    84  
    85         OUT.color.xyz = color.w; 
    8684         
    8785#if 1 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r2976 r2990  
    4444 
    4545 
     46float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
     47{ 
     48        //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); 
     49        float3 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x; 
     50        float3 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x; 
     51 
     52        float3 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y; 
     53 
     54        return v; 
     55} 
     56 
     57 
    4658/** Computes  diffuse reflections + ambient occlusion 
    4759*/ 
    4860GiStruct globIllum(fragment IN, 
    49                                  uniform sampler2D colors, 
    50                                  uniform sampler2D positions, 
    51                                  uniform sampler2D noiseTexture, 
    52                                  uniform float2 samples[NUM_SAMPLES], 
    53                                  uniform float3 currentNormal, 
    54                                  uniform float4 centerPosition, 
    55                                  float w 
    56                                  //, uniform float3 currentViewDir 
    57                                  ) 
     61                                   uniform sampler2D colors, 
     62                                   uniform sampler2D positions, 
     63                                   uniform sampler2D noiseTexture, 
     64                                   uniform float2 samples[NUM_SAMPLES], 
     65                                   uniform float3 currentNormal, 
     66                                   uniform float4 centerPosition, 
     67                                   float w, 
     68                                   // uniform float3 viewDir, 
     69                                   uniform float3 eyePos, 
     70                                   uniform float3 bl, 
     71                                   uniform float3 br, 
     72                                   uniform float3 tl, 
     73                                   uniform float3 tr 
     74                                   ) 
    5875{ 
    5976        GiStruct gi; 
     
    89106                        ++ numSamples; 
    90107 
     108                // reconstruct world space position from sample 
     109                float4 sample = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)); 
     110                const float eyeSpaceDepth = sample.w; 
     111                float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     112                 
     113                const float3 sample_position = eyePos - rotView * eyeSpaceDepth; 
     114                const float3 sample_color = sample.xyz; 
     115 
    91116                // use lower lod level to improve cache coherence 
    92                 float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
    93                 float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, GI_MIPMAP_LEVEL)).xyz; 
     117                //float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
     118                //float3 sample_color = tex2Dlod(colors, float4(texcoord, 0, GI_MIPMAP_LEVEL)).xyz; 
    94119 
    95120                float3 vector_to_sample = sample_position - centerPosition.xyz; 
     
    106131 
    107132                // if normal perpenticular to view dir, only half of the samples count 
    108                 /* 
     133#if 0 
    109134                const float view_correction = 1.0f + VIEW_CORRECTION_SCALE * (1.0f - dot(currentViewDir, currentNormal)); 
    110135                total_color.w -= cos_angle * distance_intensity * view_correction; 
    111136                total_color.xyz += cos_angle * distance_intensity * view_correction * sample_color * ILLUM_INTENSITY; 
    112                 */ 
     137#endif 
    113138                total_ao += cos_angle * distance_intensity; 
    114139                total_color += cos_angle * distance_intensity * sample_color * ILLUM_INTENSITY; 
     
    135160                   const uniform float4x4 oldModelViewProj, 
    136161                   uniform float maxDepth, 
    137                    uniform float temporalCoherence 
     162                   uniform float temporalCoherence, 
     163                   uniform float3 eyePos, 
     164                   uniform float3 bl, 
     165                   uniform float3 br, 
     166                   uniform float3 tl, 
     167                   uniform float3 tr 
    138168                   ) 
    139169{ 
     
    144174        // something like a constant ambient term 
    145175        const float amb = norm.w; 
     176         
    146177        /// the current view direction 
    147178        //float3 viewDir = normalize(IN.view); 
     
    156187        const float currentDepth = centerPosition.w; 
    157188 
    158         GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w); //, viewDir); 
     189        GiStruct gi = globIllum(IN, colors, positions, noiseTexture, samples, normal, centerPosition, w, eyePos, bl, br, tl, tr); 
    159190         
    160191 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r2989 r2990  
    2121 
    2222 
    23 float2 myreflect(float2 pt, float2 n) 
     23inline float2 myreflect(float2 pt, float2 n) 
    2424{ 
    2525        // distance to plane 
     
    3232 
    3333 
    34 float3 RotateY(float3 v, float a) 
    35 { 
    36         float3 r; 
    37  
    38         r.z = v.z * cos(a) - v.x * sin(a); 
    39         r.x = v.z * sin(a) + v.x * cos(a); 
    40         r.y = v.y; 
    41  
    42         return r; 
    43 } 
    44  
    45  
    46 float3 RotateX(float3 v, float a) 
    47 { 
    48         float3 r; 
    49  
    50         r.y = v.y * cos(a) - v.z * sin(a); 
    51         r.z = v.y * sin(a) + v.z * cos(a); 
    52         r.x = v.x; 
    53  
    54         return r; 
    55 } 
    56  
    57  
    58 float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
     34inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
    5935{ 
    6036        //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); 
     
    6844 
    6945 
    70 float2 Interpol2(float2 w, float2 bl, float2 br, float2 tl, float2 tr) 
    71 { 
    72         //float3 x1 = lerp(oldColor.w, logLumScaled, 0.1f); 
    73         float2 x1 = lerp(bl, tl, w.y); //bl * (1.0f - w.x) + br * w.x; 
    74         float2 x2 = lerp(br, tr, w.y); //tl * (1.0f - w.x) + tr * w.x; 
    75  
    76         float2 v = lerp(x1, x2, w.x); //x1 * (1.0f - w.y) + x2 * w.y; 
    77  
    78         return v; 
     46inline float3 ReconstructSamplePosition(uniform sampler2D colors, float2 texcoord, float3 bl, float3 br, float3 tl, float3 tr) 
     47{ 
     48        /*float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 
     49                 
     50        // reconstruct world space position 
     51        float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
     52        float3 sample_position = eyePos - rotView * eyeSpaceDepth; 
     53        */ 
     54        float3 sample_position = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
     55 
     56        return sample_position; 
    7957} 
    8058 
     
    8967                   uniform float4 centerPosition, 
    9068                   uniform float scaleFactor, 
    91                    uniform float3 viewDir, 
     69                   //uniform float3 viewDir, 
    9270                   uniform float3 eyePos, 
    9371                   uniform float3 bl, 
     
    124102                        ++ numSamples; 
    125103 
    126                 // sample downsampled texture in order to speed up texture accesses 
    127                 float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).w; 
    128                  
    129                 // reconstruct world space position 
    130                 float3 rotView = normalize(Interpol(texcoord, bl, br, tl, tr)); 
    131                 float3 sample_position = eyePos - rotView * eyeSpaceDepth; 
    132  
    133                 //float3 sample_position = tex2Dlod(positions, float4(texcoord, 0, SSAO_MIPMAP_LEVEL)).xyz; 
     104                float3 sample_position = ReconstructSamplePosition(colors, texcoord, bl, br, tl, tr); 
    134105 
    135106                float3 vector_to_sample = sample_position - centerPosition.xyz; 
     
    190161        // the current world position 
    191162        const float4 centerPosition = tex2D(positions, IN.texCoord.xy); 
     163         
     164        /* 
    192165        /// the current view direction 
    193166        float3 viewDir = normalize(IN.view); 
    194  
    195         /*const float eyeDepth = tex2D(colors, IN.texCoord.xy).w; 
     167        const float eyeDepth = tex2D(colors, IN.texCoord.xy).w; 
    196168        float4 centerPosition2; 
    197169        centerPosition2.xyz = eyePos - view2 * eyeDepth; 
     
    202174 
    203175        //const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, viewDir, eyePos); 
    204         const float2 ao = ssao(IN, colors, noiseTexture, samples, normal, centerPosition, w, viewDir, eyePos, bl, br, tl, tr); 
     176        const float2 ao = ssao(IN, positions, noiseTexture, samples, normal, centerPosition, w, /*viewDir, */eyePos, bl, br, tl, tr); 
    205177                 
    206178 
     
    271243        float4 ao = tex2D(ssaoTex, IN.texCoord.xy); 
    272244 
    273         //OUT.illum_col = col * ao.x; 
    274         OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w); 
     245        OUT.illum_col = col * ao.x; 
     246        //OUT.illum_col = float4(ao.x,ao.x,ao.x, ao.w); 
    275247        OUT.illum_col.w = col.w; 
    276248 
Note: See TracChangeset for help on using the changeset viewer.