diff options
Diffstat (limited to 'gfx/gl/shaders')
68 files changed, 793 insertions, 394 deletions
diff --git a/gfx/gl/shaders/billboard.frag b/gfx/gl/shaders/billboard.frag new file mode 100644 index 0000000..d5610de --- /dev/null +++ b/gfx/gl/shaders/billboard.frag @@ -0,0 +1,29 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +const float tau = 6.28318531; + +layout(binding = 0) uniform sampler2DArray billboardDepth; +layout(binding = 1) uniform sampler2DArray billboardNormal; +layout(binding = 2) uniform sampler2DArray billboardAlbedo; +uniform mat4 viewProjection; +uniform float size; + +#include "materialOut.glsl" + +flat in vec3 ModelPos; +flat in float Yaw; +flat in float Depth; + +void +main() +{ + int viewAngle = int(round(8 * Yaw / tau)) % 8; + vec3 texel = vec3(gl_PointCoord * vec2(-1, 1) + vec2(1, 0), viewAngle); + gAlbedoSpec = texture(billboardAlbedo, texel); + if (gAlbedoSpec.a < 0.5) { + discard; + } + gPosition = ivec4(ModelPos + vec3(0, 0, size * 2 * (1 - gl_PointCoord.y)), 1); + gNormal = texture(billboardNormal, texel) * vec4(-1, -1, 1, 1); +} diff --git a/gfx/gl/shaders/billboard.vert b/gfx/gl/shaders/billboard.vert new file mode 100644 index 0000000..d6d3869 --- /dev/null +++ b/gfx/gl/shaders/billboard.vert @@ -0,0 +1,27 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "commonLocationData.glsl" + +uniform mat4 viewProjection; +uniform ivec4 viewPort; +uniform ivec3 viewPoint; +uniform vec3 centre; +uniform float size; + +layout(location = 0) in uint index; + +flat out vec3 ModelPos; +flat out float Yaw; +flat out float Depth; + +void +main() +{ + const ivec3 modelPos = locations[cldIndex[index]].position.xyz; + ModelPos = modelPos - viewPoint; + Yaw = locations[cldIndex[index]].rotation.x; + gl_Position = viewProjection * vec4(ModelPos + centre, 1); + Depth = gl_Position.w; + gl_PointSize = (viewPort.w * size * 2) / gl_Position.w; +} diff --git a/gfx/gl/shaders/billboardPainter.frag b/gfx/gl/shaders/billboardPainter.frag new file mode 100644 index 0000000..cba294f --- /dev/null +++ b/gfx/gl/shaders/billboardPainter.frag @@ -0,0 +1,23 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(binding = 0) uniform sampler2D textureAlbedo; +layout(location = 0) out vec4 bNormal; +layout(location = 1) out vec4 bAlbedoSpec; + +#include "materialCommon.glsl" +#include "materialDetail.glsl" +in vec2 gTexCoords; +in vec3 gNormal; +in vec4 gColour; +flat in MaterialDetail gMaterial; + +void +main() +{ + vec4 textureColour = getTextureColour(gMaterial, gTexCoords); + float opaque = step(0.5, mix(textureColour.a, 1, gColour.a)); + bNormal = vec4(gNormal, opaque); + gl_FragDepth = mix(1.0, gl_FragCoord.z, opaque); + bAlbedoSpec = mix(textureColour, vec4(gColour.rgb, 1), gColour.a); +} diff --git a/gfx/gl/shaders/billboardPainter.geom b/gfx/gl/shaders/billboardPainter.geom new file mode 100644 index 0000000..aa4ad81 --- /dev/null +++ b/gfx/gl/shaders/billboardPainter.geom @@ -0,0 +1,35 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "materialDetail.glsl" + +layout(triangles) in; +layout(triangle_strip, max_vertices = 24) out; + +uniform mat4 viewProjection[8]; +uniform mat4 view[8]; +in vec3 FragPos[]; +in vec2 TexCoords[]; +flat in MaterialDetail Material[]; +in vec3 Normal[]; +in vec4 Colour[]; +out vec2 gTexCoords; +out vec3 gNormal; +out vec4 gColour; +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); + gNormal = (view[gl_Layer] * vec4(Normal[v], 1)).xyz; + gTexCoords = TexCoords[v]; + gMaterial = Material[v]; + gColour = Colour[v]; + EmitVertex(); + } + EndPrimitive(); + } +} diff --git a/gfx/gl/shaders/billboardPainter.vert b/gfx/gl/shaders/billboardPainter.vert new file mode 100644 index 0000000..a2d0b2e --- /dev/null +++ b/gfx/gl/shaders/billboardPainter.vert @@ -0,0 +1,24 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(binding = 1) uniform usampler2DRect materialData; + +#include "getMaterialDetail.glsl" +#include "materialDetail.glsl" +#include "meshIn.glsl" + +out vec3 FragPos; +out vec2 TexCoords; +flat out MaterialDetail Material; +out vec3 Normal; +out vec4 Colour; + +void +main() +{ + TexCoords = texCoord; + Material = getMaterialDetail(material); + FragPos = position; + Colour = colour; + Normal = normal; +} diff --git a/gfx/gl/shaders/commonLocationData.glsl b/gfx/gl/shaders/commonLocationData.glsl new file mode 100644 index 0000000..4939b9b --- /dev/null +++ b/gfx/gl/shaders/commonLocationData.glsl @@ -0,0 +1,20 @@ +#ifndef COMMON_LOCATION_DATA_INCLUDED +#define COMMON_LOCATION_DATA_INCLUDED + +struct CommonLocationData { + ivec4 position; + vec4 rotation; + mat3x4 rotationMatrix; +}; + +layout(binding = 0, std430) restrict readonly buffer commonLocationData +{ + CommonLocationData locations[]; +}; + +layout(binding = 1, std430) restrict readonly buffer commonLocationDataIndex +{ + uint cldIndex[]; +}; + +#endif diff --git a/gfx/gl/shaders/commonPoint.glsl b/gfx/gl/shaders/commonPoint.glsl index dc534d5..7c1a521 100644 --- a/gfx/gl/shaders/commonPoint.glsl +++ b/gfx/gl/shaders/commonPoint.glsl @@ -1,13 +1,18 @@ -include(`getMaterialDetail.glsl') +#ifndef COMMON_POINT_INCLUDED +#define COMMON_POINT_INCLUDED + +#include "getMaterialDetail.glsl" void main() { - FragPos = (model * position) + modelPos; + FragPos = (model * position) + modelPos - viewPoint; TexCoords = texCoord; Normal = (model * normal); Colour = colour; Material = getMaterialDetail(material); - gl_Position = viewProjection * vec4(FragPos - viewPoint, 1); + gl_Position = viewProjection * vec4(FragPos, 1); } + +#endif diff --git a/gfx/gl/shaders/commonShadowPoint.gs b/gfx/gl/shaders/commonShadowPoint-geom.glsl index 2413cc0..f373834 100644 --- a/gfx/gl/shaders/commonShadowPoint.gs +++ b/gfx/gl/shaders/commonShadowPoint-geom.glsl @@ -1,7 +1,5 @@ -#version 330 core -#extension GL_ARB_viewport_array : enable - -ifdef(`TEXTURES', include(`materialDetail.glsl')) +#ifndef COMMON_SHADOW_POINT_GEOM_INCLUDED +#define COMMON_SHADOW_POINT_GEOM_INCLUDED uniform mat4 viewProjection[4]; uniform int viewProjections; @@ -9,8 +7,14 @@ 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;) +#ifdef TEXTURES +# include "materialDetail.glsl" + +in vec2 TexCoords[]; +out vec2 texCoord; +flat in MaterialDetail Material[]; +flat out MaterialDetail material; +#endif void main() @@ -20,10 +24,14 @@ main() 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];) +#ifdef TEXTURES + texCoord = TexCoords[v]; + material = Material[v]; +#endif EmitVertex(); } EndPrimitive(); } } + +#endif diff --git a/gfx/gl/shaders/commonShadowPoint.geom b/gfx/gl/shaders/commonShadowPoint.geom new file mode 100644 index 0000000..519dc62 --- /dev/null +++ b/gfx/gl/shaders/commonShadowPoint.geom @@ -0,0 +1,4 @@ +#version 460 +#extension GL_ARB_shading_language_include : enable + +#include "commonShadowPoint-geom.glsl" diff --git a/gfx/gl/shaders/commonShadowPoint.glsl b/gfx/gl/shaders/commonShadowPoint.glsl index 9910d46..e0b71a8 100644 --- a/gfx/gl/shaders/commonShadowPoint.glsl +++ b/gfx/gl/shaders/commonShadowPoint.glsl @@ -1,3 +1,6 @@ +#ifndef COMMON_SHADOW_POINT_INCLUDED +#define COMMON_SHADOW_POINT_INCLUDED + out vec4 vworldPos; void @@ -5,6 +8,10 @@ main() { vec3 worldPos = model * position; vworldPos = vec4(worldPos - viewPoint + modelPos, 1); - ifdef(`TEXTURES', TexCoords = texCoord;); - ifdef(`TEXTURES', Material = getMaterialDetail(material);); +#ifdef TEXTURES + TexCoords = texCoord; + Material = getMaterialDetail(material); +#endif } + +#endif diff --git a/gfx/gl/shaders/directionalLight.frag b/gfx/gl/shaders/directionalLight.frag new file mode 100644 index 0000000..5da1acd --- /dev/null +++ b/gfx/gl/shaders/directionalLight.frag @@ -0,0 +1,59 @@ +#version 460 core + +const int MAX_MAPS = 4; + +out vec3 FragColor; + +in vec2 TexCoords; + +layout(binding = 0) uniform sampler2D gPosition; +layout(binding = 1) uniform sampler2D gNormal; +layout(binding = 2) uniform sampler2DArray shadowMap; + +uniform vec3 lightDirection; +uniform vec3 lightColour; +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, 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 86447ec..0000000 --- a/gfx/gl/shaders/directionalLight.fs +++ /dev/null @@ -1,50 +0,0 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable - -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; - -const vec3 e1 = vec3(0, 0, 0), e2 = vec3(1, 1, 1); - -float -insideShadowCube(vec3 v) -{ - const vec3 s = step(e1, v) - step(e2, v); - return s.x * s.y * s.z; -} - -float -isShaded(vec4 Position) -{ - for (uint m = 0u; m < lightViewProjectionCount; m++) { - const vec3 PositionInLightSpace = (lightViewProjection[m] * Position).xyz; - const float inside = insideShadowCube(PositionInLightSpace); - if (inside > 0) { - const float lightSpaceDepth = texture(shadowMap, vec3(PositionInLightSpace.xy, m)).r; - return step(PositionInLightSpace.z, lightSpaceDepth + 0.001); - } - } - return 1; -} - -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.vs b/gfx/gl/shaders/dynamicPoint.vert index 97d2983..fb4c7fd 100644 --- a/gfx/gl/shaders/dynamicPoint.vs +++ b/gfx/gl/shaders/dynamicPoint.vert @@ -1,14 +1,14 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core +#extension GL_ARB_shading_language_include : enable layout(binding = 1) uniform usampler2DRect materialData; -include(`meshIn.glsl') -include(`materialInterface.glsl') +#include "materialInterface.glsl" +#include "meshIn.glsl" uniform mat4 viewProjection; uniform ivec3 viewPoint; uniform mat3 model; uniform ivec3 modelPos; -include(`commonPoint.glsl') +#include "commonPoint.glsl" diff --git a/gfx/gl/shaders/dynamicPointInst.vert b/gfx/gl/shaders/dynamicPointInst.vert new file mode 100644 index 0000000..7c50706 --- /dev/null +++ b/gfx/gl/shaders/dynamicPointInst.vert @@ -0,0 +1,16 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(binding = 1) uniform usampler2DRect materialData; + +#include "commonLocationData.glsl" +#include "materialInterface.glsl" +#include "meshIn.glsl" + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +layout(location = 5) in uint index; +mat3 model = mat3(locations[cldIndex[index]].rotationMatrix); +ivec3 modelPos = locations[cldIndex[index]].position.xyz; + +#include "commonPoint.glsl" diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs deleted file mode 100644 index a85f9c9..0000000 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ /dev/null @@ -1,14 +0,0 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable - -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.vs b/gfx/gl/shaders/fixedPoint.vert index 435b3d1..fa9cf67 100644 --- a/gfx/gl/shaders/fixedPoint.vs +++ b/gfx/gl/shaders/fixedPoint.vert @@ -1,14 +1,14 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core +#extension GL_ARB_shading_language_include : enable layout(binding = 1) uniform usampler2DRect materialData; -include(`meshIn.glsl') -include(`materialInterface.glsl') +#include "materialInterface.glsl" +#include "meshIn.glsl" uniform mat4 viewProjection; uniform ivec3 viewPoint; const mat3 model = mat3(1); const vec3 modelPos = ivec3(0); -include(`commonPoint.glsl') +#include "commonPoint.glsl" diff --git a/gfx/gl/shaders/getMaterialDetail.glsl b/gfx/gl/shaders/getMaterialDetail.glsl index f819fb2..0169e4e 100644 --- a/gfx/gl/shaders/getMaterialDetail.glsl +++ b/gfx/gl/shaders/getMaterialDetail.glsl @@ -1,3 +1,8 @@ +#ifndef GET_MATERIAL_DETAIL_INCLUDED +#define GET_MATERIAL_DETAIL_INCLUDED + +#include "materialDetail.glsl" + MaterialDetail getMaterialDetail(uint midx) { @@ -10,3 +15,5 @@ getMaterialDetail(uint midx) } return MaterialDetail(vec2(0, 0), vec2(0, 0), uvec2(0, 0)); } + +#endif diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.frag index 55e3c24..d0a2ce3 100644 --- a/gfx/gl/shaders/landmass.fs +++ b/gfx/gl/shaders/landmass.frag @@ -1,12 +1,14 @@ -#version 330 core +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "materialOut.glsl" -include(`materialOut.glsl') in vec3 FragPos; in vec3 Normal; -flat in vec3 ColourBias; uniform sampler2D texture0; uniform ivec3 viewPoint; +uniform vec3 colourBias; const vec3 grass = vec3(.1, .4, .05); const vec3 slope = vec3(.6, .6, .4); @@ -35,8 +37,8 @@ main() vec3 color = texture(texture0, vec2(position.xy % 10000) / 10000.0).rgb; int height = position.z; - if (ColourBias.r >= 0) { - color *= ColourBias; + if (colourBias.r >= 0) { + color *= colourBias; } else if (height < beachline) { // Sandy beach color *= sand; @@ -67,7 +69,7 @@ main() } } - gPosition = ivec4(position, 1); + gPosition = vec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = vec4(color, 1); } diff --git a/gfx/gl/shaders/landmass.vs b/gfx/gl/shaders/landmass.vert index 9617cb9..91fc7f8 100644 --- a/gfx/gl/shaders/landmass.vs +++ b/gfx/gl/shaders/landmass.vert @@ -1,13 +1,10 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core layout(location = 0) in ivec3 position; layout(location = 1) in vec3 normal; -layout(location = 2) in vec3 colourBias; out vec3 FragPos; out vec3 Normal; -flat out vec3 ColourBias; uniform mat4 viewProjection; uniform ivec3 viewPoint; @@ -17,7 +14,6 @@ main() { FragPos = position - viewPoint; Normal = normal; - ColourBias = colourBias; gl_Position = viewProjection * vec4(FragPos, 1); } diff --git a/gfx/gl/shaders/lighting.fs b/gfx/gl/shaders/lighting.frag index 4646b75..b5c6c8b 100644 --- a/gfx/gl/shaders/lighting.fs +++ b/gfx/gl/shaders/lighting.frag @@ -1,5 +1,4 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core out vec3 FragColor; diff --git a/gfx/gl/shaders/lighting.vs b/gfx/gl/shaders/lighting.vert index e07cd0a..1046379 100644 --- a/gfx/gl/shaders/lighting.vs +++ b/gfx/gl/shaders/lighting.vert @@ -1,4 +1,4 @@ -#version 330 core +#version 460 core in ivec4 position; diff --git a/gfx/gl/shaders/material.fs b/gfx/gl/shaders/material.frag index 37f2e27..16ea6d1 100644 --- a/gfx/gl/shaders/material.fs +++ b/gfx/gl/shaders/material.frag @@ -1,11 +1,11 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core +#extension GL_ARB_shading_language_include : enable layout(binding = 0) uniform sampler2D textureAlbedo; -include(`materialInterface.glsl') -include(`materialOut.glsl') -include(`materialCommon.glsl') +#include "materialCommon.glsl" +#include "materialInterface.glsl" +#include "materialOut.glsl" void main() diff --git a/gfx/gl/shaders/materialCommon.glsl b/gfx/gl/shaders/materialCommon.glsl index 3fe2237..f905e76 100644 --- a/gfx/gl/shaders/materialCommon.glsl +++ b/gfx/gl/shaders/materialCommon.glsl @@ -1,3 +1,8 @@ +#ifndef MATERIAL_COMMON_INCLUDED +#define MATERIAL_COMMON_INCLUDED + +#include "materialDetail.glsl" + float map(uint mapmode, float value) { @@ -13,7 +18,7 @@ map(uint mapmode, float value) discard; } } - return 0; + return 0.0; } vec2 @@ -31,3 +36,5 @@ getTextureColour(MaterialDetail mat, vec2 uv) } return texture(textureAlbedo, uv); } + +#endif diff --git a/gfx/gl/shaders/materialDetail.glsl b/gfx/gl/shaders/materialDetail.glsl index a208d50..873b343 100644 --- a/gfx/gl/shaders/materialDetail.glsl +++ b/gfx/gl/shaders/materialDetail.glsl @@ -1,5 +1,10 @@ +#ifndef MATERIAL_DETAIL_INCLUDED +#define MATERIAL_DETAIL_INCLUDED + struct MaterialDetail { vec2 textureOrigin; vec2 textureSize; uvec2 mapmode; }; + +#endif diff --git a/gfx/gl/shaders/materialInterface.glsl b/gfx/gl/shaders/materialInterface.glsl index f2ca297..926bd6c 100644 --- a/gfx/gl/shaders/materialInterface.glsl +++ b/gfx/gl/shaders/materialInterface.glsl @@ -1,9 +1,18 @@ -include(`materialDetail.glsl') +#ifndef MATERIAL_INTERFACE_INCLUDED +#define MATERIAL_INTERFACE_INCLUDED -define(INOUT, ifelse(TYPE, .fs, in, out)); +#include "materialDetail.glsl" + +#ifdef GL_FRAGMENT_SHADER +# define INOUT in +#else +# define INOUT out +#endif INOUT vec3 FragPos; INOUT vec2 TexCoords; INOUT vec3 Normal; INOUT vec4 Colour; flat INOUT MaterialDetail Material; + +#endif diff --git a/gfx/gl/shaders/materialOut.glsl b/gfx/gl/shaders/materialOut.glsl index 846825e..928edf0 100644 --- a/gfx/gl/shaders/materialOut.glsl +++ b/gfx/gl/shaders/materialOut.glsl @@ -1,3 +1,8 @@ -layout(location = 0) out ivec4 gPosition; +#ifndef MATERIAL_OUT_INCLUDED +#define MATERIAL_OUT_INCLUDED + +layout(location = 0) out vec4 gPosition; layout(location = 1) out vec4 gNormal; layout(location = 2) out vec4 gAlbedoSpec; + +#endif diff --git a/gfx/gl/shaders/meshIn.glsl b/gfx/gl/shaders/meshIn.glsl index dd84a10..2a69391 100644 --- a/gfx/gl/shaders/meshIn.glsl +++ b/gfx/gl/shaders/meshIn.glsl @@ -1,5 +1,10 @@ +#ifndef MESH_OUT_INCLUDED +#define MESH_OUT_INCLUDED + layout(location = 0) in vec3 position; layout(location = 1) in vec2 texCoord; layout(location = 2) in vec3 normal; layout(location = 3) in vec4 colour; layout(location = 4) in uint material; + +#endif diff --git a/gfx/gl/shaders/network.fs b/gfx/gl/shaders/network.frag index 4e347b4..b7e24d2 100644 --- a/gfx/gl/shaders/network.fs +++ b/gfx/gl/shaders/network.frag @@ -1,17 +1,17 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "materialOut.glsl" -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); + gPosition = vec4(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 0bc3c1c..faa95ec 100644 --- a/gfx/gl/shaders/networkCommon.glsl +++ b/gfx/gl/shaders/networkCommon.glsl @@ -1,3 +1,6 @@ +#ifndef NETWORK_COMMON_INCLUDED +#define NETWORK_COMMON_INCLUDED + uniform vec3[10] profile; uniform float[10] texturePos; uniform uint profileLength; @@ -12,32 +15,43 @@ out vec2 texCoord; out vec3 rposition; float +viewPointDist(const ivec3 position) +{ + return length(vec3(viewPoint - position)); +} + +float segDist(const ivec3 a, const ivec3 b) { - return min(distance(viewPoint, a), distance(viewPoint, b)); + return min(viewPointDist(a), viewPointDist(b)); } -ifelse( - TYPE, .gs, - // 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); - rposition = vpos - viewPoint; - gl_Position = viewProjection * vec4(rposition, 1); - texCoord = vec2(texturePos[v], texY); - EmitVertex(); - } +#ifdef GL_GEOMETRY_SHADER // Begin: Geometry shader only function - void doSeg(const float dist, const ivec3 apos, const ivec3 bpos, const float atexY, const float btexY, - const mat2 arot, const mat2 brot) { - if (dist < clipDistance) { - uint vstep = (dist < flatDistance) ? 1u : profileLength - 1u; - for (uint v = 0u; v < profileLength; v += vstep) { - doVertex(bpos, v, btexY, brot); - doVertex(apos, v, atexY, arot); - } - EndPrimitive(); - } +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); + rposition = vpos - viewPoint; + gl_Position = viewProjection * vec4(rposition, 1); + texCoord = vec2(texturePos[v], texY); + EmitVertex(); +} + +void +doSeg(const float dist, const ivec3 apos, const ivec3 bpos, const float atexY, const float btexY, const mat2 arot, + const mat2 brot) +{ + if (dist < clipDistance) { + uint vstep = (dist < flatDistance) ? 1u : profileLength - 1u; + for (uint v = 0u; v < profileLength; v += vstep) { + doVertex(bpos, v, btexY, brot); + doVertex(apos, v, atexY, arot); } - // End: Geometry shader only function -) + EndPrimitive(); + } +} + +#endif // End: Geometry shader only function + +#endif diff --git a/gfx/gl/shaders/networkCurve.geom b/gfx/gl/shaders/networkCurve.geom new file mode 100644 index 0000000..a6bbd13 --- /dev/null +++ b/gfx/gl/shaders/networkCurve.geom @@ -0,0 +1,18 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(lines) in; +layout(triangle_strip, max_vertices = 10) out; + +flat in ivec3 pos[]; +flat in mat2 rot[]; +flat in float tpos[]; +flat in float dist[]; + +#include "networkCommon.glsl" + +void +main() +{ + doSeg(min(dist[0], dist[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 7cb6c42..0000000 --- a/gfx/gl/shaders/networkCurve.gs +++ /dev/null @@ -1,47 +0,0 @@ -#version 330 core - -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[]; - -layout(points) in; -layout(triangle_strip, max_vertices = GL_MAX_GEOMETRY_OUTPUT_VERTICES) out; - -const mat2 rot = mat2(1); - -include(`networkCommon.glsl') - -mat2 -getRot(float angle) -{ - return mat2(cos(angle), sin(angle), -sin(angle), cos(angle)); -} - -void -main() -{ - float segs = clamp( - round(reps[0] * radius[0] / 1000), 4, floor(uint(GL_MAX_GEOMETRY_OUTPUT_VERTICES) / (profileLength * 2u))); - vec3 arcstep = vec3((bangle[0] - aangle[0]), // angle - reps[0], // texture - (bpos[0].z - apos[0].z)) // height - / segs; - - ivec3 prevPos = apos[0]; - mat2 prevRot = getRot(aangle[0]); - float prevTex = 0; - for (vec3 arc = arcstep; arc.y < reps[0] - 0.01; arc += arcstep) { - mat2 rot = getRot(arc.x + aangle[0]); - ivec3 pos = cpos[0] + ivec3(rot * vec2(radius[0], 0), arc.z); - float tex = arc.y; - doSeg(segDist(prevPos, pos), pos, prevPos, tex, prevTex, rot, prevRot); - prevPos = pos; - prevRot = rot; - prevTex = tex; - } - doSeg(segDist(prevPos, bpos[0]), bpos[0], prevPos, reps[0], prevTex, getRot(bangle[0]), prevRot); -} diff --git a/gfx/gl/shaders/networkCurve.tesc b/gfx/gl/shaders/networkCurve.tesc new file mode 100644 index 0000000..5a6e449 --- /dev/null +++ b/gfx/gl/shaders/networkCurve.tesc @@ -0,0 +1,37 @@ +#version 460 core + +layout(vertices = 1) out; + +flat in ivec3 pos[][2]; +flat in ivec2 cpos[]; +flat in float reps[]; +flat in float angles[][2]; +flat in float radius[]; + +flat out ivec3 c_pos[][2]; +flat out ivec2 c_cpos[]; +flat out float c_reps[]; +flat out float c_angles[][2]; +flat out float c_radius[]; + +float +segments() +{ + const float arc = angles[gl_InvocationID][0] - angles[gl_InvocationID][1]; + const float error = 100.; + const float diff = acos(1.f - (error / radius[gl_InvocationID])); + return clamp(arc / diff, arc, 180); +} + +void +main() +{ + c_pos[gl_InvocationID] = pos[gl_InvocationID]; + c_cpos[gl_InvocationID] = cpos[gl_InvocationID]; + c_reps[gl_InvocationID] = reps[gl_InvocationID]; + c_angles[gl_InvocationID] = angles[gl_InvocationID]; + c_radius[gl_InvocationID] = radius[gl_InvocationID]; + + gl_TessLevelOuter[0] = 1; + gl_TessLevelOuter[1] = segments(); +} diff --git a/gfx/gl/shaders/networkCurve.tese b/gfx/gl/shaders/networkCurve.tese new file mode 100644 index 0000000..1331776 --- /dev/null +++ b/gfx/gl/shaders/networkCurve.tese @@ -0,0 +1,46 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(isolines, equal_spacing, cw) in; + +flat in ivec3 c_pos[][2]; +flat in ivec2 c_cpos[]; +flat in float c_reps[]; +flat in float c_angles[][2]; +flat in float c_radius[]; + +flat out ivec3 pos; +flat out mat2 rot; +flat out float tpos; +flat out float dist; + +const float startTolerance = 1. / 200.; +const float endTolerance = 1. - startTolerance; + +#include "networkCommon.glsl" + +mat2 +getRot(float angle) +{ + return mat2(cos(angle), sin(angle), -sin(angle), cos(angle)); +} + +void +main() +{ + const float angle = mix(c_angles[0][1], c_angles[0][0], gl_TessCoord.x); + rot = getRot(angle); + if (gl_TessCoord.x < startTolerance) { + pos = c_pos[0][1]; + } + else if (gl_TessCoord.x > endTolerance) { + pos = c_pos[0][0]; + } + else { + const int height = int(mix(c_pos[0][1].z, c_pos[0][0].z, gl_TessCoord.x)); + pos = ivec3(c_cpos[0] + ivec2(rot * vec2(c_radius[0], 0)), height); + } + + tpos = c_reps[0] * gl_TessCoord.x; + dist = viewPointDist(pos); +} diff --git a/gfx/gl/shaders/networkCurve.vert b/gfx/gl/shaders/networkCurve.vert new file mode 100644 index 0000000..7e363d3 --- /dev/null +++ b/gfx/gl/shaders/networkCurve.vert @@ -0,0 +1,23 @@ +#version 460 core + +layout(location = 0) in ivec3 v_pos[2]; +layout(location = 2) in ivec3 v_centre; +layout(location = 3) in float v_reps; +layout(location = 4) in float v_angles[2]; +layout(location = 6) in float v_radius; + +flat out ivec3 pos[2]; +flat out ivec2 cpos; +flat out float reps; +flat out float angles[2]; +flat out float radius; + +void +main() +{ + pos = v_pos; + cpos = v_centre.xy; + reps = v_reps; + angles = v_angles; + radius = v_radius; +} diff --git a/gfx/gl/shaders/networkCurve.vs b/gfx/gl/shaders/networkCurve.vs deleted file mode 100644 index f51bb87..0000000 --- a/gfx/gl/shaders/networkCurve.vs +++ /dev/null @@ -1,29 +0,0 @@ -#version 330 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..0aa029a --- /dev/null +++ b/gfx/gl/shaders/networkStraight.geom @@ -0,0 +1,18 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(points) in; +layout(triangle_strip, max_vertices = 10) out; + +flat in ivec3 pos[][2]; +flat in mat2 rot[]; +flat in float reps[]; +flat in float dist[]; + +#include "networkCommon.glsl" + +void +main() +{ + doSeg(dist[0], pos[0][0], pos[0][1], 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 51df5fb..0000000 --- a/gfx/gl/shaders/networkStraight.gs +++ /dev/null @@ -1,17 +0,0 @@ -#version 330 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..ffd7deb --- /dev/null +++ b/gfx/gl/shaders/networkStraight.vert @@ -0,0 +1,22 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(location = 0) in ivec3 v_pos[2]; +layout(location = 2) in mat2 v_rot; +layout(location = 4) in float v_reps; + +flat out ivec3 pos[2]; +flat out mat2 rot; +flat out float reps; +flat out float dist; + +#include "networkCommon.glsl" + +void +main() +{ + pos = v_pos; + rot = v_rot; + reps = v_reps; + dist = segDist(v_pos[0], v_pos[1]); +} diff --git a/gfx/gl/shaders/networkStraight.vs b/gfx/gl/shaders/networkStraight.vs deleted file mode 100644 index 55f9c4f..0000000 --- a/gfx/gl/shaders/networkStraight.vs +++ /dev/null @@ -1,24 +0,0 @@ -#version 330 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.fs b/gfx/gl/shaders/pointLight.frag index 7531d3e..a141592 100644 --- a/gfx/gl/shaders/pointLight.fs +++ b/gfx/gl/shaders/pointLight.frag @@ -1,9 +1,8 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core out vec3 FragColor; -layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 0) uniform sampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; flat in vec4 geo_centre; diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.geom index fc1d7c3..1ee7e06 100644 --- a/gfx/gl/shaders/pointLight.gs +++ b/gfx/gl/shaders/pointLight.geom @@ -1,6 +1,4 @@ -#version 330 core -#extension GL_ARB_enhanced_layouts : enable -#extension GL_ARB_shading_language_420pack : enable +#version 460 core const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf vec3(-1, 1, 1), // Front-top-left diff --git a/gfx/gl/shaders/pointLight.vert b/gfx/gl/shaders/pointLight.vert new file mode 100644 index 0000000..61953ad --- /dev/null +++ b/gfx/gl/shaders/pointLight.vert @@ -0,0 +1,28 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "commonLocationData.glsl" + +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 uint index; +mat3 model = mat3(locations[cldIndex[index]].rotationMatrix); +ivec3 modelPos = locations[cldIndex[index]].position.xyz; + +uniform ivec3 viewPoint; + +flat out vec3 position; +flat out vec3 colour; +flat out float size; +flat out float kq; + +void +main() +{ + position = (modelPos - viewPoint) + 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, 0); +} diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs deleted file mode 100644 index fbd031c..0000000 --- a/gfx/gl/shaders/pointLight.vs +++ /dev/null @@ -1,24 +0,0 @@ -#version 330 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..248b7b0 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPoint.vert @@ -0,0 +1,10 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#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 7335b9a..0000000 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 330 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..b978e4a --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInst.vert @@ -0,0 +1,12 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "commonLocationData.glsl" +#include "meshIn.glsl" + +uniform ivec3 viewPoint; +layout(location = 5) in uint index; +mat3 model = mat3(locations[cldIndex[index]].rotationMatrix); +ivec3 modelPos = locations[cldIndex[index]].position.xyz; + +#include "commonShadowPoint.glsl" diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs deleted file mode 100644 index d0eb649..0000000 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 330 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.fs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.frag index 47ce9c0..e9d83d2 100644 --- a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.frag @@ -1,10 +1,10 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core +#extension GL_ARB_shading_language_include : enable layout(binding = 3) uniform sampler2D textureAlbedo; -include(`materialInterface.glsl') -include(`materialCommon.glsl') +#include "materialCommon.glsl" +#include "materialDetail.glsl" in vec2 texCoord; flat in MaterialDetail material; diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.geom b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.geom new file mode 100644 index 0000000..72e4075 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.geom @@ -0,0 +1,5 @@ +#version 460 +#extension GL_ARB_shading_language_include : enable +#define TEXTURES + +#include "commonShadowPoint-geom.glsl" 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..a5e8245 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vert @@ -0,0 +1,17 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable +#define TEXTURES + +layout(binding = 4) uniform usampler2DRect materialData; + +#include "commonLocationData.glsl" +#include "getMaterialDetail.glsl" +#include "materialInterface.glsl" +#include "meshIn.glsl" + +uniform ivec3 viewPoint; +layout(location = 5) in uint index; +mat3 model = mat3(locations[cldIndex[index]].rotationMatrix); +ivec3 modelPos = locations[cldIndex[index]].position.xyz; + +#include "commonShadowPoint.glsl" diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs deleted file mode 100644 index a76c87f..0000000 --- a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs +++ /dev/null @@ -1,15 +0,0 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable - -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.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.vert b/gfx/gl/shaders/shadowDynamicPointStencil.vert new file mode 100644 index 0000000..0a41143 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointStencil.vert @@ -0,0 +1,18 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "commonLocationData.glsl" + +layout(location = 0) in uint index; +uniform ivec3 viewPoint; +uniform vec3 centre; + +out float vmodelYaw; +out ivec3 vworldPos; + +void +main() +{ + vmodelYaw = locations[cldIndex[index]].rotation.x; + vworldPos = locations[cldIndex[index]].position.xyz - viewPoint + ivec3(centre); +} diff --git a/gfx/gl/shaders/shadowLandmass.vs b/gfx/gl/shaders/shadowLandmass.vert index becf142..cf68fe5 100644 --- a/gfx/gl/shaders/shadowLandmass.vs +++ b/gfx/gl/shaders/shadowLandmass.vert @@ -1,4 +1,4 @@ -#version 330 core +#version 460 core layout(location = 0) in ivec3 position; diff --git a/gfx/gl/shaders/shadowStencil.frag b/gfx/gl/shaders/shadowStencil.frag new file mode 100644 index 0000000..35cdf6e --- /dev/null +++ b/gfx/gl/shaders/shadowStencil.frag @@ -0,0 +1,19 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(binding = 0) uniform sampler2D textureAlbedo; + +#include "materialCommon.glsl" +#include "materialDetail.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..9c5ba48 --- /dev/null +++ b/gfx/gl/shaders/shadowStencil.geom @@ -0,0 +1,28 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#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..98e8434 --- /dev/null +++ b/gfx/gl/shaders/shadowStencil.vert @@ -0,0 +1,20 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +layout(binding = 1) uniform usampler2DRect materialData; + +#include "getMaterialDetail.glsl" +#include "materialDetail.glsl" +#include "meshIn.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.fs b/gfx/gl/shaders/spotLight.frag index ad33458..0241e88 100644 --- a/gfx/gl/shaders/spotLight.fs +++ b/gfx/gl/shaders/spotLight.frag @@ -1,9 +1,8 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable +#version 460 core out vec3 FragColor; -layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 0) uniform sampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; flat in vec4 geo_centre; diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.geom index 194812a..fec191e 100644 --- a/gfx/gl/shaders/spotLight.gs +++ b/gfx/gl/shaders/spotLight.geom @@ -1,6 +1,4 @@ -#version 330 core -#extension GL_ARB_enhanced_layouts : enable -#extension GL_ARB_shading_language_420pack : enable +#version 460 core const vec3[] pyramid = vec3[]( // four-sided vec3(0, 0, 0), // Apex diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vert index e0196c3..6f72a63 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vert @@ -1,12 +1,16 @@ -#version 330 core +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "commonLocationData.glsl" 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; +layout(location = 5) in uint index; +mat3 model = mat3(locations[cldIndex[index]].rotationMatrix); +ivec3 modelPos = locations[cldIndex[index]].position.xyz; uniform ivec3 viewPoint; @@ -20,11 +24,11 @@ flat out float kq; void main() { - position = modelPos + ivec3(mat3(model) * v_position); + position = (modelPos - viewPoint) + 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); + gl_Position = vec4(position, 0); } diff --git a/gfx/gl/shaders/uiShader.fs b/gfx/gl/shaders/uiShader.fs deleted file mode 100644 index c5f4e92..0000000 --- a/gfx/gl/shaders/uiShader.fs +++ /dev/null @@ -1,11 +0,0 @@ -#version 330 core - -in vec2 texCoord0; - -uniform sampler2D sampler; - -void -main() -{ - gl_FragColor = texture(sampler, texCoord0); -} diff --git a/gfx/gl/shaders/uiShader.vs b/gfx/gl/shaders/uiShader.vs deleted file mode 100644 index e9e4373..0000000 --- a/gfx/gl/shaders/uiShader.vs +++ /dev/null @@ -1,13 +0,0 @@ -#version 330 core - -in vec4 position; - -out vec2 texCoord0; -uniform mat4 uiProjection; - -void -main() -{ - gl_Position = uiProjection * vec4(position.xy, 0.0, 1.0); - texCoord0 = position.zw; -} diff --git a/gfx/gl/shaders/uiShaderFont.fs b/gfx/gl/shaders/uiShaderFont.fs deleted file mode 100644 index a1ef6ef..0000000 --- a/gfx/gl/shaders/uiShaderFont.fs +++ /dev/null @@ -1,12 +0,0 @@ -#version 330 core - -in vec2 texCoord0; - -uniform sampler2D sampler; -uniform vec3 colour; - -void -main() -{ - gl_FragColor = vec4(colour, texture(sampler, texCoord0).r); -} diff --git a/gfx/gl/shaders/water.frag b/gfx/gl/shaders/water.frag new file mode 100644 index 0000000..0c57bfb --- /dev/null +++ b/gfx/gl/shaders/water.frag @@ -0,0 +1,18 @@ +#version 460 core +#extension GL_ARB_shading_language_include : enable + +#include "materialOut.glsl" + +in vec4 FragPos; +in vec2 TexCoords; + +uniform sampler2D texture0; + +void +main() +{ + gPosition = vec4(FragPos.xyz, 1); + gNormal = vec4(0, 0, 1, 1); + gAlbedoSpec = texture(texture0, TexCoords); + gAlbedoSpec.a *= clamp(-FragPos.w * .0007, .1, 1.0); +} diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs deleted file mode 100644 index 0918d9f..0000000 --- a/gfx/gl/shaders/water.fs +++ /dev/null @@ -1,17 +0,0 @@ -#version 330 core -#extension GL_ARB_shading_language_420pack : enable - -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.vs b/gfx/gl/shaders/water.vert index 58bf7b6..bb056b8 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vert @@ -1,7 +1,7 @@ -#version 330 core +#version 460 core layout(location = 0) in ivec3 position; -out vec3 FragPos; +out vec4 FragPos; out vec2 TexCoords; uniform mat4 viewProjection; @@ -14,8 +14,8 @@ 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); + FragPos = vec4(wpos - viewPoint, position.z); TexCoords = (position.xy / 8192) - (viewPoint.xy / 8192); - gl_Position = viewProjection * vec4(wpos - viewPoint, 1.0); + gl_Position = viewProjection * vec4(FragPos.xyz, 1.0); } |
