Ignore:
Timestamp:
10/09/08 11:19:33 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r3016 r3017  
    1717  float4 worldPos: TEXCOORD1; // world position 
    1818  float3 normal: TEXCOORD2; 
    19   float4 mypos: TEXCOORD3; 
     19  float4 projPos: TEXCOORD3; 
    2020}; 
    2121 
     
    2828        float4 texCoord: TEXCOORD0;     
    2929 
    30         float4 projPos: WPOS; 
     30        float4 winPos: WPOS; 
    3131        float4 worldPos: TEXCOORD1; // world position 
    3232        float3 normal: TEXCOORD2; 
    33         float4 mypos: TEXCOORD3; 
     33        float4 projPos: TEXCOORD3; 
    3434}; 
    3535 
     
    3838{ 
    3939        float4 col: COLOR0; 
    40         float4 norm: COLOR1; 
     40        float3 norm: COLOR1; 
    4141        float3 pos: COLOR2; 
    4242}; 
     
    5959 
    6060        OUT.normal = IN.normal; 
    61         OUT.mypos = OUT.position; 
     61        OUT.projPos = OUT.position; 
    6262 
    6363        return OUT; 
     
    7575} 
    7676 
     77//#pragma position_invariant fragtex 
    7778 
    7879pixel fragtex(fragin IN,  
     
    9697        // hack: use combination of emmisive + diffuse (emmisive used as constant ambient term) 
    9798        pix.col = (glstate.material.emission + glstate.material.diffuse) * texColor;  
    98         // save world space normal in third rt 
    99         pix.norm.xyz = IN.normal; 
    100         // store projection coordinates with positions (used for ssao) 
    101         pix.norm.w = IN.projPos.w; 
     99        // save world space normal in rt 
     100        pix.norm = IN.normal; 
    102101 
    103         const float4 projPos = IN.mypos / IN.mypos.w; 
    104          
    105102        // hack: squeeze some information about ambient into the texture 
    106103        //pix.col.w = glstate.material.emission.x; 
    107104 
    108105        // compute eye linear depth 
    109         const float2 screenCoord = projPos.xy * 0.5f + 0.5f; 
    110         const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 
    111         pix.col.w = length(eyePos - IN.worldPos.xyz) / magView; 
    112  
    113 #if 0 
    114         // save world position in second render target 
    115         pix.pos = IN.worldPos.xyz * maxDepth; 
    116 #endif 
     106        const float4 projPos = IN.projPos / IN.projPos.w; 
     107         
     108        float2 screenCoord = projPos.xy * 0.5f + 0.5f; 
     109         
     110        const float3 viewVec = Interpol(screenCoord, bl, br, tl, tr); 
     111        const float invMagView = 1.0f / length(viewVec); 
     112        // note: has to done in this order, otherwise strange precision problems! 
     113        pix.col.w = invMagView * length(eyePos - IN.worldPos.xyz); 
    117114 
    118115        return pix; 
     
    132129        pix.col = glstate.material.diffuse + glstate.material.emission; 
    133130 
    134         pix.norm.xyz = IN.normal; 
    135          
    136         // store projection coordinates with positions (used for ssao) 
    137         pix.norm.w = IN.mypos.w; 
    138  
    139         const float4 projPos = IN.mypos / IN.mypos.w; 
     131        pix.norm = IN.normal; 
    140132 
    141133        // hack: squeeze some information about the ambient term into the target 
     
    143135         
    144136        // compute eye linear depth and scale with lenght to avoid sqr root in pixel shader 
     137        const float4 projPos = IN.projPos / IN.projPos.w; 
     138         
    145139        float2 screenCoord = projPos.xy * 0.5f + 0.5f; 
    146140        const float magView = length(Interpol(screenCoord, bl, br, tl, tr)); 
    147         pix.col.w = length(eyePos - IN.worldPos.xyz)  / magView; 
    148  
    149 #if 0 
    150         pix.pos = IN.worldPos.xyz * maxDepth; 
    151 #endif 
     141        pix.col.w = length(eyePos - IN.worldPos.xyz) / magView; 
    152142 
    153143        return pix; 
Note: See TracChangeset for help on using the changeset viewer.