@vs vs9 in vec2 vert; in vec2 vuv; in vec4 vborder; in vec2 vscale; in vec4 vcolor; out vec2 uv; out vec4 border; out vec2 scale; out vec4 fcolor; uniform vs9_params { mat4 projection; }; void main() { gl_Position = projection * vec4(vert, 0.0, 1.0); uv = vuv; border = vborder; scale = vscale; fcolor = vcolor; } @end @fs fs9 in vec2 uv; /* image uv */ in vec4 border; /* uv length of border, normalized to image dimensions; left, bottom, right, top */ in vec2 scale; /* polygon dimensions ~ texture dimensions */ in vec4 fcolor; out vec4 color; uniform texture2D image; uniform sampler smp; float map(float value, float min1, float max1, float min2, float max2) { return min2 + (value - min1) * (max2 - min2) / (max1 - min1); } float processAxis(float coord, float texBorder, float winBorder) { if (coord < winBorder) return map(coord, 0, winBorder, 0, texBorder); if (coord < 1 - winBorder) return map(coord, winBorder, 1 - winBorder, texBorder, 1 - texBorder); return map(coord, 1 - winBorder, 1, 1 - texBorder, 1); } vec2 uv9slice(vec2 uv, vec2 s, vec4 b) { vec2 t = clamp((s * uv - b.xy) / (s - b.xy - b.zw), 0.0, 1.0); return mix(uv * s, 1.0 - s * (1.0 - uv), t); } void main() { vec2 nuv = uv9slice(uv, scale, border); color = fcolor * texture(sampler2D(image,smp), nuv); } @end @program slice9 vs9 fs9