Changeset 3136


Ignore:
Timestamp:
11/18/08 16:24:29 (16 years ago)
Author:
mattausch
Message:

fixed antialiasing, but ssao not working at that point (depth)

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

Legend:

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

    r3135 r3136  
    420420        /////////////////// 
    421421 
    422         string aaParams[] = {"colors", "normals"}; 
    423         sCgAntiAliasingProgram->AddParameters(aaParams, 0, 2); 
     422        string aaParams[] = {"colors", "normals", "offsets"}; 
     423        sCgAntiAliasingProgram->AddParameters(aaParams, 0, 3); 
    424424 
    425425        ///////////////////// 
     
    658658        ColorBufferObject *colorBuffer = fbo->GetColorBuffer(colorBufferIdx); 
    659659        GLuint colorsTex = colorBuffer->GetTexture(); 
    660         GLuint normalsTex = fbo->GetColorBuffer(2)->GetTexture(); 
     660        GLuint normalsTex = fbo->GetColorBuffer(1)->GetTexture(); 
    661661 
    662662        //FrameBufferObject::Release(); 
     
    664664        // read the second buffer, write to the first buffer 
    665665        FlipFbos(fbo); 
    666          
     666 
     667        // the neighbouring texels 
     668        float xOffs = 1.0f / fbo->GetWidth(); 
     669        float yOffs = 1.0f / fbo->GetHeight(); 
    667670 
    668671        sCgAntiAliasingProgram->SetTexture(0, colorsTex); 
    669672        sCgAntiAliasingProgram->SetTexture(1, normalsTex); 
    670673 
    671         sCgAntiAliasingProgram->Bind(); 
    672  
    673         glBegin(GL_QUADS); 
    674  
    675         // the neighbouring texels 
    676         float x_offs = 1.0f / mWidth; 
    677         float y_offs = 1.0f / mHeight; 
    678  
    679         SetVertex(0, 0, x_offs, y_offs); 
    680         SetVertex(1, 0, x_offs, y_offs); 
    681         SetVertex(1, 1, x_offs, y_offs); 
    682         SetVertex(0, 1, x_offs, y_offs); 
    683  
    684         glEnd(); 
     674        float offsets[16]; 
     675        int i = 0; 
     676 
     677        offsets[i] = -xOffs; offsets[i + 1] =  yOffs; i += 2; // left top 
     678        offsets[i] =  xOffs; offsets[i + 1] = -yOffs; i += 2; // right bottom 
     679        offsets[i] =  xOffs; offsets[i + 1] =  yOffs; i += 2; // right top 
     680        offsets[i] = -xOffs; offsets[i + 1] = -yOffs; i += 2; // left bottom 
     681        offsets[i] = -xOffs; offsets[i + 1] =    .0f; i += 2; // left 
     682        offsets[i] =  xOffs; offsets[i + 1] =    .0f; i += 2; // right 
     683        offsets[i] =    .0f; offsets[i + 1] =  yOffs; i += 2; // top 
     684        offsets[i] =    .0f; offsets[i + 1] = -yOffs; i += 2; // bottom 
     685 
     686        sCgAntiAliasingProgram->SetArray2f(2, offsets, 8); 
     687 
     688        DrawQuad(sCgAntiAliasingProgram); 
    685689 
    686690        PrintGLerror("antialiasing"); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/antialiasing.cg

    r3096 r3136  
    33struct fragment 
    44{ 
    5         float2 c:  TEXCOORD0; // center 
    6         float2 lt: TEXCOORD1; // left top 
    7         float2 rb: TEXCOORD2; // right bottom 
    8         float2 rt: TEXCOORD3; // right top 
    9         float2 lb: TEXCOORD4; // left bottom 
    10         float4 lr: TEXCOORD5; // left / right 
    11         float4 tb: TEXCOORD6; // top / bottom 
     5        float2 texCoords:  TEXCOORD0;  
    126}; 
    137 
    148// the barrier for detecting a discontinuity (x = normal, y = depth) 
    15 uniform float4 e_barrier = float4(5e-5, 5e-5, 0, 0);  
     9//const uniform float4 barrier = float4(5e-5f, 5e-5f, 0, 0);  
     10const uniform float4 barrier = float4(0.6f, 9e-2f, 0, 0);  
    1611// the weights for normal / depth discontinuity (x = normal, y = depth) 
    17 uniform float4 e_weights = float4(0.5f, 0.5f, 1.0f, 1.0f);  
    18 //uniform float4 e_weights = float4(1.0f, 1.0f, 1.0f, 1.0f); 
    19 uniform float4 e_kernel = float4(0.5f, 1.0f, 1.0f, 1.0f);  
     12const uniform float4 weights = float4(0.5f, 0.5f, 1.0f, 1.0f);  
     13//uniform float4 weights = float4(1.0f, 1.0f, 1.0f, 1.0f); 
     14// the maximal size of the filter kernel 
     15const uniform float kernel = 0.5f;  
    2016 
    2117 
     
    2319float4 main(fragment IN,  
    2420                        uniform sampler2D colors, 
    25                         uniform sampler2D normals 
    26                         ): COLOR 
     21                        uniform sampler2D normals, 
     22                        uniform float2 offsets[8]): COLOR 
    2723{ 
    28         //return tex2D(colors, IN.c.xy); 
     24        // center normal 
     25        const float3 centerNormal = normalize(tex2Dlod(normals, float4(IN.texCoords, 0, 0)).xyz); 
     26        // center color 
     27        const float4 centerColor = tex2Dlod(colors, float4(IN.texCoords, 0, 0)); 
     28        // center depth 
     29        const float4 centerDepth = float4(centerColor.w); 
     30         
     31        const float2 lt = IN.texCoords + offsets[0]; 
     32        const float2 rb = IN.texCoords + offsets[1]; 
     33        const float2 rt = IN.texCoords + offsets[2]; 
     34        const float2 lb = IN.texCoords + offsets[3]; 
    2935 
    30         // normal discontinuity filter 
    31         float3 nc = (float3)tex2D(normals, IN.c.xy); 
     36        // compute normal discontinuities 
     37        float4 nd; 
    3238 
    33         float4 nd; 
    34         nd.x = dot(nc, float3(tex2D(normals, IN.lt.xy))); 
    35         nd.y = dot(nc, float3(tex2D(normals, IN.rb.xy))); 
    36         nd.z = dot(nc, float3(tex2D(normals, IN.rt.xy))); 
    37         nd.w = dot(nc, float3(tex2D(normals, IN.lb.xy))); 
     39        nd.x = dot(centerNormal, normalize(tex2Dlod(normals, float4(lt, 0, 0)).xyz)); 
     40        nd.y = dot(centerNormal, normalize(tex2Dlod(normals, float4(rb, 0, 0)).xyz)); 
     41        nd.z = dot(centerNormal, normalize(tex2Dlod(normals, float4(rt, 0, 0)).xyz)); 
     42        nd.w = dot(centerNormal, normalize(tex2Dlod(normals, float4(lb, 0, 0)).xyz)); 
    3843 
    39         nd -= e_barrier.x; 
    40         nd = step((float4)0.0f, nd); 
     44        nd -= float4(barrier.x); 
     45        nd = step(float4(0.0f), nd); 
    4146 
    42         float ne = saturate(dot(nd, e_weights.x)); 
     47        // weight the influence of normal discontinuities 
     48        //const float ne = saturate(dot(nd, weights.x)); 
     49        const float ne = nd.x * nd.y *nd.z * nd.w * weights.x; 
    4350 
    44         // construct opposite coordinates 
    45         float4 lrr = IN.lr.wzyx; 
    46         float4 tbr = IN.tb.wzyx; 
    47  
    48         // depth filter: compute gradient difference: 
     51#if 1 
     52        //////////// 
     53        // depth filter => compute gradient difference 
    4954        // (c - sample) + (c - opposite sample) 
    5055 
    51         float4 dc = float4(tex2D(colors, IN.c).w); 
     56        float depthVals[8]; 
    5257 
    53         float pos_lt = (float)tex2D(colors, IN.lt.xy).w; 
    54         float pos_rb = (float)tex2D(colors, IN.rb.xy).w; 
     58        for (int i = 0; i < 8; ++ i) 
     59        {        
     60                depthVals[i] = (float)tex2Dlod(colors, float4(IN.texCoords + offsets[i], 0, 0)).w; 
     61        } 
    5562 
    56         float pos_lb = (float)tex2D(colors, IN.lb.xy).w; 
    57         float pos_rt = (float)tex2D(colors, IN.rt.xy).w; 
     63        float4 dd; // the gradients 
    5864 
    59         float pos_l = (float)tex2D(colors, IN.lr.xy).w; 
    60         float pos_r = (float)tex2D(colors, lrr.xy).w; 
     65        for (int i = 0; i < 4; ++ i) 
     66        { 
     67                dd = float4(depthVals[i * 2] + depthVals[i * 2 + 1]); 
     68        } 
    6169 
    62         float pos_t = (float)tex2D(colors, IN.tb.xy).w; 
    63         float pos_b = (float)tex2D(colors, tbr.xy).w; 
     70        //dd = abs(2.0f * (1.0f - abs(1.0f - centerDepth / dd))) - barrier.y; 
     71        dd = abs(2.0f * centerDepth - dd) - barrier.y; 
     72        dd = step(dd, float4(0.0f)); 
    6473 
    65         float4 dd; 
     74        const float de = saturate(dot(dd, weights.y)); 
    6675 
    67         dd.x = pos_lt + pos_rb; 
    68         dd.y = pos_lb + pos_rt; 
    69         dd.z = pos_l + pos_r; 
    70         dd.w = pos_t + pos_b; 
    7176 
    72         dd = abs(2.0f * dc - dd) - e_barrier.y; 
    73         dd = step(dd, (float4)0.0f); 
     77        /////////////////////////// 
    7478 
    75         float de = saturate(dot(dd, e_weights.y)); 
     79        // weight: 0 = no antialiasing, 1 = full antialiasing 
     80        const float w = (1.0f - de * ne) * kernel.x; 
    7681 
    77         // weight: 0 = no aa, 1 = full antialiasing 
    78         float w = (1.0f - de * ne) * e_kernel.x; 
     82        // smoothed color: the offset is big where discontinuities are 
     83        // (a - c) * w + c = a * w + c * (1 - w) 
     84        const float2 width = IN.texCoords * (1.0f - w); 
    7985 
    80         // smoothed color 
    81         // (a - c) * w + c = a * w + c * (1 - w) 
    82         float2 offset = IN.c.xy * (1.0f - w); 
     86        float4 s0 = tex2Dlod(colors, float4(width + lt * w, 0, 0)); 
     87        float4 s1 = tex2Dlod(colors, float4(width + rb * w, 0, 0)); 
     88        float4 s2 = tex2Dlod(colors, float4(width + rt * w, 0, 0)); 
     89        float4 s3 = tex2Dlod(colors, float4(width + lb * w, 0, 0)); 
     90#endif 
    8391 
    84         float4 s0 = tex2Dlod(colors, float4(offset + IN.lt.xy * w, 0, 0)); 
    85         float4 s1 = tex2Dlod(colors, float4(offset + IN.rb.xy * w, 0, 0)); 
    86         float4 s2 = tex2Dlod(colors, float4(offset + IN.rt.xy * w, 0, 0)); 
    87         float4 s3 = tex2Dlod(colors, float4(offset + IN.lb.xy * w, 0, 0)); 
    88  
    89         float4 centerColor = tex2Dlod(colors, float4(IN.c.xy, 0, 0)); 
    90  
    91         float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 
    92         //return (s0 + s1 + s2 + s3) * 0.25f; 
    93  
    94         col.w = centerColor.w; 
     92        //float4 col = (s0 + s1 + s2 + s3 + centerColor) * 0.2f; 
     93        //float4 col = (s0 + s1 + s2 + s3) * 0.25f; 
     94        float4 col = float4(ne.x, ne.x, ne.x, 0); 
     95        //float4 col = float4(de.x, de.x, de.x, 0); 
     96        //float4 col = float4(w, w, w, 0); 
     97        //float4 col = centerColor; 
     98        // push through the current depth 
     99        col.w = centerDepth.x; 
    95100 
    96101        return col; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r3134 r3136  
    7474        //OUT.color.xyz = normal * 0.5f + 0.5f; 
    7575        // store scaled view vector so wie don't have to normalize for e.g., ssao 
    76         OUT.color.w = color.w / length(IN.view); 
     76        OUT.color.w = color.w;// / length(IN.view); 
    7777         
    7878        return OUT; 
     
    187187 
    188188                float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, weights, noiseTex); 
    189                 //float shadowTerm = CalcShadowTerm(IN, shadowMap, sampleWidth, lightSpacePos.xy, lightSpacePos.z, samples, noiseTex); 
    190  
     189         
    191190                diffuse *= shadowTerm; 
    192191        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3126 r3136  
    6969        // the normal has to be correctly transformed with the inverse transpose 
    7070        OUT.normal = mul(glstate.matrix.invtrans.modelview[0], IN.normal); 
     71        //OUT.normal = IN.normal; 
    7172 
    7273        return OUT; 
     
    9495        // Transp(Inv(Inv(view))) = Transp(view) 
    9596        pix.norm = mul(transpose(viewMatrix), IN.normal).xyz; 
     97        //pix.norm = IN.normal.xyz; 
    9698        // compute eye linear depth 
    9799        pix.col.w = length(IN.eyePos.xyz); 
     
    115117        // multiply with the inverse transpose of T, we multiple with Transp(Inv(Inv(view))) = Transp(view) 
    116118        pix.norm = mul(transpose(viewMatrix), IN.normal).xyz; 
     119        //pix.norm = IN.normal.xyz; 
    117120        // eye space depth 
    118121        pix.col.w = length(IN.eyePos.xyz); 
Note: See TracChangeset for help on using the changeset viewer.