Ignore:
Timestamp:
07/13/06 08:17:27 (18 years ago)
Author:
szirmay
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_DepthShadow.hlsl

    r1126 r1131  
    77 
    88VS_OUT DepthVS(float4 position : POSITION,       
    9                                 uniform float4x4 worldViewProj,                          
    10                                 uniform float4x4 viewProj, 
    11                                 uniform float4x4 cameraMatrix) 
     9                                uniform float4x4 worldViewProj) 
    1210{ 
    1311   
     
    1513  
    1614  OUT.hPosition = mul(worldViewProj, position); 
    17   OUT.Position = mul(viewProj, position); 
     15  OUT.Position = mul(worldViewProj, position); 
    1816   
    1917  return OUT; 
     
    2523        float4 pos = (IN.Position / IN.Position.w); 
    2624        pos = (pos +1.0 ) / 2.0; 
    27         return pos.z;    
     25        return float4(pos.z, pos.z * pos.z, 1, 1);       
    2826} 
    2927 
     
    3937VS_OUT_SHADOW depthShadowVS(float4 position : POSITION,  
    4038                                                        uniform float4x4 worldViewProj, 
     39                                                        uniform float4x4 world, 
    4140                                                        uniform float4x4 lightViewProj) 
    4241{ 
    4342  VS_OUT_SHADOW OUT; 
    4443  OUT.hPosition = mul(worldViewProj, position); 
    45   OUT.lPosition = mul(lightViewProj, position);   
     44  float4 wPos = mul(world, position); 
     45  OUT.lPosition = mul(lightViewProj, wPos);   
    4646  OUT.Position = position;   
    4747  return OUT; 
     
    5454                                        ):COLOR 
    5555{        
    56         float bias = 0.01; 
     56        float bias = 0.1; 
    5757        float4 light = float4(1,1,1,1); 
    5858        float4 shadow = float4(0.3,0.3,0.3,1); 
    5959         
    6060        float4 pos = (IN.lPosition / IN.lPosition.w); 
    61         pos = (pos +1.0 ) / 2.0; 
     61        pos.xy = (pos.xy +1.0 ) / 2.0; 
    6262        pos.y = 1.0 - pos.y; 
    6363        float4 storedDepth = tex2D(depthShadowMap, pos.xy); 
    64         if(storedDepth.r + bias < pos.z) 
    65                 light = shadow; 
     64         
     65        if(storedDepth.r + bias > pos.z) 
     66        { 
     67                float M1 = storedDepth.r; 
     68                float M2 = storedDepth.g; 
     69                float v2 = M2 - M1 * M1; 
     70                float pmax = v2 / (v2 + pow(M1 - pos.z, 2)); 
     71                light = shadow + (1 - shadow) * pmax; 
     72                 
     73                //light = shadow; 
     74        } 
    6675        //return abs( pos.z - storedDepth.z );   
    6776        return light;    
Note: See TracChangeset for help on using the changeset viewer.