cbuffer MatrixBuffer : register(vs, cb0)
{
    matrix worldMatrix;
    matrix viewMatrix;
    matrix projectionMatrix;
};

cbuffer CameraBuffer : register(vs, cb1)
{
    float3 cameraPosition;
	float CameraBuffer_padding;
};

struct VertexInputType
{
    float4 position : POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
//	float3 tangent : TANGENT;
};

struct PixelInputType
{
    float4 position : SV_POSITION;
	float4 worldPosition : POSITION1;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
//	float3 tangent : TANGENT;
	float3 viewDirection : TEXCOORD1;
};

PixelInputType LightVertexShader(VertexInputType input)
{
    PixelInputType output;
    float4 worldPosition;
	matrix normalTransform;

    // Change the position vector to be 4 units for proper matrix calculations.
    input.position.w = 1.0f;
	
    normalTransform = worldMatrix;

    // Calculate the position of the vertex against the world, view, and projection matrices.
    output.worldPosition = mul(input.position, normalTransform);
    output.position = mul(output.worldPosition, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    // Store the texture coordinates for the pixel shader.
    output.tex = input.tex;

    // Calculate the normal vector against the world matrix only.
    output.normal = mul(input.normal, (float3x3)normalTransform);

    // Normalize the normal vector.
    output.normal = normalize(output.normal);

	// Calculate the position of the vertex in the world.
    worldPosition = mul(input.position, normalTransform);
	
    // Determine the viewing direction based on the position of the camera and the position of the vertex in the world.
    output.viewDirection = cameraPosition.xyz - worldPosition.xyz;
	
    // Normalize the viewing direction vector.
    output.viewDirection = normalize(output.viewDirection);
	
    return output;
}