summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/shaders')
-rw-r--r--gfx/gl/shaders/spotLight.fs12
-rw-r--r--gfx/gl/shaders/spotLight.gs24
-rw-r--r--gfx/gl/shaders/spotLight.vs24
3 files changed, 31 insertions, 29 deletions
diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs
index 6d5d332..ad33458 100644
--- a/gfx/gl/shaders/spotLight.fs
+++ b/gfx/gl/shaders/spotLight.fs
@@ -6,12 +6,10 @@ out vec3 FragColor;
layout(binding = 0) uniform isampler2D gPosition;
layout(binding = 1) uniform sampler2D gNormal;
uniform ivec4 viewPort;
-// uniform vec3 colour;
-// uniform float kq;
-const vec3 colour = vec3(1);
-const float kq = 0.01;
-in vec4 geo_centre;
-in vec4 geo_direction;
+flat in vec4 geo_centre;
+flat in vec4 geo_direction;
+flat in vec3 geo_colour;
+flat in float geo_kq;
void
main()
@@ -32,5 +30,5 @@ main()
if (normalDot < 0) {
discard;
}
- FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist / 1000.0, 2)));
+ FragColor = (geo_colour * normalDot) / (1 + (geo_kq * pow(lightDist / 1000.0, 2)));
}
diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.gs
index a2805fe..194812a 100644
--- a/gfx/gl/shaders/spotLight.gs
+++ b/gfx/gl/shaders/spotLight.gs
@@ -11,17 +11,19 @@ const vec3[] pyramid = vec3[]( // four-sided
);
uniform mat4 viewProjection;
uniform ivec3 viewPoint;
-// uniform float arc;
-const float arc = 1;
-in ivec3 position[];
-in vec3 direction[];
-in float size[];
-in float cosarc[];
+flat in ivec3 position[];
+flat in vec3 direction[];
+flat in vec3 colour[];
+flat in float size[];
+flat in float kq[];
+flat in vec2 arc[];
layout(points) in;
layout(triangle_strip, max_vertices = 8) out;
-out vec4 geo_centre;
-out vec4 geo_direction;
+flat out vec4 geo_centre;
+flat out vec4 geo_direction;
+flat out vec3 geo_colour;
+flat out float geo_kq;
vec3
perp(vec3 a)
@@ -36,14 +38,16 @@ doVertex(vec4 ndcpos)
{
gl_Position = ndcpos;
geo_centre = vec4(position[0], size[0]);
- geo_direction = vec4(direction[0], cosarc[0]);
+ geo_direction = vec4(direction[0], arc[0].x);
+ geo_colour = colour[0];
+ geo_kq = kq[0];
EmitVertex();
}
void
main()
{
- const float base = size[0] * tan(arc / 2);
+ const float base = size[0] * arc[0].y;
const vec3 offx = perp(direction[0]);
const vec3 offy = cross(direction[0], offx);
vec4 out_py[pyramid.length()];
diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs
index a2b755d..8023f18 100644
--- a/gfx/gl/shaders/spotLight.vs
+++ b/gfx/gl/shaders/spotLight.vs
@@ -2,29 +2,29 @@
layout(location = 0) in vec3 v_position;
layout(location = 1) in vec3 v_direction;
-// layout(location = 2) in vec3 colour;
-// layout(location = 3) in float kq;
-// layout(location = 4) in float arc;
+layout(location = 2) in vec3 v_colour;
+layout(location = 3) in float v_kq;
+layout(location = 4) in float v_arc;
layout(location = 5) in mat4 model;
layout(location = 9) in ivec3 modelPos;
-const vec3 colour = vec3(1);
-const float kq = 0.01;
-const float arc = 1;
-
uniform ivec3 viewPoint;
-out ivec3 position;
-out vec3 direction;
-out float size;
-out float cosarc;
+flat out ivec3 position;
+flat out vec3 direction;
+flat out float size;
+flat out vec2 arc; // cos,tan (v_arc/2)
+flat out vec3 colour;
+flat out float kq;
void
main()
{
position = modelPos + ivec3(v_position * mat3(model));
direction = normalize(v_direction * mat3(model));
+ colour = v_colour;
+ kq = v_kq;
size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq);
- cosarc = cos(arc / 2);
+ arc = vec2(cos(v_arc / 2), tan(v_arc / 2));
gl_Position = vec4(position - viewPoint, 0);
}