Skip to content

Commit

Permalink
Add toneMapping extended mode to Particles sample
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Jul 11, 2024
1 parent 464b104 commit c738625
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sample/particles/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

Expand Down Expand Up @@ -315,10 +316,12 @@ let numMipLevels = 1;
const simulationParams = {
simulate: true,
deltaTime: 0.04,
brightness: 1.0,
};

const simulationUBOBufferSize =
1 * 4 + // deltaTime
1 * 4 + // brightness
3 * 4 + // padding
4 * 4 + // seed
0;
Expand All @@ -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',
Expand Down Expand Up @@ -375,6 +379,7 @@ function frame() {
0,
new Float32Array([
simulationParams.simulate ? simulationParams.deltaTime : 0.0,
simulationParams.brightness,
0.0,
0.0,
0.0, // padding
Expand Down
4 changes: 4 additions & 0 deletions sample/particles/particle.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn fs_main(in : VertexOutput) -> @location(0) vec4f {
////////////////////////////////////////////////////////////////////////////////
struct SimulationParams {
deltaTime : f32,
brightness : f32,
seed : vec4f,
}

Expand Down Expand Up @@ -125,6 +126,9 @@ 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.r *= sim_params.brightness;
particle.color.g *= sim_params.brightness;
particle.color.b *= 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;
Expand Down

0 comments on commit c738625

Please sign in to comment.