summaryrefslogtreecommitdiff
path: root/advanced_lighting/7.bloom/shaders/bloom.frag
diff options
context:
space:
mode:
Diffstat (limited to 'advanced_lighting/7.bloom/shaders/bloom.frag')
-rw-r--r--advanced_lighting/7.bloom/shaders/bloom.frag45
1 files changed, 45 insertions, 0 deletions
diff --git a/advanced_lighting/7.bloom/shaders/bloom.frag b/advanced_lighting/7.bloom/shaders/bloom.frag
new file mode 100644
index 0000000..88decf8
--- /dev/null
+++ b/advanced_lighting/7.bloom/shaders/bloom.frag
@@ -0,0 +1,45 @@
+#version 330 core
+
+in VS_OUT {
+ vec3 position;
+ vec3 normal;
+ vec2 tex_coords;
+} vs_out;
+
+layout(location = 0) out vec4 frag_color;
+layout(location = 1) out vec4 bright_color;
+
+struct light_t {
+ vec3 position;
+ vec3 color;
+};
+
+uniform light_t lights[3];
+uniform sampler2D diffuse_texture;
+uniform vec3 view_pos;
+
+const int light_count = 3;
+
+void main(void)
+{
+ vec3 color = texture(diffuse_texture, vs_out.tex_coords).rgb;
+ vec3 ambient = 0.01 * color;
+ vec3 lighting = vec3(0.0);
+ vec3 view_dir = normalize(view_pos - vs_out.position);
+ for (int i = 0; i < light_count; i++) {
+ vec3 light_dir = normalize(lights[i].position - vs_out.position);
+ float diff = max(dot(light_dir, vs_out.normal), 0.0);
+ vec3 result = lights[i].color * diff * color;
+ float distance = length(vs_out.position - lights[i].position);
+ result *= 1.0 / (distance * distance);
+ lighting += result;
+ }
+ vec3 result = ambient + lighting;
+ float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
+ if (brightness > 1.0) {
+ bright_color = vec4(result, 1.0);
+ } else {
+ bright_color = vec4(0.0, 0.0, 0.0, 1.0);
+ }
+ frag_color = vec4(result, 1.0);
+}