diff options
Diffstat (limited to 'data')
-rw-r--r-- | data/shaders/pbr-frag.glsl | 22 |
1 files changed, 22 insertions, 0 deletions
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 |