三种方式防止DataTexture值归一化

Prevent DataTexture value normalization in THREE

在三个中,您可以指定具有给定数据类型和格式的 DataTexture。我的着色器管道 规范化 基于一些用户控制的制服的原始值。

如果是Float32Array,就很简单了:

data = new Float32Array(...)
texture = new THREE.DataTexture(data, columns, rows, THREE.LuminanceFormat, THREE.FloatType)

而且,在着色器中,混合后的值具有 非规范化 值。但是,如果我使用:

data = new Uint8Array(...)
texture = new THREE.DataTexture(data, columns, rows, THREE.LuminanceFormat, THREE.UnsignedByteType);

然后纹理在 0.0 和 1.0 之间标准化,作为管道的输入。不是我所期待的。有没有办法防止这种行为?

这是一个 jsfiddle 示例,演示了对意外情况的快速测试(至少对我而言):http://jsfiddle.net/VsWb9/3796/

three.js r.71

为了将来参考,这在 WebGL 中目前是不可能的。它需要使用 GL_RED_INTEGER 和不受支持的 usampler2d.

来自 the internalformat of Texture 的评论也描述了 GL 中的内部格式问题。

For that matter, the format of GL_LUMINANCE says that you're passing either floating-point data or normalized integer data (the type says that it's normalized integer data). Of course, since there's no GL_LUMINANCE_INTEGER (which is how you say that you're passing integer data, to be used with integer internal formats), you can't really use luminance data like this.

Use GL_RED_INTEGER for the format and GL_R8UI for the internal format if you really want 8-bit unsigned integers in your texture. Note that integer texture support requires OpenGL 3.x-class hardware.

That being said, you cannot use sampler2D with an integer texture. If you are using a texture that uses an unsigned integer texture format, you must use usampler2D.