From 9187edcd45e97efd5b4d699c071bc1530f298d54 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 8 May 2021 09:00:26 -0400 Subject: graphics: model: Add basic alpha mode support for glTF models. --- data/shaders/pbr-frag.glsl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'data') diff --git a/data/shaders/pbr-frag.glsl b/data/shaders/pbr-frag.glsl index ce252ab..5b21fe1 100644 --- a/data/shaders/pbr-frag.glsl +++ b/data/shaders/pbr-frag.glsl @@ -15,6 +15,7 @@ struct Material { vec3 emissiveFactor; bool emissiveTextureEnabled; int emissiveTexcoord; + int alphaMode; float alphaCutoff; }; @@ -49,6 +50,25 @@ vec4 sampleTexture(sampler2D tex, bool enabled, int texcoord, vec3 factor, vec4 } } +vec4 applyAlpha(vec4 color) { + // Apply alpha mode. + if(material.alphaMode == 0) { + return vec4(color.xyz, 1.0); + } else if(material.alphaMode == 1) { + if(color.a >= material.alphaCutoff) { + return vec4(color.xyz, 1.0); + } else { + discard; + } + } else if(material.alphaMode == 2) { + if(color.a <= 0.005) { + discard; + } else { + return color; + } + } +} + void main(void) { vec4 finalColor = sampleTexture(baseColorTexture, material.baseColorTextureEnabled, @@ -77,6 +97,8 @@ void main(void) { material.emissiveTexcoord, material.emissiveFactor, vec4(0.0, 0.0, 0.0, 0.0)); + finalColor = applyAlpha(finalColor); + #ifdef GLSL330 fragColor = finalColor; #else -- cgit v1.2.3