설명 없음

sdf.frag 840B

1234567891011121314151617181920212223242526272829303132333435
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform sampler2D samplerColor;
  5. layout (binding = 2) uniform UBO
  6. {
  7. vec4 outlineColor;
  8. float outlineWidth;
  9. float outline;
  10. } ubo;
  11. layout (location = 0) in vec2 inUV;
  12. layout (location = 0) out vec4 outFragColor;
  13. void main()
  14. {
  15. float distance = texture(samplerColor, inUV).a;
  16. float smoothWidth = fwidth(distance);
  17. float alpha = smoothstep(0.5 - smoothWidth, 0.5 + smoothWidth, distance);
  18. vec3 rgb = vec3(alpha);
  19. if (ubo.outline > 0.0)
  20. {
  21. float w = 1.0 - ubo.outlineWidth;
  22. alpha = smoothstep(w - smoothWidth, w + smoothWidth, distance);
  23. rgb += mix(vec3(alpha), ubo.outlineColor.rgb, alpha);
  24. }
  25. outFragColor = vec4(rgb, alpha);
  26. }