Advertisement
Guest User

Shader mask

a guest
May 7th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* GLSL */
  2.  
  3. // fragmentShader:
  4. #ifdef GL_ES
  5. precision mediump float;
  6. #endif
  7.  
  8. varying vec4 v_color;
  9. varying vec2 v_texCoords;
  10. uniform sampler2D u_texture;
  11. uniform sampler2D u_maskTexture;
  12.  
  13. void main() {
  14.     vec4 color = v_color texture2D( u_texture, v_texCoords );
  15.     vec2 maskCoords = vec2(v_texCoords.x 2.0, v_texCoords.y 12.0);
  16.     vec3 mask_color = texture2D(u_maskTexture, maskCoords).rgb;
  17.     if( color.a == 0.0 ) gl_FragColor = vec4( color.r, color.g, color.b, color.a );
  18.     else gl_FragColor = vec4( mask_color.r, mask_color.g, mask_color.b, color.a );
  19. }
  20.  
  21. // vertexShader:
  22. attribute vec4 a_position;
  23. attribute vec4 a_color;
  24. attribute vec2 a_texCoord0;
  25. attribute vec3 a_maskTexture;
  26.  
  27. uniform mat4 u_projTrans;
  28.  
  29. varying vec3 v_maskTexture;
  30. varying vec4 v_color;
  31. varying vec2 v_texCoords;
  32.  
  33. void main() {
  34.     v_color = a_color;
  35.     v_maskTexture = a_maskTexture;
  36.     v_texCoords = a_texCoord0;
  37.     gl_Position = u_projTrans a_position;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement