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 >
Wrap
Text File
|
2005-03-31
|
3KB
|
75 lines
/*=============================================================================
PointLight.hlsl: Shaders for calculating a single point light.
Copyright 2003 Epic Games, Inc. All Rights Reserved.
Revision history:
* Branched from HLSL code by Daniel Vogel
=============================================================================*/
#define STATICLIGHTING_VERTEXMASK 1
#include "Common.cg"
#include "UserShader.cg"
#include "VertexFactory.cg"
half3 LightColor;
sampler VisibilityTexture;
float4 LightPosition; // w = 1.0 / Radius
float4 CameraPosition;
struct pixelShaderInput
{
vertexFactoryInterpolants FactoryInterpolants;
half3 TangentLightVector : TEXCOORD5;
float3 WorldLightVector : TEXCOORD6;
float3 CameraVector : TEXCOORD7;
#if STATICLIGHTING_VERTEXMASK
half LightMask : COLOR0;
#endif
};
half4 pixelShader(pixelShaderInput Input) : COLOR0
{
userShaderInput UserShaderInput = getUserShaderInputs( Input.FactoryInterpolants );
calcUserVectors( UserShaderInput, Input.CameraVector, Input.TangentLightVector );
#if STATICLIGHTING_TEXTUREMASK
half LightMask = tex2D( VisibilityTexture, getLightMapCoordinate(Input.FactoryInterpolants) ).r;
#elif STATICLIGHTING_VERTEXMASK
half LightMask = Input.LightMask;
#else
half LightMask = 1;
#endif
return half4( LightMask * userPointLightTransfer(UserShaderInput,Input.WorldLightVector) * LightColor, 1 );
}
struct vertexShaderOutput
{
float4 Position : POSITION;
vertexFactoryInterpolants FactoryInterpolants;
float3 TangentLightVector : TEXCOORD5;
float3 WorldLightVector : TEXCOORD6;
float3 CameraVector : TEXCOORD7;
#if STATICLIGHTING_VERTEXMASK
float LightMask : COLOR0;
#endif
};
#if STATICLIGHTING_VERTEXMASK
vertexShaderOutput vertexShader(vertexInput Input,float LightMask : TEXCOORD5)
#else
vertexShaderOutput vertexShader(vertexInput Input)
#endif
{
vertexShaderOutput Result;
float4 WorldPosition = vertexFactoryGetWorldPosition(Input,Result.FactoryInterpolants);
Result.Position = mul(ViewProjectionMatrix,WorldPosition);
Result.CameraVector.xyz = vertexFactoryWorldToTangentSpace(Input,CameraPosition.xyz - WorldPosition.xyz * CameraPosition.w);
Result.TangentLightVector = vertexFactoryWorldToTangentSpace(Input,LightPosition.xyz - WorldPosition.xyz);
Result.WorldLightVector = (LightPosition.xyz - WorldPosition.xyz) * LightPosition.w;
#if STATICLIGHTING_VERTEXMASK
Result.LightMask = LightMask;
#endif
return Result;
}