I have been having some troubles to get point light to work, I looked into some code samples, but always getting a problem when trying to implement point light.
Can someone show me how do I modify my shader to implement point light?
matrix World;
matrix View;
matrix Projection;
// Point light variables
float4 lightPosition;
float lightRange;
float4 lightDiffuse;
float4 lightAmbient;
float4 lightSpecular;
// Texture
texture colorMapTexture;
sampler2D colorMap = sampler_state
{
Texture = <colorMapTexture>;
MagFilter = Linear;
MinFilter = Anisotropic;
MipFilter = Linear;
MaxAnisotropy = 16;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float2 UV : TEXCOORD0;
float3 Normal : TEXCOORD1;
};
struct VS_INPUT
{
float4 Pos : SV_POSITION;
float2 UV : TEXCOORD0;
float3 Normal : TEXCOORD1;
};
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float2 UV : TEXCOORD0;
float3 Normal : TEXCOORD1;
};
//-----------------------------------------------------------------------
// Vertex shader function
//-----------------------------------------------------------------------
VS_OUTPUT VS( VS_INPUT IN )
{
VS_OUTPUT Out;
Out = (VS_OUTPUT)0;
Out.Pos = mul (IN.Pos, World);
Out.Pos = mul (Out.Pos, View);
Out.Pos = mul (Out.Pos, Projection);
Out.UV = IN.UV;
Out.Normal = mul(IN.Normal, (float3x3)World);
return Out;
}
//-----------------------------------------------------------------------
// Pixel shader function
//-----------------------------------------------------------------------
float4 PS( PS_INPUT IN ) : COLOR
{
// *** I need to modify this function for point light ***
return tex2D(colorMap, IN.UV);
}
//-----------------------------------------------------------------------------
// Techniques.
//-----------------------------------------------------------------------------
technique PointLighting
{
pass
{
AlphaBlendEnable = false;
ZEnable = true;
VertexShader = compile vs_3_0 VS();
PixelShader = compile ps_3_0 PS();
}
}