How to do it...

To discard fragments based on alpha data from a texture, use the following steps:

  1. Use the same vertex and fragment shaders from the Applying a 2D texture recipe. However, make the following modifications to the fragment shader.
  2. Replace the sampler2D uniform variable with the following:
layout(binding=0) uniform sampler2D BaseTex; 
layout(binding=1) uniform sampler2D AlphaTex;
  1. In the blinnPhong function, use BaseTex to look up the value of the ambient and diffuse reflectivity.
  2. Replace the contents of the main function with the following code:
void main() {
vec4 alphaMap = texture( AlphaTex, TexCoord );

if(alphaMap.a < 0.15 )
discard;
else {
if( gl_FrontFacing ) {
FragColor = vec4(
blinnPhong(Position,normalize(Normal)), 1.0 );
} else {
FragColor = vec4( blinnPhong(Position,normalize(-
Normal)), 1.0 );
}
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.100.180