How to fit the texture to the plane

Try it with this code:

texture.matrixAutoUpdate = false;

var aspect = window.innerWidth / window.innerHeight;
var imageAspect = texture.image.width / texture.image.height;

if ( aspect < imageAspect ) {

    texture.matrix.setUvTransform( 0, 0, aspect / imageAspect, 1, 0, 0.5, 0.5 );

} else {

    texture.matrix.setUvTransform( 0, 0, 1, imageAspect / aspect, 0, 0.5, 0.5 );

}

Live demo: Edit fiddle - JSFiddle - Code Playground

4 Likes