summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/shaders/pointLight.fs9
-rw-r--r--gfx/gl/shaders/pointLight.gs47
-rw-r--r--gfx/gl/shaders/pointLight.vs5
3 files changed, 32 insertions, 29 deletions
diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs
index 18407fe..bd32c05 100644
--- a/gfx/gl/shaders/pointLight.fs
+++ b/gfx/gl/shaders/pointLight.fs
@@ -8,16 +8,19 @@ layout(binding = 1) uniform sampler2D gNormal;
uniform ivec4 viewPort;
uniform vec3 colour;
uniform float kq;
-in vec3 geo_centre;
+in vec4 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 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) {
diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.gs
index 2bd71e9..03d131d 100644
--- a/gfx/gl/shaders/pointLight.gs
+++ b/gfx/gl/shaders/pointLight.gs
@@ -2,43 +2,44 @@
#extension GL_ARB_enhanced_layouts : enable
#extension GL_ARB_shading_language_420pack : enable
-const int maxv = 128;
-const int maxarcs = (maxv / 2) - 1;
-const int minarcs = 10;
-const float tau = radians(360);
-const float scale = 150;
-uniform ivec4 viewPort;
+const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf
+ vec3(-1, 1, 1), // Front-top-left
+ vec3(1, 1, 1), // Front-top-right
+ vec3(-1, -1, 1), // Front-bottom-left
+ vec3(1, -1, 1), // Front-bottom-right
+ vec3(1, -1, -1), // Back-bottom-right
+ vec3(1, 1, 1), // Front-top-right
+ vec3(1, 1, -1), // Back-top-right
+ vec3(-1, 1, 1), // Front-top-left
+ vec3(-1, 1, -1), // Back-top-left
+ vec3(-1, -1, 1), // Front-bottom-left
+ vec3(-1, -1, -1), // Back-bottom-left
+ vec3(1, -1, -1), // Back-bottom-right
+ vec3(-1, 1, -1), // Back-top-left
+ vec3(1, 1, -1) // Back-top-right
+);
+uniform mat4 viewProjection;
in vec3 centre[];
in float size[];
layout(points) in;
-layout(triangle_strip, max_vertices = maxv) out;
-out vec3 geo_centre;
+layout(triangle_strip, max_vertices = cube.length()) out;
+out vec4 geo_centre;
void
-doSeg(float arc, vec2 radius)
+doVertex(int idx)
{
- gl_Position = gl_in[0].gl_Position;
- geo_centre = centre[0];
- EmitVertex();
-
- const vec2 off = vec2(cos(arc), sin(arc)) * radius;
- gl_Position.xy = gl_in[0].gl_Position.xy + off;
- geo_centre = centre[0];
+ gl_Position = viewProjection * (gl_in[0].gl_Position + vec4(cube[idx] * size[0], 1));
+ geo_centre = vec4(centre[0], size[0]);
EmitVertex();
}
void
main()
{
- const vec2 display = viewPort.zw;
- const vec2 ratio = vec2(1, display.x / display.y);
- const vec2 radius = (size[0] * ratio * scale) / gl_in[0].gl_Position.w;
- const float step = tau / clamp(radius.x, minarcs, maxarcs);
- for (float arc = 0; arc < tau; arc += step) {
- doSeg(arc, radius);
+ for (int i = 0; i < cube.length(); ++i) {
+ doVertex(i);
}
- doSeg(tau, radius);
EndPrimitive();
}
diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs
index 6236c33..35682fa 100644
--- a/gfx/gl/shaders/pointLight.vs
+++ b/gfx/gl/shaders/pointLight.vs
@@ -4,7 +4,6 @@ layout(location = 0) in vec3 position;
uniform vec3 colour;
uniform float kq;
-uniform mat4 viewProjection;
out vec3 centre;
out float size;
@@ -13,6 +12,6 @@ void
main()
{
centre = position;
- size = sqrt(256 * max(max(colour.r, colour.g), colour.b) / kq);
- gl_Position = viewProjection * vec4(centre, 1);
+ size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq);
+ gl_Position = vec4(centre, 0);
}