我正在尝试在 WebGL 2.0 中创建具有 32 位红色通道的整数纹理:
this.kdTreeTextureSize = Math.ceil(Math.sqrt(numberOfKdNodes));
this.kdTreeData = new Int32Array(this.kdTreeTextureSize * this.kdTreeTextureSize);
this.kdTree.fillDataArray(this.kdTreeData);
this.kdTreeTexture = gl.createTexture();
gl.activeTexture(gl.TEXTURE3);
gl.bindTexture(gl.TEXTURE_2D, this.kdTreeTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32I, this.kdTreeTextureSize, this.kdTreeTextureSize, 0, gl.RED_INTEGER, gl.INT, this.kdTreeData);
并在 GLES 3.0 片段着色器中阅读它:
int(texture(kdTreeTexture, getTexCoord(0, kdTreeTextureSize))
getTexCoord 函数:
vec2 getTexCoord(int i, float textureSize) {
return vec2(
(mod(float(i), float(textureSize)) + 0.5) / textureSize,
(float(i / int(textureSize)) + 0.5) / textureSize
);
}
我将第一个像素的值设置为1073741824,即 2^30,但是在片段着色器中读取它时,我得到了错误的值1100730680 。这里有什么问题?提前致谢。