Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 300
  2.  
  3. //modified from https://gamedev.stackexchange.com/q/159657/99481
  4. uniform sampler2D u_texture;
  5. uniform float u_smoothing;
  6. in vec4 v_color;
  7. in vec2 v_texCoords;
  8. out vec4 fragColor;
  9.  
  10. void main() {
  11.   // SDF
  12.   vec4 tex_color = texture(u_texture, v_texCoords);
  13.   float tex_distance = tex_color.a;
  14.   float min_bound = 0.5f - u_smoothing;
  15.   float max_bound = 0.5f + u_smoothing;
  16.   float alpha = smoothstep(min_bound, max_bound, tex_distance);
  17.   float v_alpha = v_color.a
  18.   float sdfAlpha = alpha * v_alpha;
  19.   vec3 sdfRGB = v_color.rgb;
  20.   vec4 sdfColor = vec4(sdfRGB, sdfAlpha);
  21.  
  22.   // Regular
  23.   vec4 regularColor = v_color * tex_color;
  24.  
  25.   float v_x = v_texCoords.x;
  26.   float sdf_step = step(1.0f, v_x);
  27.   // Making a choice
  28.   fragColor = mix(regularColor, sdfColor, sdf_step);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement