Changeset 3084


Ignore:
Timestamp:
10/31/08 15:08:25 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
5 edited

Legend:

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

    r3081 r3084  
    237237mIllumFboIndex(0) 
    238238{ 
    239         // create noise texture for ssao 
    240         CreateNoiseTex2D(w, h); 
    241  
    242  
    243239        /////////// 
    244240        //-- the flip-flop fbos 
     
    258254 
    259255        mFBOs.push_back(mDownSampleFbo); 
     256 
     257        // create noise texture for ssao 
     258        CreateNoiseTex2D(mDownSampleFbo->GetWidth(), mDownSampleFbo->GetHeight()); 
    260259 
    261260        InitCg(); 
     
    298297        sCgSsaoProgram->AddParameter("normals", i ++); 
    299298        sCgSsaoProgram->AddParameter("oldTex", i ++); 
    300         sCgSsaoProgram->AddParameter("noise", i ++); 
     299        sCgSsaoProgram->AddParameter("noiseTex", i ++); 
    301300        sCgSsaoProgram->AddParameter("eyePos", i ++); 
    302301        sCgSsaoProgram->AddParameter("temporalCoherence", i ++); 
     
    312311        sCgGiProgram->AddParameter("colors", i ++); 
    313312        sCgGiProgram->AddParameter("normals", i ++); 
    314         sCgGiProgram->AddParameter("noise", i ++); 
     313        sCgGiProgram->AddParameter("noiseTex", i ++); 
    315314        sCgGiProgram->AddParameter("oldSsaoTex", i ++); 
    316315        sCgGiProgram->AddParameter("oldIllumTex", i ++); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3083 r3084  
    4242#define MAX_LOD_LEVEL 10 
    4343 
    44 #define MIN_DEPTH_DIFF 1e-5f 
     44#define MIN_DEPTH_DIFF 1e-6f 
     45#define PRECISION_SCALE 1e-3f 
     46 
    4547// burnout 
    4648#define WHITE_LUMINANCE 3e4f 
     
    5355#define NUM_SSAO_FILTERSAMPLES 100 
    5456 
    55 #define PRECISION_SCALE 1e-3f 
    5657 
    5758 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/globillum.cg

    r3034 r3084  
    8989#if 1 
    9090                //////////////////// 
    91                 // add random noise: reflect around random normal vector (warning: slow!) 
     91                // add random noiseTex: reflect around random normal vector (warning: slow!) 
    9292                float2 mynoise = tex2D(noiseTexture, IN.texCoord.xy).xy; 
    9393                float2 offsetTransformed = myreflect(offset, mynoise); 
     
    151151                   uniform sampler2D colors, 
    152152                   uniform sampler2D normals, 
    153                    uniform sampler2D noise, 
     153                   uniform sampler2D noiseTex, 
    154154                   uniform float2 samples[NUM_SAMPLES], 
    155155                   uniform sampler2D oldSsaoTex, 
     
    187187        currentPos /= currentPos.w; 
    188188         
    189         const float currentDepth = currentPos.z * 1e-3f; 
     189        const float currentDepth = currentPos.z * PRECISION_SCALE; 
    190190 
    191191        /////////// 
    192192        //-- compute color bleeding + ao 
    193193 
    194         GiStruct gi = globIllum(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view)); 
     194        GiStruct gi = globIllum(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(IN.view)); 
    195195         
    196196 
     
    204204 
    205205        // the current depth projected into the old frame 
    206         const float projDepth = projPos.z * 1e-3f; 
     206        const float projDepth = projPos.z * PRECISION_SCALE; 
    207207 
    208208        // fit from unit cube into 0 .. 1 
     
    223223        //const float oldNumSamples = oldSsao.y; 
    224224         
    225         if (//(temporalCoherence > 0.0f) && 
     225        if ((temporalCoherence > 1e-6f) && 
    226226                (tex.x >= 0.0f) && (tex.x < 1.0f) &&  
    227227                (tex.y >= 0.0f) && (tex.y < 1.0f) &&  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3046 r3084  
    6161} 
    6262 
     63#pragma position_invariant fragtex 
    6364 
    6465pixel fragtex(fragin IN,  
     
    9091 
    9192 
     93#pragma position_invariant frag 
     94 
    9295pixel frag(fragin IN, uniform float4x4 viewMatrix) 
    9396{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg

    r3083 r3084  
    5454                                                                   float3 bl, float3 br, float3 tl, float3 tr) 
    5555{ 
    56         texcoord.x += 1.0f / 1024.0f; texcoord.y += 1.0f / 768.0f; 
    57  
    58         //const float eyeSpaceDepth = tex2Dlod(colors, float4(texcoord, 0, 0)).w; 
    5956        const float eyeSpaceDepth = tex2D(colors, texcoord).w; 
    6057        float3 viewVec = Interpol(texcoord, bl, br, tl, tr); 
     
    7774                                                 uniform float2 samples[NUM_SAMPLES], 
    7875                                                 uniform sampler2D colors, 
    79                                                  uniform sampler2D noiseTexture, 
     76                                                 uniform sampler2D noiseTex, 
    8077                                                 uniform float scaleFactor, 
    8178                                                 uniform float3 bl, 
     
    8380                                                 uniform float3 tl, 
    8481                                                 uniform float3 tr,  
    85                                                  float2 texcoord0 
     82                                                 float2 texcoord0, 
     83                                                 float3 eyePos 
    8684                                                 ) 
    8785{ 
     
    9290 
    9391        // reproject into old frame and calculate projected depth 
    94         float4 backProjPos = mul(oldModelViewProj, worldPos); 
     92        const float3 dummyPos = ReconstructSamplePos(colors, texcoord0, bl, br, tl, tr) + eyePos; 
     93        float4 backProjPos = mul(oldModelViewProj, float4(dummyPos, 1.0f)); 
     94        //float4 backProjPos = mul(oldModelViewProj, worldPos); 
     95         
    9596        backProjPos /= backProjPos.w; 
    9697         
     
    106107 
    107108        //const float oldNumSamples = oldCol.y; 
    108         const float oldWeight = clamp(oldCol.y, 0, temporalCoherence); 
     109        const float oldWeight = clamp(oldCol.y, .0f, temporalCoherence); 
    109110        float newWeight; 
    110111 
     
    115116                const float2 offset = samples[i]; 
    116117 
    117                 //////////////////// 
    118                 // add random noise: reflect around random normal vector (warning: slow!) 
    119  
    120                 float2 mynoise = tex2D(noiseTexture, texcoord0).xy; 
     118                float2 mynoise = tex2D(noiseTex, texcoord0).xy; 
    121119                const float2 offsetTransformed = myreflect(offset, mynoise); 
    122120 
    123                 const float2 texCoord = texcoord0 + offsetTransformed * scaleFactor; 
    124                 const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr); 
     121                const float2 texCoord = texcoord0;// + offsetTransformed * scaleFactor; 
     122                const float3 samplePos = ReconstructSamplePos(colors, texCoord, bl, br, tl, tr) + eyePos; 
    125123 
    126124                // reproject into old frame and calculate projected depth 
     
    136134 
    137135                if (abs(dDiff) > 1e-5f) isValid = false; 
    138                 //if (oldSample.y < oldWeight) isValid = false; 
    139136        } 
    140137 
     
    142139        //const float newNumSamples = ao.y; 
    143140 
    144         if ((temporalCoherence > 0) 
     141        if ((temporalCoherence > 1e-6f) 
    145142                && (tex.x >= 0.0f) && (tex.x < 1.0f) 
    146143                && (tex.y >= 0.0f) && (tex.y < 1.0f) 
    147                 //&& (abs(depthDif) < MIN_DEPTH_DIFF)  
     144                && (abs(depthDif) <= MIN_DEPTH_DIFF)  
    148145                // if visibility changed in the surrounding area we have to recompute 
    149146                //&& (oldNumSamples > 0.8f * newNumSamples) 
     
    161158                newWeight = .0f; 
    162159        } 
    163  
     160         
     161        //isValid = 0.0f; 
     162        //illum_col.y = isValid / 16.0f; 
    164163        illum_col.y = newWeight; 
    165164        illum_col.z = currentDepth; 
     
    173172float2 ssao(fragment IN, 
    174173                        uniform sampler2D colors, 
    175                         uniform sampler2D noiseTexture, 
     174                        uniform sampler2D noiseTex, 
    176175                        uniform float2 samples[NUM_SAMPLES], 
    177176                        uniform float3 currentNormal, 
     
    189188        // Summing up these angles gives an estimation of the occlusion at the current position. 
    190189 
    191         float total_ao = 0.0; 
    192         float numSamples = 0; 
     190        float total_ao = .0f; 
     191        float numSamples = .0f; 
    193192 
    194193 
     
    199198#if 1 
    200199                //////////////////// 
    201                 // add random noise: reflect around random normal vector (warning: slow!) 
    202  
    203                 float2 mynoise = tex2D(noiseTexture, IN.texCoord).xy; 
     200                //-- add random noise: reflect around random normal vector (rather slow!) 
     201 
     202                float2 mynoise = tex2D(noiseTex, IN.texCoord).xy; 
    204203                const float2 offsetTransformed = myreflect(offset, mynoise); 
    205204#else 
     
    250249                   uniform sampler2D colors, 
    251250                   uniform sampler2D normals, 
    252                    uniform sampler2D noise, 
     251                   uniform sampler2D noiseTex, 
    253252                   uniform float2 samples[NUM_SAMPLES], 
    254253                   uniform sampler2D oldTex, 
     
    280279        float4 projPos = mul(modelViewProj, worldPos); 
    281280         
    282         const float w = SAMPLE_RADIUS / projPos.w; 
    283         projPos /= projPos.w; 
     281        float w = 1.0f / projPos.w; 
     282        projPos *= w; 
     283        w *= SAMPLE_RADIUS; 
    284284         
    285285        const float currentDepth = projPos.z * PRECISION_SCALE; 
    286286 
    287         const float2 ao = ssao(IN, colors, noise, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 
     287        const float2 ao = ssao(IN, colors, noiseTex, samples, normal, eyeSpacePos, w, bl, br, tl, tr, normalize(viewDir)); 
    288288 
    289289 
     
    292292         
    293293        OUT.illum_col = temporalSmoothing(projPos, worldPos, currentDepth, oldTex, oldModelViewProj, temporalCoherence, ao, 
    294                                               samples, colors, noise, w, bl, br, tl, tr, IN.texCoord); 
     294                                              samples, colors, noiseTex, w, bl, br, tl, tr, IN.texCoord, eyePos); 
    295295 
    296296        return OUT; 
     
    336336        //OUT.illum_col = col * ao.x; 
    337337        OUT.illum_col.xyz = float3(1.0f - ao.x, 1.0f - ao.y * 1e-2f, 1); 
     338        //OUT.illum_col.xyz = float3(1.0f - ao.x, ao.y, 0); 
    338339        OUT.illum_col.w = col.w; 
    339340 
Note: See TracChangeset for help on using the changeset viewer.