Hi.
Now it's about spotlight I can't understand why it dosn't work. I did it based on the information here: http://msdn2.microsoft.com/en-us/library/bb172279.aspx, but it shows only dark cube. It seems I coded something wrong. I've made my shader based on this :
.gif)
.gif)
.gif)
Where rho = norm(Ldcs).norm(Ldir) , and
Ldcs - The negative of the light direction in camera space;
Ldir - Direction vector from vertex position to the light position;
The code of the shader is as follows (the GetAngleIntensity always returns 0???):
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float3 InterPos : TEXTCOORD0;
float3 Normal : TEXTCOORD1;
};
//-----------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------
matrix World;
matrix View;
matrix Projection;
float4 LightColor;
float4 LightPosition;
float4 LightDirection;
float Phi;
float Theta;
//-----------------------------------------------------------------------
// Vertex shader function
//-----------------------------------------------------------------------
PS_INPUT VS( VS_INPUT Data )
{
PS_INPUT Out;
Out = (PS_INPUT)0;
Out.Pos = mul (Data.Pos, World);
Out.InterPos = Out.Pos.xyz;
Out.Pos = mul (Out.Pos, View);
Out.Pos = mul (Out.Pos, Projection);
Out.Normal = mul (Data.Normal, World);
return Out;
}
// HELP FUNCTION TO GET
// LIGHT INTENSITY DEPENDING ON
// ANGLE ALPHA (the problem is here, I think)
float GetAngleIntensity ( float3 LightDir, float3 PixelToLight )
{
float F = 1.0;
float AngleIntensity = 0.0;
Phi = radians(Phi);
Theta = radians (Theta);
float rho = dot((float3)(LightDir), PixelToLight);
if ( (rho<cos(Theta/2)) && (rho>cos(Phi/2)) )
AngleIntensity = pow( (rho-cos(Phi/2))/(cos(Theta/2)-cos(Phi/2)), F );
if (rho <= cos(Phi/2))
AngleIntensity = 0.0;
if (rho > cos(Theta/2))
AngleIntensity = 1.0;
return AngleIntensity;
}
//-----------------------------------------------------------------------
// Pixel shader function
//-----------------------------------------------------------------------
float4 PS_SpotLight( PS_INPUT Vertex ) : SV_Target
{
float A = 1.0;
float B = 0.0;
float C = 0.0;
float3 PixelToLight = (float3)LightPosition - Vertex.InterPos;
float3 NewNormal = normalize(Vertex.Normal);
float3 NewDirection = normalize(PixelToLight);
float LightAtten =1/( A*pow(length(PixelToLight),2.0)+B*length(PixelToLight)+C );
float LightAngle = GetAngleIntensity (normalize(LightDirection), NewDirection);
float4 LightIntensity = LightColor*LightAngle*LightAtten;
float4 FinalColor = saturate(0.3+max(LightIntensity*dot(NewNormal, NewDirection),0) );
FinalColor.a = 1;
return FinalColor;
}
PLEASE HELP TO FIGURE IT OUT