diff options
| author | Mel <einebeere@gmail.com> | 2022-10-23 02:48:51 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-23 02:48:51 +0200 |
| commit | 75a9c87b50cef2f1d749bd9042a9348bc28b4c09 (patch) | |
| tree | 8d82f3cbbb5bdc63c7e5b6431dac3d49b23a478d /assets | |
| parent | 589bfb5cad0052856077ce867f3858ca3741d95d (diff) | |
| download | meowcraft-75a9c87b50cef2f1d749bd9042a9348bc28b4c09.tar.zst meowcraft-75a9c87b50cef2f1d749bd9042a9348bc28b4c09.zip | |
Sun lighting
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/shaders/fragment.glsl | 8 | ||||
| -rw-r--r-- | assets/shaders/vertex.glsl | 6 |
2 files changed, 12 insertions, 2 deletions
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 |
