Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Half-float attribute support #15480

Closed
3 tasks done
simon-paris opened this issue Dec 27, 2018 · 10 comments · Fixed by #20587
Closed
3 tasks done

Half-float attribute support #15480

simon-paris opened this issue Dec 27, 2018 · 10 comments · Fixed by #20587

Comments

@simon-paris
Copy link

Description of the problem

It's currently impossible to make a half float attributes work, since the GL buffer type is derived from the JS buffer type, and JS doesn't have a half float buffer type.

I'd like to add a special case to Uint16 and Int16 attributes that causes them to be interpreted as half floats.

var myAttr = new THREE.BufferAttribute(new Uint16Array(whatever), 3);
myAttr.useHalfFloat = true;

Would this be acceptable?

Three.js version
  • All
Browser
  • All of them
OS
  • All of them
@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 27, 2018

I personally would love to see Float16Array 😇

https://esdiscuss.org/topic/float16array

Without such a data type, you have to manually perform the conversion to half-float which is cumbersome. I'm not sure we want code like the following in the library core:

http://codeflow.org/experiment/half-float/main.js

@mrdoob
Copy link
Owner

mrdoob commented Dec 28, 2018

Could be a good idea to start with a example though.

If I understand correctly, what we need in core is a way to hint the renderer that we attribute is half-float and then a helper (in examples) to convert the array. Correct?

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2018

I think so. @simon-paris Do you want to give it a try?

BTW: I have create a test fiddle for the forum some time ago that shows how to use a data texture with half float data (THREE.HalfFloatType):

https://jsfiddle.net/f2Lommf5/1856/

It would be great if the helper could also be used to convert the data for this use case. Right now, I manually set the half float value for 10000.

@WestLangley
Copy link
Collaborator

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2018

How convenient^^

@mrdoob
Copy link
Owner

mrdoob commented Dec 28, 2018

https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/HDRCubeTextureLoader.js#L27

We may want to add that code in core then, so we can do it at upload time and it all works nicely?

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2018

Okay. But one thing bothers me. BufferAttribute.useHalfFloat would only work in specific cases (when using Uint16Array and Int16Array). I think it's better to put the property to Int16BufferAttribute and Uint16BufferAttribute.

@mrdoob
Copy link
Owner

mrdoob commented Dec 28, 2018

So rather than adding useHalfFloat you are suggesting we check for attribute.isFloat16BufferAttribute instead?

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2018

I've meant we should not introduce a new property to BufferAttribute. I would add a property to the more specific classes Int16BufferAttribute and Uint16BufferAttribute. Another option might be to introduce Float16BufferAttribute...

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 2, 2019

Um, it seems that WebGLRenderingContext.vertexAttribPointer() accepts half float attributes only with WebGL 2, see

https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants