From 356e874050e5ad5af87b04a2bb01ce34a86640bb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 13 Nov 2023 00:17:11 +0000 Subject: Send position and rotation matrix to GPU separately --- gfx/gl/shaders/commonPoint.glsl | 2 +- gfx/gl/shaders/commonShadowPoint.glsl | 3 ++- gfx/gl/shaders/dynamicPoint.vs | 2 ++ gfx/gl/shaders/dynamicPointInst.vs | 2 ++ gfx/gl/shaders/fixedPoint.vs | 2 ++ gfx/gl/shaders/pointLight.gs | 1 + gfx/gl/shaders/pointLight.vs | 3 ++- gfx/gl/shaders/shadowDynamicPoint.vs | 2 ++ gfx/gl/shaders/shadowDynamicPointInst.vs | 2 ++ gfx/gl/shaders/shadowFixedPoint.vs | 2 ++ gfx/gl/shaders/spotLight.gs | 1 + gfx/gl/shaders/spotLight.vs | 3 ++- gfx/gl/shaders/water.vs | 7 ++++--- 13 files changed, 25 insertions(+), 7 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/commonPoint.glsl b/gfx/gl/shaders/commonPoint.glsl index 35510e1..046da27 100644 --- a/gfx/gl/shaders/commonPoint.glsl +++ b/gfx/gl/shaders/commonPoint.glsl @@ -24,5 +24,5 @@ main() Colour = colour; Material = getMaterialDetail(material); - gl_Position = viewProjection * worldPos; + gl_Position = viewProjection * vec4(FragPos - viewPoint + modelPos, 1); } diff --git a/gfx/gl/shaders/commonShadowPoint.glsl b/gfx/gl/shaders/commonShadowPoint.glsl index c7cbd3e..216642e 100644 --- a/gfx/gl/shaders/commonShadowPoint.glsl +++ b/gfx/gl/shaders/commonShadowPoint.glsl @@ -1,6 +1,7 @@ void main() { - gl_Position = viewProjection * model * vec4(position, 1.0); + vec4 worldPos = model * vec4(position, 1.0); + gl_Position = viewProjection * vec4(worldPos.xyz - viewPoint + modelPos, 1); gl_Position.z = max(gl_Position.z, -1); } diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs index 961535c..9dd6a47 100644 --- a/gfx/gl/shaders/dynamicPoint.vs +++ b/gfx/gl/shaders/dynamicPoint.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform mat4 model; +uniform vec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs index 2d6cee5..4ae6813 100644 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ b/gfx/gl/shaders/dynamicPointInst.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; layout(location = 5) in mat4 model; +layout(location = 9) in vec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs index ed78c96..0adbb02 100644 --- a/gfx/gl/shaders/fixedPoint.vs +++ b/gfx/gl/shaders/fixedPoint.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; const mat4 model = mat4(1); +const vec3 modelPos = vec3(0); include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.gs index 03d131d..ec089f5 100644 --- a/gfx/gl/shaders/pointLight.gs +++ b/gfx/gl/shaders/pointLight.gs @@ -19,6 +19,7 @@ const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf vec3(1, 1, -1) // Back-top-right ); uniform mat4 viewProjection; +uniform vec3 viewPoint; in vec3 centre[]; in float size[]; diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs index 35682fa..b3fe7b9 100644 --- a/gfx/gl/shaders/pointLight.vs +++ b/gfx/gl/shaders/pointLight.vs @@ -4,6 +4,7 @@ layout(location = 0) in vec3 position; uniform vec3 colour; uniform float kq; +uniform vec3 viewPoint; out vec3 centre; out float size; @@ -13,5 +14,5 @@ main() { centre = position; size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); - gl_Position = vec4(centre, 0); + gl_Position = vec4(centre - viewPoint, 0); } diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs index f3ed533..eb25423 100644 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ b/gfx/gl/shaders/shadowDynamicPoint.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform mat4 model; +uniform vec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs index 1bf74ef..a0f51c3 100644 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ b/gfx/gl/shaders/shadowDynamicPointInst.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; layout(location = 5) in mat4 model; +layout(location = 9) in vec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs index 8921707..dfc5c42 100644 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ b/gfx/gl/shaders/shadowFixedPoint.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; const mat4 model = mat4(1); +const vec3 modelPos = vec3(0); include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.gs index ad65675..0529614 100644 --- a/gfx/gl/shaders/spotLight.gs +++ b/gfx/gl/shaders/spotLight.gs @@ -10,6 +10,7 @@ const vec3[] pyramid = vec3[]( // four-sided vec3(1, -1, 1) // Front-right ); uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform float arc; in vec3 position[]; diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index dca0854..e61b641 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -6,6 +6,7 @@ uniform vec3 v_direction; uniform vec3 colour; uniform float kq; uniform float arc; +uniform vec3 viewPoint; out vec3 position; out vec3 direction; @@ -19,5 +20,5 @@ main() direction = normalize(v_direction); size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); cosarc = cos(arc / 2); - gl_Position = vec4(position, 0); + gl_Position = vec4(position - viewPoint, 0); } diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs index a21b49f..014499f 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vs @@ -4,17 +4,18 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform vec3 waves; void main() { - vec4 wpos = vec4(position.x + cos(waves.x), position.y + cos(waves.x * waves.y / 2), - cos(waves.x + position.x + (position.y / 8)) * .3, 1.0); + vec3 wpos = vec3(position.x + cos(waves.x), position.y + cos(waves.x * waves.y / 2), + cos(waves.x + position.x + (position.y / 8)) * .3); FragPos = vec3(wpos.xy, position.z); TexCoords = texCoord; Normal = normal; - gl_Position = viewProjection * wpos; + gl_Position = viewProjection * vec4(wpos - viewPoint, 1.0); } -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- gfx/gl/shaders/landmass.fs | 6 +++--- gfx/gl/shaders/pointLight.fs | 2 +- gfx/gl/shaders/pointLight.vs | 2 +- gfx/gl/shaders/spotLight.fs | 2 +- gfx/gl/shaders/spotLight.vs | 2 +- gfx/gl/shaders/water.fs | 2 +- gfx/gl/shaders/water.vs | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs index 4dc92bb..9865d11 100644 --- a/gfx/gl/shaders/landmass.fs +++ b/gfx/gl/shaders/landmass.fs @@ -11,9 +11,9 @@ const vec3 rock = vec3(.2, .2, .1); const vec3 sand = vec3(.76, .7, .5); const vec3 snow = vec3(.97, .97, .99); -const float beachline = .5; -const float snowline_low = 28; -const float snowline_high = 30; +const float beachline = 500; +const float snowline_low = 28000; +const float snowline_high = 30000; const float slope_min = .99; const float slope_mid = .95; diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs index bd32c05..1a68df8 100644 --- a/gfx/gl/shaders/pointLight.fs +++ b/gfx/gl/shaders/pointLight.fs @@ -26,5 +26,5 @@ main() if (normalDot < 0) { discard; } - FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2))); + FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist / 1000.0, 2))); } diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs index b3fe7b9..7694a25 100644 --- a/gfx/gl/shaders/pointLight.vs +++ b/gfx/gl/shaders/pointLight.vs @@ -13,6 +13,6 @@ void main() { centre = position; - size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); + size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); gl_Position = vec4(centre - viewPoint, 0); } diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs index add86fd..78b8f72 100644 --- a/gfx/gl/shaders/spotLight.fs +++ b/gfx/gl/shaders/spotLight.fs @@ -30,5 +30,5 @@ main() if (normalDot < 0) { discard; } - FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2))); + FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist / 1000.0, 2))); } diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index e61b641..08197a4 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -18,7 +18,7 @@ main() { position = v_position; direction = normalize(v_direction); - size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); + size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); cosarc = cos(arc / 2); gl_Position = vec4(position - viewPoint, 0); } diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs index 04aa94c..2ccc924 100644 --- a/gfx/gl/shaders/water.fs +++ b/gfx/gl/shaders/water.fs @@ -13,5 +13,5 @@ main() gPosition = vec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = texture(texture0, TexCoords); - gAlbedoSpec.a *= clamp(-FragPos.z * .7, .1, 1.0); + gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0); } diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs index 014499f..03eabb2 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vs @@ -10,8 +10,8 @@ uniform vec3 waves; void main() { - vec3 wpos = vec3(position.x + cos(waves.x), position.y + cos(waves.x * waves.y / 2), - cos(waves.x + position.x + (position.y / 8)) * .3); + vec3 wpos = vec3(position.x + (cos(waves.x) * 1000.0), position.y + (cos(waves.x * waves.y / 2) * 1000.0), + cos(waves.x + (position.x / 1000.0) + (position.y * 125.0)) * 300.0); FragPos = vec3(wpos.xy, position.z); TexCoords = texCoord; -- cgit v1.2.3 From 0aa665c3648d788755b00c9e431c872d57fddbb8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 16:28:39 +0000 Subject: Model positions as integers Introduces test failure in arcs due to rounding, but I don't want to create a complicated fix as link positions are still floats and hopefully that'll go away... somehow --- gfx/gl/shaders/dynamicPoint.vs | 2 +- gfx/gl/shaders/dynamicPointInst.vs | 2 +- gfx/gl/shaders/fixedPoint.vs | 2 +- gfx/gl/shaders/shadowDynamicPoint.vs | 2 +- gfx/gl/shaders/shadowDynamicPointInst.vs | 2 +- gfx/gl/shaders/shadowFixedPoint.vs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs index 9dd6a47..667f247 100644 --- a/gfx/gl/shaders/dynamicPoint.vs +++ b/gfx/gl/shaders/dynamicPoint.vs @@ -7,6 +7,6 @@ include(`materialInterface.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; uniform mat4 model; -uniform vec3 modelPos; +uniform ivec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs index 4ae6813..adf39bd 100644 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ b/gfx/gl/shaders/dynamicPointInst.vs @@ -7,6 +7,6 @@ include(`materialInterface.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; layout(location = 5) in mat4 model; -layout(location = 9) in vec3 modelPos; +layout(location = 9) in ivec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs index 0adbb02..6e1ab49 100644 --- a/gfx/gl/shaders/fixedPoint.vs +++ b/gfx/gl/shaders/fixedPoint.vs @@ -7,6 +7,6 @@ include(`materialInterface.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; const mat4 model = mat4(1); -const vec3 modelPos = vec3(0); +const vec3 modelPos = ivec3(0); include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs index eb25423..e20d31a 100644 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ b/gfx/gl/shaders/shadowDynamicPoint.vs @@ -5,6 +5,6 @@ include(`meshIn.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; uniform mat4 model; -uniform vec3 modelPos; +uniform ivec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs index a0f51c3..ab3e976 100644 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ b/gfx/gl/shaders/shadowDynamicPointInst.vs @@ -5,6 +5,6 @@ include(`meshIn.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; layout(location = 5) in mat4 model; -layout(location = 9) in vec3 modelPos; +layout(location = 9) in ivec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs index dfc5c42..a9fb4a3 100644 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ b/gfx/gl/shaders/shadowFixedPoint.vs @@ -5,6 +5,6 @@ include(`meshIn.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; const mat4 model = mat4(1); -const vec3 modelPos = vec3(0); +const ivec3 modelPos = ivec3(0); include(`commonShadowPoint.glsl') -- cgit v1.2.3 From 4e6f8db35ddc8fd3f310bb5616d257b5f9996d94 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 3 Dec 2023 12:37:46 +0000 Subject: Shader viewPoint now an integer --- gfx/gl/shaders/dynamicPoint.vs | 2 +- gfx/gl/shaders/dynamicPointInst.vs | 2 +- gfx/gl/shaders/fixedPoint.vs | 2 +- gfx/gl/shaders/pointLight.gs | 2 +- gfx/gl/shaders/pointLight.vs | 2 +- gfx/gl/shaders/shadowDynamicPoint.vs | 2 +- gfx/gl/shaders/shadowDynamicPointInst.vs | 2 +- gfx/gl/shaders/shadowFixedPoint.vs | 2 +- gfx/gl/shaders/spotLight.gs | 2 +- gfx/gl/shaders/spotLight.vs | 2 +- gfx/gl/shaders/water.vs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs index 667f247..097cd11 100644 --- a/gfx/gl/shaders/dynamicPoint.vs +++ b/gfx/gl/shaders/dynamicPoint.vs @@ -5,7 +5,7 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; uniform mat4 model; uniform ivec3 modelPos; diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs index adf39bd..529fe1d 100644 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ b/gfx/gl/shaders/dynamicPointInst.vs @@ -5,7 +5,7 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; layout(location = 5) in mat4 model; layout(location = 9) in ivec3 modelPos; diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs index 6e1ab49..3cea737 100644 --- a/gfx/gl/shaders/fixedPoint.vs +++ b/gfx/gl/shaders/fixedPoint.vs @@ -5,7 +5,7 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; const mat4 model = mat4(1); const vec3 modelPos = ivec3(0); diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.gs index ec089f5..9c41ed4 100644 --- a/gfx/gl/shaders/pointLight.gs +++ b/gfx/gl/shaders/pointLight.gs @@ -19,7 +19,7 @@ const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf vec3(1, 1, -1) // Back-top-right ); uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; in vec3 centre[]; in float size[]; diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs index 7694a25..00a34a3 100644 --- a/gfx/gl/shaders/pointLight.vs +++ b/gfx/gl/shaders/pointLight.vs @@ -4,7 +4,7 @@ layout(location = 0) in vec3 position; uniform vec3 colour; uniform float kq; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; out vec3 centre; out float size; diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs index e20d31a..f21b3b6 100644 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ b/gfx/gl/shaders/shadowDynamicPoint.vs @@ -3,7 +3,7 @@ include(`meshIn.glsl') uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; uniform mat4 model; uniform ivec3 modelPos; diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs index ab3e976..28a62d9 100644 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ b/gfx/gl/shaders/shadowDynamicPointInst.vs @@ -3,7 +3,7 @@ include(`meshIn.glsl') uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; layout(location = 5) in mat4 model; layout(location = 9) in ivec3 modelPos; diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs index a9fb4a3..168d5f1 100644 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ b/gfx/gl/shaders/shadowFixedPoint.vs @@ -3,7 +3,7 @@ include(`meshIn.glsl') uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; const mat4 model = mat4(1); const ivec3 modelPos = ivec3(0); diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.gs index 0529614..b58c169 100644 --- a/gfx/gl/shaders/spotLight.gs +++ b/gfx/gl/shaders/spotLight.gs @@ -10,7 +10,7 @@ const vec3[] pyramid = vec3[]( // four-sided vec3(1, -1, 1) // Front-right ); uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; uniform float arc; in vec3 position[]; diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index 08197a4..ac1d1db 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -6,7 +6,7 @@ uniform vec3 v_direction; uniform vec3 colour; uniform float kq; uniform float arc; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; out vec3 position; out vec3 direction; diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs index 03eabb2..f609d9e 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vs @@ -4,7 +4,7 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; -uniform vec3 viewPoint; +uniform ivec3 viewPoint; uniform vec3 waves; void -- cgit v1.2.3 From cbc94ed8572cd4ea4e22ad5437b54eea055235d9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 17 Dec 2023 12:14:35 +0000 Subject: Use 32bit integer texture for position render data --- gfx/gl/shaders/directionalLight.fs | 6 +++--- gfx/gl/shaders/landmass.fs | 2 +- gfx/gl/shaders/material.fs | 2 +- gfx/gl/shaders/materialOut.glsl | 2 +- gfx/gl/shaders/pointLight.fs | 2 +- gfx/gl/shaders/spotLight.fs | 2 +- gfx/gl/shaders/water.fs | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs index ca10ef5..3756db7 100644 --- a/gfx/gl/shaders/directionalLight.fs +++ b/gfx/gl/shaders/directionalLight.fs @@ -7,7 +7,7 @@ out vec3 FragColor; in vec2 TexCoords; -layout(binding = 0) uniform sampler2D gPosition; +layout(binding = 0) uniform isampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; layout(binding = 2) uniform sampler2D shadowMap; @@ -27,7 +27,7 @@ insideShadowCube(vec3 v) } float -isShaded(vec3 Position) +isShaded(ivec3 Position) { for (uint m = 0u; m < lightViewProjectionCount; m++) { vec3 PositionInLightSpace = (lightViewProjection[m] * vec4(Position, 1.0f)).xyz; @@ -44,7 +44,7 @@ isShaded(vec3 Position) void main() { - const vec3 Position = texture(gPosition, TexCoords).xyz; + const ivec3 Position = texture(gPosition, TexCoords).xyz; const vec3 Normal = texture(gNormal, TexCoords).rgb; const float shaded = isShaded(Position); FragColor = (1 - shaded) * max(dot(-lightDirection, Normal) * lightColour, 0); diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs index 9865d11..fc43bf2 100644 --- a/gfx/gl/shaders/landmass.fs +++ b/gfx/gl/shaders/landmass.fs @@ -60,7 +60,7 @@ main() } } - gPosition = vec4(FragPos, 1); + gPosition = ivec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = vec4(color, 1); } diff --git a/gfx/gl/shaders/material.fs b/gfx/gl/shaders/material.fs index 20fa8ab..5b93707 100644 --- a/gfx/gl/shaders/material.fs +++ b/gfx/gl/shaders/material.fs @@ -42,7 +42,7 @@ main() { vec4 textureColour = getTextureColour(Material, TexCoords); float opaque = step(0.5, mix(textureColour.a, 1, Colour.a)); - gPosition = vec4(FragPos, opaque); + gPosition = ivec4(FragPos, opaque); gNormal = vec4(Normal, opaque); gl_FragDepth = mix(1.0, gl_FragCoord.z, opaque); gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a); diff --git a/gfx/gl/shaders/materialOut.glsl b/gfx/gl/shaders/materialOut.glsl index dc5f8e8..846825e 100644 --- a/gfx/gl/shaders/materialOut.glsl +++ b/gfx/gl/shaders/materialOut.glsl @@ -1,3 +1,3 @@ -layout(location = 0) out vec4 gPosition; +layout(location = 0) out ivec4 gPosition; layout(location = 1) out vec4 gNormal; layout(location = 2) out vec4 gAlbedoSpec; diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs index 1a68df8..ba327b6 100644 --- a/gfx/gl/shaders/pointLight.fs +++ b/gfx/gl/shaders/pointLight.fs @@ -3,7 +3,7 @@ out vec3 FragColor; -layout(binding = 0) uniform sampler2D gPosition; +layout(binding = 0) uniform isampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; uniform vec3 colour; diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs index 78b8f72..937f922 100644 --- a/gfx/gl/shaders/spotLight.fs +++ b/gfx/gl/shaders/spotLight.fs @@ -3,7 +3,7 @@ out vec3 FragColor; -layout(binding = 0) uniform sampler2D gPosition; +layout(binding = 0) uniform isampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; uniform vec3 colour; diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs index 2ccc924..a0daa17 100644 --- a/gfx/gl/shaders/water.fs +++ b/gfx/gl/shaders/water.fs @@ -10,7 +10,7 @@ uniform vec3 waves; void main() { - gPosition = vec4(FragPos, 1); + gPosition = ivec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = texture(texture0, TexCoords); gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0); -- cgit v1.2.3 From 41fb7a02d7b24c88f91164670a5bf2973fd666f1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 17 Dec 2023 12:42:41 +0000 Subject: Fix output of position data to include model position --- gfx/gl/shaders/commonPoint.glsl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/commonPoint.glsl b/gfx/gl/shaders/commonPoint.glsl index 046da27..a9817fb 100644 --- a/gfx/gl/shaders/commonPoint.glsl +++ b/gfx/gl/shaders/commonPoint.glsl @@ -16,13 +16,11 @@ getMaterialDetail(uint midx) void main() { - vec4 worldPos = model * vec4(position, 1.0); - - FragPos = worldPos.xyz; + FragPos = (model * vec4(position, 1.0)).xyz + modelPos; TexCoords = texCoord; Normal = (model * vec4(normal, 0.0)).xyz; Colour = colour; Material = getMaterialDetail(material); - gl_Position = viewProjection * vec4(FragPos - viewPoint + modelPos, 1); + gl_Position = viewProjection * vec4(FragPos - viewPoint, 1); } -- cgit v1.2.3 From edb63bcb5fd140d0d4db71e170a43f767a4b70be Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 17 Dec 2023 18:58:53 +0000 Subject: Run shadow mapper in camera relative space --- gfx/gl/shaders/directionalLight.fs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs index 3756db7..f36d83f 100644 --- a/gfx/gl/shaders/directionalLight.fs +++ b/gfx/gl/shaders/directionalLight.fs @@ -13,6 +13,7 @@ layout(binding = 2) uniform sampler2D shadowMap; uniform vec3 lightDirection; uniform vec3 lightColour; +uniform ivec3 lightPoint; uniform mat4 lightViewProjection[MAX_MAPS]; uniform vec4 shadowMapRegion[MAX_MAPS]; uniform uint lightViewProjectionCount; @@ -27,10 +28,10 @@ insideShadowCube(vec3 v) } float -isShaded(ivec3 Position) +isShaded(vec4 Position) { for (uint m = 0u; m < lightViewProjectionCount; m++) { - vec3 PositionInLightSpace = (lightViewProjection[m] * vec4(Position, 1.0f)).xyz; + const vec3 PositionInLightSpace = (lightViewProjection[m] * Position).xyz; const float inside = insideShadowCube(PositionInLightSpace); if (inside > 0) { const float lightSpaceDepth @@ -44,7 +45,7 @@ isShaded(ivec3 Position) void main() { - const ivec3 Position = texture(gPosition, TexCoords).xyz; + const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1); const vec3 Normal = texture(gNormal, TexCoords).rgb; const float shaded = isShaded(Position); FragColor = (1 - shaded) * max(dot(-lightDirection, Normal) * lightColour, 0); -- cgit v1.2.3 From 8635bb43078dec951da63e3a4442f6a2f70ac686 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 Jan 2024 11:36:26 +0000 Subject: Simplify and 'fix' the wave cycle --- gfx/gl/shaders/water.fs | 1 - gfx/gl/shaders/water.vs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs index a0daa17..8891733 100644 --- a/gfx/gl/shaders/water.fs +++ b/gfx/gl/shaders/water.fs @@ -5,7 +5,6 @@ include(`materialInterface.glsl') include(`materialOut.glsl') uniform sampler2D texture0; -uniform vec3 waves; void main() diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs index f609d9e..f6c7c8f 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vs @@ -5,13 +5,13 @@ include(`materialInterface.glsl') uniform mat4 viewProjection; uniform ivec3 viewPoint; -uniform vec3 waves; +uniform float waves; void main() { - vec3 wpos = vec3(position.x + (cos(waves.x) * 1000.0), position.y + (cos(waves.x * waves.y / 2) * 1000.0), - cos(waves.x + (position.x / 1000.0) + (position.y * 125.0)) * 300.0); + vec3 wpos = vec3(position.x + (cos(waves) * 1000.0), position.y + (cos(waves * 0 / 2) * 1000.0), + cos(waves + (position.x / 1000000.0) + (position.y / 8000.0)) * 300.0); FragPos = vec3(wpos.xy, position.z); TexCoords = texCoord; -- cgit v1.2.3