From f6c0498c9728a286c13980ed3b60763d02e1b3a0 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 11 May 2019 12:08:45 +0800 Subject: *misc --- .../graphics/shaders/image_slice.shader.h | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 source/Asura.Editor/graphics/shaders/image_slice.shader.h (limited to 'source/Asura.Editor/graphics/shaders/image_slice.shader.h') diff --git a/source/Asura.Editor/graphics/shaders/image_slice.shader.h b/source/Asura.Editor/graphics/shaders/image_slice.shader.h new file mode 100644 index 0000000..58be2b1 --- /dev/null +++ b/source/Asura.Editor/graphics/shaders/image_slice.shader.h @@ -0,0 +1,64 @@ +#ifndef __ASURA_EDITOR_SHADER_H__ +#include "../shader.h" +#endif + +// 九宫格分割的图片 +static AsuraEditor::Graphics::ShaderProgram image_slice_shader = +{ +R"( +in vec2 _position; + +uniform _mvp_matrix; + +out vec2 offset; // top-left + +void main() +{ + gl_Position = _mvp_matrix * vec4(_position, 0, 1); + offset = _position - vec2(0.5, 0.5); +} + +)", + +R"( +in vec2 offset; + +uniform vec4 _sliceline; // l, r, t, b +uniform vec2 _texsize; // w0, h0 in pixel +uniform sampler2D _maintex; +uniform vec2 _area; // w, h +// 如果在(a, b]范围内,返回1,否则返回0 +int factor(float v, float a, float b) +{ + return clamp(sign(v-a), 0, 1) * step(-b, -v); +} + +void main() +{ + float x = offset.x; + float y = offset.y; + float l = _sliceline.x; + float r = _sliceline.y; + float t = _sliceline.z; + float b = _sliceline.w; + float w0 = _texsize.x; + float h0 = _texsize.y; + float w = _area.x; + float h = _area.y; + + vec2 uv = vec2(0, 0); + + //uv.x *= 0; // x = 0 + uv.x *= factor(x, 0, l) * x / w0; // 0