diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-01-23 21:57:31 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-01-23 21:57:31 -0500 |
| commit | e93eb289ca44e98967482ab80fd5329f85ccd03e (patch) | |
| tree | 4164b6d5b9ac2e40d18ec3eea52730c9f9606ccb /assets/shaders | |
| parent | 846a6e1185417ee3e187edc06ef327d180bf0d9b (diff) | |
pke: first-pass 2d overlay render pass scaffolding
Diffstat (limited to 'assets/shaders')
| -rw-r--r-- | assets/shaders/glyph.frag | 24 | ||||
| -rw-r--r-- | assets/shaders/glyph.vert | 32 | ||||
| -rw-r--r-- | assets/shaders/present.vert | 8 | ||||
| -rw-r--r-- | assets/shaders/vertex.vert | 22 |
4 files changed, 71 insertions, 15 deletions
diff --git a/assets/shaders/glyph.frag b/assets/shaders/glyph.frag new file mode 100644 index 0000000..90186a3 --- /dev/null +++ b/assets/shaders/glyph.frag @@ -0,0 +1,24 @@ +# version 450 + +layout(location = 0) in vec4 in_fg_color; +layout(location = 1) in vec4 in_bg_color; +layout(location = 2) in vec4 in_sprite_region; +layout(location = 3) in vec2 in_uv; +layout(location = 4) in float in_width; + +layout(location = 0) out vec4 out_color; + +layout(binding = 1) uniform sampler2D mtsdfSampler; + +float median(float r, float g, float b) { + return max(min(r, g), min(max(r, g), b)); +} + +void main() { + vec2 atlas_coord = (in_uv - in_sprite_region.xy) / in_sprite_region.zw; + vec4 msd = texture(mtsdfSampler, atlas_coord); + float sd = median(msd.r, msd.g, msd.b); + float screenPxDistance = in_width * (sd - 0.5); + float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + out_color = mix(in_bg_color, in_fg_color, opacity); +} diff --git a/assets/shaders/glyph.vert b/assets/shaders/glyph.vert new file mode 100644 index 0000000..52981c2 --- /dev/null +++ b/assets/shaders/glyph.vert @@ -0,0 +1,32 @@ +#version 450 + +// vertex +layout(location = 0) in vec2 in_position; +layout(location = 1) in vec2 in_uv; + +// instance +layout(location = 2) in vec4 in_fg_color; +layout(location = 3) in vec4 in_bg_color; +layout(location = 4) in vec4 in_sprite_region; +layout(location = 5) in float in_width; + +layout(location = 0) out vec4 out_fg_color; +layout(location = 1) out vec4 out_bg_color; +layout(location = 2) out vec4 out_sprite_region; +layout(location = 3) out vec2 out_uv; +layout(location = 4) out float out_width; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() +{ + gl_Position = vec4(in_position, 0.0, 1.0); + out_fg_color = in_fg_color; + out_bg_color = in_bg_color; + out_sprite_region = in_sprite_region; + out_uv = in_uv; + out_width = in_width; +} diff --git a/assets/shaders/present.vert b/assets/shaders/present.vert index 5423fcf..a5d60d0 100644 --- a/assets/shaders/present.vert +++ b/assets/shaders/present.vert @@ -4,11 +4,11 @@ layout (location = 0) out vec2 outUV; out gl_PerVertex { - vec4 gl_Position; + vec4 gl_Position; }; void main() { - outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); - gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f); -}
\ No newline at end of file + outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); + gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f); +} diff --git a/assets/shaders/vertex.vert b/assets/shaders/vertex.vert index 57fa219..8b2c133 100644 --- a/assets/shaders/vertex.vert +++ b/assets/shaders/vertex.vert @@ -1,9 +1,9 @@ #version 450 layout(binding = 0) uniform UniformBufferObject { - mat4 model; - mat4 view; - mat4 proj; + mat4 model; + mat4 view; + mat4 proj; } ubo; // vertex @@ -20,12 +20,12 @@ layout(location = 0) out vec4 fragColor; layout(location = 1) out vec3 fragTexCoord; void main() { - gl_Position = - ubo.proj * - ubo.view * - ubo.model * - instPosRotScale * - vec4(inPosition, 1.0); - fragColor = vec4(0.0, 0.0, 0.0, 0.0); - fragTexCoord = vec3(inUV, 0); + gl_Position = + ubo.proj * + ubo.view * + ubo.model * + instPosRotScale * + vec4(inPosition, 1.0); + fragColor = vec4(0.0, 0.0, 0.0, 0.0); + fragTexCoord = vec3(inUV, 0); } |
