diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-23 19:07:18 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-23 19:07:18 +0000 |
commit | 50d6f63fb28c82a35e68914fe941b685d26f6e89 (patch) | |
tree | 4a86d800d36341aedee7319307675cd1e6e5b784 /gfx/gl/shaders/pointLight.fs | |
parent | Support setting a viewPort uniform for those shaders which need it (diff) | |
download | ilt-50d6f63fb28c82a35e68914fe941b685d26f6e89.tar.bz2 ilt-50d6f63fb28c82a35e68914fe941b685d26f6e89.tar.xz ilt-50d6f63fb28c82a35e68914fe941b685d26f6e89.zip |
Add rendering support for point lights
Diffstat (limited to 'gfx/gl/shaders/pointLight.fs')
-rw-r--r-- | gfx/gl/shaders/pointLight.fs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs new file mode 100644 index 0000000..18407fe --- /dev/null +++ b/gfx/gl/shaders/pointLight.fs @@ -0,0 +1,27 @@ +#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 vec3 geo_centre; + +void +main() +{ + const vec2 texCoord = gl_FragCoord.xy / viewPort.zw; + const vec3 position = texture(gPosition, texCoord).xyz; + const vec3 normal = texture(gNormal, texCoord).xyz; + const vec3 lightv = position - geo_centre; + const float lightDist = length(lightv); + const vec3 lightDirection = normalize(lightv); + const float normalDot = dot(-lightDirection, normal); + if (normalDot < 0) { + discard; + } + FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2))); +} |