Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vec2 ps = vec2(1.0) / iResolution.xy;
- float ar = iResolution.x / iResolution.y;
- const vec2 image_res = vec2(3840, 2160);
- const float image_ar = image_res.x / image_res.y;
- vec2 scaleUV(vec2, vec2);
- bool crop(vec2);
- vec2 correctAspect(vec2);
- void main() {
- vec2 uv = gl_FragCoord.xy * ps;
- vec2 image_uv = correctAspect(uv);
- vec3 col = texture2D(iChannel0, image_uv).rgb;
- col = crop(uv) ? col : vec3(0.0);
- gl_FragColor = vec4(col, 1.0);
- }
- vec2 scaleUV(vec2 uv, vec2 scale) {
- return (uv - vec2(0.5)) * scale + vec2(0.5);
- }
- bool crop(vec2 uv) {
- bool x_or_y = ar > image_ar;
- float ar_result = x_or_y ? (image_ar / ar) :
- (ar / image_ar);
- float mask = (1.0 - (ar_result)) * 0.5;
- return x_or_y ? (uv.x > mask && uv.x < 1.0 - mask) :
- (uv.y > mask && uv.y < 1.0 - mask);
- }
- vec2 correctAspect(vec2 uv) {
- bool x_or_y = ar > image_ar;
- vec2 ar_fix = vec2(1.0);
- ar_fix = x_or_y ? vec2(ar / image_ar, 1.0) :
- vec2(1.0, image_ar / ar);
- uv = scaleUV(uv, ar_fix);
- return uv;
- }
Add Comment
Please, Sign In to add comment