From 65c0f5ae4a9fb290239f2407b58bf0b893126a2e Mon Sep 17 00:00:00 2001
From: xkamikoo <58092037+xkamikoo@users.noreply.github.com>
Date: Sun, 24 Jan 2021 01:02:35 +0100
Subject: [PATCH] shaders for bloom (i'm working on it!)
---
grk-project.vcxproj | 8 +++---
grk-project.vcxproj.filters | 6 +++++
shaders/shader_bloom.frag | 50 +++++++++++++++++++++++++++++++++++++
shaders/shader_bloom.vert | 22 ++++++++++++++++
4 files changed, 83 insertions(+), 3 deletions(-)
create mode 100644 shaders/shader_bloom.frag
create mode 100644 shaders/shader_bloom.vert
diff --git a/grk-project.vcxproj b/grk-project.vcxproj
index 9bed514..09917c8 100644
--- a/grk-project.vcxproj
+++ b/grk-project.vcxproj
@@ -15,6 +15,8 @@
+
+
@@ -47,7 +49,7 @@
{1B448102-E76C-4347-BDC7-40D02A567DB6}
Win32Proj
grk-cw9
- 10.0
+ 10.0.17134.0
grk-project
@@ -55,14 +57,14 @@
Application
true
Unicode
- v142
+ v141
Application
false
true
Unicode
- v142
+ v141
diff --git a/grk-project.vcxproj.filters b/grk-project.vcxproj.filters
index 0110884..af35209 100644
--- a/grk-project.vcxproj.filters
+++ b/grk-project.vcxproj.filters
@@ -48,6 +48,12 @@
Shader Files
+
+ Shader Files
+
+
+ Shader Files
+
diff --git a/shaders/shader_bloom.frag b/shaders/shader_bloom.frag
new file mode 100644
index 0000000..f7d6ce8
--- /dev/null
+++ b/shaders/shader_bloom.frag
@@ -0,0 +1,50 @@
+#version 430 core
+layout (location = 0) out vec4 fragColor;
+layout (location = 1) out vec4 BrightColor;
+
+in vec3 fragPos;
+in vec3 interpNormal;
+in vec2 vTexCoords;
+
+struct PointLight {
+ vec3 position;
+ vec3 color;
+};
+
+#define NR_POINT_LIGHTS 2
+
+uniform vec3 objectColor;
+uniform vec3 lightPos;
+uniform vec3 cameraPos;
+uniform sampler2D colorTexture;
+uniform PointLight pointLights[NR_POINT_LIGHTS];
+
+void main()
+{
+ vec3 result = vec3(0,0,0);
+ vec4 textureColor = texture2D(colorTexture, -vTexCoords);
+ vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor;
+ vec3 normal = normalize(interpNormal);
+ for(int i = 0; i < NR_POINT_LIGHTS; i++)
+ {
+ vec3 lightDir = normalize(pointLights[i].position - fragPos);
+
+ vec3 V = normalize(cameraPos-fragPos);
+ vec3 R = reflect(-normalize(lightDir),normal);
+
+ float specular = pow(max(0,dot(R,V)),10);
+ float diffuse = max(0,dot(normal,normalize(lightDir)));
+ vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * pointLights[i].color;
+ result += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
+ }
+
+ result = (fragColor + ambient).xyz;
+
+ // check whether result is higher than some threshold, if so, output as bloom threshold color
+ float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
+ if(brightness > 1.0)
+ BrightColor = vec4(result, 1.0);
+ else
+ BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
+ fragColor = vec4(result, 1.0);
+}
\ No newline at end of file
diff --git a/shaders/shader_bloom.vert b/shaders/shader_bloom.vert
new file mode 100644
index 0000000..fb0bd99
--- /dev/null
+++ b/shaders/shader_bloom.vert
@@ -0,0 +1,22 @@
+#version 330 core
+layout (location = 0) in vec3 vertexPosition;
+layout (location = 1) in vec3 vertexNormal;
+layout (location = 2) in vec2 vertexTexCoords;
+
+out vec3 fragPos;
+out vec3 interpNormal;
+out vec2 vTexCoords;
+
+uniform mat4 transformation;
+uniform mat4 matrixModel;
+
+void main()
+{
+ fragPos = vec3(matrixModel * vec4(vertexPosition, 1.0));
+ vTexCoords = vertexTexCoords;
+
+ mat3 normalMatrix = transpose(inverse(mat3(matrixModel)));
+ interpNormal = normalize(normalMatrix * vertexNormal);
+
+ gl_Position = transformation * matrixModel * vec4(vertexPosition, 1.0);
+}
\ No newline at end of file