38 lines
1.2 KiB
GLSL
38 lines
1.2 KiB
GLSL
// XC_BUILTIN_FORWARD_LIT_VULKAN_PS
|
|
#version 450
|
|
layout(set = 3, binding = 0) uniform texture2D uBaseColorTexture;
|
|
layout(set = 4, binding = 0) uniform sampler uLinearSampler;
|
|
|
|
layout(set = 1, binding = 0, std140) uniform PerObjectConstants {
|
|
mat4 gProjectionMatrix;
|
|
mat4 gViewMatrix;
|
|
mat4 gModelMatrix;
|
|
mat4 gNormalMatrix;
|
|
vec4 gMainLightDirectionAndIntensity;
|
|
vec4 gMainLightColorAndFlags;
|
|
};
|
|
|
|
layout(set = 2, binding = 0, std140) uniform MaterialConstants {
|
|
vec4 gBaseColorFactor;
|
|
};
|
|
|
|
layout(location = 0) in vec3 vNormalWS;
|
|
layout(location = 1) in vec2 vTexCoord;
|
|
|
|
layout(location = 0) out vec4 fragColor;
|
|
|
|
void main() {
|
|
vec4 baseColor = texture(sampler2D(uBaseColorTexture, uLinearSampler), vTexCoord) * gBaseColorFactor;
|
|
if (gMainLightColorAndFlags.w < 0.5) {
|
|
fragColor = baseColor;
|
|
return;
|
|
}
|
|
|
|
vec3 normalWS = normalize(vNormalWS);
|
|
vec3 directionToLightWS = normalize(gMainLightDirectionAndIntensity.xyz);
|
|
float diffuse = max(dot(normalWS, directionToLightWS), 0.0);
|
|
vec3 lighting = vec3(0.28) +
|
|
gMainLightColorAndFlags.rgb * (diffuse * gMainLightDirectionAndIntensity.w);
|
|
fragColor = vec4(baseColor.rgb * lighting, baseColor.a);
|
|
}
|