From bc0958cc863083b4082161bf12456fdf28ab1c77 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 31 Jan 2026 02:51:16 +0000 Subject: Rename shader source in keeping with glsl expectations Swaps name/type of generated files to match class names and source files. --- Jamroot.jam | 2 +- gfx/gl/sceneRenderer.cpp | 10 +-- gfx/gl/sceneShader.cpp | 56 ++++++++--------- gfx/gl/shaders/commonShadowPoint.geom | 28 +++++++++ gfx/gl/shaders/commonShadowPoint.gs | 28 --------- gfx/gl/shaders/directionalLight.frag | 60 ++++++++++++++++++ gfx/gl/shaders/directionalLight.fs | 60 ------------------ gfx/gl/shaders/dynamicPoint.vert | 13 ++++ gfx/gl/shaders/dynamicPoint.vs | 13 ---- gfx/gl/shaders/dynamicPointInst.vert | 13 ++++ gfx/gl/shaders/dynamicPointInst.vs | 13 ---- gfx/gl/shaders/fixedPoint.vert | 13 ++++ gfx/gl/shaders/fixedPoint.vs | 13 ---- gfx/gl/shaders/landmass.frag | 73 ++++++++++++++++++++++ gfx/gl/shaders/landmass.fs | 73 ---------------------- gfx/gl/shaders/landmass.vert | 19 ++++++ gfx/gl/shaders/landmass.vs | 19 ------ gfx/gl/shaders/lighting.frag | 17 +++++ gfx/gl/shaders/lighting.fs | 17 ----- gfx/gl/shaders/lighting.vert | 12 ++++ gfx/gl/shaders/lighting.vs | 12 ---- gfx/gl/shaders/material.frag | 18 ++++++ gfx/gl/shaders/material.fs | 18 ------ gfx/gl/shaders/materialInterface.glsl | 2 +- gfx/gl/shaders/network.frag | 16 +++++ gfx/gl/shaders/network.fs | 16 ----- gfx/gl/shaders/networkCommon.glsl | 2 +- gfx/gl/shaders/networkCurve.geom | 15 +++++ gfx/gl/shaders/networkCurve.gs | 15 ----- gfx/gl/shaders/networkCurve.tcs | 43 ------------- gfx/gl/shaders/networkCurve.tes | 30 --------- gfx/gl/shaders/networkCurve.tesc | 43 +++++++++++++ gfx/gl/shaders/networkCurve.tese | 30 +++++++++ gfx/gl/shaders/networkCurve.vert | 29 +++++++++ gfx/gl/shaders/networkCurve.vs | 29 --------- gfx/gl/shaders/networkStraight.geom | 17 +++++ gfx/gl/shaders/networkStraight.gs | 17 ----- gfx/gl/shaders/networkStraight.vert | 24 +++++++ gfx/gl/shaders/networkStraight.vs | 24 ------- gfx/gl/shaders/pointLight.frag | 29 +++++++++ gfx/gl/shaders/pointLight.fs | 29 --------- gfx/gl/shaders/pointLight.geom | 49 +++++++++++++++ gfx/gl/shaders/pointLight.gs | 49 --------------- gfx/gl/shaders/pointLight.vert | 24 +++++++ gfx/gl/shaders/pointLight.vs | 24 ------- gfx/gl/shaders/shadowDynamicPoint.vert | 9 +++ gfx/gl/shaders/shadowDynamicPoint.vs | 9 --- gfx/gl/shaders/shadowDynamicPointInst.vert | 9 +++ gfx/gl/shaders/shadowDynamicPointInst.vs | 9 --- .../shadowDynamicPointInstWithTextures.frag | 18 ++++++ .../shaders/shadowDynamicPointInstWithTextures.fs | 18 ------ .../shadowDynamicPointInstWithTextures.geom | 3 + .../shaders/shadowDynamicPointInstWithTextures.gs | 3 - .../shadowDynamicPointInstWithTextures.vert | 14 +++++ .../shaders/shadowDynamicPointInstWithTextures.vs | 14 ----- gfx/gl/shaders/shadowDynamicPointStencil.frag | 15 +++++ gfx/gl/shaders/shadowDynamicPointStencil.fs | 15 ----- gfx/gl/shaders/shadowDynamicPointStencil.geom | 35 +++++++++++ gfx/gl/shaders/shadowDynamicPointStencil.gs | 35 ----------- gfx/gl/shaders/shadowDynamicPointStencil.vert | 16 +++++ gfx/gl/shaders/shadowDynamicPointStencil.vs | 16 ----- gfx/gl/shaders/shadowLandmass.vert | 13 ++++ gfx/gl/shaders/shadowLandmass.vs | 13 ---- gfx/gl/shaders/shadowStencil.frag | 17 +++++ gfx/gl/shaders/shadowStencil.fs | 17 ----- gfx/gl/shaders/shadowStencil.geom | 27 ++++++++ gfx/gl/shaders/shadowStencil.gs | 27 -------- gfx/gl/shaders/shadowStencil.vert | 19 ++++++ gfx/gl/shaders/shadowStencil.vs | 19 ------ gfx/gl/shaders/spotLight.frag | 33 ++++++++++ gfx/gl/shaders/spotLight.fs | 33 ---------- gfx/gl/shaders/spotLight.geom | 66 +++++++++++++++++++ gfx/gl/shaders/spotLight.gs | 66 ------------------- gfx/gl/shaders/spotLight.vert | 30 +++++++++ gfx/gl/shaders/spotLight.vs | 30 --------- gfx/gl/shaders/water.frag | 16 +++++ gfx/gl/shaders/water.fs | 16 ----- gfx/gl/shaders/water.vert | 21 +++++++ gfx/gl/shaders/water.vs | 21 ------- gfx/gl/shadowMapper.cpp | 32 +++++----- gfx/gl/shadowStenciller.cpp | 8 +-- glsl.jam | 27 ++++---- lib/embed-glsl.cpp.m4 | 2 +- 83 files changed, 974 insertions(+), 973 deletions(-) create mode 100644 gfx/gl/shaders/commonShadowPoint.geom delete mode 100644 gfx/gl/shaders/commonShadowPoint.gs create mode 100644 gfx/gl/shaders/directionalLight.frag delete mode 100644 gfx/gl/shaders/directionalLight.fs create mode 100644 gfx/gl/shaders/dynamicPoint.vert delete mode 100644 gfx/gl/shaders/dynamicPoint.vs create mode 100644 gfx/gl/shaders/dynamicPointInst.vert delete mode 100644 gfx/gl/shaders/dynamicPointInst.vs create mode 100644 gfx/gl/shaders/fixedPoint.vert delete mode 100644 gfx/gl/shaders/fixedPoint.vs create mode 100644 gfx/gl/shaders/landmass.frag delete mode 100644 gfx/gl/shaders/landmass.fs create mode 100644 gfx/gl/shaders/landmass.vert delete mode 100644 gfx/gl/shaders/landmass.vs create mode 100644 gfx/gl/shaders/lighting.frag delete mode 100644 gfx/gl/shaders/lighting.fs create mode 100644 gfx/gl/shaders/lighting.vert delete mode 100644 gfx/gl/shaders/lighting.vs create mode 100644 gfx/gl/shaders/material.frag delete mode 100644 gfx/gl/shaders/material.fs create mode 100644 gfx/gl/shaders/network.frag delete mode 100644 gfx/gl/shaders/network.fs create mode 100644 gfx/gl/shaders/networkCurve.geom delete mode 100644 gfx/gl/shaders/networkCurve.gs delete mode 100644 gfx/gl/shaders/networkCurve.tcs delete mode 100644 gfx/gl/shaders/networkCurve.tes create mode 100644 gfx/gl/shaders/networkCurve.tesc create mode 100644 gfx/gl/shaders/networkCurve.tese create mode 100644 gfx/gl/shaders/networkCurve.vert delete mode 100644 gfx/gl/shaders/networkCurve.vs create mode 100644 gfx/gl/shaders/networkStraight.geom delete mode 100644 gfx/gl/shaders/networkStraight.gs create mode 100644 gfx/gl/shaders/networkStraight.vert delete mode 100644 gfx/gl/shaders/networkStraight.vs create mode 100644 gfx/gl/shaders/pointLight.frag delete mode 100644 gfx/gl/shaders/pointLight.fs create mode 100644 gfx/gl/shaders/pointLight.geom delete mode 100644 gfx/gl/shaders/pointLight.gs create mode 100644 gfx/gl/shaders/pointLight.vert delete mode 100644 gfx/gl/shaders/pointLight.vs create mode 100644 gfx/gl/shaders/shadowDynamicPoint.vert delete mode 100644 gfx/gl/shaders/shadowDynamicPoint.vs create mode 100644 gfx/gl/shaders/shadowDynamicPointInst.vert delete mode 100644 gfx/gl/shaders/shadowDynamicPointInst.vs create mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.frag delete mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs create mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.geom delete mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs create mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.vert delete mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs create mode 100644 gfx/gl/shaders/shadowDynamicPointStencil.frag delete mode 100644 gfx/gl/shaders/shadowDynamicPointStencil.fs create mode 100644 gfx/gl/shaders/shadowDynamicPointStencil.geom delete mode 100644 gfx/gl/shaders/shadowDynamicPointStencil.gs create mode 100644 gfx/gl/shaders/shadowDynamicPointStencil.vert delete mode 100644 gfx/gl/shaders/shadowDynamicPointStencil.vs create mode 100644 gfx/gl/shaders/shadowLandmass.vert delete mode 100644 gfx/gl/shaders/shadowLandmass.vs create mode 100644 gfx/gl/shaders/shadowStencil.frag delete mode 100644 gfx/gl/shaders/shadowStencil.fs create mode 100644 gfx/gl/shaders/shadowStencil.geom delete mode 100644 gfx/gl/shaders/shadowStencil.gs create mode 100644 gfx/gl/shaders/shadowStencil.vert delete mode 100644 gfx/gl/shaders/shadowStencil.vs create mode 100644 gfx/gl/shaders/spotLight.frag delete mode 100644 gfx/gl/shaders/spotLight.fs create mode 100644 gfx/gl/shaders/spotLight.geom delete mode 100644 gfx/gl/shaders/spotLight.gs create mode 100644 gfx/gl/shaders/spotLight.vert delete mode 100644 gfx/gl/shaders/spotLight.vs create mode 100644 gfx/gl/shaders/water.frag delete mode 100644 gfx/gl/shaders/water.fs create mode 100644 gfx/gl/shaders/water.vert delete mode 100644 gfx/gl/shaders/water.vs diff --git a/Jamroot.jam b/Jamroot.jam index 34ce9ac..d8d195e 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -57,7 +57,7 @@ always runresviewer ; run resviewer : -- : [ sequence.insertion-sort [ glob-tree-ex res : *.xml ] ] : : runresviewer ; lib ilt : - [ glob-tree *.cpp *.?s *.t?s : application bin test thirdparty ] + [ glob-tree *.cpp *.vert *.frag *.geom *.tesc *.tese : application bin test thirdparty ] [ lib generated : [ glob-tree *.ll *.c : bin thirdparty ] : . lib diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 65b4609..5e8241f 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -1,9 +1,9 @@ #include "sceneRenderer.h" #include "maths.h" #include "vertexArrayObject.h" -#include -#include -#include +#include +#include +#include #include static constexpr const std::array displayVAOdata {{ @@ -18,7 +18,7 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) : SceneRenderer {s, o, SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o, glDebugScope) : camera {{-1250000, -1250000, 35.0F}, quarter_pi, ratio(s), 100, 10000000}, size {s}, output {o}, - lighting {lighting_vs, lighting_fs}, shadowMapper {{2048, 2048}} + lighting {lighting_vert, lighting_frag}, shadowMapper {{2048, 2048}} { shader.setViewPort({0, 0, size.x, size.y}); VertexArrayObject {displayVAO}.addAttribs(displayVBO, displayVAOdata); @@ -175,7 +175,7 @@ SceneRenderer::renderQuad() const glBindVertexArray(0); } -SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : Program {lighting_vs, directionalLight_fs} { } +SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : Program {lighting_vert, directionalLight_frag} { } const auto toTextureSpaceMat = glm::translate(glm::identity(), glm::vec3 {0.5F}) * glm::scale(glm::identity(), glm::vec3 {0.5F}); diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index ec54fd1..72cde91 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -1,25 +1,25 @@ #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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -36,11 +36,11 @@ SceneShader::allPrograms(auto member, auto &&... ps) const } SceneShader::SceneShader() : - basicInst {dynamicPointInst_vs, material_fs}, absolute {fixedPoint_vs, material_fs}, - spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs}, - pointLightInst {pointLight_vs, pointLight_gs, pointLight_fs}, landmass {landmass_vs, landmass_fs}, - networkStraight {networkStraight_vs, networkStraight_gs, network_fs}, - networkCurve {networkCurve_vs, networkCurve_tcs, networkCurve_tes, networkCurve_gs, network_fs} + basicInst {dynamicPointInst_vert, material_frag}, absolute {fixedPoint_vert, material_frag}, + spotLightInst {spotLight_vert, spotLight_geom, spotLight_frag}, + pointLightInst {pointLight_vert, pointLight_geom, pointLight_frag}, landmass {landmass_vert, landmass_frag}, + networkStraight {networkStraight_vert, networkStraight_geom, network_frag}, + networkCurve {networkCurve_vert, networkCurve_tesc, networkCurve_tese, networkCurve_geom, network_frag} { } @@ -73,7 +73,7 @@ SceneShader::SceneProgram::setViewPort(const ViewPort & viewPort) const } } -SceneShader::BasicProgram::BasicProgram() : SceneProgram {dynamicPoint_vs, material_fs} { } +SceneShader::BasicProgram::BasicProgram() : SceneProgram {dynamicPoint_vert, material_frag} { } void SceneShader::BasicProgram::setModel(Location const & location) const @@ -106,7 +106,7 @@ SceneShader::NetworkProgram::use( glUniform(profileLengthLoc, static_cast(profile.size())); } -SceneShader::WaterProgram::WaterProgram() : SceneProgram {water_vs, water_fs} { } +SceneShader::WaterProgram::WaterProgram() : SceneProgram {water_vert, water_frag} { } void SceneShader::WaterProgram::use(float waveCycle) const diff --git a/gfx/gl/shaders/commonShadowPoint.geom b/gfx/gl/shaders/commonShadowPoint.geom new file mode 100644 index 0000000..a515d97 --- /dev/null +++ b/gfx/gl/shaders/commonShadowPoint.geom @@ -0,0 +1,28 @@ +#version 460 core + +ifdef(`TEXTURES', include(`materialDetail.glsl')) + +uniform mat4 viewProjection[4]; +uniform int viewProjections; +in vec4 vworldPos[]; +layout(triangles) in; +layout(triangle_strip, max_vertices = 12) out; + +ifdef(`TEXTURES', in vec2 TexCoords[]; out vec2 texCoord;) +ifdef(`TEXTURES', flat in MaterialDetail Material[]; flat out MaterialDetail material;) + +void +main() +{ + for (int vp = 0; vp < viewProjections; ++vp) { + for (int v = 0; v < vworldPos.length(); ++v) { + gl_Position = viewProjection[vp] * vworldPos[v]; + gl_Position.z = max(gl_Position.z, -1); + gl_Layer = vp; + ifdef(`TEXTURES', texCoord = TexCoords[v];) + ifdef(`TEXTURES', material = Material[v];) + EmitVertex(); + } + EndPrimitive(); + } +} diff --git a/gfx/gl/shaders/commonShadowPoint.gs b/gfx/gl/shaders/commonShadowPoint.gs deleted file mode 100644 index a515d97..0000000 --- a/gfx/gl/shaders/commonShadowPoint.gs +++ /dev/null @@ -1,28 +0,0 @@ -#version 460 core - -ifdef(`TEXTURES', include(`materialDetail.glsl')) - -uniform mat4 viewProjection[4]; -uniform int viewProjections; -in vec4 vworldPos[]; -layout(triangles) in; -layout(triangle_strip, max_vertices = 12) out; - -ifdef(`TEXTURES', in vec2 TexCoords[]; out vec2 texCoord;) -ifdef(`TEXTURES', flat in MaterialDetail Material[]; flat out MaterialDetail material;) - -void -main() -{ - for (int vp = 0; vp < viewProjections; ++vp) { - for (int v = 0; v < vworldPos.length(); ++v) { - gl_Position = viewProjection[vp] * vworldPos[v]; - gl_Position.z = max(gl_Position.z, -1); - gl_Layer = vp; - ifdef(`TEXTURES', texCoord = TexCoords[v];) - ifdef(`TEXTURES', material = Material[v];) - EmitVertex(); - } - EndPrimitive(); - } -} diff --git a/gfx/gl/shaders/directionalLight.frag b/gfx/gl/shaders/directionalLight.frag new file mode 100644 index 0000000..e5ebfb0 --- /dev/null +++ b/gfx/gl/shaders/directionalLight.frag @@ -0,0 +1,60 @@ +#version 460 core + +const int MAX_MAPS = 4; + +out vec3 FragColor; + +in vec2 TexCoords; + +layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 1) uniform sampler2D gNormal; +layout(binding = 2) uniform sampler2DArray shadowMap; + +uniform vec3 lightDirection; +uniform vec3 lightColour; +uniform ivec3 lightPoint; +uniform mat4 lightViewProjection[MAX_MAPS]; +uniform uint lightViewProjectionCount; + +float +getShadow(vec3 positionInLightSpace, float m, vec2 texelSize) +{ + float shadow = 0.0; + for (float x = -texelSize.x; x <= texelSize.x; x += texelSize.x) { + for (float y = -texelSize.y; y <= texelSize.y; y += texelSize.y) { + const float lightSpaceDepth = texture(shadowMap, vec3(positionInLightSpace.xy + vec2(x, y), m)).r; + shadow += step(positionInLightSpace.z, lightSpaceDepth + 0.001); + } + } + return shadow / 9.0; +} + +float +insideShadowCube(vec3 v, vec2 texelSize) +{ + const vec3 s = step(vec3(texelSize, 0), v) - step(vec3(1 - texelSize, 1), v); + return s.x * s.y * s.z; +} + +float +isShaded(vec4 Position) +{ + const vec2 texelSize = 1.0 / textureSize(shadowMap, 0).xy; + for (uint m = 0u; m < lightViewProjectionCount; m++) { + const vec3 positionInLightSpace = (lightViewProjection[m] * Position).xyz; + const float inside = insideShadowCube(positionInLightSpace, texelSize); + if (inside > 0) { + return getShadow(positionInLightSpace, m, texelSize); + } + } + return 1.0; +} + +void +main() +{ + const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1); + const vec3 Normal = texture(gNormal, TexCoords).rgb; + const float shaded = isShaded(Position); + FragColor = shaded * max(dot(-lightDirection, Normal) * lightColour, 0); +} diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs deleted file mode 100644 index e5ebfb0..0000000 --- a/gfx/gl/shaders/directionalLight.fs +++ /dev/null @@ -1,60 +0,0 @@ -#version 460 core - -const int MAX_MAPS = 4; - -out vec3 FragColor; - -in vec2 TexCoords; - -layout(binding = 0) uniform isampler2D gPosition; -layout(binding = 1) uniform sampler2D gNormal; -layout(binding = 2) uniform sampler2DArray shadowMap; - -uniform vec3 lightDirection; -uniform vec3 lightColour; -uniform ivec3 lightPoint; -uniform mat4 lightViewProjection[MAX_MAPS]; -uniform uint lightViewProjectionCount; - -float -getShadow(vec3 positionInLightSpace, float m, vec2 texelSize) -{ - float shadow = 0.0; - for (float x = -texelSize.x; x <= texelSize.x; x += texelSize.x) { - for (float y = -texelSize.y; y <= texelSize.y; y += texelSize.y) { - const float lightSpaceDepth = texture(shadowMap, vec3(positionInLightSpace.xy + vec2(x, y), m)).r; - shadow += step(positionInLightSpace.z, lightSpaceDepth + 0.001); - } - } - return shadow / 9.0; -} - -float -insideShadowCube(vec3 v, vec2 texelSize) -{ - const vec3 s = step(vec3(texelSize, 0), v) - step(vec3(1 - texelSize, 1), v); - return s.x * s.y * s.z; -} - -float -isShaded(vec4 Position) -{ - const vec2 texelSize = 1.0 / textureSize(shadowMap, 0).xy; - for (uint m = 0u; m < lightViewProjectionCount; m++) { - const vec3 positionInLightSpace = (lightViewProjection[m] * Position).xyz; - const float inside = insideShadowCube(positionInLightSpace, texelSize); - if (inside > 0) { - return getShadow(positionInLightSpace, m, texelSize); - } - } - return 1.0; -} - -void -main() -{ - const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1); - const vec3 Normal = texture(gNormal, TexCoords).rgb; - const float shaded = isShaded(Position); - FragColor = shaded * max(dot(-lightDirection, Normal) * lightColour, 0); -} diff --git a/gfx/gl/shaders/dynamicPoint.vert b/gfx/gl/shaders/dynamicPoint.vert new file mode 100644 index 0000000..cd5fc26 --- /dev/null +++ b/gfx/gl/shaders/dynamicPoint.vert @@ -0,0 +1,13 @@ +#version 460 core + +layout(binding = 1) uniform usampler2DRect materialData; + +include(`meshIn.glsl') +include(`materialInterface.glsl') + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +uniform mat3 model; +uniform ivec3 modelPos; + +include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs deleted file mode 100644 index cd5fc26..0000000 --- a/gfx/gl/shaders/dynamicPoint.vs +++ /dev/null @@ -1,13 +0,0 @@ -#version 460 core - -layout(binding = 1) uniform usampler2DRect materialData; - -include(`meshIn.glsl') -include(`materialInterface.glsl') - -uniform mat4 viewProjection; -uniform ivec3 viewPoint; -uniform mat3 model; -uniform ivec3 modelPos; - -include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPointInst.vert b/gfx/gl/shaders/dynamicPointInst.vert new file mode 100644 index 0000000..46fead9 --- /dev/null +++ b/gfx/gl/shaders/dynamicPointInst.vert @@ -0,0 +1,13 @@ +#version 460 core + +layout(binding = 1) uniform usampler2DRect materialData; + +include(`meshIn.glsl') +include(`materialInterface.glsl') + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +layout(location = 5) in mat3 model; +layout(location = 8) in ivec3 modelPos; + +include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs deleted file mode 100644 index 46fead9..0000000 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ /dev/null @@ -1,13 +0,0 @@ -#version 460 core - -layout(binding = 1) uniform usampler2DRect materialData; - -include(`meshIn.glsl') -include(`materialInterface.glsl') - -uniform mat4 viewProjection; -uniform ivec3 viewPoint; -layout(location = 5) in mat3 model; -layout(location = 8) in ivec3 modelPos; - -include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/fixedPoint.vert b/gfx/gl/shaders/fixedPoint.vert new file mode 100644 index 0000000..9201251 --- /dev/null +++ b/gfx/gl/shaders/fixedPoint.vert @@ -0,0 +1,13 @@ +#version 460 core + +layout(binding = 1) uniform usampler2DRect materialData; + +include(`meshIn.glsl') +include(`materialInterface.glsl') + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +const mat3 model = mat3(1); +const vec3 modelPos = ivec3(0); + +include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs deleted file mode 100644 index 9201251..0000000 --- a/gfx/gl/shaders/fixedPoint.vs +++ /dev/null @@ -1,13 +0,0 @@ -#version 460 core - -layout(binding = 1) uniform usampler2DRect materialData; - -include(`meshIn.glsl') -include(`materialInterface.glsl') - -uniform mat4 viewProjection; -uniform ivec3 viewPoint; -const mat3 model = mat3(1); -const vec3 modelPos = ivec3(0); - -include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/landmass.frag b/gfx/gl/shaders/landmass.frag new file mode 100644 index 0000000..b5c7fa1 --- /dev/null +++ b/gfx/gl/shaders/landmass.frag @@ -0,0 +1,73 @@ +#version 460 core + +include(`materialOut.glsl') +in vec3 FragPos; +in vec3 Normal; + +uniform sampler2D texture0; +uniform ivec3 viewPoint; +uniform vec3 colourBias; + +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 int beachline = 500; +const int snowline_low = 28000; +const int snowline_high = 30000; + +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() +{ + ivec3 position = ivec3(FragPos) + viewPoint; + vec3 color = texture(texture0, vec2(position.xy % 10000) / 10000.0).rgb; + + int height = position.z; + if (colourBias.r >= 0) { + color *= colourBias; + } + else 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 = ivec4(position, 1); + gNormal = vec4(Normal, 1); + gAlbedoSpec = vec4(color, 1); +} diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs deleted file mode 100644 index b5c7fa1..0000000 --- a/gfx/gl/shaders/landmass.fs +++ /dev/null @@ -1,73 +0,0 @@ -#version 460 core - -include(`materialOut.glsl') -in vec3 FragPos; -in vec3 Normal; - -uniform sampler2D texture0; -uniform ivec3 viewPoint; -uniform vec3 colourBias; - -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 int beachline = 500; -const int snowline_low = 28000; -const int snowline_high = 30000; - -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() -{ - ivec3 position = ivec3(FragPos) + viewPoint; - vec3 color = texture(texture0, vec2(position.xy % 10000) / 10000.0).rgb; - - int height = position.z; - if (colourBias.r >= 0) { - color *= colourBias; - } - else 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 = ivec4(position, 1); - gNormal = vec4(Normal, 1); - gAlbedoSpec = vec4(color, 1); -} diff --git a/gfx/gl/shaders/landmass.vert b/gfx/gl/shaders/landmass.vert new file mode 100644 index 0000000..91fc7f8 --- /dev/null +++ b/gfx/gl/shaders/landmass.vert @@ -0,0 +1,19 @@ +#version 460 core + +layout(location = 0) in ivec3 position; +layout(location = 1) in vec3 normal; + +out vec3 FragPos; +out vec3 Normal; + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; + +void +main() +{ + FragPos = position - viewPoint; + Normal = normal; + + gl_Position = viewProjection * vec4(FragPos, 1); +} diff --git a/gfx/gl/shaders/landmass.vs b/gfx/gl/shaders/landmass.vs deleted file mode 100644 index 91fc7f8..0000000 --- a/gfx/gl/shaders/landmass.vs +++ /dev/null @@ -1,19 +0,0 @@ -#version 460 core - -layout(location = 0) in ivec3 position; -layout(location = 1) in vec3 normal; - -out vec3 FragPos; -out vec3 Normal; - -uniform mat4 viewProjection; -uniform ivec3 viewPoint; - -void -main() -{ - FragPos = position - viewPoint; - Normal = normal; - - gl_Position = viewProjection * vec4(FragPos, 1); -} diff --git a/gfx/gl/shaders/lighting.frag b/gfx/gl/shaders/lighting.frag new file mode 100644 index 0000000..b5c6c8b --- /dev/null +++ b/gfx/gl/shaders/lighting.frag @@ -0,0 +1,17 @@ +#version 460 core + +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.fs b/gfx/gl/shaders/lighting.fs deleted file mode 100644 index b5c6c8b..0000000 --- a/gfx/gl/shaders/lighting.fs +++ /dev/null @@ -1,17 +0,0 @@ -#version 460 core - -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.vert b/gfx/gl/shaders/lighting.vert new file mode 100644 index 0000000..1046379 --- /dev/null +++ b/gfx/gl/shaders/lighting.vert @@ -0,0 +1,12 @@ +#version 460 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/lighting.vs b/gfx/gl/shaders/lighting.vs deleted file mode 100644 index 1046379..0000000 --- a/gfx/gl/shaders/lighting.vs +++ /dev/null @@ -1,12 +0,0 @@ -#version 460 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.frag b/gfx/gl/shaders/material.frag new file mode 100644 index 0000000..18a3169 --- /dev/null +++ b/gfx/gl/shaders/material.frag @@ -0,0 +1,18 @@ +#version 460 core + +layout(binding = 0) uniform sampler2D textureAlbedo; + +include(`materialInterface.glsl') +include(`materialOut.glsl') +include(`materialCommon.glsl') + +void +main() +{ + vec4 textureColour = getTextureColour(Material, TexCoords); + float opaque = step(0.5, mix(textureColour.a, 1, Colour.a)); + 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/material.fs b/gfx/gl/shaders/material.fs deleted file mode 100644 index 18a3169..0000000 --- a/gfx/gl/shaders/material.fs +++ /dev/null @@ -1,18 +0,0 @@ -#version 460 core - -layout(binding = 0) uniform sampler2D textureAlbedo; - -include(`materialInterface.glsl') -include(`materialOut.glsl') -include(`materialCommon.glsl') - -void -main() -{ - vec4 textureColour = getTextureColour(Material, TexCoords); - float opaque = step(0.5, mix(textureColour.a, 1, Colour.a)); - 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/materialInterface.glsl b/gfx/gl/shaders/materialInterface.glsl index 52eee80..bf78290 100644 --- a/gfx/gl/shaders/materialInterface.glsl +++ b/gfx/gl/shaders/materialInterface.glsl @@ -1,6 +1,6 @@ include(`materialDetail.glsl') -define(INOUT, ifelse(TYPE, .fs, in, out)) +define(INOUT, ifelse(TYPE, .frag, in, out)) INOUT vec3 FragPos; INOUT vec2 TexCoords; diff --git a/gfx/gl/shaders/network.frag b/gfx/gl/shaders/network.frag new file mode 100644 index 0000000..2f291ea --- /dev/null +++ b/gfx/gl/shaders/network.frag @@ -0,0 +1,16 @@ +#version 460 core + +include(`materialOut.glsl') +in vec3 rposition; +in vec2 texCoord; + +layout(binding = 0) uniform sampler2D texture0; +uniform ivec3 viewPoint; + +void +main() +{ + gPosition = ivec4(viewPoint + rposition, 1); + gNormal = vec4(0, 0, 1, 1); + gAlbedoSpec = texture(texture0, texCoord); +} diff --git a/gfx/gl/shaders/network.fs b/gfx/gl/shaders/network.fs deleted file mode 100644 index 2f291ea..0000000 --- a/gfx/gl/shaders/network.fs +++ /dev/null @@ -1,16 +0,0 @@ -#version 460 core - -include(`materialOut.glsl') -in vec3 rposition; -in vec2 texCoord; - -layout(binding = 0) uniform sampler2D texture0; -uniform ivec3 viewPoint; - -void -main() -{ - gPosition = ivec4(viewPoint + rposition, 1); - gNormal = vec4(0, 0, 1, 1); - gAlbedoSpec = texture(texture0, texCoord); -} diff --git a/gfx/gl/shaders/networkCommon.glsl b/gfx/gl/shaders/networkCommon.glsl index 8b58e51..4ff24e8 100644 --- a/gfx/gl/shaders/networkCommon.glsl +++ b/gfx/gl/shaders/networkCommon.glsl @@ -18,7 +18,7 @@ segDist(const ivec3 a, const ivec3 b) } ifelse( - TYPE, .gs, + TYPE, .geom, // Begin: Geometry shader only function void doVertex(const ivec3 end, const uint v, const float texY, const mat2 rot) { ivec3 vpos = end + ivec3(rot * profile[v].xy, profile[v].z); diff --git a/gfx/gl/shaders/networkCurve.geom b/gfx/gl/shaders/networkCurve.geom new file mode 100644 index 0000000..1002fd4 --- /dev/null +++ b/gfx/gl/shaders/networkCurve.geom @@ -0,0 +1,15 @@ +#version 460 core + +flat in ivec3 pos[]; +flat in mat2 rot[]; +flat in float tpos[]; + +layout(lines) in; +layout(triangle_strip, max_vertices = 10) out; +include(`networkCommon.glsl') + +void +main() +{ + doSeg(segDist(pos[0], pos[1]), pos[0], pos[1], tpos[0], tpos[1], rot[0], rot[1]); +} diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs deleted file mode 100644 index 1002fd4..0000000 --- a/gfx/gl/shaders/networkCurve.gs +++ /dev/null @@ -1,15 +0,0 @@ -#version 460 core - -flat in ivec3 pos[]; -flat in mat2 rot[]; -flat in float tpos[]; - -layout(lines) in; -layout(triangle_strip, max_vertices = 10) out; -include(`networkCommon.glsl') - -void -main() -{ - doSeg(segDist(pos[0], pos[1]), pos[0], pos[1], tpos[0], tpos[1], rot[0], rot[1]); -} diff --git a/gfx/gl/shaders/networkCurve.tcs b/gfx/gl/shaders/networkCurve.tcs deleted file mode 100644 index 4221e64..0000000 --- a/gfx/gl/shaders/networkCurve.tcs +++ /dev/null @@ -1,43 +0,0 @@ -#version 460 core - -layout(vertices = 1) out; -flat in ivec3 apos[]; -flat in ivec3 bpos[]; -flat in ivec3 cpos[]; -flat in float reps[]; -flat in float aangle[]; -flat in float bangle[]; -flat in float radius[]; - -flat out ivec3 c_apos[]; -flat out ivec3 c_bpos[]; -flat out ivec3 c_cpos[]; -flat out float c_reps[]; -flat out float c_aangle[]; -flat out float c_bangle[]; -flat out float c_radius[]; - -int -min2pow(float target) -{ - int x = 1; - while (x < target) { - x <<= 1; - } - return x; -} - -void -main() -{ - c_apos[gl_InvocationID] = apos[gl_InvocationID]; - c_bpos[gl_InvocationID] = bpos[gl_InvocationID]; - c_cpos[gl_InvocationID] = cpos[gl_InvocationID]; - c_reps[gl_InvocationID] = reps[gl_InvocationID]; - c_aangle[gl_InvocationID] = aangle[gl_InvocationID]; - c_bangle[gl_InvocationID] = bangle[gl_InvocationID]; - c_radius[gl_InvocationID] = radius[gl_InvocationID]; - - gl_TessLevelOuter[0] = 1; - gl_TessLevelOuter[1] = min2pow(reps[gl_InvocationID]); -} diff --git a/gfx/gl/shaders/networkCurve.tes b/gfx/gl/shaders/networkCurve.tes deleted file mode 100644 index a02503c..0000000 --- a/gfx/gl/shaders/networkCurve.tes +++ /dev/null @@ -1,30 +0,0 @@ -#version 460 core -layout(isolines, equal_spacing, cw) in; - -flat in ivec3 c_apos[]; -flat in ivec3 c_bpos[]; -flat in ivec3 c_cpos[]; -flat in float c_reps[]; -flat in float c_aangle[]; -flat in float c_bangle[]; -flat in float c_radius[]; - -flat out ivec3 pos; -flat out mat2 rot; -flat out float tpos; - -mat2 -getRot(float angle) -{ - return mat2(cos(angle), sin(angle), -sin(angle), cos(angle)); -} - -void -main() -{ - float angle = mix(c_bangle[0], c_aangle[0], gl_TessCoord.x); - int height = int(mix(c_bpos[0].z, c_apos[0].z, gl_TessCoord.x)) - c_cpos[0].z; - rot = getRot(angle); - tpos = c_reps[0] * gl_TessCoord.x; - pos = c_cpos[0] + ivec3(rot * vec2(c_radius[0], 0), height); -} diff --git a/gfx/gl/shaders/networkCurve.tesc b/gfx/gl/shaders/networkCurve.tesc new file mode 100644 index 0000000..4221e64 --- /dev/null +++ b/gfx/gl/shaders/networkCurve.tesc @@ -0,0 +1,43 @@ +#version 460 core + +layout(vertices = 1) out; +flat in ivec3 apos[]; +flat in ivec3 bpos[]; +flat in ivec3 cpos[]; +flat in float reps[]; +flat in float aangle[]; +flat in float bangle[]; +flat in float radius[]; + +flat out ivec3 c_apos[]; +flat out ivec3 c_bpos[]; +flat out ivec3 c_cpos[]; +flat out float c_reps[]; +flat out float c_aangle[]; +flat out float c_bangle[]; +flat out float c_radius[]; + +int +min2pow(float target) +{ + int x = 1; + while (x < target) { + x <<= 1; + } + return x; +} + +void +main() +{ + c_apos[gl_InvocationID] = apos[gl_InvocationID]; + c_bpos[gl_InvocationID] = bpos[gl_InvocationID]; + c_cpos[gl_InvocationID] = cpos[gl_InvocationID]; + c_reps[gl_InvocationID] = reps[gl_InvocationID]; + c_aangle[gl_InvocationID] = aangle[gl_InvocationID]; + c_bangle[gl_InvocationID] = bangle[gl_InvocationID]; + c_radius[gl_InvocationID] = radius[gl_InvocationID]; + + gl_TessLevelOuter[0] = 1; + gl_TessLevelOuter[1] = min2pow(reps[gl_InvocationID]); +} diff --git a/gfx/gl/shaders/networkCurve.tese b/gfx/gl/shaders/networkCurve.tese new file mode 100644 index 0000000..a02503c --- /dev/null +++ b/gfx/gl/shaders/networkCurve.tese @@ -0,0 +1,30 @@ +#version 460 core +layout(isolines, equal_spacing, cw) in; + +flat in ivec3 c_apos[]; +flat in ivec3 c_bpos[]; +flat in ivec3 c_cpos[]; +flat in float c_reps[]; +flat in float c_aangle[]; +flat in float c_bangle[]; +flat in float c_radius[]; + +flat out ivec3 pos; +flat out mat2 rot; +flat out float tpos; + +mat2 +getRot(float angle) +{ + return mat2(cos(angle), sin(angle), -sin(angle), cos(angle)); +} + +void +main() +{ + float angle = mix(c_bangle[0], c_aangle[0], gl_TessCoord.x); + int height = int(mix(c_bpos[0].z, c_apos[0].z, gl_TessCoord.x)) - c_cpos[0].z; + rot = getRot(angle); + tpos = c_reps[0] * gl_TessCoord.x; + pos = c_cpos[0] + ivec3(rot * vec2(c_radius[0], 0), height); +} diff --git a/gfx/gl/shaders/networkCurve.vert b/gfx/gl/shaders/networkCurve.vert new file mode 100644 index 0000000..9cf149b --- /dev/null +++ b/gfx/gl/shaders/networkCurve.vert @@ -0,0 +1,29 @@ +#version 460 core + +layout(location = 0) in ivec3 v_apos; +layout(location = 1) in ivec3 v_bpos; +layout(location = 2) in ivec3 v_centre; +layout(location = 3) in float v_reps; +layout(location = 4) in float v_aangle; +layout(location = 5) in float v_bangle; +layout(location = 6) in float v_radius; + +flat out ivec3 apos; +flat out ivec3 bpos; +flat out ivec3 cpos; +flat out float reps; +flat out float aangle; +flat out float bangle; +flat out float radius; + +void +main() +{ + apos = v_apos; + bpos = v_bpos; + cpos = v_centre; + reps = v_reps; + aangle = v_aangle; + bangle = v_bangle; + radius = v_radius; +} diff --git a/gfx/gl/shaders/networkCurve.vs b/gfx/gl/shaders/networkCurve.vs deleted file mode 100644 index 9cf149b..0000000 --- a/gfx/gl/shaders/networkCurve.vs +++ /dev/null @@ -1,29 +0,0 @@ -#version 460 core - -layout(location = 0) in ivec3 v_apos; -layout(location = 1) in ivec3 v_bpos; -layout(location = 2) in ivec3 v_centre; -layout(location = 3) in float v_reps; -layout(location = 4) in float v_aangle; -layout(location = 5) in float v_bangle; -layout(location = 6) in float v_radius; - -flat out ivec3 apos; -flat out ivec3 bpos; -flat out ivec3 cpos; -flat out float reps; -flat out float aangle; -flat out float bangle; -flat out float radius; - -void -main() -{ - apos = v_apos; - bpos = v_bpos; - cpos = v_centre; - reps = v_reps; - aangle = v_aangle; - bangle = v_bangle; - radius = v_radius; -} diff --git a/gfx/gl/shaders/networkStraight.geom b/gfx/gl/shaders/networkStraight.geom new file mode 100644 index 0000000..6abcecb --- /dev/null +++ b/gfx/gl/shaders/networkStraight.geom @@ -0,0 +1,17 @@ +#version 460 core + +flat in ivec3 apos[]; +flat in ivec3 bpos[]; +flat in mat2 rot[]; +flat in float reps[]; +flat in float dist[]; + +layout(points) in; +layout(triangle_strip, max_vertices = 10) out; +include(`networkCommon.glsl') + +void +main() +{ + doSeg(dist[0], apos[0], bpos[0], 0.f, reps[0], rot[0], rot[0]); +} diff --git a/gfx/gl/shaders/networkStraight.gs b/gfx/gl/shaders/networkStraight.gs deleted file mode 100644 index 6abcecb..0000000 --- a/gfx/gl/shaders/networkStraight.gs +++ /dev/null @@ -1,17 +0,0 @@ -#version 460 core - -flat in ivec3 apos[]; -flat in ivec3 bpos[]; -flat in mat2 rot[]; -flat in float reps[]; -flat in float dist[]; - -layout(points) in; -layout(triangle_strip, max_vertices = 10) out; -include(`networkCommon.glsl') - -void -main() -{ - doSeg(dist[0], apos[0], bpos[0], 0.f, reps[0], rot[0], rot[0]); -} diff --git a/gfx/gl/shaders/networkStraight.vert b/gfx/gl/shaders/networkStraight.vert new file mode 100644 index 0000000..2834613 --- /dev/null +++ b/gfx/gl/shaders/networkStraight.vert @@ -0,0 +1,24 @@ +#version 460 core + +layout(location = 0) in ivec3 v_apos; +layout(location = 1) in ivec3 v_bpos; +layout(location = 2) in mat2 v_rot; +layout(location = 4) in float v_reps; + +flat out ivec3 apos; +flat out ivec3 bpos; +flat out mat2 rot; +flat out float reps; +flat out float dist; + +include(`networkCommon.glsl') + +void +main() +{ + apos = v_apos; + bpos = v_bpos; + rot = v_rot; + reps = v_reps; + dist = segDist(v_apos, v_bpos); +} diff --git a/gfx/gl/shaders/networkStraight.vs b/gfx/gl/shaders/networkStraight.vs deleted file mode 100644 index 2834613..0000000 --- a/gfx/gl/shaders/networkStraight.vs +++ /dev/null @@ -1,24 +0,0 @@ -#version 460 core - -layout(location = 0) in ivec3 v_apos; -layout(location = 1) in ivec3 v_bpos; -layout(location = 2) in mat2 v_rot; -layout(location = 4) in float v_reps; - -flat out ivec3 apos; -flat out ivec3 bpos; -flat out mat2 rot; -flat out float reps; -flat out float dist; - -include(`networkCommon.glsl') - -void -main() -{ - apos = v_apos; - bpos = v_bpos; - rot = v_rot; - reps = v_reps; - dist = segDist(v_apos, v_bpos); -} diff --git a/gfx/gl/shaders/pointLight.frag b/gfx/gl/shaders/pointLight.frag new file mode 100644 index 0000000..bb2c453 --- /dev/null +++ b/gfx/gl/shaders/pointLight.frag @@ -0,0 +1,29 @@ +#version 460 core + +out vec3 FragColor; + +layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 1) uniform sampler2D gNormal; +uniform ivec4 viewPort; +flat in vec4 geo_centre; +flat in vec3 geo_colour; +flat in float geo_kq; + +void +main() +{ + const vec2 texCoord = gl_FragCoord.xy / viewPort.zw; + const vec3 position = texture(gPosition, texCoord).xyz; + const vec3 lightv = position - geo_centre.xyz; + const float lightDist = length(lightv); + if (lightDist > geo_centre.w) { + discard; + } + const vec3 normal = texture(gNormal, texCoord).xyz; + const vec3 lightDirection = normalize(lightv); + const float normalDot = dot(-lightDirection, normal); + if (normalDot < 0) { + discard; + } + FragColor = (geo_colour * normalDot) / (1 + (geo_kq * pow(lightDist / 1000.0, 2))); +} diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs deleted file mode 100644 index bb2c453..0000000 --- a/gfx/gl/shaders/pointLight.fs +++ /dev/null @@ -1,29 +0,0 @@ -#version 460 core - -out vec3 FragColor; - -layout(binding = 0) uniform isampler2D gPosition; -layout(binding = 1) uniform sampler2D gNormal; -uniform ivec4 viewPort; -flat in vec4 geo_centre; -flat in vec3 geo_colour; -flat in float geo_kq; - -void -main() -{ - const vec2 texCoord = gl_FragCoord.xy / viewPort.zw; - const vec3 position = texture(gPosition, texCoord).xyz; - const vec3 lightv = position - geo_centre.xyz; - const float lightDist = length(lightv); - if (lightDist > geo_centre.w) { - discard; - } - const vec3 normal = texture(gNormal, texCoord).xyz; - const vec3 lightDirection = normalize(lightv); - const float normalDot = dot(-lightDirection, normal); - if (normalDot < 0) { - discard; - } - FragColor = (geo_colour * normalDot) / (1 + (geo_kq * pow(lightDist / 1000.0, 2))); -} diff --git a/gfx/gl/shaders/pointLight.geom b/gfx/gl/shaders/pointLight.geom new file mode 100644 index 0000000..1ee7e06 --- /dev/null +++ b/gfx/gl/shaders/pointLight.geom @@ -0,0 +1,49 @@ +#version 460 core + +const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf + vec3(-1, 1, 1), // Front-top-left + vec3(1, 1, 1), // Front-top-right + vec3(-1, -1, 1), // Front-bottom-left + vec3(1, -1, 1), // Front-bottom-right + vec3(1, -1, -1), // Back-bottom-right + vec3(1, 1, 1), // Front-top-right + vec3(1, 1, -1), // Back-top-right + vec3(-1, 1, 1), // Front-top-left + vec3(-1, 1, -1), // Back-top-left + vec3(-1, -1, 1), // Front-bottom-left + vec3(-1, -1, -1), // Back-bottom-left + vec3(1, -1, -1), // Back-bottom-right + vec3(-1, 1, -1), // Back-top-left + vec3(1, 1, -1) // Back-top-right +); +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +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; +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(position[0], size[0]); + geo_colour = colour[0]; + geo_kq = kq[0]; + EmitVertex(); +} + +void +main() +{ + for (int i = 0; i < cube.length(); ++i) { + doVertex(i); + } + EndPrimitive(); +} diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.gs deleted file mode 100644 index 1ee7e06..0000000 --- a/gfx/gl/shaders/pointLight.gs +++ /dev/null @@ -1,49 +0,0 @@ -#version 460 core - -const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf - vec3(-1, 1, 1), // Front-top-left - vec3(1, 1, 1), // Front-top-right - vec3(-1, -1, 1), // Front-bottom-left - vec3(1, -1, 1), // Front-bottom-right - vec3(1, -1, -1), // Back-bottom-right - vec3(1, 1, 1), // Front-top-right - vec3(1, 1, -1), // Back-top-right - vec3(-1, 1, 1), // Front-top-left - vec3(-1, 1, -1), // Back-top-left - vec3(-1, -1, 1), // Front-bottom-left - vec3(-1, -1, -1), // Back-bottom-left - vec3(1, -1, -1), // Back-bottom-right - vec3(-1, 1, -1), // Back-top-left - vec3(1, 1, -1) // Back-top-right -); -uniform mat4 viewProjection; -uniform ivec3 viewPoint; -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; -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(position[0], size[0]); - geo_colour = colour[0]; - geo_kq = kq[0]; - EmitVertex(); -} - -void -main() -{ - for (int i = 0; i < cube.length(); ++i) { - doVertex(i); - } - EndPrimitive(); -} diff --git a/gfx/gl/shaders/pointLight.vert b/gfx/gl/shaders/pointLight.vert new file mode 100644 index 0000000..2fd5418 --- /dev/null +++ b/gfx/gl/shaders/pointLight.vert @@ -0,0 +1,24 @@ +#version 460 core + +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 mat3 model; +layout(location = 6) in ivec3 modelPos; + +uniform ivec3 viewPoint; + +flat out vec3 position; +flat out vec3 colour; +flat out float size; +flat out float kq; + +void +main() +{ + 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); +} diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs deleted file mode 100644 index 2fd5418..0000000 --- a/gfx/gl/shaders/pointLight.vs +++ /dev/null @@ -1,24 +0,0 @@ -#version 460 core - -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 mat3 model; -layout(location = 6) in ivec3 modelPos; - -uniform ivec3 viewPoint; - -flat out vec3 position; -flat out vec3 colour; -flat out float size; -flat out float kq; - -void -main() -{ - 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); -} diff --git a/gfx/gl/shaders/shadowDynamicPoint.vert b/gfx/gl/shaders/shadowDynamicPoint.vert new file mode 100644 index 0000000..907378e --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPoint.vert @@ -0,0 +1,9 @@ +#version 460 core + +include(`meshIn.glsl') + +uniform ivec3 viewPoint; +uniform mat3 model; +uniform ivec3 modelPos; + +include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs deleted file mode 100644 index 907378e..0000000 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 460 core - -include(`meshIn.glsl') - -uniform ivec3 viewPoint; -uniform mat3 model; -uniform ivec3 modelPos; - -include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vert b/gfx/gl/shaders/shadowDynamicPointInst.vert new file mode 100644 index 0000000..da4a76f --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInst.vert @@ -0,0 +1,9 @@ +#version 460 core + +include(`meshIn.glsl') + +uniform ivec3 viewPoint; +layout(location = 5) in mat3 model; +layout(location = 8) in ivec3 modelPos; + +include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs deleted file mode 100644 index da4a76f..0000000 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 460 core - -include(`meshIn.glsl') - -uniform ivec3 viewPoint; -layout(location = 5) in mat3 model; -layout(location = 8) in ivec3 modelPos; - -include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.frag b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.frag new file mode 100644 index 0000000..cad9d9d --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.frag @@ -0,0 +1,18 @@ +#version 460 core + +layout(binding = 3) uniform sampler2D textureAlbedo; + +include(`materialInterface.glsl') +include(`materialCommon.glsl') + +in vec2 texCoord; +flat in MaterialDetail material; + +void +main() +{ + if (getTextureColour(material, texCoord).a < 0.5) { + discard; + } + gl_FragDepth = gl_FragCoord.z; +} diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs deleted file mode 100644 index cad9d9d..0000000 --- a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs +++ /dev/null @@ -1,18 +0,0 @@ -#version 460 core - -layout(binding = 3) uniform sampler2D textureAlbedo; - -include(`materialInterface.glsl') -include(`materialCommon.glsl') - -in vec2 texCoord; -flat in MaterialDetail material; - -void -main() -{ - if (getTextureColour(material, texCoord).a < 0.5) { - discard; - } - gl_FragDepth = gl_FragCoord.z; -} diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.geom b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.geom new file mode 100644 index 0000000..3aaf9a8 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.geom @@ -0,0 +1,3 @@ +define(`TEXTURES', 1) + +include(`commonShadowPoint.geom') diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs deleted file mode 100644 index e6e213e..0000000 --- a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs +++ /dev/null @@ -1,3 +0,0 @@ -define(`TEXTURES', 1) - -include(`commonShadowPoint.gs') diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vert b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vert new file mode 100644 index 0000000..41a47b0 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vert @@ -0,0 +1,14 @@ +#version 460 core + +layout(binding = 4) uniform usampler2DRect materialData; + +define(`TEXTURES', 1) +include(`materialInterface.glsl') +include(`getMaterialDetail.glsl') +include(`meshIn.glsl') + +uniform ivec3 viewPoint; +layout(location = 5) in mat3 model; +layout(location = 8) in ivec3 modelPos; + +include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs deleted file mode 100644 index 41a47b0..0000000 --- a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs +++ /dev/null @@ -1,14 +0,0 @@ -#version 460 core - -layout(binding = 4) uniform usampler2DRect materialData; - -define(`TEXTURES', 1) -include(`materialInterface.glsl') -include(`getMaterialDetail.glsl') -include(`meshIn.glsl') - -uniform ivec3 viewPoint; -layout(location = 5) in mat3 model; -layout(location = 8) in ivec3 modelPos; - -include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointStencil.frag b/gfx/gl/shaders/shadowDynamicPointStencil.frag new file mode 100644 index 0000000..d6b8a0e --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointStencil.frag @@ -0,0 +1,15 @@ +#version 460 core + +layout(binding = 0) uniform sampler2DArray stencilDepth; +flat in vec3 scale; +in vec3 texCoord; + +void +main() +{ + float stDepth = texture(stencilDepth, texCoord).r; + if (stDepth >= 1) { + discard; + } + gl_FragDepth = gl_FragCoord.z + ((stDepth - 0.5) * scale.z); +} diff --git a/gfx/gl/shaders/shadowDynamicPointStencil.fs b/gfx/gl/shaders/shadowDynamicPointStencil.fs deleted file mode 100644 index d6b8a0e..0000000 --- a/gfx/gl/shaders/shadowDynamicPointStencil.fs +++ /dev/null @@ -1,15 +0,0 @@ -#version 460 core - -layout(binding = 0) uniform sampler2DArray stencilDepth; -flat in vec3 scale; -in vec3 texCoord; - -void -main() -{ - float stDepth = texture(stencilDepth, texCoord).r; - if (stDepth >= 1) { - discard; - } - gl_FragDepth = gl_FragCoord.z + ((stDepth - 0.5) * scale.z); -} diff --git a/gfx/gl/shaders/shadowDynamicPointStencil.geom b/gfx/gl/shaders/shadowDynamicPointStencil.geom new file mode 100644 index 0000000..df8be8d --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointStencil.geom @@ -0,0 +1,35 @@ +#version 460 core + +const vec2[] corners = vec2[4](vec2(-1, -1), vec2(-1, 1), vec2(1, -1), vec2(1, 1)); +const float tau = 6.28318531; + +uniform mat4 viewProjection[4]; +uniform int viewProjections; +uniform vec3 sizes[4]; +uniform float size; + +in float vmodelYaw[]; +in ivec3 vworldPos[]; + +flat out vec3 scale; +out vec3 texCoord; + +layout(points) in; +layout(triangle_strip, max_vertices = 16) out; + +void +main() +{ + int viewAngle = int(round(4.0 + (vmodelYaw[0] / tau))) % 8; + for (gl_Layer = 0; gl_Layer < viewProjections; ++gl_Layer) { + scale = 2.0 * size / sizes[gl_Layer]; + vec4 pos = viewProjection[gl_Layer] * vec4(vworldPos[0], 1); + for (int c = 0; c < corners.length(); ++c) { + gl_Position = pos + vec4(scale.xy * corners[c], 0, 0); + gl_Position.z = max(gl_Position.z, -1); + texCoord = vec3((corners[c] * 0.5) + 0.5, viewAngle); + EmitVertex(); + } + EndPrimitive(); + } +} diff --git a/gfx/gl/shaders/shadowDynamicPointStencil.gs b/gfx/gl/shaders/shadowDynamicPointStencil.gs deleted file mode 100644 index df8be8d..0000000 --- a/gfx/gl/shaders/shadowDynamicPointStencil.gs +++ /dev/null @@ -1,35 +0,0 @@ -#version 460 core - -const vec2[] corners = vec2[4](vec2(-1, -1), vec2(-1, 1), vec2(1, -1), vec2(1, 1)); -const float tau = 6.28318531; - -uniform mat4 viewProjection[4]; -uniform int viewProjections; -uniform vec3 sizes[4]; -uniform float size; - -in float vmodelYaw[]; -in ivec3 vworldPos[]; - -flat out vec3 scale; -out vec3 texCoord; - -layout(points) in; -layout(triangle_strip, max_vertices = 16) out; - -void -main() -{ - int viewAngle = int(round(4.0 + (vmodelYaw[0] / tau))) % 8; - for (gl_Layer = 0; gl_Layer < viewProjections; ++gl_Layer) { - scale = 2.0 * size / sizes[gl_Layer]; - vec4 pos = viewProjection[gl_Layer] * vec4(vworldPos[0], 1); - for (int c = 0; c < corners.length(); ++c) { - gl_Position = pos + vec4(scale.xy * corners[c], 0, 0); - gl_Position.z = max(gl_Position.z, -1); - texCoord = vec3((corners[c] * 0.5) + 0.5, viewAngle); - EmitVertex(); - } - EndPrimitive(); - } -} diff --git a/gfx/gl/shaders/shadowDynamicPointStencil.vert b/gfx/gl/shaders/shadowDynamicPointStencil.vert new file mode 100644 index 0000000..b750b3e --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointStencil.vert @@ -0,0 +1,16 @@ +#version 460 core + +layout(location = 0) in ivec3 worldPos; +layout(location = 1) in float modelYaw; +uniform ivec3 viewPoint; +uniform vec3 centre; + +out float vmodelYaw; +out ivec3 vworldPos; + +void +main() +{ + vmodelYaw = modelYaw; + vworldPos = worldPos - viewPoint + ivec3(centre); +} diff --git a/gfx/gl/shaders/shadowDynamicPointStencil.vs b/gfx/gl/shaders/shadowDynamicPointStencil.vs deleted file mode 100644 index b750b3e..0000000 --- a/gfx/gl/shaders/shadowDynamicPointStencil.vs +++ /dev/null @@ -1,16 +0,0 @@ -#version 460 core - -layout(location = 0) in ivec3 worldPos; -layout(location = 1) in float modelYaw; -uniform ivec3 viewPoint; -uniform vec3 centre; - -out float vmodelYaw; -out ivec3 vworldPos; - -void -main() -{ - vmodelYaw = modelYaw; - vworldPos = worldPos - viewPoint + ivec3(centre); -} diff --git a/gfx/gl/shaders/shadowLandmass.vert b/gfx/gl/shaders/shadowLandmass.vert new file mode 100644 index 0000000..cf68fe5 --- /dev/null +++ b/gfx/gl/shaders/shadowLandmass.vert @@ -0,0 +1,13 @@ +#version 460 core + +layout(location = 0) in ivec3 position; + +uniform ivec3 viewPoint; + +out vec4 vworldPos; + +void +main() +{ + vworldPos = vec4(position - viewPoint, 1); +} diff --git a/gfx/gl/shaders/shadowLandmass.vs b/gfx/gl/shaders/shadowLandmass.vs deleted file mode 100644 index cf68fe5..0000000 --- a/gfx/gl/shaders/shadowLandmass.vs +++ /dev/null @@ -1,13 +0,0 @@ -#version 460 core - -layout(location = 0) in ivec3 position; - -uniform ivec3 viewPoint; - -out vec4 vworldPos; - -void -main() -{ - vworldPos = vec4(position - viewPoint, 1); -} diff --git a/gfx/gl/shaders/shadowStencil.frag b/gfx/gl/shaders/shadowStencil.frag new file mode 100644 index 0000000..3269f69 --- /dev/null +++ b/gfx/gl/shaders/shadowStencil.frag @@ -0,0 +1,17 @@ +#version 460 core + +layout(binding = 0) uniform sampler2D textureAlbedo; + +include(`materialDetail.glsl') +include(`materialCommon.glsl') +in vec2 gTexCoords; +flat in MaterialDetail gMaterial; + +void +main() +{ + if (getTextureColour(gMaterial, gTexCoords).a < 0.5) { + discard; + } + gl_FragDepth = gl_FragCoord.z; +} diff --git a/gfx/gl/shaders/shadowStencil.fs b/gfx/gl/shaders/shadowStencil.fs deleted file mode 100644 index 3269f69..0000000 --- a/gfx/gl/shaders/shadowStencil.fs +++ /dev/null @@ -1,17 +0,0 @@ -#version 460 core - -layout(binding = 0) uniform sampler2D textureAlbedo; - -include(`materialDetail.glsl') -include(`materialCommon.glsl') -in vec2 gTexCoords; -flat in MaterialDetail gMaterial; - -void -main() -{ - if (getTextureColour(gMaterial, gTexCoords).a < 0.5) { - discard; - } - gl_FragDepth = gl_FragCoord.z; -} diff --git a/gfx/gl/shaders/shadowStencil.geom b/gfx/gl/shaders/shadowStencil.geom new file mode 100644 index 0000000..53a4c19 --- /dev/null +++ b/gfx/gl/shaders/shadowStencil.geom @@ -0,0 +1,27 @@ +#version 460 core + +include(`materialDetail.glsl') + +layout(triangles) in; +layout(triangle_strip, max_vertices = 24) out; + +uniform mat4 viewProjection[8]; +in vec3 FragPos[]; +in vec2 TexCoords[]; +flat in MaterialDetail Material[]; +out vec2 gTexCoords; +flat out MaterialDetail gMaterial; + +void +main() +{ + for (gl_Layer = 0; gl_Layer < viewProjection.length(); ++gl_Layer) { + for (int v = 0; v < FragPos.length(); ++v) { + gl_Position = viewProjection[gl_Layer] * vec4(FragPos[v], 1); + gTexCoords = TexCoords[v]; + gMaterial = Material[v]; + EmitVertex(); + } + EndPrimitive(); + } +} diff --git a/gfx/gl/shaders/shadowStencil.gs b/gfx/gl/shaders/shadowStencil.gs deleted file mode 100644 index 53a4c19..0000000 --- a/gfx/gl/shaders/shadowStencil.gs +++ /dev/null @@ -1,27 +0,0 @@ -#version 460 core - -include(`materialDetail.glsl') - -layout(triangles) in; -layout(triangle_strip, max_vertices = 24) out; - -uniform mat4 viewProjection[8]; -in vec3 FragPos[]; -in vec2 TexCoords[]; -flat in MaterialDetail Material[]; -out vec2 gTexCoords; -flat out MaterialDetail gMaterial; - -void -main() -{ - for (gl_Layer = 0; gl_Layer < viewProjection.length(); ++gl_Layer) { - for (int v = 0; v < FragPos.length(); ++v) { - gl_Position = viewProjection[gl_Layer] * vec4(FragPos[v], 1); - gTexCoords = TexCoords[v]; - gMaterial = Material[v]; - EmitVertex(); - } - EndPrimitive(); - } -} diff --git a/gfx/gl/shaders/shadowStencil.vert b/gfx/gl/shaders/shadowStencil.vert new file mode 100644 index 0000000..e6286e6 --- /dev/null +++ b/gfx/gl/shaders/shadowStencil.vert @@ -0,0 +1,19 @@ +#version 460 core + +layout(binding = 1) uniform usampler2DRect materialData; + +include(`meshIn.glsl') +include(`materialDetail.glsl') +include(`getMaterialDetail.glsl') + +out vec3 FragPos; +out vec2 TexCoords; +flat out MaterialDetail Material; + +void +main() +{ + TexCoords = texCoord; + Material = getMaterialDetail(material); + FragPos = position; +} diff --git a/gfx/gl/shaders/shadowStencil.vs b/gfx/gl/shaders/shadowStencil.vs deleted file mode 100644 index e6286e6..0000000 --- a/gfx/gl/shaders/shadowStencil.vs +++ /dev/null @@ -1,19 +0,0 @@ -#version 460 core - -layout(binding = 1) uniform usampler2DRect materialData; - -include(`meshIn.glsl') -include(`materialDetail.glsl') -include(`getMaterialDetail.glsl') - -out vec3 FragPos; -out vec2 TexCoords; -flat out MaterialDetail Material; - -void -main() -{ - TexCoords = texCoord; - Material = getMaterialDetail(material); - FragPos = position; -} diff --git a/gfx/gl/shaders/spotLight.frag b/gfx/gl/shaders/spotLight.frag new file mode 100644 index 0000000..1305dbd --- /dev/null +++ b/gfx/gl/shaders/spotLight.frag @@ -0,0 +1,33 @@ +#version 460 core + +out vec3 FragColor; + +layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 1) uniform sampler2D gNormal; +uniform ivec4 viewPort; +flat in vec4 geo_centre; +flat in vec4 geo_direction; +flat in vec3 geo_colour; +flat in float geo_kq; + +void +main() +{ + const vec2 texCoord = gl_FragCoord.xy / viewPort.zw; + const vec3 position = texture(gPosition, texCoord).xyz; + const vec3 lightv = position - geo_centre.xyz; + const float lightDist = length(lightv); + if (lightDist > geo_centre.w) { + discard; + } + const vec3 lightDirection = normalize(lightv); + if (dot(lightDirection, geo_direction.xyz) < geo_direction.w) { + discard; + } + const vec3 normal = texture(gNormal, texCoord).xyz; + const float normalDot = dot(-lightDirection, normal); + if (normalDot < 0) { + discard; + } + FragColor = (geo_colour * normalDot) / (1 + (geo_kq * pow(lightDist / 1000.0, 2))); +} diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs deleted file mode 100644 index 1305dbd..0000000 --- a/gfx/gl/shaders/spotLight.fs +++ /dev/null @@ -1,33 +0,0 @@ -#version 460 core - -out vec3 FragColor; - -layout(binding = 0) uniform isampler2D gPosition; -layout(binding = 1) uniform sampler2D gNormal; -uniform ivec4 viewPort; -flat in vec4 geo_centre; -flat in vec4 geo_direction; -flat in vec3 geo_colour; -flat in float geo_kq; - -void -main() -{ - const vec2 texCoord = gl_FragCoord.xy / viewPort.zw; - const vec3 position = texture(gPosition, texCoord).xyz; - const vec3 lightv = position - geo_centre.xyz; - const float lightDist = length(lightv); - if (lightDist > geo_centre.w) { - discard; - } - const vec3 lightDirection = normalize(lightv); - if (dot(lightDirection, geo_direction.xyz) < geo_direction.w) { - discard; - } - const vec3 normal = texture(gNormal, texCoord).xyz; - const float normalDot = dot(-lightDirection, normal); - if (normalDot < 0) { - discard; - } - FragColor = (geo_colour * normalDot) / (1 + (geo_kq * pow(lightDist / 1000.0, 2))); -} diff --git a/gfx/gl/shaders/spotLight.geom b/gfx/gl/shaders/spotLight.geom new file mode 100644 index 0000000..fec191e --- /dev/null +++ b/gfx/gl/shaders/spotLight.geom @@ -0,0 +1,66 @@ +#version 460 core + +const vec3[] pyramid = vec3[]( // four-sided + vec3(0, 0, 0), // Apex + vec3(-1, 1, 1), // Back-left + vec3(-1, -1, 1), // Front-left + vec3(1, 1, 1), // Back-right + vec3(1, -1, 1) // Front-right +); +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +flat in ivec3 position[]; +flat in vec3 direction[]; +flat in vec3 colour[]; +flat in float size[]; +flat in float kq[]; +flat in vec2 arc[]; +layout(points) in; + +layout(triangle_strip, max_vertices = 8) out; +flat out vec4 geo_centre; +flat out vec4 geo_direction; +flat out vec3 geo_colour; +flat out float geo_kq; + +vec3 +perp(vec3 a) +{ + return normalize(a.x != 0 ? vec3((a.y + a.z) / -a.x, 1, 1) + : a.y != 0 ? vec3(1, (a.x + a.z) / -a.y, 1) + : vec3(1, 1, (a.x + a.y) / -a.z)); +} + +void +doVertex(vec4 ndcpos) +{ + gl_Position = ndcpos; + geo_centre = vec4(position[0], size[0]); + geo_direction = vec4(direction[0], arc[0].x); + geo_colour = colour[0]; + geo_kq = kq[0]; + EmitVertex(); +} + +void +main() +{ + const float base = size[0] * arc[0].y; + const vec3 offx = perp(direction[0]); + const vec3 offy = cross(direction[0], offx); + vec4 out_py[pyramid.length()]; + for (int i = 0; i < pyramid.length(); ++i) { + const vec3 p = pyramid[i]; + const vec3 edge = (offx * base * p.x) + (offy * base * p.y) + (direction[0] * size[0] * p.z); + out_py[i] = viewProjection * (gl_in[0].gl_Position + vec4(edge, 1)); + } + doVertex(out_py[3]); + doVertex(out_py[0]); + doVertex(out_py[1]); + doVertex(out_py[2]); + doVertex(out_py[3]); + doVertex(out_py[4]); + doVertex(out_py[0]); + doVertex(out_py[2]); + EndPrimitive(); +} diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.gs deleted file mode 100644 index fec191e..0000000 --- a/gfx/gl/shaders/spotLight.gs +++ /dev/null @@ -1,66 +0,0 @@ -#version 460 core - -const vec3[] pyramid = vec3[]( // four-sided - vec3(0, 0, 0), // Apex - vec3(-1, 1, 1), // Back-left - vec3(-1, -1, 1), // Front-left - vec3(1, 1, 1), // Back-right - vec3(1, -1, 1) // Front-right -); -uniform mat4 viewProjection; -uniform ivec3 viewPoint; -flat in ivec3 position[]; -flat in vec3 direction[]; -flat in vec3 colour[]; -flat in float size[]; -flat in float kq[]; -flat in vec2 arc[]; -layout(points) in; - -layout(triangle_strip, max_vertices = 8) out; -flat out vec4 geo_centre; -flat out vec4 geo_direction; -flat out vec3 geo_colour; -flat out float geo_kq; - -vec3 -perp(vec3 a) -{ - return normalize(a.x != 0 ? vec3((a.y + a.z) / -a.x, 1, 1) - : a.y != 0 ? vec3(1, (a.x + a.z) / -a.y, 1) - : vec3(1, 1, (a.x + a.y) / -a.z)); -} - -void -doVertex(vec4 ndcpos) -{ - gl_Position = ndcpos; - geo_centre = vec4(position[0], size[0]); - geo_direction = vec4(direction[0], arc[0].x); - geo_colour = colour[0]; - geo_kq = kq[0]; - EmitVertex(); -} - -void -main() -{ - const float base = size[0] * arc[0].y; - const vec3 offx = perp(direction[0]); - const vec3 offy = cross(direction[0], offx); - vec4 out_py[pyramid.length()]; - for (int i = 0; i < pyramid.length(); ++i) { - const vec3 p = pyramid[i]; - const vec3 edge = (offx * base * p.x) + (offy * base * p.y) + (direction[0] * size[0] * p.z); - out_py[i] = viewProjection * (gl_in[0].gl_Position + vec4(edge, 1)); - } - doVertex(out_py[3]); - doVertex(out_py[0]); - doVertex(out_py[1]); - doVertex(out_py[2]); - doVertex(out_py[3]); - doVertex(out_py[4]); - doVertex(out_py[0]); - doVertex(out_py[2]); - EndPrimitive(); -} diff --git a/gfx/gl/shaders/spotLight.vert b/gfx/gl/shaders/spotLight.vert new file mode 100644 index 0000000..36d2ee5 --- /dev/null +++ b/gfx/gl/shaders/spotLight.vert @@ -0,0 +1,30 @@ +#version 460 core + +layout(location = 0) in vec3 v_position; +layout(location = 1) in vec3 v_direction; +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 mat3 model; +layout(location = 8) in ivec3 modelPos; + +uniform ivec3 viewPoint; + +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(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); + arc = vec2(cos(v_arc / 2), tan(v_arc / 2)); + gl_Position = vec4(position - viewPoint, 0); +} diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs deleted file mode 100644 index 36d2ee5..0000000 --- a/gfx/gl/shaders/spotLight.vs +++ /dev/null @@ -1,30 +0,0 @@ -#version 460 core - -layout(location = 0) in vec3 v_position; -layout(location = 1) in vec3 v_direction; -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 mat3 model; -layout(location = 8) in ivec3 modelPos; - -uniform ivec3 viewPoint; - -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(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); - arc = vec2(cos(v_arc / 2), tan(v_arc / 2)); - gl_Position = vec4(position - viewPoint, 0); -} diff --git a/gfx/gl/shaders/water.frag b/gfx/gl/shaders/water.frag new file mode 100644 index 0000000..a09e754 --- /dev/null +++ b/gfx/gl/shaders/water.frag @@ -0,0 +1,16 @@ +#version 460 core + +in vec3 FragPos; +in vec2 TexCoords; +include(`materialOut.glsl') + +uniform sampler2D texture0; + +void +main() +{ + gPosition = ivec4(FragPos, 1); + gNormal = vec4(0, 0, 1, 1); + gAlbedoSpec = texture(texture0, TexCoords); + gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0); +} diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs deleted file mode 100644 index a09e754..0000000 --- a/gfx/gl/shaders/water.fs +++ /dev/null @@ -1,16 +0,0 @@ -#version 460 core - -in vec3 FragPos; -in vec2 TexCoords; -include(`materialOut.glsl') - -uniform sampler2D texture0; - -void -main() -{ - gPosition = ivec4(FragPos, 1); - gNormal = vec4(0, 0, 1, 1); - gAlbedoSpec = texture(texture0, TexCoords); - gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0); -} diff --git a/gfx/gl/shaders/water.vert b/gfx/gl/shaders/water.vert new file mode 100644 index 0000000..60e4fb8 --- /dev/null +++ b/gfx/gl/shaders/water.vert @@ -0,0 +1,21 @@ +#version 460 core + +layout(location = 0) in ivec3 position; +out vec3 FragPos; +out vec2 TexCoords; + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +uniform float waves; + +void +main() +{ + vec3 wpos = vec3(position.x + (cos(waves) * 1000.0), position.y + (cos(waves * 1.4) * 1000.0), + cos(waves + (position.x / 1000000) + (position.y / 8000)) * 300.0); + + FragPos = vec3(wpos.xy, position.z); + TexCoords = (position.xy / 8192) - (viewPoint.xy / 8192); + + gl_Position = viewProjection * vec4(wpos - viewPoint, 1.0); +} diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs deleted file mode 100644 index 60e4fb8..0000000 --- a/gfx/gl/shaders/water.vs +++ /dev/null @@ -1,21 +0,0 @@ -#version 460 core - -layout(location = 0) in ivec3 position; -out vec3 FragPos; -out vec2 TexCoords; - -uniform mat4 viewProjection; -uniform ivec3 viewPoint; -uniform float waves; - -void -main() -{ - vec3 wpos = vec3(position.x + (cos(waves) * 1000.0), position.y + (cos(waves * 1.4) * 1000.0), - cos(waves + (position.x / 1000000) + (position.y / 8000)) * 300.0); - - FragPos = vec3(wpos.xy, position.z); - TexCoords = (position.xy / 8192) - (viewPoint.xy / 8192); - - gl_Position = viewProjection * vec4(wpos - viewPoint, 1.0); -} diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 486ba1c..7035162 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -2,16 +2,6 @@ #include "collections.h" #include "game/gamestate.h" #include "gfx/aabb.h" -#include "gfx/gl/shaders/fs-shadowDynamicPointInstWithTextures.h" -#include "gfx/gl/shaders/fs-shadowDynamicPointStencil.h" -#include "gfx/gl/shaders/gs-commonShadowPoint.h" -#include "gfx/gl/shaders/gs-shadowDynamicPointInstWithTextures.h" -#include "gfx/gl/shaders/gs-shadowDynamicPointStencil.h" -#include "gfx/gl/shaders/vs-shadowDynamicPoint.h" -#include "gfx/gl/shaders/vs-shadowDynamicPointInst.h" -#include "gfx/gl/shaders/vs-shadowDynamicPointInstWithTextures.h" -#include "gfx/gl/shaders/vs-shadowDynamicPointStencil.h" -#include "gfx/gl/shaders/vs-shadowLandmass.h" #include "gfx/gl/shadowStenciller.h" #include "gfx/lightDirection.h" #include "gfx/renderable.h" @@ -22,15 +12,25 @@ #include "sceneProvider.h" #include "sceneShader.h" #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include ShadowMapper::ShadowMapper(const TextureAbsCoord & s) : - landmess {shadowLandmass_vs}, dynamicPointInst {shadowDynamicPointInst_vs}, - dynamicPointInstWithTextures {shadowDynamicPointInstWithTextures_vs, shadowDynamicPointInstWithTextures_gs, - shadowDynamicPointInstWithTextures_fs}, + landmess {shadowLandmass_vert}, dynamicPointInst {shadowDynamicPointInst_vert}, + dynamicPointInstWithTextures {shadowDynamicPointInstWithTextures_vert, shadowDynamicPointInstWithTextures_geom, + shadowDynamicPointInstWithTextures_frag}, size {s} { glDebugScope _ {depthMap}; @@ -135,7 +135,7 @@ ShadowMapper::update(const SceneProvider & scene, const LightDirection & dir, co return out; } -ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) : Program {vs, commonShadowPoint_gs} { } +ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs) : Program {vs, commonShadowPoint_geom} { } ShadowMapper::ShadowProgram::ShadowProgram(const Shader & vs, const Shader & gs, const Shader & fs) : Program {vs, gs, fs} @@ -161,7 +161,7 @@ ShadowMapper::ShadowProgram::use() const glUseProgram(*this); } -ShadowMapper::DynamicPoint::DynamicPoint() : ShadowProgram {shadowDynamicPoint_vs} { } +ShadowMapper::DynamicPoint::DynamicPoint() : ShadowProgram {shadowDynamicPoint_vert} { } void ShadowMapper::DynamicPoint::use(const Location & location) const @@ -178,7 +178,7 @@ ShadowMapper::DynamicPoint::setModel(const Location & location) const } ShadowMapper::StencilShadowProgram::StencilShadowProgram() : - ShadowProgram {shadowDynamicPointStencil_vs, shadowDynamicPointStencil_gs, shadowDynamicPointStencil_fs} + ShadowProgram {shadowDynamicPointStencil_vert, shadowDynamicPointStencil_geom, shadowDynamicPointStencil_frag} { } diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp index a6124f5..aee7161 100644 --- a/gfx/gl/shadowStenciller.cpp +++ b/gfx/gl/shadowStenciller.cpp @@ -1,17 +1,17 @@ #include "shadowStenciller.h" -#include "gfx/gl/shaders/fs-shadowStencil.h" -#include "gfx/gl/shaders/gs-shadowStencil.h" -#include "gfx/gl/shaders/vs-shadowStencil.h" #include "gfx/lightDirection.h" #include "gfx/models/mesh.h" #include "glArrays.h" #include "gl_traits.h" #include "gldebug.h" #include "maths.h" +#include +#include +#include #include ShadowStenciller::ShadowStenciller() : - shadowCaster {shadowStencil_vs, shadowStencil_gs, shadowStencil_fs}, viewProjections {} + shadowCaster {shadowStencil_vert, shadowStencil_geom, shadowStencil_frag}, viewProjections {} { glDebugScope _ {fbo}; glBindFramebuffer(GL_FRAMEBUFFER, fbo); diff --git a/glsl.jam b/glsl.jam index 34509fd..c9ba82a 100644 --- a/glsl.jam +++ b/glsl.jam @@ -3,18 +3,18 @@ import type : type ; import generators : register-standard ; import scanner : register ; -type.register GL_VERTEX_SHADER : vs ; -type.register GL_TESS_CONTROL_SHADER : tcs ; -type.register GL_TESS_EVALUATION_SHADER : tes ; -type.register GL_GEOMETRY_SHADER : gs ; -type.register GL_FRAGMENT_SHADER : fs ; +type.register GL_VERTEX_SHADER : vert ; +type.register GL_TESS_CONTROL_SHADER : tesc ; +type.register GL_TESS_EVALUATION_SHADER : tese ; +type.register GL_GEOMETRY_SHADER : geom ; +type.register GL_FRAGMENT_SHADER : frag ; type.register GL_GENERIC_SHADER : glsl ; -generators.register-standard glsl.embed : GL_VERTEX_SHADER : CPP(vs-%) H(vs-%) GL_GENERIC_SHADER(vs-%) ; -generators.register-standard glsl.embed : GL_TESS_CONTROL_SHADER : CPP(tcs-%) H(tcs-%) GL_GENERIC_SHADER(tcs-%) ; -generators.register-standard glsl.embed : GL_TESS_EVALUATION_SHADER : CPP(tes-%) H(tes-%) GL_GENERIC_SHADER(tes-%) ; -generators.register-standard glsl.embed : GL_GEOMETRY_SHADER : CPP(gs-%) H(gs-%) GL_GENERIC_SHADER(gs-%) ; -generators.register-standard glsl.embed : GL_FRAGMENT_SHADER : CPP(fs-%) H(fs-%) GL_GENERIC_SHADER(fs-%) ; +generators.register-standard glsl.embed : GL_VERTEX_SHADER : CPP(%-vert) H(%-vert) GL_GENERIC_SHADER(%-vert) ; +generators.register-standard glsl.embed : GL_TESS_CONTROL_SHADER : CPP(%-tesc) H(%-tesc) GL_GENERIC_SHADER(%-tesc) ; +generators.register-standard glsl.embed : GL_TESS_EVALUATION_SHADER : CPP(%-tese) H(%-tese) GL_GENERIC_SHADER(%-tese) ; +generators.register-standard glsl.embed : GL_GEOMETRY_SHADER : CPP(%-geom) H(%-geom) GL_GENERIC_SHADER(%-geom) ; +generators.register-standard glsl.embed : GL_FRAGMENT_SHADER : CPP(%-frag) H(%-frag) GL_GENERIC_SHADER(%-frag) ; class m4-scanner : common-scanner { rule pattern ( ) { @@ -29,13 +29,14 @@ type.set-scanner GL_TESS_CONTROL_SHADER : m4-scanner ; type.set-scanner GL_TESS_EVALUATION_SHADER : m4-scanner ; type.set-scanner GL_GEOMETRY_SHADER : m4-scanner ; type.set-scanner GL_FRAGMENT_SHADER : m4-scanner ; +type.set-scanner GL_GENERIC_SHADER : m4-scanner ; actions glsl.embed { set -e - m4 -I$(2:D) -DSOURCE=$(2) -DOUTPUT=$(1[3]) -DNAME=$(2:B) -DTYPE=$(2:S) -DGLTYPE=$(OPTIONS) $(2) > $(1[3]) -#STAGE=$(OPTIONS:L) -#glslangValidator -S ${STAGE:3:4} -DGL_MAX_GEOMETRY_OUTPUT_VERTICES=64 -DGL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS=64 -l $(1[3]) + m4 -I$(2:D) -DSOURCE=$(2) -DOUTPUT=$(1[3]) -DNAME=$(2:B) -DTYPE=$(2:S) -DGLTYPE=$(OPTIONS) $(2) > $(1[3])$(2:S) + glslangValidator -l $(1[3])$(2:S) + mv $(1[3])$(2:S) $(1[3]) clang-format -i $(1[3]) m4 -I$(2:D) -DSOURCE=$(1[3]) -DOUTPUT=$(1[3]) -DNAME=$(2:B) -DTYPE=$(2:S) -DGLTYPE=$(OPTIONS) lib/embed-glsl.h.m4 > $(1[2]) m4 -I$(2:D) -DSOURCE=$(1[3]) -DOUTPUT=$(1[3]) -DNAME=$(2:B) -DTYPE=$(2:S) -DGLTYPE=$(OPTIONS) lib/embed-glsl.cpp.m4 > $(1[1]) diff --git a/lib/embed-glsl.cpp.m4 b/lib/embed-glsl.cpp.m4 index ecae004..02ba732 100644 --- a/lib/embed-glsl.cpp.m4 +++ b/lib/embed-glsl.cpp.m4 @@ -1,7 +1,7 @@ changecom() dnl // NAME #include "gfx/gl/shader.h" -#include "substr(TYPE,1)-NAME.h" +#include "NAME-substr(TYPE,1).h" #include constexpr Shader NAME`_'substr(TYPE,1) { -- cgit v1.2.3