From 43d8fdb3f6aeb88762c68179d7bb1dc58507bb60 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 11 Apr 2023 18:54:41 +0100 Subject: Move lots of common glsl interface to include files --- gfx/gl/shaders/basicShader.fs | 5 +---- gfx/gl/shaders/basicShader.vs | 6 +----- gfx/gl/shaders/geometryOut.glsl | 3 +++ gfx/gl/shaders/landmassShader.fs | 5 +---- gfx/gl/shaders/landmassShader.vs | 6 +----- gfx/gl/shaders/meshIn.glsl | 4 ++++ gfx/gl/shaders/shadowDynamicPoint.vs | 2 +- gfx/gl/shaders/shadowFixedPoint.vs | 2 +- gfx/gl/shaders/waterShader.fs | 5 +---- gfx/gl/shaders/waterShader.vs | 5 +---- 10 files changed, 15 insertions(+), 28 deletions(-) create mode 100644 gfx/gl/shaders/geometryOut.glsl create mode 100644 gfx/gl/shaders/meshIn.glsl (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs index 24b2791..0d0b904 100644 --- a/gfx/gl/shaders/basicShader.fs +++ b/gfx/gl/shaders/basicShader.fs @@ -4,10 +4,7 @@ in vec3 FragPos; in vec2 TexCoords; in vec3 Normal; in vec4 Colour; - -out vec4 gPosition; -out vec4 gNormal; -out vec4 gAlbedoSpec; +include(`geometryOut.glsl') uniform sampler2D texture0; diff --git a/gfx/gl/shaders/basicShader.vs b/gfx/gl/shaders/basicShader.vs index ff9a401..a96d478 100644 --- a/gfx/gl/shaders/basicShader.vs +++ b/gfx/gl/shaders/basicShader.vs @@ -1,10 +1,6 @@ #version 330 core -in vec3 position; -in vec2 texCoord; -in vec3 normal; -in vec4 colour; - +include(`meshIn.glsl') out vec3 FragPos; out vec2 TexCoords; out vec3 Normal; diff --git a/gfx/gl/shaders/geometryOut.glsl b/gfx/gl/shaders/geometryOut.glsl new file mode 100644 index 0000000..dc5f8e8 --- /dev/null +++ b/gfx/gl/shaders/geometryOut.glsl @@ -0,0 +1,3 @@ +layout(location = 0) out vec4 gPosition; +layout(location = 1) out vec4 gNormal; +layout(location = 2) out vec4 gAlbedoSpec; diff --git a/gfx/gl/shaders/landmassShader.fs b/gfx/gl/shaders/landmassShader.fs index 7c08e8e..5daeeb6 100644 --- a/gfx/gl/shaders/landmassShader.fs +++ b/gfx/gl/shaders/landmassShader.fs @@ -3,10 +3,7 @@ in vec3 FragPos; in vec2 TexCoords; in vec3 Normal; - -layout(location = 0) out vec4 gPosition; -layout(location = 1) out vec4 gNormal; -layout(location = 2) out vec4 gAlbedoSpec; +include(`geometryOut.glsl') uniform sampler2D texture0; diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs index 30c4ef4..3eb9aa3 100644 --- a/gfx/gl/shaders/landmassShader.vs +++ b/gfx/gl/shaders/landmassShader.vs @@ -1,10 +1,6 @@ #version 330 core -in vec3 position; -in vec2 texCoord; -in vec3 normal; -in vec4 colour; - +include(`meshIn.glsl') out vec3 FragPos; out vec2 TexCoords; out vec3 Normal; diff --git a/gfx/gl/shaders/meshIn.glsl b/gfx/gl/shaders/meshIn.glsl new file mode 100644 index 0000000..2b244c1 --- /dev/null +++ b/gfx/gl/shaders/meshIn.glsl @@ -0,0 +1,4 @@ +layout(location = 0) in vec3 position; +layout(location = 1) in vec2 texCoord; +layout(location = 2) in vec3 normal; +layout(location = 3) in vec4 colour; diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs index 6ea352f..531d8de 100644 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ b/gfx/gl/shaders/shadowDynamicPoint.vs @@ -1,6 +1,6 @@ #version 330 core -in vec3 position; +include(`meshIn.glsl') uniform mat4 viewProjection; uniform mat4 model; diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs index 246890c..c9fa19b 100644 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ b/gfx/gl/shaders/shadowFixedPoint.vs @@ -1,6 +1,6 @@ #version 330 core -layout(location = 0) in vec3 position; +include(`meshIn.glsl') uniform mat4 viewProjection; diff --git a/gfx/gl/shaders/waterShader.fs b/gfx/gl/shaders/waterShader.fs index d242566..d457f27 100644 --- a/gfx/gl/shaders/waterShader.fs +++ b/gfx/gl/shaders/waterShader.fs @@ -4,10 +4,7 @@ in vec3 FragPos; in vec2 TexCoords; in vec3 Normal; - -out vec4 gPosition; -out vec4 gNormal; -out vec4 gAlbedoSpec; +include(`geometryOut.glsl') uniform sampler2D texture0; uniform vec3 waves; diff --git a/gfx/gl/shaders/waterShader.vs b/gfx/gl/shaders/waterShader.vs index fe9206f..6f96c19 100644 --- a/gfx/gl/shaders/waterShader.vs +++ b/gfx/gl/shaders/waterShader.vs @@ -1,9 +1,6 @@ #version 330 core -in vec3 position; -in vec2 texCoord; -in vec3 normal; - +include(`meshIn.glsl') out vec3 FragPos; out vec2 TexCoords; out vec3 Normal; -- cgit v1.2.3 From d0186d81127056ac2647807dcf05b454e234a7cb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 11 Apr 2023 22:54:44 +0100 Subject: Move the vertex/fragment shader interface for materials into an include --- gfx/gl/shaders/basicShader.fs | 5 +---- gfx/gl/shaders/basicShader.vs | 5 +---- gfx/gl/shaders/landmassShader.fs | 4 +--- gfx/gl/shaders/landmassShader.vs | 5 +---- gfx/gl/shaders/materialInterface.glsl | 4 ++++ gfx/gl/shaders/waterShader.fs | 4 +--- gfx/gl/shaders/waterShader.vs | 4 +--- 7 files changed, 10 insertions(+), 21 deletions(-) create mode 100644 gfx/gl/shaders/materialInterface.glsl (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs index 0d0b904..8bb6350 100644 --- a/gfx/gl/shaders/basicShader.fs +++ b/gfx/gl/shaders/basicShader.fs @@ -1,9 +1,6 @@ #version 330 core -in vec3 FragPos; -in vec2 TexCoords; -in vec3 Normal; -in vec4 Colour; +include(`materialInterface.glsl') include(`geometryOut.glsl') uniform sampler2D texture0; diff --git a/gfx/gl/shaders/basicShader.vs b/gfx/gl/shaders/basicShader.vs index a96d478..4d648f3 100644 --- a/gfx/gl/shaders/basicShader.vs +++ b/gfx/gl/shaders/basicShader.vs @@ -1,10 +1,7 @@ #version 330 core include(`meshIn.glsl') -out vec3 FragPos; -out vec2 TexCoords; -out vec3 Normal; -out vec4 Colour; +include(`materialInterface.glsl') uniform mat4 viewProjection; uniform mat4 model; diff --git a/gfx/gl/shaders/landmassShader.fs b/gfx/gl/shaders/landmassShader.fs index 5daeeb6..f3cc3e8 100644 --- a/gfx/gl/shaders/landmassShader.fs +++ b/gfx/gl/shaders/landmassShader.fs @@ -1,8 +1,6 @@ #version 330 core -in vec3 FragPos; -in vec2 TexCoords; -in vec3 Normal; +include(`materialInterface.glsl') include(`geometryOut.glsl') uniform sampler2D texture0; diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs index 3eb9aa3..cabe39f 100644 --- a/gfx/gl/shaders/landmassShader.vs +++ b/gfx/gl/shaders/landmassShader.vs @@ -1,10 +1,7 @@ #version 330 core include(`meshIn.glsl') -out vec3 FragPos; -out vec2 TexCoords; -out vec3 Normal; -out vec4 Colour; +include(`materialInterface.glsl') uniform mat4 viewProjection; diff --git a/gfx/gl/shaders/materialInterface.glsl b/gfx/gl/shaders/materialInterface.glsl new file mode 100644 index 0000000..3e09c85 --- /dev/null +++ b/gfx/gl/shaders/materialInterface.glsl @@ -0,0 +1,4 @@ +ifelse(TYPE, .fs, in, out) vec3 FragPos; +ifelse(TYPE, .fs, in, out) vec2 TexCoords; +ifelse(TYPE, .fs, in, out) vec3 Normal; +ifelse(TYPE, .fs, in, out) vec4 Colour; diff --git a/gfx/gl/shaders/waterShader.fs b/gfx/gl/shaders/waterShader.fs index d457f27..5936da4 100644 --- a/gfx/gl/shaders/waterShader.fs +++ b/gfx/gl/shaders/waterShader.fs @@ -1,9 +1,7 @@ #version 330 core #extension GL_ARB_shading_language_420pack : enable -in vec3 FragPos; -in vec2 TexCoords; -in vec3 Normal; +include(`materialInterface.glsl') include(`geometryOut.glsl') uniform sampler2D texture0; diff --git a/gfx/gl/shaders/waterShader.vs b/gfx/gl/shaders/waterShader.vs index 6f96c19..a21b49f 100644 --- a/gfx/gl/shaders/waterShader.vs +++ b/gfx/gl/shaders/waterShader.vs @@ -1,9 +1,7 @@ #version 330 core include(`meshIn.glsl') -out vec3 FragPos; -out vec2 TexCoords; -out vec3 Normal; +include(`materialInterface.glsl') uniform mat4 viewProjection; uniform vec3 waves; -- cgit v1.2.3 From 936f54e86f71d8e4af4784ebb32b6518c6fc3a01 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 13 Apr 2023 00:44:20 +0100 Subject: Fix submitting of integer values via vertex arrays --- gfx/gl/shaders/lightingShader.vs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/lightingShader.vs b/gfx/gl/shaders/lightingShader.vs index 2271d2e..e07cd0a 100644 --- a/gfx/gl/shaders/lightingShader.vs +++ b/gfx/gl/shaders/lightingShader.vs @@ -1,6 +1,6 @@ #version 330 core -in vec4 position; +in ivec4 position; out vec2 TexCoords; -- cgit v1.2.3 From f16a7df6135262c91fee2a2f6c46ad2f3caa7157 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 13 Apr 2023 02:15:41 +0100 Subject: Update shaders to use material to conditionally lookup sub-texture in the atlas --- gfx/gl/shaders/basicShader.fs | 16 ++++++++++++++-- gfx/gl/shaders/basicShader.vs | 1 + gfx/gl/shaders/landmassShader.vs | 1 + gfx/gl/shaders/materialInterface.glsl | 3 +++ gfx/gl/shaders/meshIn.glsl | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs index 8bb6350..ab5e58b 100644 --- a/gfx/gl/shaders/basicShader.fs +++ b/gfx/gl/shaders/basicShader.fs @@ -1,14 +1,26 @@ #version 330 core +#extension GL_ARB_shading_language_420pack : enable include(`materialInterface.glsl') include(`geometryOut.glsl') -uniform sampler2D texture0; +layout(binding = 0) uniform sampler2D texture0; +layout(binding = 1) uniform usampler2DRect material; + +vec4 getTextureColour(uint midx, vec2 uv) +{ + if (midx > 0u) { + const vec2 tSize = textureSize(texture0, 0); + const vec4 sPosSize = texture(material, uvec2(0, midx - 1u)); + uv = (sPosSize.xy + sPosSize.zw * fract(uv)) / tSize; + } + return texture(texture0, uv); +} void main() { - vec4 textureColour = texture(texture0, TexCoords); + vec4 textureColour = getTextureColour(Material, TexCoords); float clear = round(mix(textureColour.a, 1, Colour.a)); gPosition = vec4(FragPos, clear); gNormal = vec4(Normal, clear); diff --git a/gfx/gl/shaders/basicShader.vs b/gfx/gl/shaders/basicShader.vs index 4d648f3..e1701ed 100644 --- a/gfx/gl/shaders/basicShader.vs +++ b/gfx/gl/shaders/basicShader.vs @@ -15,6 +15,7 @@ main() TexCoords = texCoord; Normal = (model * vec4(normal, 0.0)).xyz; Colour = colour; + Material = material; gl_Position = viewProjection * worldPos; } diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs index cabe39f..0cc8153 100644 --- a/gfx/gl/shaders/landmassShader.vs +++ b/gfx/gl/shaders/landmassShader.vs @@ -12,6 +12,7 @@ main() TexCoords = texCoord; Normal = normal; Colour = colour; + Material = material; gl_Position = viewProjection * vec4(position, 1.0); } diff --git a/gfx/gl/shaders/materialInterface.glsl b/gfx/gl/shaders/materialInterface.glsl index 3e09c85..5735cf9 100644 --- a/gfx/gl/shaders/materialInterface.glsl +++ b/gfx/gl/shaders/materialInterface.glsl @@ -2,3 +2,6 @@ ifelse(TYPE, .fs, in, out) vec3 FragPos; ifelse(TYPE, .fs, in, out) vec2 TexCoords; ifelse(TYPE, .fs, in, out) vec3 Normal; ifelse(TYPE, .fs, in, out) vec4 Colour; +flat +ifelse(TYPE, .fs, in, out) +uint Material; diff --git a/gfx/gl/shaders/meshIn.glsl b/gfx/gl/shaders/meshIn.glsl index 2b244c1..dd84a10 100644 --- a/gfx/gl/shaders/meshIn.glsl +++ b/gfx/gl/shaders/meshIn.glsl @@ -2,3 +2,4 @@ layout(location = 0) in vec3 position; layout(location = 1) in vec2 texCoord; layout(location = 2) in vec3 normal; layout(location = 3) in vec4 colour; +layout(location = 4) in uint material; -- cgit v1.2.3 From 2f5a53d9dfec54bd33609dbe5a0af44c565d8069 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 13 Apr 2023 17:53:38 +0100 Subject: Adjust gl_FragDepth according to texel opacity --- gfx/gl/shaders/basicShader.fs | 1 + 1 file changed, 1 insertion(+) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs index ab5e58b..ff1c822 100644 --- a/gfx/gl/shaders/basicShader.fs +++ b/gfx/gl/shaders/basicShader.fs @@ -24,5 +24,6 @@ main() float clear = round(mix(textureColour.a, 1, Colour.a)); gPosition = vec4(FragPos, clear); gNormal = vec4(Normal, clear); + gl_FragDepth = mix(1.0, gl_FragCoord.z, clear); gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a); } -- cgit v1.2.3 From 31e2bd9b5738498be3d13dc96cc78f48825a8601 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 13 Apr 2023 18:02:28 +0100 Subject: Rename clear to opaque as its 1 for solid --- gfx/gl/shaders/basicShader.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs index ff1c822..8a72e6d 100644 --- a/gfx/gl/shaders/basicShader.fs +++ b/gfx/gl/shaders/basicShader.fs @@ -21,9 +21,9 @@ void main() { vec4 textureColour = getTextureColour(Material, TexCoords); - float clear = round(mix(textureColour.a, 1, Colour.a)); - gPosition = vec4(FragPos, clear); - gNormal = vec4(Normal, clear); - gl_FragDepth = mix(1.0, gl_FragCoord.z, clear); + float opaque = step(0.5, mix(textureColour.a, 1, Colour.a)); + gPosition = vec4(FragPos, opaque); + gNormal = vec4(Normal, opaque); + gl_FragDepth = mix(1.0, gl_FragCoord.z, opaque); gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a); } -- cgit v1.2.3 From 4a7cff8f634122314d0bb4766795ea2d1e652ed4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 16:39:57 +0100 Subject: Handle different mapmodes in basic shader --- gfx/gl/shaders/basicShader.fs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs index 8a72e6d..57eaba2 100644 --- a/gfx/gl/shaders/basicShader.fs +++ b/gfx/gl/shaders/basicShader.fs @@ -7,12 +7,37 @@ include(`geometryOut.glsl') layout(binding = 0) uniform sampler2D texture0; layout(binding = 1) uniform usampler2DRect material; +float map(uint mapmode, float value) +{ + switch (mapmode) { + case 0u: // Repeat + return fract(value); + case 1u: // Clamp to edge + return clamp(0.0, 1.0, value); + case 2u: // Mirror + discard; + case 3u: // Decal + if (value != clamp(0.0, 1.0, value)) { + discard; + } + } + return 0; +} + +vec2 map(uint mapmodeU, uint mapmodeV, vec2 value) +{ + return vec2(map(mapmodeU, value.x), map(mapmodeV, value.y)); +} + vec4 getTextureColour(uint midx, vec2 uv) { if (midx > 0u) { const vec2 tSize = textureSize(texture0, 0); const vec4 sPosSize = texture(material, uvec2(0, midx - 1u)); - uv = (sPosSize.xy + sPosSize.zw * fract(uv)) / tSize; + const uvec4 sMode = texture(material, uvec2(1, midx - 1u)); + const uint mapmodeU = sMode.x & 0xFu; + const uint mapmodeV = (sMode.x & 0xF0u) >> 1; + uv = (sPosSize.xy + sPosSize.zw * map(mapmodeU, mapmodeV, uv)) / tSize; } return texture(texture0, uv); } -- cgit v1.2.3