BabylonJS / Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
http://www.babylonjs.com
Apache License 2.0
23.17k stars 3.42k forks source link

Support for UVW texture coordinates and volume textures #7982

Closed unicomp21 closed 4 years ago

unicomp21 commented 4 years ago

We need support for 3d textures which wrap in the u,v, and w directions, ie toroidal. It might make sense to simply use the vertex "position.xyz" for uvw when doing the texture lookup?

unicomp21 commented 4 years ago

I'm trying to figure out if the correct terminology is volume texture or 3d texture.

sebavan commented 4 years ago

We support it with https://doc.babylonjs.com/api/classes/babylon.rawtexture3d

This actually what we use for our color grading Lookup.

Be careful as it is a WebGL2 feature only

unicomp21 commented 4 years ago

Is there an example somewhere of using it? I guess this means we are supposed to use "vertex color" as the "uvw" coordinate?

unicomp21 commented 4 years ago

@deltakosh ^ I'm struggling, trying to understand how to put UVW texture3D coords on the existing vertex.

sebavan commented 4 years ago

You can have a look at our color grading process: https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ShadersInclude/imageProcessingFunctions.fx#L154

Basically, you have a volume and you lookup inside with 3 coordinates instead of 2 here I use as an input the output of my previous rendering pass so I can easily apply a LUT on screen.

The thing is what are you trying to achieve ?

unicomp21 commented 4 years ago

Instead of having u, v texture coordinates for lookup against a 2D bitmap, I need u, v, w texture coordinates for lookup against a 3D bitmap, in order to texture my meshes.

unicomp21 commented 4 years ago

Color grading, looks like it's more of an image space thing, not really what I need. I need to use x,y,z from vertex position, or a u,v,w coordinate on the vertex, in order to do a 3D texture lookup.

sebavan commented 4 years ago

does it mean you are trying to texture in object space directly ?

In this case you will need a custom attribute as uvs are meant to be only in 2d.

Maybe if your vertices positions are all mapping directly you could reuse them but it might be less flexible for your artists.

unicomp21 commented 4 years ago

Yes, I am trying to texture in object space. The WebGL spec has support for 3D textures, why doesn't Babylon.js surface that support?

sebavan commented 4 years ago

Adding @bghgary for the gltf part.