Three.js: [WebGL2] Texture Internal Format discussion

Created on 3 Aug 2018  路  13Comments  路  Source: mrdoob/three.js

I would like to open a discussion about internal format, and how we could integrate them without breaking the current Three.js API.

So, right now, the internal format is derived from the format, like this.

What I did on my side, is to add an attribute inside the Texture class, which represents the internal format, but is not given through the constructor, but rather explicitely:

```javascript
const texture = new THREE.DataTexture(data, width, height);
texture.internalFormat = THREE.RGBA8UIFormat;
````
I also added support for unsgined integer sampler, etc... And everything seems to work great.

What do you think about this change? I agree it's not the best regarding the API, but at least it backward compatible with WebGL1.

Suggestion WebGL2

Most helpful comment

Sorry, I was in long holidays. It will be done this week end. @takahirox

All 13 comments

I'm thinking of adding internalFormat constructor parameter

function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding, internalFormat ) {

That works the same, so I am fine with it!

If you want I can separate my code to a commit that handle that, I already changed WebGLTextures.

Nice, PR is welcome.

Continuing texture discussion from this comment in #13717 ... @yoshikiohshima the desire for utilizing R16UI and R16I texture formats is that most medical images (CT, MR, X-Ray, etc) are signed/unsigned 16 bit images (well actually they are anywhere from 10-16 bits but required 2 bytes of data per pixel). Hence I would like to pass in the images to my shader for rendering using these texture formats. Currently I encode the 2 bytes of data into 2 of the channels in an RGB texture format and then reconstruct the 16 bit values in the shader. This works fine but it would be nice to reduce my texture memory footprint by 1/3 by utilizing these 2 byte texture formats directly.

Did not have time to work on it sorry, I was attending the SIGGRAPH. I implemented that on my own fork already, I just have to separate the work to make a PR on three.js, not the most fun work but I have to do it.
For medical images it is indeed needed, not only for the memory footprint, but also because packing induces some imprecision.

Instead of adding another parameter to the constructor, I would add a new method:

texture.setInternalFormat( THREE.RGBA8UIFormat );

Because we lean toward .setXXX() method from constructor parameters? https://github.com/mrdoob/three.js/pull/14726#issuecomment-414086592

Yeah. That kind of API tends to be more resilient to API changes.

I see.

Until we move to such style APIs, only custom internal format needs to be setup via .setXXX() method, not via constructor. But it may be ok, I guess not so many users wanna set internal format by themselves. It may be acceptable.

Any updates? @DavidPeicho

Sorry, I was in long holidays. It will be done this week end. @takahirox

Hey guys, just wondering if there is anything happening in regards to this issue ... we would really like to start taking advantage of this capability once implemented ... thx?

Hey, I added the internal format support in a PR. You can follow the status here: #15121

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fuzihaofzh picture fuzihaofzh  路  3Comments

seep picture seep  路  3Comments

akshaysrin picture akshaysrin  路  3Comments

donmccurdy picture donmccurdy  路  3Comments

jack-jun picture jack-jun  路  3Comments