Ignore:
Timestamp:
03/01/07 18:04:37 (17 years ago)
Author:
szirmay
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl

    r2024 r2179  
    1515#define DEPTH_BIAS_VSM  0.001 
    1616#define DEPTH_EPSILON   0.001 
    17 #define DIST_BIAS       0.001 
     17#define DIST_BIAS       0.1 
    1818#define DIST_BIAS_VSM   0.001 
    1919#define DIST_EPSILON    0.001 
    2020 
    21 const float4 shadowColor = float4(0.85,0.85,0.85,1); 
     21#define shadowColor float4(0.85,0.85,0.85,1) 
    2222 
    2323float4 shadowMapDepth(LightVPos_OUT IN, 
     
    2525{ 
    2626  float4 light = shadowColor;    
    27   float4 pos = (IN.LightVPos / IN.LightVPos.w); 
    28   if( pos.z > 0.0) 
     27  if( IN.LightVPos.z > 0.0) 
    2928  { 
    30     pos.xy = (pos.xy + 1.0) / 2.0; 
     29    float4 pos = (IN.LightVPos / IN.LightVPos.w); 
     30        pos.xy = (pos.xy + 1.0) / 2.0; 
    3131    pos.y = 1.0 - pos.y; 
    3232    float storedDepth = tex2D(shadowMap, pos.xy).r; 
    33  
    34     if(pos.z - DEPTH_BIAS <= storedDepth.r) 
    35       light = 1; 
     33        pos.z -= DIST_BIAS; 
     34        light = max(pos.z <= storedDepth.r, shadowColor);            
    3635  } 
    37   
    3836  return light;  
    3937} 
     
    7472} 
    7573 
    76 float4 shadowMapDist(LightCPos_OUT IN,                      
    77                      uniform sampler2D shadowMap) : COLOR 
     74float4 shadowMapDist(LightCPos_OUT IN, 
     75                                        //uniform float lightFarPlane, 
     76                                         uniform sampler2D shadowMap) : COLOR 
    7877{ 
    79   float4 light = shadowColor;    
    80   float4 pos = (IN.LightVPos / IN.LightVPos.w); 
     78  float4 light = shadowColor; 
    8179   
    82   if( pos.z > 0.0) 
     80  if( IN.LightVPos.z > 0.0) 
    8381  {      
    84     //float d = length(pos.xy); 
     82    float4 pos = (IN.LightVPos / IN.LightVPos.w); 
     83        //float d = length(pos.xy); 
    8584    //light = saturate((1.0 - d)/0.05);          
    8685    //if(d <= 1.0) 
    87     { 
    88         float dist = length(IN.LightCPos.xyz); 
    89         pos.xy = (pos.xy + 1.0) / 2.0; 
    90         pos.y = 1.0 - pos.y; 
    91         float storedDist = tex2D(shadowMap, pos.xy).r; 
    92         dist -= DIST_BIAS; 
    93  
    94         if(dist <= storedDist); 
    95           light = 1; 
    96      } 
    97   }   
    98          
     86    //{ 
     87                float dist = length(IN.LightCPos.xyz) ; 
     88                pos.xy = (pos.xy + 1.0) / 2.0; 
     89                pos.y = 1.0 - pos.y; 
     90                float4 storedDist = tex2D(shadowMap, pos.xy); 
     91                dist -= DIST_BIAS; 
     92                light = max(dist <= storedDist.r, shadowColor);          
     93    //} 
     94  } 
     95         
    9996  return light; 
    10097} 
     
    105102{ 
    106103  float4 light = float4(1,1,1,1); 
    107          
    108   float4 pos = (IN.LightVPos / IN.LightVPos.w); 
    109104   
    110   if( pos.z > 0.0) 
     105  if( IN.LightVPos.z > 0.0) 
    111106  {      
    112     //float d = length(pos.xy); 
    113     //light = saturate((1.0 - d)/0.05);          
    114     //if(d <= 1.0) 
     107    float4 pos = (IN.LightVPos / IN.LightVPos.w); 
     108        float d = length(pos.xy); 
     109    light = saturate((1.0 - d)/0.05);            
     110    if(d <= 1.0) 
    115111    { 
    116         float dist = length(IN.LightCPos.xyz) / lightFarPlane; 
    117         pos.xy = (pos.xy + 1.0) / 2.0; 
    118         pos.y = 1.0 - pos.y; 
    119         float4 storedDist = tex2D(shadowMap, pos.xy); 
    120         dist -= DIST_BIAS_VSM; 
    121         float lit_factor = light * (dist <= storedDist.r);       
     112                float dist = length(IN.LightCPos.xyz) / lightFarPlane; 
     113                pos.xy = (pos.xy + 1.0) / 2.0; 
     114                pos.y = 1.0 - pos.y; 
     115                float4 storedDist = tex2D(shadowMap, pos.xy); 
     116                dist -= DIST_BIAS_VSM; 
     117                float lit_factor = light * (dist <= storedDist.r);       
    122118          
    123         float M1 = storedDist.r; 
    124         float M2 = storedDist.g; 
    125         float v2 = min(max(M2 - M1 * M1, 0.0) +  DIST_EPSILON, 1.0); 
    126         float m_d = M1 - dist; 
     119                float M1 = storedDist.r; 
     120                float M2 = storedDist.g; 
     121                float v2 = min(max(M2 - M1 * M1, 0.0) +  DIST_EPSILON, 1.0); 
     122                float m_d = M1 - dist; 
    127123        float pmax = v2 / (v2 + m_d * m_d); 
    128124                                                 
    129125        // Adjust the light color based on the shadow attenuation 
    130         light = max(lit_factor, pmax); 
    131          
    132      } 
     126        light = max(lit_factor, pmax);           
     127    } 
    133128  } 
    134129  else 
Note: See TracChangeset for help on using the changeset viewer.