Ignore:
Timestamp:
09/02/08 15:29:20 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2893 r2895  
    8181                                  uniform sampler2D shadowMap, 
    8282                                  uniform float4x4 shadowMatrix, 
    83                                   uniform float maxDepth 
     83                                  uniform float maxDepth, 
     84                                  uniform float sampleWidth 
    8485                                  ) 
    8586{ 
     
    102103        float4 lightSpacePos = mul(shadowMatrix, position); 
    103104 
    104         float shadowDepth = tex2D(shadowMap, lightSpacePos.xy); 
     105        float shadowDepth[9]; 
     106 
     107        float w = sampleWidth; 
     108 
     109        // pcf sampling using 3 x 3 tab 
     110 
     111        shadowDepth[0] = tex2D(shadowMap, lightSpacePos.xy).x; 
     112         
     113        shadowDepth[1] = tex2D(shadowMap, lightSpacePos.xy + float2( w,  w)).x; 
     114        shadowDepth[2] = tex2D(shadowMap, lightSpacePos.xy - float2( w, -w)).x; 
     115        shadowDepth[3] = tex2D(shadowMap, lightSpacePos.xy - float2(-w, -w)).x; 
     116        shadowDepth[4] = tex2D(shadowMap, lightSpacePos.xy - float2(-w,  w)).x; 
     117 
     118        shadowDepth[5] = tex2D(shadowMap, lightSpacePos.xy - float2( w,  0)).x; 
     119        shadowDepth[6] = tex2D(shadowMap, lightSpacePos.xy - float2( 0,  w)).x; 
     120        shadowDepth[7] = tex2D(shadowMap, lightSpacePos.xy - float2(-w,  0)).x; 
     121        shadowDepth[8] = tex2D(shadowMap, lightSpacePos.xy - float2( 0, -w)).x; 
    105122 
    106123        OUT.color = col; 
    107124         
    108         // hack: prevent shadowing the sky 
    109         if ((amb < 0.9) &&       
     125        float depth = lightSpacePos.z / lightSpacePos.w; 
     126 
     127        float d = 0.0f; 
     128 
     129        for (int i = 0; i < 9; ++ i) 
     130        { 
     131                d += step(shadowDepth[i], depth); 
     132        } 
     133 
     134        d /= 9.0f; 
     135         
     136        /*if ((amb < 0.9) && // hack: prevent shadowing the sky  
    110137                (lightSpacePos.z / lightSpacePos.w > shadowDepth)) 
    111138        { 
    112139                OUT.color *= 0.1f; 
     140        }*/ 
     141         
     142        if (amb < 0.9) // hack: prevent shadowing the sky        
     143        { 
     144                const float x = 0.1f; 
     145                OUT.color *= x + (1.0f - x) * (1.0f - d); 
    113146        } 
    114147         
Note: See TracChangeset for help on using the changeset viewer.