]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/phong.glsl
Add support for alpha to coverage
[libs/gl.git] / shaderlib / phong.glsl
index 28e9e5007be0af9c7e706353d2a67c16ea965ab2..5334455cd240cf1cba32084852ad33b3a673f1f2 100644 (file)
@@ -14,7 +14,7 @@ struct BasicMaterialParameters
 layout(set=1) uniform BasicMaterial
 {
        BasicMaterialParameters basic_material;
-       float alpha_cutoff;
+       AlphaCutoffParameters alpha_cutoff;
 };
 
 layout(set=1) uniform sampler2D diffuse_map;
@@ -31,7 +31,6 @@ layout(constant_id=auto) const bool use_emission = false;
 layout(constant_id=auto) const bool use_emission_map = false;
 layout(constant_id=auto) const bool use_reflectivity = false;
 layout(constant_id=auto) const bool use_reflectivity_map = false;
-layout(constant_id=auto) const bool use_alpha_cutoff = false;
 
 #pragma MSP stage(fragment)
 virtual vec4 get_diffuse_color()
@@ -115,8 +114,7 @@ vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_s
 void main()
 {
        vec4 surface_diffuse = get_diffuse_color();
-       if(use_alpha_cutoff && surface_diffuse.a<alpha_cutoff)
-               discard;
+       float alpha = apply_alpha_cutoff(surface_diffuse.a, alpha_cutoff);
 
        vec3 normal = get_fragment_normal();
        vec3 look = normalize(world_look_dir);
@@ -126,5 +124,5 @@ void main()
 
        vec3 lit_color = phong_lighting(normal, look, surface_diffuse.rgb, surface_specular, shininess);
 
-       frag_color = vec4(lit_color, surface_diffuse.a);
+       frag_color = vec4(lit_color, alpha);
 }