[英]Is it possible to use texSubImage2D on a depth texture?
I'm following this tutorial on 2D shadow mapping and I've gotten it working in WebGL.我正在关注这个关于 2D 阴影映射的教程,并且我已经让它在 WebGL 中工作。 Now, I am looking to develop a way to recompute single rows in the depth texture, without clearing the entire texture and recomputing every light's value.
现在,我正在寻找一种方法来重新计算深度纹理中的单行,而无需清除整个纹理并重新计算每个灯光的值。
My depth texture is a regular WebGLTexture
made like this:我的深度纹理是这样制作的常规
WebGLTexture
:
gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, width, height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_SHORT, null);
To do this, I had the idea to do something like this:为此,我想到了做这样的事情:
let SHADOW_MAP_WIDTH = 360;
let emptyDepthValues = new Array(SHADOW_MAP_WIDTH * 4).fill(255);
let emptyDepthRow = new Uint8Array(emptyDepthValues);
// down further..
gl.bindTexture(gl.TEXTURE_2D, this.shadowMapFramebuffer.depthTexture);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, slot, SHADOW_MAP_WIDTH, 1, gl.RGBA, gl.UNSIGNED_BYTE, emptyDepthRow);
this.shadowMapper.computeRow(vertices, lightPosition, lightSlot, lightRadius);
Unfortunately, it does not seem to be working.不幸的是,它似乎不起作用。 I know this because if I move the calls to
bindTexture
and texSubImage2D
to after the computeRow
function, the values still persist.我知道这一点,因为如果我将对 bindTexture 和
texSubImage2D
的调用移到bindTexture
computeRow
之后,这些值仍然存在。 That is, they are not reset to the defaults by the call to texSubImage2D
.也就是说,它们不会通过调用
texSubImage2D
重置为默认值。
I'm currently using WebGL 1 (with the depth texture extension) and would preferably like to keep doing so if possible.我目前正在使用 WebGL 1(带有深度纹理扩展),如果可能的话,我希望继续这样做。 All I'm looking for is a trivial way to reset a row in my
WebGLTexture
to its default value.我正在寻找的只是一种将
WebGLTexture
中的行重置为其默认值的简单方法。
Ah, I had a better idea.啊,我有一个更好的主意。 Since I only need to reset the depth values for a specific row, I can just write a function like this, which works perfectly:
由于我只需要重置特定行的深度值,因此我可以像这样编写一个 function,效果很好:
function clearShadowMapSlot(gl, slot, shadowMapWidth) {
gl.enable(gl.SCISSOR_TEST);
gl.scissor(0, slot, shadowMapWidth, 1);
gl.clear(gl.DEPTH_BUFFER_BIT);
gl.disable(gl.SCISSOR_TEST);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.