From 425add81fc8718f1ac4fde48a71344cd332d5a58 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jul 2024 20:10:24 +0100 Subject: Add shadow shader which takes into account texture transparency --- gfx/gl/shaders/commonShadowPoint.glsl | 3 +++ gfx/gl/shaders/commonShadowPoint.gs | 3 +++ gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs | 15 +++++++++++++++ gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs | 3 +++ gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs | 3 +++ 5 files changed, 27 insertions(+) create mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs create mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs create mode 100644 gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/commonShadowPoint.glsl b/gfx/gl/shaders/commonShadowPoint.glsl index ba4611a..c4ea827 100644 --- a/gfx/gl/shaders/commonShadowPoint.glsl +++ b/gfx/gl/shaders/commonShadowPoint.glsl @@ -1,8 +1,11 @@ out vec4 vworldPos; +ifdef(`TEXTURES', out vec2 vtexCoord;); + void main() { vec3 worldPos = model * position; vworldPos = vec4(worldPos - viewPoint + modelPos, 1); + ifdef(`TEXTURES', vtexCoord = texCoord;); } diff --git a/gfx/gl/shaders/commonShadowPoint.gs b/gfx/gl/shaders/commonShadowPoint.gs index b008f29..b99bd20 100644 --- a/gfx/gl/shaders/commonShadowPoint.gs +++ b/gfx/gl/shaders/commonShadowPoint.gs @@ -7,6 +7,8 @@ in vec4 vworldPos[]; layout(triangles) in; layout(triangle_strip, max_vertices = 12) out; +ifdef(`TEXTURES', in vec2 vtexCoord[]; out vec2 texCoord;); + void main() { @@ -15,6 +17,7 @@ main() gl_Position = viewProjection[vp] * vworldPos[v]; gl_Position.z = max(gl_Position.z, -1); gl_Layer = vp; + ifdef(`TEXTURES', texCoord = vtexCoord[v];); EmitVertex(); } EndPrimitive(); diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs new file mode 100644 index 0000000..90519e3 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.fs @@ -0,0 +1,15 @@ +#version 330 core +#extension GL_ARB_shading_language_420pack : enable + +layout(binding = 3) uniform sampler2D texture0; + +in vec2 texCoord; + +void +main() +{ + if (texture(texture0, texCoord).a < 0.5) { + discard; + } + gl_FragDepth = gl_FragCoord.z; +} diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs new file mode 100644 index 0000000..e6e213e --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.gs @@ -0,0 +1,3 @@ +define(`TEXTURES', 1) + +include(`commonShadowPoint.gs') diff --git a/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs new file mode 100644 index 0000000..27ad9d7 --- /dev/null +++ b/gfx/gl/shaders/shadowDynamicPointInstWithTextures.vs @@ -0,0 +1,3 @@ +define(`TEXTURES', 1) + +include(`shadowDynamicPointInst.vs') -- cgit v1.2.3