question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

THREE.UnsignedShortType

See original GitHub issue

Hi, I’m making a terrain renderer, and I’m using 16bit grayscale pngs as displacement maps. When I load them using THREE.ImageUtils.loadTexture, it works, but I get noticable rounding errors. So I tried to modifiy it like this:

function loadDEM(path, mapping, callback) {
    var image = new Image(), texture = new THREE.Texture(image, mapping);
    texture.type = THREE.UnsignedShortType;
    image.onload = function() {
        texture.needsUpdate = true;
        if (callback) {
            callback(this);
        }
    }
    image.crossOrigin = "anonymous";
    image.src = path;
    return texture;
}

Just added texture.type = THREE.UnsignedShortType, and now I get these errors in console and terrain is flat.

WebGL: INVALID_ENUM: texImage2D: invalid texture type index.html:1
WebGL: INVALID_OPERATION: generateMipmap: level 0 not power of 2 or not all the same size

So how can I use 16bit images?

This is the actual terrain tile: Terrain tile

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
greggmancommented, Apr 15, 2020

Like all image formats in browsers it’s up to the browser what image formats are supported and what the browser does with them. 😭 For example Chrome and Firefox support webp but Safari does not.

Also Safari supports (or used to support) TIFF files as <img> tags and it would load and display floating point TIFFs but I’m 99% it did not support uploading those floating point TIFFs as floating point textures as there is no conformance test for it (not that Apple has ever cared about passing the conformance tests 😂)

Currently though the WebGL2 spec explicitly disallows 16 int formats from images 🙄

When the data source is a DOM element (HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement), or is an ImageBitmap, ImageData, or OffscreenCanvas object, commonly each channel’s representation is an unsigned integer type of at least 8 bits. Converting such representation to signed integers or unsigned integers with more bits is not clearly defined. For example, when converting RGBA8 to RGBA16UI, it is unclear whether or not the intention is to scale up values to the full range of a 16-bit unsigned integer. Therefore, only converting to unsigned integer of at most 8 bits, half float, or float is allowed.

0reactions
Mugen87commented, Apr 15, 2020

Currently though the WebGL2 spec explicitly disallows 16 int formats from images.

@greggman Thank your for clarifying! In this case, the issue can safely be closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Texture Constants
The last pixel of the texture stretches to the edge of the mesh. With MirroredRepeatWrapping the texture will repeats to infinity, mirroring on...
Read more >
three UnsignedShortType JavaScript Examples
This page shows JavaScript code examples of three UnsignedShortType. ... depthTexture = new DepthTexture(); depthTexture.type = UnsignedShortType; this.
Read more >
DataTexture with LuminanceFormat UnsignedShort is not ...
I have some OpenGL code I want to bring to WebGL / three.js: glTexImage2D(GL_TEXTURE_2D, 0 ... UnsignedShortType); var material = new THREE.
Read more >
DataTexture
Other valid types (as WebGL allows) are THREE. ... UnsignedShortType, THREE. ... CubeReflectionMapping, for cube maps used as a reflection map; THREE.
Read more >
examples/webgl_depth_texture.html - three.js
DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <title>three.js webgl - Depth ... DepthStencilFormat }; 98 const types = { UnsignedShortType: THREE.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found