summaryrefslogtreecommitdiff
path: root/glsl/shader.frag
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2022-08-11 15:46:36 -0300
committerFrederico Linhares <fred@linhares.blue>2022-08-16 16:22:19 -0300
commiteb6fc926be7f29d6d92f238146180d510d69c79e (patch)
treefd619189a699b2a2d6f80b36aa5dbc1f2a0f0f57 /glsl/shader.frag
parentb8838794e135c1b849ac7a8638ca8e948042ef86 (diff)
feat Create directional light
Diffstat (limited to 'glsl/shader.frag')
-rw-r--r--glsl/shader.frag34
1 files changed, 29 insertions, 5 deletions
diff --git a/glsl/shader.frag b/glsl/shader.frag
index 39aa83c..8ecf883 100644
--- a/glsl/shader.frag
+++ b/glsl/shader.frag
@@ -1,14 +1,38 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
-layout(location = 0) in vec3 in_frag_color;
-layout(location = 1) in vec2 in_frag_texture_coord;
+struct DataTransferObject
+{
+ vec4 frag_color;
+ vec2 frag_texture_coord;
+ vec3 normal;
+};
+
+layout(location = 0) in DataTransferObject in_dto;
layout(location = 0) out vec4 out_color;
-layout(set = 0, binding = 1) uniform sampler2D texture_sampler;
+layout(set = 0, binding = 1) uniform UBODirectionalLight
+{
+ vec3 direction;
+ vec4 color;
+} ubo_directional_light;
+
+layout(set = 1, binding = 1) uniform sampler2D texture_sampler;
-void main()
+void
+main()
{
- out_color = texture(texture_sampler, in_frag_texture_coord);
+ float diffuse_factor =
+ max(dot(in_dto.normal, -ubo_directional_light.direction), 0.0);
+
+ vec4 diff_samp = texture(texture_sampler, in_dto.frag_texture_coord);
+ vec4 ambient = vec4(vec3(in_dto.frag_color), diff_samp.a);
+ vec4 diffuse =
+ vec4(vec3(ubo_directional_light.color * diffuse_factor), diff_samp.a);
+
+ diffuse *= diff_samp;
+ ambient *= diff_samp;
+
+ out_color = (ambient + diffuse);
}