From 75a9c87b50cef2f1d749bd9042a9348bc28b4c09 Mon Sep 17 00:00:00 2001 From: Mel Date: Sun, 23 Oct 2022 02:48:51 +0200 Subject: Sun lighting --- assets/shaders/fragment.glsl | 8 +++++++- assets/shaders/vertex.glsl | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'assets') diff --git a/assets/shaders/fragment.glsl b/assets/shaders/fragment.glsl index f8e9e46..eca50d9 100644 --- a/assets/shaders/fragment.glsl +++ b/assets/shaders/fragment.glsl @@ -1,11 +1,17 @@ #version 330 core uniform sampler2D tex; +uniform vec3 sun_direction; +in vec3 surface_normal; in vec2 frag_tex_coord; out vec4 color; void main() { - color = texture(tex, frag_tex_coord); + float brightness = dot(normalize(surface_normal), normalize(-sun_direction)); + vec3 diffuse = vec3(max(brightness, 0.3)); + + color = vec4(diffuse, 1.0) * texture(tex, frag_tex_coord); + // color = texture(tex, frag_tex_coord); } \ No newline at end of file diff --git a/assets/shaders/vertex.glsl b/assets/shaders/vertex.glsl index 1ad43f4..c59d6cd 100644 --- a/assets/shaders/vertex.glsl +++ b/assets/shaders/vertex.glsl @@ -5,11 +5,15 @@ uniform mat4 view_matrix; uniform mat4 projection_matrix; layout (location = 0) in vec3 position; -layout (location = 1) in vec2 tex_coord; +layout (location = 1) in vec3 normal; +layout (location = 2) in vec2 tex_coord; out vec2 frag_tex_coord; +out vec3 surface_normal; void main() { gl_Position = projection_matrix * view_matrix * model_matrix * vec4(position, 1.0); frag_tex_coord = tex_coord; + + surface_normal = (model_matrix * vec4(normal, 0.0)).xyz; } \ No newline at end of file -- cgit 1.4.1