diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-13 10:05:44 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-13 10:05:44 +0000 |
commit | eb2094a1641c333a6e6f953e3b37aa962937cd59 (patch) | |
tree | 01908d3a3d5bf28a96784bbb2e931e46a53a5090 /gfx/gl/shaders | |
parent | Add model support for point lights (diff) | |
download | ilt-eb2094a1641c333a6e6f953e3b37aa962937cd59.tar.bz2 ilt-eb2094a1641c333a6e6f953e3b37aa962937cd59.tar.xz ilt-eb2094a1641c333a6e6f953e3b37aa962937cd59.zip |
Update point light shaders for instancing
Diffstat (limited to 'gfx/gl/shaders')
-rw-r--r-- | gfx/gl/shaders/pointLight.fs | 8 | ||||
-rw-r--r-- | gfx/gl/shaders/pointLight.gs | 15 | ||||
-rw-r--r-- | gfx/gl/shaders/pointLight.vs | 22 |
3 files changed, 28 insertions, 17 deletions
diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs index ba327b6..7531d3e 100644 --- a/gfx/gl/shaders/pointLight.fs +++ b/gfx/gl/shaders/pointLight.fs @@ -6,9 +6,9 @@ out vec3 FragColor; layout(binding = 0) uniform isampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; -uniform vec3 colour; -uniform float kq; -in vec4 geo_centre; +flat in vec4 geo_centre; +flat in vec3 geo_colour; +flat in float geo_kq; void main() @@ -26,5 +26,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/pointLight.gs b/gfx/gl/shaders/pointLight.gs index 9c41ed4..fc1d7c3 100644 --- a/gfx/gl/shaders/pointLight.gs +++ b/gfx/gl/shaders/pointLight.gs @@ -20,19 +20,24 @@ const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf ); uniform mat4 viewProjection; uniform ivec3 viewPoint; - -in vec3 centre[]; -in float size[]; +flat in vec3 position[]; +flat in vec3 colour[]; +flat in float size[]; +flat in float kq[]; layout(points) in; layout(triangle_strip, max_vertices = cube.length()) out; -out vec4 geo_centre; +flat out vec4 geo_centre; +flat out vec3 geo_colour; +flat out float geo_kq; void doVertex(int idx) { gl_Position = viewProjection * (gl_in[0].gl_Position + vec4(cube[idx] * size[0], 1)); - geo_centre = vec4(centre[0], size[0]); + geo_centre = vec4(position[0], size[0]); + geo_colour = colour[0]; + geo_kq = kq[0]; EmitVertex(); } diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs index 00a34a3..c538207 100644 --- a/gfx/gl/shaders/pointLight.vs +++ b/gfx/gl/shaders/pointLight.vs @@ -1,18 +1,24 @@ #version 330 core -layout(location = 0) in vec3 position; +layout(location = 0) in vec3 v_position; +layout(location = 1) in vec3 v_colour; +layout(location = 2) in float v_kq; +layout(location = 3) in mat4 model; +layout(location = 7) in ivec3 modelPos; -uniform vec3 colour; -uniform float kq; uniform ivec3 viewPoint; -out vec3 centre; -out float size; +flat out vec3 position; +flat out vec3 colour; +flat out float size; +flat out float kq; void main() { - centre = position; - size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); - gl_Position = vec4(centre - viewPoint, 0); + position = modelPos + ivec3(mat3(model) * v_position); + kq = v_kq; + size = (8000 * sqrt(max(max(v_colour.r, v_colour.g), v_colour.b))) / sqrt(v_kq); + colour = v_colour; + gl_Position = vec4(position - viewPoint, 0); } |