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

  1. //--------------------------------------------------------------------------
  2. //  TMShaders
  3. //  Copyright (c) 2002 by Tools-Media Corp., All Right Reserved.
  4. //  Programmer: Tima Tcvetkov
  5. //
  6. //  vertexlights.fx
  7. //  Vertex Shaders for vertex lighting
  8. //--------------------------------------------------------------------------
  9. #ifndef __VERTEX_LIGHTS_FX__
  10. #define __VERTEX_LIGHTS_FX__
  11.  
  12. void CalculateCubeLighting(){
  13. #ifdef __USE_LOOPS__ // we use loops and coditinals for VS20 and higher
  14.     if( constBCubeLight ){
  15. #endif
  16.     int3 Sample  = ( g_fWorldNormal < 0.0f );
  17.     float3 Scale = g_fWorldNormal * g_fWorldNormal;
  18.     
  19.     float3 c1 = vecCubeColors[Sample.x + 0] * Scale.x;
  20.     float3 c2 = vecCubeColors[Sample.y + 2] * Scale.y;
  21.     float3 c3 = vecCubeColors[Sample.z + 4] * Scale.z;
  22.     
  23.     g_fVertexLightColor += (c1 + c2 + c3);
  24.     
  25. #ifdef __USE_LOOPS__ // we use loops coditinals for VS20 and higher
  26.     }
  27. #endif    
  28. }
  29.  
  30. void CopyVertexLightColorTo( uniform bool bColorReg0 ){
  31.  if( bColorReg0 ){
  32.    g_fColor0.xyz += g_fVertexLightColor;
  33.  }
  34.  else{
  35.    g_fColor1.xyz += g_fVertexLightColor;
  36.  }
  37. }
  38.  
  39. void AddAmbient2Diffuse(){
  40.   g_fVertexLightColor += vecAmbient;
  41. }
  42. void CalculatePointLightColorAttenuation( uniform int uiNumLights, float fAngleDot, float fAttenuation  ){
  43.     float  fAngleDotClamped = max(fAngleDot,0.0f) * fAttenuation;
  44.     g_fVertexLightColor += vecPointLightColor[uiNumLights] * fAngleDotClamped;
  45. }
  46. void CalculatePointLightSpecularColorAttenuation( uniform int uiNumLights, float3 Vertex2PointLight, float fAngleDot, float fAttenuation  ){
  47.     
  48.     float  fAngleDotClamped = max(fAngleDot,0.0) * fAttenuation;
  49.     float3 fVertex2Eye = normalize((float3)-g_fWorldViewVertexPosition);
  50.     float3 fHalf = normalize(Vertex2PointLight + fVertex2Eye);
  51.     float4 fColor = lit(fAngleDot,dot(fHalf,g_fWorldViewNormal),vecPointLightColor[uiNumLights].w);
  52.  
  53.     g_fVertexLightColor += (vecPointLightColor[uiNumLights] * fColor.y ) * fColor.z;
  54. }
  55.  
  56. #ifndef __USE_LOOPS__ // we use loops for VS20 and higher
  57. void CalculatePointLightVector( uniform int uiNumLights, uniform bool bSpecularPass ){
  58.     for( int i =0; i<uiNumLights; i++ ){
  59. #else // old VS11 school
  60. void CalculatePointLightVector( uniform bool bSpecularPass ){
  61.     for( int i =0; i<constINumLights; i++ ){
  62. #endif   
  63.  /*
  64.         float3 fVertex2Light = vecPointLightPosition[i] - g_fWorldViewVertexPosition;
  65.         float fDot = dot(fVertex2Light,fVertex2Light);
  66.         float RevDistance = rsqrt(fDot);
  67.         float3 fVertex2LightNormalized = fVertex2Light * RevDistance;
  68.         float fAttenuation = 1.0 - ( fDot * RevDistance ) * vecPointLightPosition[i].w;
  69.         float fAngle = dot(g_fWorldViewNormal,fVertex2LightNormalized);
  70. */        
  71.         float3 fVertex2Light = vecPointLightPosition[i] - g_fWorldViewVertexPosition;
  72.         float3 fVertex2LightNormalized = normalize(fVertex2Light);
  73.         fVertex2Light = fVertex2Light * vecPointLightPosition[i].w;
  74.         
  75.         float fAttenuation = clamp( 1.0 - dot(fVertex2Light,fVertex2Light),0.0f,1.0f );
  76.         
  77.         float fAngle = dot(g_fWorldViewNormal,fVertex2LightNormalized);
  78.         
  79.         if( bSpecularPass ){
  80.         CalculatePointLightSpecularColorAttenuation(i,fVertex2LightNormalized,fAngle,fAttenuation);
  81.         }//if
  82.         else {
  83.         CalculatePointLightColorAttenuation(i,fAngle,fAttenuation);
  84.         }//else
  85.         
  86.    }// for
  87. }
  88.  
  89.  
  90. #endif //__VERTEX_LIGHTS_FX__