From df6935c074721cdbf23d1907e540d8d3062f827d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Wed, 10 Jul 2024 16:52:21 +0200 Subject: [PATCH] Add toneMapping extended mode to Particles sample --- sample/particles/main.ts | 7 ++++++- sample/particles/particle.wgsl | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sample/particles/main.ts b/sample/particles/main.ts index e718fd91..67f743cd 100644 --- a/sample/particles/main.ts +++ b/sample/particles/main.ts @@ -24,11 +24,12 @@ const context = canvas.getContext('webgpu') as GPUCanvasContext; const devicePixelRatio = window.devicePixelRatio; canvas.width = canvas.clientWidth * devicePixelRatio; canvas.height = canvas.clientHeight * devicePixelRatio; -const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); +const presentationFormat = 'rgba16float'; context.configure({ device, format: presentationFormat, + toneMapping: { mode: 'extended' }, alphaMode: 'premultiplied', }); @@ -315,10 +316,12 @@ let numMipLevels = 1; const simulationParams = { simulate: true, deltaTime: 0.04, + brightness: 1, }; const simulationUBOBufferSize = 1 * 4 + // deltaTime + 1 * 4 + // brightness 3 * 4 + // padding 4 * 4 + // seed 0; @@ -330,6 +333,7 @@ const simulationUBOBuffer = device.createBuffer({ const gui = new GUI(); gui.add(simulationParams, 'simulate'); gui.add(simulationParams, 'deltaTime'); +gui.add(simulationParams, 'brightness', 0, 4, 0.1); const computePipeline = device.createComputePipeline({ layout: 'auto', @@ -375,6 +379,7 @@ function frame() { 0, new Float32Array([ simulationParams.simulate ? simulationParams.deltaTime : 0.0, + simulationParams.brightness, 0.0, 0.0, 0.0, // padding diff --git a/sample/particles/particle.wgsl b/sample/particles/particle.wgsl index 15c3f604..3e332ac3 100644 --- a/sample/particles/particle.wgsl +++ b/sample/particles/particle.wgsl @@ -64,6 +64,7 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4f { //////////////////////////////////////////////////////////////////////////////// struct SimulationParams { deltaTime : f32, + brightness : f32, seed : vec4f, } @@ -124,7 +125,7 @@ fn simulate(@builtin(global_invocation_id) global_invocation_id : vec3u) { } let uv = vec2f(coord) / vec2f(textureDimensions(texture)); particle.position = vec3f((uv - 0.5) * 3.0 * vec2f(1.0, -1.0), 0.0); - particle.color = textureLoad(texture, coord, 0); + particle.color = textureLoad(texture, coord, 0) * sim_params.brightness; particle.velocity.x = (rand() - 0.5) * 0.1; particle.velocity.y = (rand() - 0.5) * 0.1; particle.velocity.z = rand() * 0.3;