37 lines
1.1 KiB
HLSL
37 lines
1.1 KiB
HLSL
// XC_BUILTIN_FORWARD_LIT_D3D12_PS
|
|
Texture2D gBaseColorTexture : register(t1);
|
|
SamplerState gLinearSampler : register(s1);
|
|
|
|
cbuffer PerObjectConstants : register(b1) {
|
|
float4x4 gProjectionMatrix;
|
|
float4x4 gViewMatrix;
|
|
float4x4 gModelMatrix;
|
|
float4x4 gNormalMatrix;
|
|
float4 gMainLightDirectionAndIntensity;
|
|
float4 gMainLightColorAndFlags;
|
|
};
|
|
|
|
cbuffer MaterialConstants : register(b2) {
|
|
float4 gBaseColorFactor;
|
|
};
|
|
|
|
struct PSInput {
|
|
float4 position : SV_POSITION;
|
|
float3 normalWS : TEXCOORD0;
|
|
float2 texcoord : TEXCOORD1;
|
|
};
|
|
|
|
float4 MainPS(PSInput input) : SV_TARGET {
|
|
float4 baseColor = gBaseColorTexture.Sample(gLinearSampler, input.texcoord) * gBaseColorFactor;
|
|
if (gMainLightColorAndFlags.a < 0.5f) {
|
|
return baseColor;
|
|
}
|
|
|
|
float3 normalWS = normalize(input.normalWS);
|
|
float3 directionToLightWS = normalize(gMainLightDirectionAndIntensity.xyz);
|
|
float diffuse = saturate(dot(normalWS, directionToLightWS));
|
|
float3 lighting = float3(0.28f, 0.28f, 0.28f) +
|
|
gMainLightColorAndFlags.rgb * (diffuse * gMainLightDirectionAndIntensity.w);
|
|
return float4(baseColor.rgb * lighting, baseColor.a);
|
|
}
|