Ivan Belyavtsev
08.07.2022
\[L_d = k_dI\max(0, \vec{n}\cdot\vec{l})\]
where \(L_d\) - diffusely reflected light,
\(k_d\) - material’s diffuse coefficient,
\(\vec{n}\) - surface normal,
\(\vec{l}\) - direction toward the light [1]
cbuffer ConstantBuffer: register(b0)
{
float4x4 mwpMatrix;
}
Texture2D g_texture : register(t0);
SamplerState g_sampler : register(s0);
struct PSInput
{
float4 position : SV_POSITION;
float4 color: COLOR;
float2 uv : TEXCOORD;
float3 world_position : POSITION;
float3 normal : NORMAL;
};
PSInput VSMain(float4 position : POSITION, float4 normal: NORMAL, float4 ambient : COLOR0, float4 diffuse : COLOR1, float4 emissive : COLOR2, float4 texcoords : TEXCOORD)
{
PSInput result;
result.position = mul(mwpMatrix, position);
result.color = ambient;
result.uv = texcoords.xy;
result.world_position = position.xyz;
result.normal = normal.xyz;
return result;
}
float GetLambertIntensity(PSInput input)
{
// (1, 1, 1) is light position in world space
float3 to_light = normalize(float3(1.f, 1.f, 1.f) - input.world_position);
return saturate(dot(input.normal, to_light));
}
float4 PSMain_texture(PSInput input) : SV_TARGET
{
return g_texture.Sample(g_sampler, input.uv);
}