我正在尝试在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 值。这是什么问题?提前谢谢。