#define SpotlightArc 10.0f // Spotlight-Cone-Arc, ~(180 / Angle)^2 || 4 = 90°; 16 = 45°
#define SpotlightArc2 9.0f // == SpotlightArc - 1
//Variables
float4x4 matWorld;
float4x4 matWorldViewProj;
float4 vecFog;
float4 vecTime;
float4 vecColor;
float4 vecViewDir;
float4 vecViewPos;
float4 vecSunDir;
float4 vecSunColor;
float4 vecLight;
float4 vecLightPos[8];
float4 vecLightDir[8];
float4 vecLightColor[8];
float fAlpha;
float fAmbient;
//Textures
texture entSkin1;
//Sampler
sampler colorMap = sampler_state
{
Texture = (entSkin1);
AddressU = Wrap;
AddressV = Wrap;
MagFilter = Linear;
MinFilter = Linear;
MipFilter = Linear;
};
//Structs
struct VS_TO_PS // Output to the pixelshader
{
float4 Pos : POSITION;
float Fog : FOG;
float2 Tex0 : TEXCOORD0;
float3 WPos : TEXCOORD1;
float3 Norm : TEXCOORD2;
};
//Vertexshader
VS_TO_PS VS_v0( float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTex0 : TEXCOORD0 )
{
VS_TO_PS Out;
//Do transformations
Out.Pos = mul(inPos,matWorldViewProj);
//Pass the Texcoords
Out.Tex0 = inTex0;
//Vertexposition in worldspace
Out.WPos = mul(inPos,matWorld);
//Vertexnormal
Out.Norm = normalize(mul(inNormal,matWorld));
//Fog
Out.Fog = 1 - (distance(Out.WPos,vecViewPos)-vecFog.x) * vecFog.z;
return Out;
}
//Pixelshader
float4 PS_p0( VS_TO_PS In ) : COLOR
{
float3 LightDir;
float3 Diffuse = fAmbient+saturate(dot(-vecSunDir,In.Norm))*vecSunColor;
float attenuation = 0;
for(int i = 0; i < 8; i++)
{
LightDir = normalize(vecLightPos[i] - In.WPos);
attenuation = saturate(1.0f - length(LightDir/vecLightPos[i].w));
if(vecLightDir[i].w > 0) // Spotlight?
attenuation = saturate(attenuation * dot(-normalize(vecLightDir[i].xyz), LightDir) * SpotlightArc - SpotlightArc2);
Diffuse += saturate(dot(normalize(LightDir),In.Norm))*vecLightColor[i]*attenuation;
}
float4 Color = tex2D(colorMap,In.Tex0);
Color.rgb *= Diffuse;
Color.a = step(0.5,Color.a);
return Color;
}
//////////////////////////////////////////////////////////////////
technique Lighting
{
pass one
{
AlphaTestEnable = True;
zWriteEnable = true;
VertexShader = compile vs_3_0 VS_v0();
PixelShader = compile ps_3_0 PS_p0();
}
}
technique fallback { pass one { } }
This version of the shader uses entity.ambient as ambient brightness only (and supports now 8 lights).
This should work for making things darker
@3run did you set the *entity.red green and blue high enough?
This controlls the light color and brightness.
EDIT: * I mean the entity which you're using as pointlight.
EDIT#2: I've tested it, the pointlight works fine, I guess you left the entity.red / green / blue at default.