home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 February / Gamestar_81_2006-02_dvd.iso / Dema / roboblitz_demo.msi / disk1.cab / PointLight.cg < prev    next >
Text File  |  2005-03-31  |  3KB  |  75 lines

  1. /*=============================================================================
  2.     PointLight.hlsl: Shaders for calculating a single point light.
  3.     Copyright 2003 Epic Games, Inc. All Rights Reserved.
  4.  
  5.     Revision history:
  6.         * Branched from HLSL code by Daniel Vogel
  7. =============================================================================*/
  8.  
  9. #define STATICLIGHTING_VERTEXMASK    1
  10.  
  11. #include "Common.cg"
  12. #include "UserShader.cg"
  13. #include "VertexFactory.cg"
  14.  
  15. half3        LightColor;
  16. sampler        VisibilityTexture;
  17. float4        LightPosition;        // w = 1.0 / Radius
  18. float4        CameraPosition;
  19.  
  20. struct pixelShaderInput
  21. {
  22.     vertexFactoryInterpolants    FactoryInterpolants;
  23.     half3                        TangentLightVector    : TEXCOORD5;
  24.     float3                        WorldLightVector    : TEXCOORD6;
  25.     float3                        CameraVector        : TEXCOORD7;
  26. #if STATICLIGHTING_VERTEXMASK
  27.     half                        LightMask            : COLOR0;
  28. #endif
  29. };
  30.  
  31. half4 pixelShader(pixelShaderInput Input) : COLOR0
  32. {
  33.     userShaderInput    UserShaderInput = getUserShaderInputs( Input.FactoryInterpolants );
  34.     calcUserVectors( UserShaderInput, Input.CameraVector, Input.TangentLightVector );
  35.  
  36. #if STATICLIGHTING_TEXTUREMASK
  37.     half LightMask = tex2D( VisibilityTexture, getLightMapCoordinate(Input.FactoryInterpolants) ).r;
  38. #elif STATICLIGHTING_VERTEXMASK
  39.     half LightMask = Input.LightMask;
  40. #else
  41.     half LightMask = 1;
  42. #endif
  43.  
  44.     return half4( LightMask * userPointLightTransfer(UserShaderInput,Input.WorldLightVector) * LightColor, 1 );
  45. }
  46.  
  47. struct vertexShaderOutput
  48. {
  49.     float4                        Position            : POSITION;
  50.     vertexFactoryInterpolants    FactoryInterpolants;
  51.     float3                        TangentLightVector    : TEXCOORD5;
  52.     float3                        WorldLightVector    : TEXCOORD6;
  53.     float3                        CameraVector        : TEXCOORD7;
  54. #if STATICLIGHTING_VERTEXMASK
  55.     float                        LightMask            : COLOR0;
  56. #endif
  57. };
  58.  
  59. #if STATICLIGHTING_VERTEXMASK
  60. vertexShaderOutput vertexShader(vertexInput Input,float LightMask : TEXCOORD5)
  61. #else
  62. vertexShaderOutput vertexShader(vertexInput Input)
  63. #endif
  64. {
  65.     vertexShaderOutput    Result;
  66.     float4    WorldPosition        = vertexFactoryGetWorldPosition(Input,Result.FactoryInterpolants);
  67.     Result.Position                = mul(ViewProjectionMatrix,WorldPosition);
  68.     Result.CameraVector.xyz        = vertexFactoryWorldToTangentSpace(Input,CameraPosition.xyz - WorldPosition.xyz * CameraPosition.w);
  69.     Result.TangentLightVector    = vertexFactoryWorldToTangentSpace(Input,LightPosition.xyz - WorldPosition.xyz);
  70.     Result.WorldLightVector        = (LightPosition.xyz - WorldPosition.xyz) * LightPosition.w;
  71. #if STATICLIGHTING_VERTEXMASK
  72.     Result.LightMask            = LightMask;
  73. #endif
  74.     return Result;
  75. }