prosperon/shaders/9slice.cg

33 lines
601 B
Plaintext
Raw Normal View History

2024-07-09 01:03:39 -05:00
@block vert
uniform vec4 rect;
uniform vec2 diffuse_size;
void vert()
{
pos *= vec3(diffuse_size*rect.zw, 1);
uv = (uv*rect.zw)+rect.xy;
}
@end
@block frag
uniform vec4 border;
2024-07-09 13:48:15 -05:00
uniform vec2 scale;
uniform vec4 shade;
// border given as [left,down,right,top], in scaled coordinates
2024-07-09 01:03:39 -05:00
vec2 uv9slice(vec2 uv, vec2 s, vec4 b)
{
vec2 t = clamp((s * uv - b.xy) / (s - b.xy - b.zw), 0., 1.);
return mix(uv * s, 1. - s * (1. - uv), t);
}
void frag()
{
2024-07-09 13:48:15 -05:00
vec2 ruv = uv9slice(uv, scale, border);
color = texture(sampler2D(diffuse,smp), ruv);
if (color.a < 0.1) discard;
2024-07-09 01:03:39 -05:00
}
@end
2024-07-09 13:48:15 -05:00
#include <base.cg>