From b8401062e1d3f5e6554ab7fd9b983ea63cfb05c5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 10 Jan 2024 19:04:30 +0000 Subject: Initial commit with working light instancing --- gfx/gl/shaders/spotLight.vs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'gfx/gl/shaders/spotLight.vs') diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index ac1d1db..a2b755d 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -1,14 +1,20 @@ #version 330 core 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 = 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 vec3 v_direction; -uniform vec3 colour; -uniform float kq; -uniform float arc; uniform ivec3 viewPoint; -out vec3 position; +out ivec3 position; out vec3 direction; out float size; out float cosarc; @@ -16,8 +22,8 @@ out float cosarc; void main() { - position = v_position; - direction = normalize(v_direction); + position = modelPos + ivec3(v_position * mat3(model)); + direction = normalize(v_direction * mat3(model)); size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); cosarc = cos(arc / 2); gl_Position = vec4(position - viewPoint, 0); -- cgit v1.2.3 From b6fbe0bf35bf58447f2f83f6fc519b4d3eaea107 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 11 Jan 2024 18:57:57 +0000 Subject: Full implementation passing through light defs from vertex data Note: there is a bug where the light position/direction are rotated backwards to the model even though its using the model's rotation matrix... no idea why/how. --- gfx/gl/shaders/spotLight.vs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'gfx/gl/shaders/spotLight.vs') 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); } -- cgit v1.2.3 From 972d7260affe7f0d8eebaef609f5576a18f66f73 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 12 Jan 2024 19:21:37 +0000 Subject: Fix order or multiple to address reversed rotation --- gfx/gl/shaders/spotLight.vs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shaders/spotLight.vs') diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index 8023f18..eed8778 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -20,8 +20,8 @@ flat out float kq; void main() { - position = modelPos + ivec3(v_position * mat3(model)); - direction = normalize(v_direction * mat3(model)); + position = modelPos + ivec3(mat3(model) * v_position); + direction = normalize(mat3(model) * v_direction); colour = v_colour; kq = v_kq; size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); -- cgit v1.2.3