feat(render): basic normal-based lighting
This commit is contained in:
parent
5e2cb15e13
commit
22a58044d5
2 changed files with 12 additions and 0 deletions
|
@ -1,10 +1,19 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 tex_coords;
|
||||
layout(location = 1) in vec3 normal;
|
||||
layout(set = 1, binding = 0) uniform texture2D t_diffuse;
|
||||
layout(set = 1, binding = 1) uniform sampler s_diffuse;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
// layout(group = 0, binding = 0) out texture2D;
|
||||
void main() {
|
||||
float ambient = 0.2;
|
||||
vec3 light_dir = normalize(vec3(0.5, 1.0, 0.5));
|
||||
float diffuse = clamp(dot(normalize(normal), light_dir), 0.0, 1.0);
|
||||
float brightness = ambient + (1.0 - ambient) * diffuse;
|
||||
|
||||
out_color = texture(sampler2D(t_diffuse, s_diffuse), tex_coords);
|
||||
out_color.r = clamp(out_color.r * 0.6 * brightness, 0.0, 1.0);
|
||||
out_color.g = clamp(out_color.g * 0.6 * brightness, 0.0, 1.0);
|
||||
out_color.b = clamp(out_color.b * 0.9 * brightness, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
layout(location = 0) in vec3 position;
|
||||
layout(location = 1) in vec3 color;
|
||||
layout(location = 2) in vec3 normal_in;
|
||||
layout(location = 3) in vec2 tex_coords;
|
||||
layout(location = 0) out vec2 tex_coord;
|
||||
layout(location = 1) out vec3 normal;
|
||||
layout(set = 0, binding = 0) uniform UniformBufferObject {
|
||||
mat4x4 projection;
|
||||
} view;
|
||||
void main() {
|
||||
gl_Position = view.projection * vec4(position, 1.0);
|
||||
tex_coord = tex_coords;
|
||||
normal = normal_in;
|
||||
// gl_Position
|
||||
// out_color = color;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue