我正在 Three.js 中研究体积渲染原始数据。我很难理解 Three.js 中纹理的类型和格式之间的关系(在我的例子中是texture3d)。
我尝试将原始数据的u8int数据类型的类型设置为 THREE.UnsignedIntType ,但它给出了无效的纹理内部格式错误,但对于THREE.UnsignedByteType类型,一切正常。
这是我的纹理代码,
var texture = new THREE.DataTexture3D(data, dims[0], dims[1], dims[2]);
texture.format = THREE.RedFormat;
texture.type = THREE.UnsignedByteType;
Run Code Online (Sandbox Code Playgroud)
谁能说一下两者之间的关系。我不能使静态,因为原始数据类型可以是任何位(8/16/32)和类型(int/float)。
Three.js 纹理格式和类型是 WebGL 格式和类型的别名。仅允许某些组合。
WebGL1 的有效组合列表是
| format | type
+-----------------+------
| RGBA | UNSIGNED_BYTE
| RGB | UNSIGNED_BYTE
| RGBA | UNSIGNED_SHORT_4_4_4_4
| RGBA | UNSIGNED_SHORT_5_5_5_1
| RGB | UNSIGNED_SHORT_5_6_5
| LUMINANCE_ALPHA | UNSIGNED_BYTE
| LUMINANCE | UNSIGNED_BYTE
| ALPHA | UNSIGNED_BYTE
Run Code Online (Sandbox Code Playgroud)
所以将其转换为 Three.js 是
| format | type
+----------------------+------
| RGBAFormat | UnsignedByteType
| RGBFormat | UnsignedByteType
| RGBAFormat | UnsignedShort4444
| RGBAFormat | UnsignedShort5551
| RGBFormat | UnsignedShort565
| LuminanceAlphaFormat | UnsignedByteType
| LuminanceFormat | UnsignedByteType
| AlphaFormat | UnsignedByteType
Run Code Online (Sandbox Code Playgroud)
注意:WebGL1 不直接支持 3D 纹理,尽管您可以通过创意着色器自己实现它们
请注意,格式/类型组合是您提供给 Three.js 的数据的格式和类型,而不是存储数据的纹理的格式。
指定您设置的内部格式texture.internalFormat。要指定formatandtype您可以设置texture.formatandtexture.type
只有某些格式/类型的组合可以用作给定内部格式的输入。请参阅上面的链接查看列表。
如果你想要 1 个通道 unsigned int 纹理,你需要设置
texture.internalFormat = 'R32UI';
texture.format = THREE.RedIntegerFormat;
texture.type = THREE.UnsignedIntType;
Run Code Online (Sandbox Code Playgroud)
您还需要确保您设置了texture.minFilter和texture.magFiltertoTHREE.NearestFilter并且您需要确保您的着色器使用uniform usampler3D someSamplerName;
| format | type
+-----------------+------
| RGBA | UNSIGNED_BYTE
| RGB | UNSIGNED_BYTE
| RGBA | UNSIGNED_SHORT_4_4_4_4
| RGBA | UNSIGNED_SHORT_5_5_5_1
| RGB | UNSIGNED_SHORT_5_6_5
| LUMINANCE_ALPHA | UNSIGNED_BYTE
| LUMINANCE | UNSIGNED_BYTE
| ALPHA | UNSIGNED_BYTE
Run Code Online (Sandbox Code Playgroud)
使用RGIntegerFormat和UnsignedByteType,您需要使用内部格式RG8UI并将数据传递为Uint8Array
| format | type
+----------------------+------
| RGBAFormat | UnsignedByteType
| RGBFormat | UnsignedByteType
| RGBAFormat | UnsignedShort4444
| RGBAFormat | UnsignedShort5551
| RGBFormat | UnsignedShort565
| LuminanceAlphaFormat | UnsignedByteType
| LuminanceFormat | UnsignedByteType
| AlphaFormat | UnsignedByteType
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1637 次 |
| 最近记录: |