Advertisement
Xorboo

[Defold] Fragment shader

Nov 27th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. varying mediump vec4 position;
  2. varying mediump vec2 var_texcoord0;
  3. varying lowp vec4 colors[10];
  4.  
  5. uniform lowp sampler2D DIFFUSE_TEXTURE;
  6. uniform lowp vec4 tint;
  7. uniform lowp vec4 saturation;
  8.  
  9. void main()
  10. {
  11.     lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
  12.    
  13.     lowp vec4 initial_color = texture2D(DIFFUSE_TEXTURE, var_texcoord0.xy);
  14.     // Convert red channel to index [0..9]
  15.     lowp int index = int(floor(min(initial_color.x * 10.0, 9.9)));
  16.     // Use that index to get the new color from colors array
  17.     lowp vec4 color = colors[index];
  18.     // Save the original alpha channel value
  19.     color.w = initial_color.w;
  20.        
  21.     {
  22.         color.x = (color.x * (1.0 - saturation.w) + saturation.x * saturation.w) * color.w;
  23.         color.y = (color.y * (1.0 - saturation.w) + saturation.y * saturation.w) * color.w;
  24.         color.z = (color.z * (1.0 - saturation.w) + saturation.z * saturation.w) * color.w;
  25.     }    
  26.    
  27.     gl_FragColor = color * tint_pm;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement