|
@@ -24,7 +24,7 @@
|
|
|
<script type="module">
|
|
|
|
|
|
import * as THREE from 'three';
|
|
|
- import { texture, textureStore, wgslFn, code, instanceIndex, uniform } from 'three/nodes';
|
|
|
+ import { storageTexture, wgslFn, code, instanceIndex, uniform } from 'three/nodes';
|
|
|
|
|
|
import WebGPU from 'three/addons/capabilities/WebGPU.js';
|
|
|
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
|
|
@@ -73,6 +73,11 @@
|
|
|
}
|
|
|
|
|
|
const wgslFormat = hdr ? 'rgba16float' : 'rgba8unorm';
|
|
|
+
|
|
|
+ const readPing = storageTexture( pingTexture ).setAccess( 'read-only' );
|
|
|
+ const writePing = storageTexture( pingTexture ).setAccess( 'write-only' );
|
|
|
+ const readPong = storageTexture( pongTexture ).setAccess( 'read-only' );
|
|
|
+ const writePong = storageTexture( pongTexture ).setAccess( 'write-only' );
|
|
|
|
|
|
// compute init
|
|
|
|
|
@@ -83,15 +88,15 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- fn blur( image : texture_2d<f32>, uv : vec2i ) -> vec4f {
|
|
|
+ fn blur( image : texture_storage_2d<${wgslFormat}, read>, uv : vec2i ) -> vec4f {
|
|
|
|
|
|
var color = vec4f( 0.0 );
|
|
|
|
|
|
- color += textureLoad( image, uv + vec2i( - 1, 1 ), 0 );
|
|
|
- color += textureLoad( image, uv + vec2i( - 1, - 1 ), 0 );
|
|
|
- color += textureLoad( image, uv + vec2i( 0, 0 ), 0 );
|
|
|
- color += textureLoad( image, uv + vec2i( 1, - 1 ), 0 );
|
|
|
- color += textureLoad( image, uv + vec2i( 1, 1 ), 0 );
|
|
|
+ color += textureLoad( image, uv + vec2i( - 1, 1 ));
|
|
|
+ color += textureLoad( image, uv + vec2i( - 1, - 1 ));
|
|
|
+ color += textureLoad( image, uv + vec2i( 0, 0 ));
|
|
|
+ color += textureLoad( image, uv + vec2i( 1, - 1 ));
|
|
|
+ color += textureLoad( image, uv + vec2i( 1, 1 ));
|
|
|
|
|
|
return color / 5.0;
|
|
|
}
|
|
@@ -122,12 +127,12 @@
|
|
|
}
|
|
|
`, [ rand2 ] );
|
|
|
|
|
|
- computeInitNode = computeInitWGSL( { writeTex: textureStore( pingTexture ), index: instanceIndex, seed } ).compute( width * height );
|
|
|
+ computeInitNode = computeInitWGSL( { writeTex: storageTexture( pingTexture ), index: instanceIndex, seed } ).compute( width * height );
|
|
|
|
|
|
// compute loop
|
|
|
|
|
|
const computePingPongWGSL = wgslFn( `
|
|
|
- fn computePingPongWGSL( readTex: texture_2d<f32>, writeTex: texture_storage_2d<${ wgslFormat }, write>, index: u32 ) -> void {
|
|
|
+ fn computePingPongWGSL( readTex: texture_storage_2d<${wgslFormat}, read>, writeTex: texture_storage_2d<${ wgslFormat }, write>, index: u32 ) -> void {
|
|
|
|
|
|
let posX = index % ${ width };
|
|
|
let posY = index / ${ width };
|
|
@@ -142,8 +147,8 @@
|
|
|
|
|
|
//
|
|
|
|
|
|
- computeToPong = computePingPongWGSL( { readTex: texture( pingTexture ), writeTex: textureStore( pongTexture ), index: instanceIndex } ).compute( width * height );
|
|
|
- computeToPing = computePingPongWGSL( { readTex: texture( pongTexture ), writeTex: textureStore( pingTexture ), index: instanceIndex } ).compute( width * height );
|
|
|
+ computeToPong = computePingPongWGSL( { readTex: readPing, writeTex: writePong, index: instanceIndex } ).compute( width * height );
|
|
|
+ computeToPing = computePingPongWGSL( { readTex: readPong, writeTex: writePing, index: instanceIndex } ).compute( width * height );
|
|
|
|
|
|
//
|
|
|
|