I'm trying to implement lighting in my engine but running into some issue. I'm using Frank Luna's book Beginner's Guide to Programming with DirectX 11, but I'm not sure that I'm reading the descriptions right.
This is the pseudocode that I wrote based on the book's guidelines.
1) Calculate vertex normals for the mesh (on the cpu)
2) Find angle between light direction and vertex normal (in the pixel shader)
angle = max( dotproduct(light_dir, vertex_normal), 0)
3) Find the color of the pixel if the texture was applied to it
textured_pixel_color = sample(texture)
4) Combine the light color with the textured pixel color
final_color = lightColor * textured_pixel_color
5) Combine the intensity with the final_color to get the final_pixel_color_and_intensity
final_pixel_color_and_intensity = angle * final_color
This is it implemented in the pixel shader
cbuffer DirectionalLight : register (b2)
{
float3 LightDirection;
float3 LightColor;
};
struct TexturedLitVertex
{
float4 Pos : SV_POSITION;
float3 Normal: NORMAL;
float2 Uv: TEXCOORD;
};
float4 PS_DirectionalLight(TexturedLitVertex psInput) : SV_Target
{
float4 colorAfterTexture = txDiffuse.Sample(triLinearSampler, psInput.Uv);
float lightNormalAngle = max(dot(LightDirection, psInput.Normal), 0.0f);
return lightNormalAngle * (colorAfterTexture*float4(LightColor, 1.0f));
}
This is the result I'm getting (see image). What could be the problem?