summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/lightingShader.fs
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-01 19:12:04 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-01 19:12:04 +0000
commit3b791f79bf53e481d053ea4516eedce8be3423bf (patch)
tree39817b0996eaa867c7f7abbc5dbd5cb706ecbaa5 /gfx/gl/shaders/lightingShader.fs
parentSomewhat dirty but functional helper to save a texture (diff)
downloadilt-3b791f79bf53e481d053ea4516eedce8be3423bf.tar.bz2
ilt-3b791f79bf53e481d053ea4516eedce8be3423bf.tar.xz
ilt-3b791f79bf53e481d053ea4516eedce8be3423bf.zip
Switch to a deferred lighting based render pipeline
Tidy-up required.
Diffstat (limited to 'gfx/gl/shaders/lightingShader.fs')
-rw-r--r--gfx/gl/shaders/lightingShader.fs62
1 files changed, 62 insertions, 0 deletions
diff --git a/gfx/gl/shaders/lightingShader.fs b/gfx/gl/shaders/lightingShader.fs
new file mode 100644
index 0000000..b0ca20a
--- /dev/null
+++ b/gfx/gl/shaders/lightingShader.fs
@@ -0,0 +1,62 @@
+#version 330 core
+#extension GL_ARB_shading_language_420pack : enable
+
+out vec3 FragColor;
+
+in vec2 TexCoords;
+
+layout(binding = 0) uniform sampler2D gPosition;
+layout(binding = 1) uniform sampler2D gNormal;
+layout(binding = 2) uniform sampler2D gAlbedoSpec;
+
+// struct Light {
+// vec3 Position;
+// vec3 Color;
+
+// float Linear;
+// float Quadratic;
+// float Radius;
+//};
+// const int NR_LIGHTS_MAX = 12;
+// uniform Light lights[NR_LIGHTS_MAX];
+// uniform vec3 viewPos;
+
+uniform vec3 lightDirection = normalize(vec3(1, 0, -1));
+uniform vec3 lightColor = vec3(0.6, 0.6, 0.6);
+uniform vec3 ambientColor = vec3(0.5, 0.5, 0.5);
+
+void
+main()
+{
+ // retrieve data from gbuffer
+ // const vec3 FragPos = texture(gPosition, TexCoords).rgb;
+ const vec3 Normal = texture(gNormal, TexCoords).rgb;
+ const vec3 Diffuse = texture(gAlbedoSpec, TexCoords).rgb;
+ // float Specular = texture(gAlbedoSpec, TexCoords).a;
+
+ // then calculate lighting as usual
+ // vec3 lighting = Diffuse;
+ const vec3 lighting = ambientColor + clamp((dot(-lightDirection, Normal) * lightColor), 0, 0.5);
+ // vec3 viewDir = normalize(viewPos - FragPos);
+ // for (int i = 0; i < NR_LIGHTS_MAX; ++i) {
+ // calculate distance between light source and current fragment
+ // float distance = length(lights[i].Position - FragPos);
+ // if (distance < lights[i].Radius) {
+ // diffuse
+ // vec3 lightDir = normalize(lights[i].Position - FragPos);
+ // vec3 diffuse = max(dot(Normal, lightDir), 0.0) * Diffuse * lights[i].Color;
+ // specular
+ // vec3 halfwayDir = normalize(lightDir + viewDir);
+ // float spec = pow(max(dot(Normal, halfwayDir), 0.0), 16.0);
+ // vec3 specular = lights[i].Color * spec * Specular;
+ // attenuation
+ // float attenuation = 1.0 / (1.0 + lights[i].Linear * distance + lights[i].Quadratic * distance * distance);
+ // diffuse *= attenuation;
+ // specular *= attenuation;
+ // lighting += diffuse + specular;
+ //}
+ //}
+ // FragColor = vec4(lighting, 1.0);
+
+ FragColor = vec3(Diffuse * lighting);
+}