diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-02-06 19:56:46 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-02-06 19:56:46 +0000 |
| commit | 99f5033fdc6e2701bf5bb76e89e100a846cbba80 (patch) | |
| tree | b72ec7920738132166daab88b6fdb895819dac04 /gfx/gl/shaders/pointLight.frag | |
| parent | Add glDebugScope (diff) | |
| parent | Make similar array tidy-up to networkStraight shaders (diff) | |
| download | ilt-99f5033fdc6e2701bf5bb76e89e100a846cbba80.tar.bz2 ilt-99f5033fdc6e2701bf5bb76e89e100a846cbba80.tar.xz ilt-99f5033fdc6e2701bf5bb76e89e100a846cbba80.zip | |
Merge branch 'glmax'
Diffstat (limited to 'gfx/gl/shaders/pointLight.frag')
| -rw-r--r-- | gfx/gl/shaders/pointLight.frag | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/gfx/gl/shaders/pointLight.frag b/gfx/gl/shaders/pointLight.frag new file mode 100644 index 0000000..bb2c453 --- /dev/null +++ b/gfx/gl/shaders/pointLight.frag @@ -0,0 +1,29 @@ +#version 460 core + +out vec3 FragColor; + +layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 1) uniform sampler2D gNormal; +uniform ivec4 viewPort; +flat in vec4 geo_centre; +flat in vec3 geo_colour; +flat in float geo_kq; + +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 normal = texture(gNormal, texCoord).xyz; + const vec3 lightDirection = normalize(lightv); + const float normalDot = dot(-lightDirection, normal); + if (normalDot < 0) { + discard; + } + FragColor = (geo_colour * normalDot) / (1 + (geo_kq * pow(lightDist / 1000.0, 2))); +} |
