minecraftvulkan/res/shaders/simple_shader.vert

34 lines
829 B
GLSL
Raw Normal View History

2022-09-19 01:20:51 +00:00
#version 450
2022-09-21 02:02:58 +00:00
layout (location = 0) in vec3 position;
2022-09-26 03:08:03 +00:00
layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 uv;
layout (location = 3) in int tex;
2022-09-19 01:20:51 +00:00
2022-09-27 16:32:09 +00:00
layout (location = 0) out float fragLight;
2022-09-21 02:02:58 +00:00
layout (location = 1) out vec2 fragUv;
layout (location = 2) out int fragTex;
2022-09-19 01:20:51 +00:00
2022-09-21 02:02:58 +00:00
layout (binding = 0) uniform GlobalUbo {
2022-09-19 01:20:51 +00:00
mat4 projectionViewMatrix;
vec3 directionToLight;
} ubo;
2022-09-21 02:02:58 +00:00
layout (push_constant) uniform Push {
2022-09-19 01:20:51 +00:00
mat4 modelMatrix;
mat4 normalMatrix;
} push;
const float AMBIENT = 0.02;
void main() {
gl_Position = ubo.projectionViewMatrix * push.modelMatrix * vec4(position, 1.0);
vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal);
float lightIntensity = AMBIENT + max(dot(normalWorldSpace, ubo.directionToLight), 0);
2022-09-27 16:32:09 +00:00
fragLight = lightIntensity / 5;
2022-09-21 02:02:58 +00:00
fragUv = uv;
2022-09-26 22:03:07 +00:00
fragTex = tex;
2022-09-19 01:20:51 +00:00
}