Skip to content

Commit

Permalink
docs(examples): add an example of single pass post-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jsulpis committed Dec 20, 2024
1 parent 47fd5cf commit 05bad31
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
4 changes: 0 additions & 4 deletions docs/src/components/ExamplePage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ const sidebar = [
--sl-sidebar-width: 12.5rem;
}

footer {
display: none !important;
}

.content-panel {
border: none !important;

Expand Down
43 changes: 43 additions & 0 deletions docs/src/pages/examples/post-processing/single-pass/_main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useEffectPass, useWebGLCanvas, loadTexture } from "usegl";
import "./styles.css";

(async () => {
const sepiaEffect = useEffectPass({
fragment: /* glsl */ `
uniform sampler2D uTexture; // output of the render pass
in vec2 vUv;
out vec4 fragColor;
#define SEPIA_COLOR vec3(1.2, 1.0, 0.7)
#define STRENGTH .75
vec3 sepia(vec3 color) {
float grayScale = dot(color, vec3(0.299, 0.587, 0.114));
return grayScale * SEPIA_COLOR;
}
void main() {
vec3 color = texture(uTexture, vUv).rgb;
color = mix(color, sepia(color), STRENGTH);
fragColor = vec4(color, 1.);
}
`,
});

useWebGLCanvas({
canvas: "#glCanvas",
fragment: /* glsl */ `
in vec2 vUv;
uniform sampler2D uPicture;
out vec4 fragColor;
void main() {
fragColor = texture(uPicture, vUv);
}
`,
uniforms: {
uPicture: await loadTexture("https://picsum.photos/id/323/600/400"),
},
postEffects: [sepiaEffect],
});
})();
14 changes: 14 additions & 0 deletions docs/src/pages/examples/post-processing/single-pass/_styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
margin: 0;
height: 100svh;
display: grid;
place-items: center;
background: black;
}

canvas {
max-width: 100svw;
max-height: 100svh;
aspect-ratio: 600 / 400;
display: block;
}
18 changes: 18 additions & 0 deletions docs/src/pages/examples/post-processing/single-pass/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: "Single pass (sepia)"
---

import ExamplePage from "../../../../components/ExamplePage.astro";
import ExampleEditor from "../../../../components/ExampleEditor/ExampleEditor.astro";
import ts from "./_main.ts?raw";
import styles from "./_styles.css?raw";

<ExamplePage>
<ExampleEditor
exampleTitle={frontmatter.title}
files={{
"index.ts": { code: ts },
"styles.css": { code: styles },
}}
/>
</ExamplePage>
4 changes: 4 additions & 0 deletions docs/src/styles/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
}
}

footer {
display: none !important;
}

.page > header > .header {
grid-template-columns: auto 1fr auto;
}
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default unjs({
"unicorn/no-null": "off",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/triple-slash-reference": "off",
"unicorn/prefer-top-level-await": "off",
},
});

0 comments on commit 05bad31

Please sign in to comment.