precision highp float; uniform sampler2D uTexture; uniform vec2 uPlaneSizes; uniform vec2 uImageSizes; varying vec2 vUv; void main() { // Calculate the proper UVs to cover the plane with the image while keeping its aspect ratio vec2 ratio = vec2( min((uPlaneSizes.x / uPlaneSizes.y) / (uImageSizes.x / uImageSizes.y), 1.0), min((uPlaneSizes.y / uPlaneSizes.x) / (uImageSizes.y / uImageSizes.x), 1.0) ); vec2 uv = vec2( vUv.x * ratio.x + (1.0 - ratio.x) * 0.5, vUv.y * ratio.y + (1.0 - ratio.y) * 0.5 ); vec4 finalColor = texture2D(uTexture, uv); gl_FragColor = finalColor; }