summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/spotLight.fs
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-01-05 19:45:36 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-01-05 19:45:36 +0000
commit7c1e9b25fa4062a69ea00c20cdbcc745d1b82659 (patch)
tree03a200a82211016a70420930ee88d2afd01f60a5 /gfx/gl/shaders/spotLight.fs
parentInclude uniform name in required uniform does not exist error message (diff)
downloadilt-7c1e9b25fa4062a69ea00c20cdbcc745d1b82659.tar.bz2
ilt-7c1e9b25fa4062a69ea00c20cdbcc745d1b82659.tar.xz
ilt-7c1e9b25fa4062a69ea00c20cdbcc745d1b82659.zip
Add rendering support for spot lights
Diffstat (limited to 'gfx/gl/shaders/spotLight.fs')
-rw-r--r--gfx/gl/shaders/spotLight.fs34
1 files changed, 34 insertions, 0 deletions
diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs
new file mode 100644
index 0000000..add86fd
--- /dev/null
+++ b/gfx/gl/shaders/spotLight.fs
@@ -0,0 +1,34 @@
+#version 330 core
+#extension GL_ARB_shading_language_420pack : enable
+
+out vec3 FragColor;
+
+layout(binding = 0) uniform sampler2D gPosition;
+layout(binding = 1) uniform sampler2D gNormal;
+uniform ivec4 viewPort;
+uniform vec3 colour;
+uniform float kq;
+in vec4 geo_centre;
+in vec4 geo_direction;
+
+void
+main()
+{
+ const vec2 texCoord = gl_FragCoord.xy / viewPort.zw;
+ const vec3 position = texture(gPosition, texCoord).xyz;
+ const vec3 lightv = position - geo_centre.xyz;
+ const float lightDist = length(lightv);
+ if (lightDist > geo_centre.w) {
+ discard;
+ }
+ const vec3 lightDirection = normalize(lightv);
+ if (dot(lightDirection, geo_direction.xyz) < geo_direction.w) {
+ discard;
+ }
+ const vec3 normal = texture(gNormal, texCoord).xyz;
+ const float normalDot = dot(-lightDirection, normal);
+ if (normalDot < 0) {
+ discard;
+ }
+ FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2)));
+}