Advertisement
MLSTRM

minimal optimisations lol

Oct 7th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. varying vec2 v_vTexcoord;
  2. varying vec4 v_vColour;
  3.  
  4. uniform sampler2D interior;
  5. uniform vec3 u_color;
  6. #define OUTLINE_RADIUS 4.0
  7. #define ASPECT_X (1.0/800.0)
  8. #define ASPECT_Y (1.0/608.0)
  9.  
  10. void main() {
  11. vec3 outline_color = u_color/255.0;
  12. // Final alpha of the fragment (for cutout effect)
  13. float final_alpha = texture2D(gm_BaseTexture, v_vTexcoord).a;
  14.  
  15. // Interior color of the fragment (for interior effect)
  16. vec3 interior_color = texture2D(interior, v_vTexcoord).rgb;
  17.  
  18. // Minimum distance to non-interior (for outline efect)
  19. float mindist_squared = 17.0;
  20. for (int oy = -OUTLINE_RADIUS; oy <= OUTLINE_RADIUS; oy += 1) {
  21. for (int ox = -OUTLINE_RADIUS; ox <= OUTLINE_RADIUS; ox += 1) {
  22. vec4 geom_test = texture2D(gm_BaseTexture, v_vTexcoord+vec2(ox * ASPECT_X, oy * ASPECT_Y));
  23. float distsquared = ox * ox + oy * oy;
  24. mindist_squared = min( mindist_squared,
  25. mix(distsquared, 999.0, geom_test.a));
  26. }
  27. }
  28. float outline_strength =(sqrt(mindist_squared)/OUTLINE_RADIUS);
  29. float final_outline = smoothstep(0.4, 0.8, outline_strength);
  30. float solid_alpha = smoothstep(0.75, 0.95, final_alpha);
  31.  
  32. gl_FragColor = vec4(mix(vec3(outline_color), interior_color, final_outline), solid_alpha);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement