Changeset 3163


Ignore:
Timestamp:
11/25/08 13:28:05 (16 years ago)
Author:
mattausch
Message:

getting better results using the position for the filter

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r3126 r3163  
    752752                        </File> 
    753753                        <File 
     754                                RelativePath=".\src\shaders\common.h" 
     755                                > 
     756                        </File> 
     757                        <File 
    754758                                RelativePath=".\src\shaders\deferred.cg" 
    755759                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3162 r3163  
    414414        string combineSsaoParams[] =  
    415415                {"colorsTex", "normalsTex", "ssaoTex", "filterOffs",  
    416                  "filterWeights", "modelViewProj"}; 
    417         sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 6); 
     416                 "filterWeights", "modelViewProj", "bl", "br", "tl", "tr"}; 
     417        sCgCombineSsaoProgram->AddParameters(combineSsaoParams, 0, 10); 
    418418 
    419419        ////////////// 
     
    826826        sCgCombineSsaoProgram->SetMatrix(i++, mProjViewMatrix); 
    827827 
     828        for (int j = 0; j < 4; ++ j, ++ i) 
     829                sCgCombineSsaoProgram->SetValue3f(i, mCornersView[j].x, mCornersView[j].y, mCornersView[j].z); 
    828830 
    829831        DrawQuad(sCgCombineSsaoProgram); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg

    r3162 r3163  
    11#include "../shaderenv.h" 
    2  
    3  
    4 /******************************************/ 
    5 /* Filter for combining ssao with image   */ 
    6 /******************************************/ 
     2#include "common.h" 
     3 
     4 
     5/*************************************************/ 
     6/*     Filter for combining ssao with image      */ 
     7/*************************************************/ 
    78 
    89 
     
    2122 
    2223/** Filter taking into account depth and normal differences,  
    23    and convergence of a sample   
     24    and convergence of a sample   
    2425*/ 
    2526float DiscontinuityFilter(float2 texCoord, 
     
    3132                                                  uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    3233                                                  uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    33                                                   float scale) 
     34                                                  float scale 
     35                                                  ) 
    3436{ 
    3537        float average = .0f; 
     
    8486 
    8587 
     88 
     89/** Filter taking into account depth and normal differences,  
     90   and convergence of a sample   
     91*/ 
     92float DiscontinuityFilter2(float2 texCoord, 
     93                                                   float4 ao, 
     94                                                   float4 color, 
     95                                                   uniform sampler2D ssaoTex, 
     96                                                   uniform sampler2D normalsTex, 
     97                                                   uniform sampler2D colorsTex, 
     98                                                   uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
     99                                                   uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
     100                                                   float scale, 
     101                                                   float3 bl, 
     102                                                   float3 br, 
     103                                                   float3 tl, 
     104                                                   float3 tr) 
     105{ 
     106        float average = .0f; 
     107        float total_w = .0f; 
     108 
     109        const float3 centerPos = ReconstructSamplePos(ssaoTex, texCoord, bl, br, tl, tr); 
     110        const float3 centerNormal = normalize(tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz); 
     111        //const float3 centerNormal = tex2Dlod(normalsTex, float4(texCoord, 0, 0)).xyz; 
     112 
     113        float4 aoSample; 
     114        float3 sampleNorm; 
     115        float3 samplePos; 
     116        float w; 
     117        float4 sampleTexCoord; 
     118        float spatialFactor; 
     119        float normalFactor; 
     120        float convergenceFactor; 
     121        float sampleDepth; 
     122 
     123        for (int i = 0; i < NUM_SSAO_FILTERSAMPLES; ++ i) 
     124        { 
     125                sampleTexCoord = float4(texCoord + filterOffs[i] * scale, 0, 0); 
     126 
     127                aoSample = tex2Dlod(ssaoTex, sampleTexCoord); 
     128                sampleNorm = normalize(tex2Dlod(normalsTex, sampleTexCoord).xyz); 
     129                //sampleNorm = tex2Dlod(normalsTex, sampleTexCoord).xyz; 
     130 
     131                // check spatial discontinuity 
     132                samplePos = ReconstructSamplePos(ssaoTex, sampleTexCoord.xy, bl, br, tl, tr); 
     133                float len = SqrLen(centerPos - samplePos); 
     134 
     135                spatialFactor = 1.0f / max(len, 1e-3f); 
     136 
     137                //normalFactor = max(step(0.6f, dot(sampleNorm, centerNormal)), 1e-3f); 
     138                normalFactor = max(dot(sampleNorm, samplePos), 1e-3f); 
     139                convergenceFactor = min(100.0f, aoSample.y); 
     140                //convergenceFactor = aoSample.y; 
     141 
     142                // combine the weights 
     143                w = convergenceFactor * spatialFactor * normalFactor; 
     144 
     145                average += aoSample.x * w; 
     146                total_w += w; 
     147        } 
     148 
     149        average /= max(total_w, 1e-6f); 
     150 
     151        return saturate(average); 
     152} 
     153 
     154 
    86155/** Function combining image and indirect illumination buffer using a  
    87156        depth and normal aware discontinuity filter. 
     
    93162                          uniform float2 filterOffs[NUM_SSAO_FILTERSAMPLES], 
    94163                          uniform float filterWeights[NUM_SSAO_FILTERSAMPLES], 
    95                           uniform float4x4 modelViewProj 
     164                          uniform float4x4 modelViewProj, 
     165                          uniform float3 bl, 
     166                          uniform float3 br, 
     167                          uniform float3 tl, 
     168                          uniform float3 tr 
    96169                          ) 
    97170{ 
     
    122195        //if (col.w < 1e10f) 
    123196        { 
    124                 ao.x = DiscontinuityFilter(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, convergenceScale * distanceScale); 
     197                ao.x = DiscontinuityFilter2(IN.texCoord, ao, col, ssaoTex, normalsTex, colorsTex, filterOffs, filterWeights, convergenceScale * distanceScale, bl, br, tl, tr); 
    125198        } 
    126199 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/normalMapping.cg

    r3154 r3163  
    9696/******************************************************************/ 
    9797 
     98 
    9899pixel frag(fragin IN, 
    99100                   uniform float4x4 viewMatrix, 
Note: See TracChangeset for help on using the changeset viewer.