Textures with dimensions non power of two get downscaled to power of two dimensions

Textures with dimensions non power of two get always downscaled to power of two dimensions. Previous algorithm was performing a “round” to aproximate power of two dimensions rather than floor.
Example :
r89: THREE.WebGLRenderer: image is not power of two (1638×2166). Resized to 1024×2048
r80: THREE.WebGLRenderer: image is not power of two (1638×2166). Resized to 2048×2048

Code in WebGLTextures.js r89:

function makePowerOfTwo( image ) {
...
canvas.width = _Math.floorPowerOfTwo( image.width );
canvas.height = _Math.floorPowerOfTwo( image.height ); 
...
}

Code in WebGLTextures.js r80:

function makePowerOfTwo( image ) {
...
canvas.width = _Math.nearestPowerOfTwo( image.width );
canvas.height = _Math.nearestPowerOfTwo( image.height ); 
...
}

Note: nearestPowerOfTwo is now deprecated and replaced with floorPowerOfTwo.

Three.js version
  • [x ] Dev
  • [x ] r89
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS

Author: Fantashit

2 thoughts on “Textures with dimensions non power of two get downscaled to power of two dimensions

  1. That’s quite a hack

    would it be less of a hack if 3js had

    Texture.resizeMethod = Math.floorPowerOfTwo
    

    and users then could override this function?

  2. That works. I was just suggesting to round large textures down; small textures up.

    Yeah, I understand. But I bet it wouldn’t take long for someone to come with a use-case that doesn’t fit that expectation.

Comments are closed.