home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 April / Gamestar_72_2005-04_dvd.iso / Dema / Liquidator / Liquidator.tma / data / renderer / shadows.fx < prev    next >
Text File  |  2004-12-13  |  3KB  |  100 lines

  1. #ifndef __SHADOWS_FX__
  2. #define __SHADOWS_FX__
  3.  
  4. void CalculateHClipDistance( uniform int Stage ){
  5.  float4 fTVertex;
  6.  if( Stage == 0 ){
  7.    fTVertex = mul(g_fVertexPosition,matProjection);
  8.  }
  9.  else if( Stage == 1 ){
  10.    fTVertex = mul(g_fVertexPosition,matTextureProjection[0]);
  11.  }
  12.  g_fTexCoords[Stage] = fTVertex.zzzw;
  13. }
  14. void CalculateShadowVolume(){
  15.  
  16.  float4 fLightRdius = vecShadowParams.x;
  17.  float4 fVertex2Light;
  18.  fVertex2Light.xyz = (float3)g_fVertexPosition - (float3)vecPointLightPosition[0];
  19.  fVertex2Light.w = rsqrt( dot((float3)fVertex2Light,(float3)fVertex2Light) );
  20.  fVertex2Light.xyz *=fVertex2Light.w;
  21.  
  22.  fVertex2Light.w = dot( fVertex2Light.xyz,-g_fNormal);
  23.  
  24.  if( fVertex2Light.w < 0.0 ){
  25.     float4 fDistance = 1.0 / fVertex2Light.w;
  26.     float4 fRange = ( fDistance < fLightRdius ) ? 1.0 : 0.0;
  27.     fDistance = fDistance * fRange; 
  28.     fLightRdius = fLightRdius * fRange + (-fDistance);
  29.     float3 fLightDir = (float3)fVertex2Light  *  fLightRdius.x;
  30.     g_fVertexPosition.xyz = fLightDir + g_fVertexPosition.xyz;
  31.  }
  32.  
  33. }
  34.  
  35. void CalculateVisualShadowVolume(){
  36.  
  37.  float4 fLightRdius = vecShadowParams.x;
  38.  float4 fVertex2Light;
  39.  fVertex2Light.xyz = (float3)g_fVertexPosition - (float3)vecPointLightPosition[0];
  40.  fVertex2Light.w = rsqrt( dot((float3)fVertex2Light,(float3)fVertex2Light) );
  41.  fVertex2Light.xyz *=fVertex2Light.w;
  42.  
  43.  fVertex2Light.w = dot( fVertex2Light.xyz,-g_fNormal);
  44.  
  45.  if( fVertex2Light.w < 0.0 ){
  46.     float4 fDistance = 1.0 / fVertex2Light.w;
  47.     float4 fRange = ( fDistance < fLightRdius ) ? 1.0 : 0.0;
  48.     fDistance = fDistance * fRange; 
  49.     fLightRdius = fLightRdius * fRange + (-fDistance);
  50.     float3 fLightDir = (float3)fVertex2Light  *  fLightRdius.x;
  51.     g_fVertexPosition.xyz = fLightDir + g_fVertexPosition.xyz;
  52.  }
  53.  g_fColor0.w = dot(g_fNormal,(float3)fVertex2Light);
  54.  g_fColor0.zw = g_fColor0.w * vecShadowParams.z + vecShadowParams.w;
  55. }
  56.  
  57. void CalculateProjectiveShadow( uniform int NumShadows ){
  58.  
  59.   for( int i =0; i < NumShadows; i++ ){
  60.    g_fTexCoords[i] = mul(g_fVertexPosition,matTextureProjection[i]);
  61.   }
  62.   if( NumShadows == 1 ){  
  63.     Vector clippingPlane = vecDiffuseColor;
  64.     Vector fTVertex = mul(g_fVertexPosition,matProjection);
  65.     float c = dot(clippingPlane, fTVertex);
  66.     g_fTexCoords[NumShadows] = c;
  67.   }
  68.   
  69. }
  70. void TransformPositionWithDirMask( uniform int NumShadows,uniform bool bAttenuated ){
  71.  
  72.   for( int i =0; i<NumShadows; i++ ){
  73.  
  74.     g_fTexCoords[i] = mul(g_fVertexPosition,matTextureProjection[i]);
  75.     float1 fZDistance =  ( g_fTexCoords[i].z >= 0.0001 ) ? 1.0 : 0.0;
  76.     float3 fZRow;
  77.     fZRow.x = matTextureProjection[i][0][2];
  78.     fZRow.y = matTextureProjection[i][1][2];
  79.     fZRow.z = matTextureProjection[i][2][2];
  80.     float fDot;
  81.     if( bAttenuated ){
  82.        fDot = -dot(g_fNormal,fZRow) * fZDistance;
  83.     }else{
  84.      fDot = (dot(g_fNormal,fZRow) < 0.0001) ? 1.0 : 0.0;
  85.      fDot *= fZDistance;
  86.     }
  87.     if( i == 0 ){
  88.      g_fColor0.xyz = fDot;
  89.     }else if( i == 1 ){
  90.      g_fColor0.w = fDot;
  91.     }else if( i == 2 ){
  92.      g_fColor1.xyz = fDot;
  93.     }else if( i == 3 ){
  94.      g_fColor1.w = fDot;
  95.     } // if
  96.  
  97.   }// for 
  98. }
  99. #endif //__SHADOWS_FX__
  100.