diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-27 12:38:26 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-27 12:38:26 +0000 |
commit | a21cbb6fa7c62014eb5ffea6c8f096c2b0737c38 (patch) | |
tree | 1ea0302585fd3b169721bce82ef3d3f203a8173f /gfx/gl/shaders/pointLight.gs | |
parent | Add light stage to renderable objects (diff) | |
download | ilt-a21cbb6fa7c62014eb5ffea6c8f096c2b0737c38.tar.bz2 ilt-a21cbb6fa7c62014eb5ffea6c8f096c2b0737c38.tar.xz ilt-a21cbb6fa7c62014eb5ffea6c8f096c2b0737c38.zip |
Change pointlight render area definition to a cube
Diffstat (limited to 'gfx/gl/shaders/pointLight.gs')
-rw-r--r-- | gfx/gl/shaders/pointLight.gs | 47 |
1 files changed, 24 insertions, 23 deletions
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(); } |