Add clamped to option background_image_layout

This commit is contained in:
itepechi
2021-10-26 03:18:36 +09:00
parent cae31ab336
commit 86d7aaa03a
9 changed files with 17 additions and 19 deletions

View File

@@ -8,7 +8,7 @@
#define tex_right 1
#define tex_bottom 1
uniform float tiled;
uniform float unscaled;
uniform vec2 translate; // [ left, top ]
uniform vec4 sizes; // [ window_width, window_height, image_width, image_height ]
@@ -28,16 +28,12 @@ const vec2 tex_map[] = vec2[4](
);
float scale_factor(float window, float image) {
return window / image;
}
float tiling_factor(int i) {
return tiled * scale_factor(sizes[i], sizes[i + 2]) + (1 - tiled);
float unscaling_factor(int i) {
return unscaled * (sizes[i] / sizes[i + 2]) + (1 - unscaled);
}
void main() {
vec2 tex_coords = tex_map[gl_VertexID];
texcoord = vec2(tex_coords[0] * tiling_factor(0) - translate[0], tex_coords[1] * tiling_factor(1) - translate[1]);
texcoord = vec2(tex_coords[0] * unscaling_factor(0) - translate[0], tex_coords[1] * unscaling_factor(1) - translate[1]);
gl_Position = vec4(pos_map[gl_VertexID], 0, 1);
}