Код: Выделить всё
const storageTexture = this._device.createTexture({
dimension: '2d',
size: [512, 512, 1],
format: 'r32float',
usage: GPUTextureUsage.STORAGE_BINDING
})
const textureView = storageTexture.createView({
dimension: '2d-array',
format: 'r32float',
})
const bindGroup = this.device.createBindGroup({
layout: this.lightsBindGroupLayout,
entries: [
.....irrelevant stuff
{
binding: 3,
resource: textureView,
},
],
})
const firstPass = commandEncoder.beginRenderPass(this._renderPassDescriptor)
......
firstPass.setBindGroup(2, bindGroup)
......
firstPass.end()
const secondPass = commandEncoder.beginRenderPass(this._renderPassDescriptor)
.....
secondPass.setBindGroup(3, bindGroup)
.....
secondPass.end()
< /code>
Fragment Shader Code для первого прохода: < /p>
@fragment
fn fragment_main(in: VertexOutput) -> @location(0) float4 {
textureStore(texture, vec2u(0, 0), 0, vec4f(1, 1, 1, 1));
return in.position;
}
< /code>
Fragment Shader Code для второго прохода: < /p>
@fragment
fn fragment_main(in: VertexOutput) -> @location(0) float4 {
let a = textureLoad(texture, vec2u(0, 0), 0);
return vec4(a.r, 0, 0, 0);
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... lue-in-web