-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): add an example of single pass post-processing
- Loading branch information
Showing
6 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
docs/src/pages/examples/post-processing/single-pass/_main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
docs/src/pages/examples/post-processing/single-pass/_styles.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
docs/src/pages/examples/post-processing/single-pass/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters