From 48ec3a869029bad34773516df193519a4fe9103a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 15 Apr 2023 00:08:20 +0100 Subject: Rename lots of shader files Names and paths still not perfect, but better and the weird name missuse is gone --- gfx/gl/sceneRenderer.cpp | 8 ++--- gfx/gl/sceneShader.cpp | 21 ++++++------- gfx/gl/shaders/basicShader.fs | 54 -------------------------------- gfx/gl/shaders/basicShader.vs | 21 ------------- gfx/gl/shaders/dynamicPoint.vs | 21 +++++++++++++ gfx/gl/shaders/fixedPoint.vs | 18 +++++++++++ gfx/gl/shaders/geometryOut.glsl | 3 -- gfx/gl/shaders/landmass.fs | 66 ++++++++++++++++++++++++++++++++++++++++ gfx/gl/shaders/landmassShader.fs | 66 ---------------------------------------- gfx/gl/shaders/landmassShader.vs | 18 ----------- gfx/gl/shaders/lighting.fs | 18 +++++++++++ gfx/gl/shaders/lighting.vs | 12 ++++++++ gfx/gl/shaders/lightingShader.fs | 18 ----------- gfx/gl/shaders/lightingShader.vs | 12 -------- gfx/gl/shaders/material.fs | 54 ++++++++++++++++++++++++++++++++ gfx/gl/shaders/materialOut.glsl | 3 ++ gfx/gl/shaders/water.fs | 17 +++++++++++ gfx/gl/shaders/water.vs | 20 ++++++++++++ gfx/gl/shaders/waterShader.fs | 17 ----------- gfx/gl/shaders/waterShader.vs | 20 ------------ 20 files changed, 242 insertions(+), 245 deletions(-) delete mode 100644 gfx/gl/shaders/basicShader.fs delete mode 100644 gfx/gl/shaders/basicShader.vs create mode 100644 gfx/gl/shaders/dynamicPoint.vs create mode 100644 gfx/gl/shaders/fixedPoint.vs delete mode 100644 gfx/gl/shaders/geometryOut.glsl create mode 100644 gfx/gl/shaders/landmass.fs delete mode 100644 gfx/gl/shaders/landmassShader.fs delete mode 100644 gfx/gl/shaders/landmassShader.vs create mode 100644 gfx/gl/shaders/lighting.fs create mode 100644 gfx/gl/shaders/lighting.vs delete mode 100644 gfx/gl/shaders/lightingShader.fs delete mode 100644 gfx/gl/shaders/lightingShader.vs create mode 100644 gfx/gl/shaders/material.fs create mode 100644 gfx/gl/shaders/materialOut.glsl create mode 100644 gfx/gl/shaders/water.fs create mode 100644 gfx/gl/shaders/water.vs delete mode 100644 gfx/gl/shaders/waterShader.fs delete mode 100644 gfx/gl/shaders/waterShader.vs (limited to 'gfx') diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 31b01ff..873dc5b 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -2,8 +2,8 @@ #include "maths.h" #include "vertexArrayObject.hpp" #include -#include -#include +#include +#include #include static constexpr const std::array displayVAOdata {{ @@ -15,7 +15,7 @@ static constexpr const std::array displayVAOdata {{ }}; SceneRenderer::SceneRenderer(glm::ivec2 s, GLuint o) : camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, ratio(s), 0.1F, 10000.0F}, size {s}, output {o}, - lighting {lightingShader_vs, lightingShader_fs}, shadowMapper {{2048, 2048}} + lighting {lighting_vs, lighting_fs}, shadowMapper {{2048, 2048}} { shader.setViewPort({0, 0, size.x, size.y}); VertexArrayObject::configure(displayVAO, displayVBO, displayVAOdata); @@ -126,7 +126,7 @@ SceneRenderer::renderQuad() const } SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : - Program {lightingShader_vs, directionalLight_fs}, directionLoc {*this, "lightDirection"}, + Program {lighting_vs, directionalLight_fs}, directionLoc {*this, "lightDirection"}, colourLoc {*this, "lightColour"}, lightViewProjectionLoc {*this, "lightViewProjection"}, lightViewProjectionCountLoc {*this, "lightViewProjectionCount"}, lightViewShadowMapRegionLoc { *this, "shadowMapRegion"} diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 981e7df..bcd0590 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -1,27 +1,24 @@ #include "sceneShader.h" #include -#include -#include +#include +#include #include #include -#include +#include #include #include -#include -#include +#include +#include #include #include -#include +#include #include #include #include #include #include -SceneShader::SceneShader() : - landmass {landmassShader_vs, landmassShader_fs}, absolute {landmassShader_vs, basicShader_fs} -{ -} +SceneShader::SceneShader() : landmass {fixedPoint_vs, landmass_fs}, absolute {fixedPoint_vs, material_fs} { } void SceneShader::setViewProjection(const glm::mat4 & viewProjection) const @@ -57,7 +54,7 @@ SceneShader::SceneProgram::setViewPort(const glm::ivec4 & viewPort) const } } -SceneShader::BasicProgram::BasicProgram() : SceneProgram {basicShader_vs, basicShader_fs}, modelLoc {*this, "model"} { } +SceneShader::BasicProgram::BasicProgram() : SceneProgram {dynamicPoint_vs, material_fs}, modelLoc {*this, "model"} { } void SceneShader::BasicProgram::setModel(Location const & location) const @@ -73,7 +70,7 @@ SceneShader::BasicProgram::use(Location const & location) const setModel(location); } -SceneShader::WaterProgram::WaterProgram() : SceneProgram {waterShader_vs, waterShader_fs}, waveLoc {*this, "waves"} { } +SceneShader::WaterProgram::WaterProgram() : SceneProgram {water_vs, water_fs}, waveLoc {*this, "waves"} { } void SceneShader::WaterProgram::use(float waveCycle) const diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs deleted file mode 100644 index 57eaba2..0000000 --- a/gfx/gl/shaders/basicShader.fs +++ /dev/null @@ -1,54 +0,0 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable - -include(`materialInterface.glsl') -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)); - 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); -} - -void -main() -{ - vec4 textureColour = getTextureColour(Material, TexCoords); - 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); -} diff --git a/gfx/gl/shaders/basicShader.vs b/gfx/gl/shaders/basicShader.vs deleted file mode 100644 index e1701ed..0000000 --- a/gfx/gl/shaders/basicShader.vs +++ /dev/null @@ -1,21 +0,0 @@ -#version 330 core - -include(`meshIn.glsl') -include(`materialInterface.glsl') - -uniform mat4 viewProjection; -uniform mat4 model; - -void -main() -{ - vec4 worldPos = model * vec4(position, 1.0); - - FragPos = worldPos.xyz; - TexCoords = texCoord; - Normal = (model * vec4(normal, 0.0)).xyz; - Colour = colour; - Material = material; - - gl_Position = viewProjection * worldPos; -} diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs new file mode 100644 index 0000000..e1701ed --- /dev/null +++ b/gfx/gl/shaders/dynamicPoint.vs @@ -0,0 +1,21 @@ +#version 330 core + +include(`meshIn.glsl') +include(`materialInterface.glsl') + +uniform mat4 viewProjection; +uniform mat4 model; + +void +main() +{ + vec4 worldPos = model * vec4(position, 1.0); + + FragPos = worldPos.xyz; + TexCoords = texCoord; + Normal = (model * vec4(normal, 0.0)).xyz; + Colour = colour; + Material = material; + + gl_Position = viewProjection * worldPos; +} diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs new file mode 100644 index 0000000..0cc8153 --- /dev/null +++ b/gfx/gl/shaders/fixedPoint.vs @@ -0,0 +1,18 @@ +#version 330 core + +include(`meshIn.glsl') +include(`materialInterface.glsl') + +uniform mat4 viewProjection; + +void +main() +{ + FragPos = position; + TexCoords = texCoord; + Normal = normal; + Colour = colour; + Material = material; + + gl_Position = viewProjection * vec4(position, 1.0); +} diff --git a/gfx/gl/shaders/geometryOut.glsl b/gfx/gl/shaders/geometryOut.glsl deleted file mode 100644 index dc5f8e8..0000000 --- a/gfx/gl/shaders/geometryOut.glsl +++ /dev/null @@ -1,3 +0,0 @@ -layout(location = 0) out vec4 gPosition; -layout(location = 1) out vec4 gNormal; -layout(location = 2) out vec4 gAlbedoSpec; diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs new file mode 100644 index 0000000..4dc92bb --- /dev/null +++ b/gfx/gl/shaders/landmass.fs @@ -0,0 +1,66 @@ +#version 330 core + +include(`materialInterface.glsl') +include(`materialOut.glsl') + +uniform sampler2D texture0; + +const vec3 grass = vec3(.1, .4, .05); +const vec3 slope = vec3(.6, .6, .4); +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 slope_min = .99; +const float slope_mid = .95; +const float slope_max = .90; + +vec3 +mixBetween(vec3 colA, vec3 colB, float blend, float low, float high) +{ + return mix(colA, colB, (blend - low) / (high - low)); +} + +void +main() +{ + vec3 color = texture(texture0, TexCoords).rgb; + + float height = FragPos.z; + if (height < beachline) { // Sandy beach + color *= sand; + } + else if (Normal.z < slope_max) { // Dark rocky face + color *= rock; + } + else { // Colour by lesser slope + if (Normal.z < slope_mid) { + color *= mixBetween(rock, slope, Normal.z, slope_max, slope_mid); + } + else if (Normal.z < slope_min) { + color *= mixBetween(slope, grass, Normal.z, slope_mid, slope_min); + } + else { + color *= grass; + } + + // Add a snow covering + if (height > snowline_low) { + vec3 tsnow = color * snow; + if (height > snowline_high) { + color = tsnow; + } + else { + color = mixBetween(color, tsnow, height, snowline_low, snowline_high); + } + } + } + + gPosition = vec4(FragPos, 1); + gNormal = vec4(Normal, 1); + gAlbedoSpec = vec4(color, 1); +} diff --git a/gfx/gl/shaders/landmassShader.fs b/gfx/gl/shaders/landmassShader.fs deleted file mode 100644 index f3cc3e8..0000000 --- a/gfx/gl/shaders/landmassShader.fs +++ /dev/null @@ -1,66 +0,0 @@ -#version 330 core - -include(`materialInterface.glsl') -include(`geometryOut.glsl') - -uniform sampler2D texture0; - -const vec3 grass = vec3(.1, .4, .05); -const vec3 slope = vec3(.6, .6, .4); -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 slope_min = .99; -const float slope_mid = .95; -const float slope_max = .90; - -vec3 -mixBetween(vec3 colA, vec3 colB, float blend, float low, float high) -{ - return mix(colA, colB, (blend - low) / (high - low)); -} - -void -main() -{ - vec3 color = texture(texture0, TexCoords).rgb; - - float height = FragPos.z; - if (height < beachline) { // Sandy beach - color *= sand; - } - else if (Normal.z < slope_max) { // Dark rocky face - color *= rock; - } - else { // Colour by lesser slope - if (Normal.z < slope_mid) { - color *= mixBetween(rock, slope, Normal.z, slope_max, slope_mid); - } - else if (Normal.z < slope_min) { - color *= mixBetween(slope, grass, Normal.z, slope_mid, slope_min); - } - else { - color *= grass; - } - - // Add a snow covering - if (height > snowline_low) { - vec3 tsnow = color * snow; - if (height > snowline_high) { - color = tsnow; - } - else { - color = mixBetween(color, tsnow, height, snowline_low, snowline_high); - } - } - } - - gPosition = vec4(FragPos, 1); - gNormal = vec4(Normal, 1); - gAlbedoSpec = vec4(color, 1); -} diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs deleted file mode 100644 index 0cc8153..0000000 --- a/gfx/gl/shaders/landmassShader.vs +++ /dev/null @@ -1,18 +0,0 @@ -#version 330 core - -include(`meshIn.glsl') -include(`materialInterface.glsl') - -uniform mat4 viewProjection; - -void -main() -{ - FragPos = position; - TexCoords = texCoord; - Normal = normal; - Colour = colour; - Material = material; - - gl_Position = viewProjection * vec4(position, 1.0); -} diff --git a/gfx/gl/shaders/lighting.fs b/gfx/gl/shaders/lighting.fs new file mode 100644 index 0000000..4646b75 --- /dev/null +++ b/gfx/gl/shaders/lighting.fs @@ -0,0 +1,18 @@ +#version 330 core +#extension GL_ARB_shading_language_420pack : enable + +out vec3 FragColor; + +in vec2 TexCoords; + +layout(binding = 2) uniform sampler2D gAlbedoSpec; +layout(binding = 3) uniform sampler2D gIllumination; + +void +main() +{ + const vec3 Albedo = texture(gAlbedoSpec, TexCoords).rgb; + const vec3 Illumination = texture(gIllumination, TexCoords).rgb; + + FragColor = Albedo * Illumination; +} diff --git a/gfx/gl/shaders/lighting.vs b/gfx/gl/shaders/lighting.vs new file mode 100644 index 0000000..e07cd0a --- /dev/null +++ b/gfx/gl/shaders/lighting.vs @@ -0,0 +1,12 @@ +#version 330 core + +in ivec4 position; + +out vec2 TexCoords; + +void +main() +{ + gl_Position = vec4(position.xy, 0.0, 1.0); + TexCoords = position.zw; +} diff --git a/gfx/gl/shaders/lightingShader.fs b/gfx/gl/shaders/lightingShader.fs deleted file mode 100644 index 4646b75..0000000 --- a/gfx/gl/shaders/lightingShader.fs +++ /dev/null @@ -1,18 +0,0 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable - -out vec3 FragColor; - -in vec2 TexCoords; - -layout(binding = 2) uniform sampler2D gAlbedoSpec; -layout(binding = 3) uniform sampler2D gIllumination; - -void -main() -{ - const vec3 Albedo = texture(gAlbedoSpec, TexCoords).rgb; - const vec3 Illumination = texture(gIllumination, TexCoords).rgb; - - FragColor = Albedo * Illumination; -} diff --git a/gfx/gl/shaders/lightingShader.vs b/gfx/gl/shaders/lightingShader.vs deleted file mode 100644 index e07cd0a..0000000 --- a/gfx/gl/shaders/lightingShader.vs +++ /dev/null @@ -1,12 +0,0 @@ -#version 330 core - -in ivec4 position; - -out vec2 TexCoords; - -void -main() -{ - gl_Position = vec4(position.xy, 0.0, 1.0); - TexCoords = position.zw; -} diff --git a/gfx/gl/shaders/material.fs b/gfx/gl/shaders/material.fs new file mode 100644 index 0000000..cafb35d --- /dev/null +++ b/gfx/gl/shaders/material.fs @@ -0,0 +1,54 @@ +#version 330 core +#extension GL_ARB_shading_language_420pack : enable + +include(`materialInterface.glsl') +include(`materialOut.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)); + 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); +} + +void +main() +{ + vec4 textureColour = getTextureColour(Material, TexCoords); + 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); +} diff --git a/gfx/gl/shaders/materialOut.glsl b/gfx/gl/shaders/materialOut.glsl new file mode 100644 index 0000000..dc5f8e8 --- /dev/null +++ b/gfx/gl/shaders/materialOut.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/water.fs b/gfx/gl/shaders/water.fs new file mode 100644 index 0000000..04aa94c --- /dev/null +++ b/gfx/gl/shaders/water.fs @@ -0,0 +1,17 @@ +#version 330 core +#extension GL_ARB_shading_language_420pack : enable + +include(`materialInterface.glsl') +include(`materialOut.glsl') + +uniform sampler2D texture0; +uniform vec3 waves; + +void +main() +{ + gPosition = vec4(FragPos, 1); + gNormal = vec4(Normal, 1); + gAlbedoSpec = texture(texture0, TexCoords); + gAlbedoSpec.a *= clamp(-FragPos.z * .7, .1, 1.0); +} diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs new file mode 100644 index 0000000..a21b49f --- /dev/null +++ b/gfx/gl/shaders/water.vs @@ -0,0 +1,20 @@ +#version 330 core + +include(`meshIn.glsl') +include(`materialInterface.glsl') + +uniform mat4 viewProjection; +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); + + FragPos = vec3(wpos.xy, position.z); + TexCoords = texCoord; + Normal = normal; + + gl_Position = viewProjection * wpos; +} diff --git a/gfx/gl/shaders/waterShader.fs b/gfx/gl/shaders/waterShader.fs deleted file mode 100644 index 5936da4..0000000 --- a/gfx/gl/shaders/waterShader.fs +++ /dev/null @@ -1,17 +0,0 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable - -include(`materialInterface.glsl') -include(`geometryOut.glsl') - -uniform sampler2D texture0; -uniform vec3 waves; - -void -main() -{ - gPosition = vec4(FragPos, 1); - gNormal = vec4(Normal, 1); - gAlbedoSpec = texture(texture0, TexCoords); - gAlbedoSpec.a *= clamp(-FragPos.z * .7, .1, 1.0); -} diff --git a/gfx/gl/shaders/waterShader.vs b/gfx/gl/shaders/waterShader.vs deleted file mode 100644 index a21b49f..0000000 --- a/gfx/gl/shaders/waterShader.vs +++ /dev/null @@ -1,20 +0,0 @@ -#version 330 core - -include(`meshIn.glsl') -include(`materialInterface.glsl') - -uniform mat4 viewProjection; -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); - - FragPos = vec3(wpos.xy, position.z); - TexCoords = texCoord; - Normal = normal; - - gl_Position = viewProjection * wpos; -} -- cgit v1.2.3