summaryrefslogtreecommitdiff
path: root/data/shaders
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-05-08 09:00:26 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-05-08 09:00:26 -0400
commit9187edcd45e97efd5b4d699c071bc1530f298d54 (patch)
tree1f08cca206b8ed26c6f91248b97dcab101eccd2f /data/shaders
parent636f3bde96b9878d241500e38fe830fbd7013465 (diff)
graphics: model: Add basic alpha mode support for glTF models.
Diffstat (limited to 'data/shaders')
-rw-r--r--data/shaders/pbr-frag.glsl22
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