diff options
author | chai <chaifix@163.com> | 2019-05-11 12:08:45 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-05-11 12:08:45 +0800 |
commit | f6c0498c9728a286c13980ed3b60763d02e1b3a0 (patch) | |
tree | c07b283cb2183b320730cf3811b130eca3d90353 /source/Asura.Editor/graphics | |
parent | 59a0e32991b5b714b6bdba504b6fbacdcd4b907a (diff) |
*misc
Diffstat (limited to 'source/Asura.Editor/graphics')
-rw-r--r-- | source/Asura.Editor/graphics/shaders/image.shader.h | 11 | ||||
-rw-r--r-- | source/Asura.Editor/graphics/shaders/image_slice.shader.h | 64 | ||||
-rw-r--r-- | source/Asura.Editor/graphics/shaders/polygon.shader.h | 7 |
3 files changed, 71 insertions, 11 deletions
diff --git a/source/Asura.Editor/graphics/shaders/image.shader.h b/source/Asura.Editor/graphics/shaders/image.shader.h index ee6be43..fbca5b5 100644 --- a/source/Asura.Editor/graphics/shaders/image.shader.h +++ b/source/Asura.Editor/graphics/shaders/image.shader.h @@ -2,20 +2,17 @@ #include "../shader.h" #endif -// static AsuraEditor::Graphics::ShaderProgram image_shader = { R"( in vec2 asura_position; in vec2 asura_texcoord0; -uniform mat4 asura_model_matrix; -uniform mat4 asura_view_matrix; -uniform mat4 asura_projection_matrix; +uniform asura_mvp_matrix; void main() { - gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1); + gl_Position = asura_mvp_matrix * vec4(asura_position, 0, 1); uv = asura_texcoord0; } @@ -28,8 +25,8 @@ uniform sampler2D asura_maintex; void main() { - + gl_FragColor = texture2D(asura_maintex, uv); } )" -};
\ No newline at end of file +}; 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]Χڣ10 +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<x<=l + uv.x *= factor(x, l, w-r) * (l/w0 + (x-l)/(w-l-r) * (w0-l-r) / w0); // l<x<=w-r + uv.x *= factor(x, w-r, w) * (1 - (w-x)/w0); // w-r<x<=w + + //uv.y *= 0; // y = 0 + + + gl_FragColor = texture2D(_maintex, uv); + +} + +)" +}; diff --git a/source/Asura.Editor/graphics/shaders/polygon.shader.h b/source/Asura.Editor/graphics/shaders/polygon.shader.h index eed4f5a..ee80f32 100644 --- a/source/Asura.Editor/graphics/shaders/polygon.shader.h +++ b/source/Asura.Editor/graphics/shaders/polygon.shader.h @@ -2,17 +2,16 @@ #include "../shader.h" #endif -// static AsuraEditor::Graphics::ShaderProgram polygon_shader = { R"( in vec2 position; -uniform mat4 mvp_matrix; +uniform mat4 asura_mvp_matrix; void main() { - gl_Position = mvp_matrix * vec4(position, 0, 1); + gl_Position = asura_mvp_matrix * vec4(position, 0, 1); } )", @@ -26,4 +25,4 @@ void main() } )" -};
\ No newline at end of file +}; |