Ignore:
Timestamp:
10/03/08 14:35:07 (16 years ago)
Author:
mattausch
Message:

trying to use smaller fbo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r2989 r2999  
    3838{ 
    3939  float4 col: COLOR0; 
    40   float4 pos: COLOR1; 
     40  //float4 pos: COLOR1; 
     41  float2 pos: COLOR1; 
    4142  float4 norm: COLOR2; 
    4243}; 
     
    6566 
    6667 
     68// bilinear interpolation 
     69inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) 
     70{ 
     71        float3 x1 = lerp(bl, tl, w.y); 
     72        float3 x2 = lerp(br, tr, w.y);  
     73        float3 v = lerp(x1, x2, w.x);  
     74 
     75        return v; 
     76} 
     77 
     78 
    6779pixel fragtex(fragin IN,  
    6880                          uniform sampler2D dirtTex, 
    6981                          uniform float maxDepth, 
    7082                          uniform sampler2D tex, 
    71                           uniform float3 currentPos) 
     83                          uniform float3 eyePos, 
     84                          uniform float3 bl, 
     85                          uniform float3 br, 
     86                          uniform float3 tl, 
     87                          uniform float3 tr) 
    7288{ 
     89        float4 texColor = tex2D(tex, IN.texCoord.xy); 
     90 
     91        // account for alpha blending 
     92        if (texColor.w < 0.5f) discard; 
     93 
    7394        pixel pix; 
    74  
    75         float4 texColor = tex2D(tex, IN.texCoord.xy); 
    7695 
    7796        // save color in first render target 
    7897        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 
    7998        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;  
    80          
     99 
    81100        // save world position in second render target 
    82         pix.pos = IN.worldPos * maxDepth; 
     101        //pix.pos = IN.worldPos * maxDepth; 
    83102        // save world space normal in third rt 
    84103        pix.norm.xyz = IN.normal; 
     
    86105        // store projection coordinates with positions (used for ssao) 
    87106        pix.norm.w = IN.projPos.w; 
    88         // write the depth 
    89         pix.pos.w = IN.mypos.z / IN.mypos.w; 
    90107 
    91         // account for alpha blending 
    92         if (pix.col.w < 0.5f) 
    93                 discard; 
     108        const float4 projPos = IN.mypos / IN.mypos.w; 
     109        // store the projected depth 
     110        pix.pos.y = projPos.z; 
     111 
     112        float2 screenCoord = projPos.xy * 0.5f + 0.5f; 
     113        const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 
    94114 
    95115        // hack: squeeze some information about ambient into the texture 
    96116        //pix.col.w = glstate.material.emission.x; 
    97         pix.col.w = length(currentPos - IN.worldPos) * maxDepth; 
     117 
     118        // eye linear depth 
     119        pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView; 
     120        pix.pos.x = pix.col.x; 
    98121 
    99122        return pix; 
     
    101124 
    102125 
    103 pixel frag(fragin IN, uniform float maxDepth, uniform float3 currentPos) 
     126pixel frag(fragin IN,  
     127                   uniform float maxDepth,  
     128                   uniform float3 eyePos, 
     129                   uniform float3 bl, 
     130                   uniform float3 br, 
     131                   uniform float3 tl, 
     132                   uniform float3 tr) 
    104133{ 
    105134        pixel pix; 
     
    107136        // hack: use comination of emmisive + diffuse (emmisive used as constant ambient term) 
    108137        pix.col = glstate.material.diffuse + glstate.material.emission; 
    109         pix.pos = IN.worldPos * maxDepth; 
     138        //pix.pos = IN.worldPos * maxDepth; 
    110139 
    111140        pix.norm.xyz = IN.normal; 
     
    113142        // store projection coordinates with positions (used for ssao) 
    114143        pix.norm.w = IN.mypos.w; 
    115         // the projected depth 
    116         pix.pos.w = IN.mypos.z / IN.mypos.w; 
    117          
     144 
     145        const float4 projPos = IN.mypos / IN.mypos.w; 
     146        // store the projected depth 
     147        pix.pos.y = projPos.z; 
     148 
     149        float2 screenCoord = projPos.xy * 0.5f + 0.5f; 
     150        const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 
     151 
    118152        // hack: squeeze some information about the ambient term into the target 
    119153        //pix.col.w = glstate.material.emission.x; 
    120         pix.col.w = length(currentPos - IN.worldPos) * maxDepth; 
     154        pix.col.w = (length(eyePos - IN.worldPos.xyz) * maxDepth) / magView; 
     155        pix.pos.x = pix.col.x; 
    121156 
    122157        return pix; 
Note: See TracChangeset for help on using the changeset viewer.