Skip to content

Commit 7c3b3b4

Browse files
committed
docs: add tone mapping in the bloom example
1 parent 2d39ca7 commit 7c3b3b4

File tree

6 files changed

+27
-29
lines changed

6 files changed

+27
-29
lines changed

docs/components/ExampleEditor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
...props,
88
deps: {
99
...deps,
10-
usegl: '0.7.0',
10+
usegl: '0.8.0',
1111
},
1212
}"
1313
>

docs/examples/gpgpu/boids/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,14 @@ const renderPass = useWebGLCanvas({
6767
transparent: true,
6868
});
6969

70-
// Wait for the canvas to be resized to avoid a flash at the first renders
71-
renderPass.onCanvasReady(() => {
72-
useLoop(({ deltaTime }) => {
73-
velocities.uniforms.uDeltaTime = deltaTime / 500;
74-
velocities.render();
70+
useLoop(({ deltaTime }) => {
71+
velocities.uniforms.uDeltaTime = deltaTime / 500;
72+
velocities.render();
7573

76-
positions.uniforms.uDeltaTime = deltaTime / 500;
77-
positions.render();
74+
positions.uniforms.uDeltaTime = deltaTime / 500;
75+
positions.render();
7876

79-
renderPass.render();
80-
});
77+
renderPass.render();
8178
});
8279

8380
const pane = new Pane({ title: "Uniforms", expanded: false });

docs/examples/gpgpu/particles/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const positions = usePingPongFBO(gl, {
4343
/* G */ Math.random() * 0.2 - 0.1,
4444
/* B */ 0,
4545
/* A */ 0,
46-
]),
46+
])
4747
),
4848
},
4949
dataTexture: {
@@ -86,11 +86,8 @@ const renderPass = useWebGLCanvas({
8686
transparent: true,
8787
});
8888

89-
// Wait for the canvas to be resized to avoid a flash at the first renders
90-
renderPass.onCanvasReady(() => {
91-
useLoop(({ deltaTime }) => {
92-
positions.uniforms.uDeltaTime = deltaTime / 500;
93-
positions.render();
94-
renderPass.render();
95-
});
89+
useLoop(({ deltaTime }) => {
90+
positions.uniforms.uDeltaTime = deltaTime / 500;
91+
positions.render();
92+
renderPass.render();
9693
});

docs/examples/post-processing/builtin-bloom/dots.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ void main() {
2222
offset += atan(4. * r, ringRadius);
2323
}
2424

25-
// important !
25+
// important!
2626
// - the colors need to be in linear space for the bloom calculation to be correct
27-
// - there needs to be a final pass to convert linear RGB back to sRGB
27+
// - a final pass is needed to convert linear RGB back to sRGB (can be done with a builtin tone mapping pass)
2828
color = pow(color, vec3(2.2));
2929

3030
gl_FragColor = vec4(color, 1.0);
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import { useWebGLCanvas, bloom, linearToSRGB } from "usegl";
1+
import { useWebGLCanvas, bloom, hableToneMapping } from "usegl";
22
import { Pane } from "tweakpane";
33
import fragment from "./dots.frag?raw";
44
import "./styles.css";
55

66
const bloomEffect = bloom();
7+
const toneMapping = hableToneMapping({ exposure: 3 });
78

89
useWebGLCanvas({
910
canvas: "#glCanvas",
1011
fragment,
11-
postEffects: [bloomEffect, linearToSRGB()],
12+
postEffects: [bloomEffect, toneMapping],
1213
});
1314

1415
// You can dynamically update the uniforms of an effect pass, like any other pass
1516
const pane = new Pane({ title: "Uniforms" });
16-
pane.addBinding(bloomEffect.uniforms, "uRadius", { min: 0, max: 1 });
17-
pane.addBinding(bloomEffect.uniforms, "uMix", { min: 0, max: 1 });
17+
18+
const bloomUniforms = pane.addFolder({ title: "Bloom" });
19+
bloomUniforms.addBinding(bloomEffect.uniforms, "uRadius", { min: 0, max: 1 });
20+
bloomUniforms.addBinding(bloomEffect.uniforms, "uMix", { min: 0, max: 1 });
21+
22+
const toneMappingUniforms = pane.addFolder({ title: "Tone Mapping" });
23+
toneMappingUniforms.addBinding(toneMapping.uniforms, "uExposure", { min: 0, max: 5 });

docs/examples/textures/video/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { loadVideoTexture, useWebGLCanvas } from "usegl";
22
import "./styles.css";
33

4-
const texture = loadVideoTexture(
5-
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
6-
);
7-
84
useWebGLCanvas({
95
canvas: "#glCanvas",
106
fragment: /* glsl */ `
@@ -21,6 +17,8 @@ useWebGLCanvas({
2117
}
2218
`,
2319
uniforms: {
24-
uTexture: texture,
20+
uTexture: loadVideoTexture(
21+
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
22+
),
2523
},
2624
});

0 commit comments

Comments
 (0)