Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure Shader Composer #363

Merged
merged 56 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f9c770f
Add shader-composer-three package
hmans Nov 29, 2022
a01ef8b
Update examples
hmans Nov 29, 2022
8776485
Merge branch 'main' into shader-composer-restructure
hmans Nov 29, 2022
c501094
Change default color in ShaderMaterialMaster
hmans Nov 29, 2022
75756bd
Remove three dependency from test
hmans Nov 29, 2022
58c0c7d
Remove 3.js bits from UpdateCallback
hmans Nov 29, 2022
6da86a3
Update update API
hmans Nov 29, 2022
1bdb4a8
Update payloads
hmans Nov 29, 2022
a60bba2
Change sc-r3d dependency to sc-three
hmans Nov 29, 2022
ade00a8
Fix render-composer
hmans Nov 29, 2022
9e7a9a7
Fix MC examples
hmans Nov 29, 2022
50de88a
Fix CameraNear and CameraFar
hmans Nov 29, 2022
0ac12fd
Cleanup
hmans Nov 29, 2022
6623f84
Patch CameraNear and CameraFar
hmans Nov 29, 2022
cdc8b1f
Resolution
hmans Nov 29, 2022
2a341d6
Don't need to change the default
hmans Nov 29, 2022
0b4187d
Configure UsingInstancing
hmans Nov 29, 2022
99329ae
Cleanup
hmans Nov 29, 2022
9500272
Remove three dependencies from glslType
hmans Nov 29, 2022
dc611b8
Clean up, make proper types
hmans Nov 29, 2022
43ace1f
Typesssss
hmans Nov 29, 2022
b957867
Note
hmans Nov 29, 2022
d0e35fe
REWORK OMG
hmans Nov 29, 2022
c04f936
glmatrix support
hmans Nov 29, 2022
c4b6ece
Cleanup
hmans Nov 29, 2022
6323850
Cleanup
hmans Nov 29, 2022
f1d720f
Fix
hmans Nov 29, 2022
076b0e1
More fixes
hmans Nov 29, 2022
863503f
Fixes
hmans Nov 29, 2022
f22e053
Clean up examples
hmans Nov 29, 2022
93113e6
$vec3 -> vec3 etc.
hmans Nov 29, 2022
fa83ca6
Remove the last three reference
hmans Nov 29, 2022
4071059
Move three into peerdeps
hmans Nov 29, 2022
821349b
Use shader-composer-three in vfx-composer-examples
hmans Nov 29, 2022
b9fd98d
Mark sc-three package as sideEffectful
hmans Nov 29, 2022
8ce4e6a
Remove three dependency from toybox
hmans Nov 29, 2022
913a413
shader-composer as peerdep
hmans Nov 29, 2022
58bfe69
Rename to @shader-composer/three
hmans Nov 29, 2022
cec3909
@shader-composer/three and @shader-composer/core
hmans Nov 29, 2022
8583bb8
Move tests
hmans Nov 29, 2022
c003c75
Rewire
hmans Nov 29, 2022
9fe9e8a
@shader-composer/r3f
hmans Nov 29, 2022
f0a79ab
@shader-composer/r3f
hmans Nov 29, 2022
5ad3193
Amend examples
hmans Nov 29, 2022
7ce33fc
@shader-composer/postprocessing
hmans Nov 29, 2022
1511edf
Fix material-composer
hmans Nov 29, 2022
7a1cec7
Fix vfx composer
hmans Nov 29, 2022
e19b8e4
Noise
hmans Nov 29, 2022
b7abf9d
Directly export noise units
hmans Nov 29, 2022
61015d8
Auto-import three
hmans Nov 29, 2022
25bde85
Comment
hmans Nov 29, 2022
1f2c243
Come on, Vercel
hmans Nov 29, 2022
28eba54
Eh
hmans Nov 29, 2022
8a73cb5
Add a README to toybox
hmans Nov 30, 2022
3c403c0
Another test
hmans Nov 30, 2022
b98a31c
changesets
hmans Nov 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fixed": [],
"linked": [
["vfx-composer", "vfx-composer-r3f"],
["shader-composer", "shader-composer-r3f"],
["shader-composer", "shader-composer-*", "@shader-composer/*"],
["material-composer", "material-composer-r3f"]
],
"access": "public",
Expand Down
14 changes: 14 additions & 0 deletions .changeset/curvy-llamas-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"shader-composer": minor
"@shader-composer/core": minor
---

**Breaking:** The casting helpers (eg. `$vec3()`, `$mat3()` etc.) have been renamed to `vec3()`, `mat3()` etc., and have had their signature changed. Where the old implementations were able to take any number of arguments, the new helpers will only ever take _a single argument_. (If you want to cast multiple arguments, you can pass an array.)

```js
/* Before: */
$vec3(1, 2, 3)

/* After: */
vec3([1, 2, 3])
```
23 changes: 23 additions & 0 deletions .changeset/olive-coats-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"shader-composer": minor
"@shader-composer/core": minor
"@shader-composer/noise": minor
"@shader-composer/postprocessing": minor
"@shader-composer/r3f": minor
"@shader-composer/three": minor
"shader-composer-toybox": minor
---

**Breaking:** Shader Composer has received a new package structure! Its code is now spread across multiple smaller packages scoped within the `@shader-composer/*` organization, with the main `shader-composer` package acting as an umbrella package.

The user can now choose between either picking the scoped packages they need, or just using the umbrella package, which provides additional entrypoints for specific frameworks and libraries.

Example for working with individual scoped packages:

```js
import { compileShader } from "@shader-composer/core"
import { setupThree } from "@shader-composer/three"
import { PostProcessingEffectMaster } from "@shader-composer/postprocessing"
```

TODO: finalize examples
10 changes: 10 additions & 0 deletions .changeset/spotty-students-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"material-composer": minor
"@material-composer/patch-material": minor
"material-composer-r3f": minor
"render-composer": minor
"vfx-composer": minor
"vfx-composer-r3f": minor
---

Upgraded to the new version of Shader Composer.
14 changes: 14 additions & 0 deletions .changeset/stale-moles-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"shader-composer": minor
"@shader-composer/core": minor
"@shader-composer/r3f": minor
"@shader-composer/three": minor
---

**Breaking:** The core Shader Composer package `@shader-composer/core` no longer requires Three.js as a peer dependency, and is now ready to be used together with other frameworks (or directly with WebGL.)

Since some of the units provided within the standard library require framework-specific code to operate (like `CameraFar`, `CameraNear`, `Resolution` etc.), glue code needs to be created to use Shader Composer with other frameworks.

The Three.js glue code lives in the `@shader-composer/three` package.

TODO: example for usage
22 changes: 22 additions & 0 deletions .changeset/two-jokes-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"shader-composer": minor
"@shader-composer/core": minor
---

**New:** Arrays of specific lengths are now automatically casts to vectors and matrices; an array with 2 elements will be rendered as a `vec2`, an array with 3 elements will be rendered as a `vec3`, and so on.

```js
/* Before, and this still works: */
ScaleAndOffset(value, Vec2([0.5, 0.5]), Vec2([0.5, 0.5]))

/* But now this is also possible: */
ScaleAndOffset(value, [0.5, 0.5], [0.5, 0.5])
```

If you want to cast an array to a specific type, you can use the `vec2()`, `vec3()` etc. helpers:

```js
ScaleAndOffset(value, vec2([0.5, 0.5]), vec2([0.5, 0.5]))
```

Or wrap them in full units, like above.
5 changes: 5 additions & 0 deletions .changeset/yellow-pens-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shader-composer": minor
---

Removed Three-specific bits from `UpdateCallback`
1 change: 0 additions & 1 deletion apps/material-composer-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"react-dom": "^18.2.0",
"react-merge-refs": "^2.0.1",
"shader-composer": "0.4.9",
"shader-composer-r3f": "^0.4.5",
"shader-composer-toybox": "^0.1.3",
"three": "^0.145.0",
"timeline-composer": "^0.1.7",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useControls } from "leva"
import { composable, Layer, LayerProps, modules } from "material-composer-r3f"
import { useUniformUnit } from "shader-composer-r3f"
import { useUniformUnit } from "shader-composer/r3f"
import { Color } from "three"

export const ColorLayer = (props: LayerProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useControls } from "leva"
import { composable, Layer, modules } from "material-composer-r3f"
import { Description } from "r3f-stage"
import { useUniformUnit } from "shader-composer-r3f"
import { useUniformUnit } from "shader-composer/r3f"

export default function HelloWorld() {
const controls = useControls({ mix: { value: 0.5, min: 0, max: 1 } })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Time,
VertexPosition
} from "shader-composer"
import { useUniformUnit } from "shader-composer-r3f"
import { useUniformUnit } from "shader-composer/r3f"
import { DoubleSide } from "three"
import { Lava } from "./Fireball"
import { Plasma } from "./PlasmaBall"
Expand Down
2 changes: 1 addition & 1 deletion apps/material-composer-examples/src/examples/Textures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useControls } from "leva"
import { composable, Layer, modules } from "material-composer-r3f"
import { Description } from "r3f-stage"
import { Mul, Time, UV } from "shader-composer"
import { useUniformUnit } from "shader-composer-r3f"
import { useUniformUnit } from "shader-composer/r3f"
import textureUrl from "./textures/hexgrid.jpeg"

export default function Textures() {
Expand Down
2 changes: 1 addition & 1 deletion apps/material-composer-examples/src/examples/Vanilla.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const vanillaCode = (

/* Create mesh and add it to the scene. */
const stopLoop = loop((dt) => {
shaderMeta.update(dt, camera, scene, renderer)
shaderMeta.update(dt, { camera, scene, renderer })
})

return () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/shader-composer-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"r3f-stage": "^0.3.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"shader-composer": "^0.4.9",
"shader-composer-r3f": "^0.4.5",
"shader-composer": "workspace:^0.4.9",
"shader-composer-toybox": "^0.1.3",
"three": "^0.145.0"
},
Expand Down
6 changes: 3 additions & 3 deletions apps/shader-composer-examples/src/examples/Billboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Description, FlatStage } from "r3f-stage"
import { ShaderMaterialMaster, VertexPosition } from "shader-composer"
import { useShader } from "shader-composer-r3f"
import { useShader } from "shader-composer/r3f"
import { Billboard } from "shader-composer-toybox"
import { Color } from "three"

Expand All @@ -21,8 +21,8 @@ export default function BillboardingExample() {
</mesh>

<Description>
Use the <strong>Billboard</strong> unit to turn a mesh (like this plane) into a
billboard that is always facing the camera.
Use the <strong>Billboard</strong> unit to turn a mesh (like this plane)
into a billboard that is always facing the camera.
</Description>
</FlatStage>
)
Expand Down
4 changes: 2 additions & 2 deletions apps/shader-composer-examples/src/examples/DiscoCube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
Sub,
VertexPosition
} from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer-r3f"
import { PSRDNoise3D } from "shader-composer-toybox"
import { Shader, ShaderMaster, useShader } from "shader-composer/r3f"
import { PSRDNoise3D } from "shader-composer"
import { Color, Mesh } from "three"

export default function DiscoCube() {
Expand Down
2 changes: 1 addition & 1 deletion apps/shader-composer-examples/src/examples/Dissolve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ShaderMaster,
useShader,
useUniformUnit
} from "shader-composer-r3f"
} from "shader-composer/r3f"
import { Dissolve } from "shader-composer-toybox"
import { Color, DoubleSide } from "three"

Expand Down
4 changes: 2 additions & 2 deletions apps/shader-composer-examples/src/examples/Fireball.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
ShaderMaster,
useShader,
useUniformUnit
} from "shader-composer-r3f"
import { PSRDNoise3D, Turbulence3D } from "shader-composer-toybox"
} from "shader-composer/r3f"
import { PSRDNoise3D, Turbulence3D } from "shader-composer"
import textureUrl from "./textures/explosion.png"

export default function Fireball() {
Expand Down
2 changes: 1 addition & 1 deletion apps/shader-composer-examples/src/examples/Flag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Vec3,
VertexPosition
} from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer-r3f"
import { Shader, ShaderMaster, useShader } from "shader-composer/r3f"
import { DoubleSide } from "three"
import textureUrl from "./textures/shader-composer-logo.jpg"

Expand Down
5 changes: 3 additions & 2 deletions apps/shader-composer-examples/src/examples/FloatingIsland.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import {
Vec2,
Vec3
} from "shader-composer"
import { Displacement } from "shader-composer-toybox"
import { PSRDNoise2D } from "shader-composer"
import {
Shader,
ShaderMaster,
useShader,
useUniformUnit
} from "shader-composer-r3f"
import { Displacement, PSRDNoise2D } from "shader-composer-toybox"
} from "shader-composer/r3f"
import { Color, RGBADepthPacking, Vector2 } from "three"

export default function FloatingIslandExample() {
Expand Down
2 changes: 1 addition & 1 deletion apps/shader-composer-examples/src/examples/ForceField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
ShaderMaster,
useShader,
useUniformUnit
} from "shader-composer-r3f"
} from "shader-composer/r3f"
import { Color } from "three"
import { useRepeatingTexture } from "./helpers"

Expand Down
2 changes: 1 addition & 1 deletion apps/shader-composer-examples/src/examples/HelloWorld.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Sin,
VertexPosition
} from "shader-composer"
import { useShader, useUniformUnit } from "shader-composer-r3f"
import { useShader, useUniformUnit } from "shader-composer/r3f"
import { Color } from "three"

export default function HelloWorld() {
Expand Down
4 changes: 2 additions & 2 deletions apps/shader-composer-examples/src/examples/Planet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
Vec3,
VertexPosition
} from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer-r3f"
import { Simplex3DNoise } from "shader-composer-toybox"
import { Simplex3DNoise } from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer/r3f"
import { Color } from "three"

const getNoise = (
Expand Down
2 changes: 1 addition & 1 deletion apps/shader-composer-examples/src/examples/Rotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
VertexNormal,
VertexPosition
} from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer-r3f"
import { Shader, ShaderMaster, useShader } from "shader-composer/r3f"
import { Vector3 } from "three"

export default function MatrixTransformations() {
Expand Down
4 changes: 2 additions & 2 deletions apps/shader-composer-examples/src/examples/StylizedWater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import {
ShaderMaster,
useShader,
useUniformUnit
} from "shader-composer-r3f"
import { PSRDNoise2D, PSRDNoise3D } from "shader-composer-toybox"
} from "shader-composer/r3f"
import { PSRDNoise2D, PSRDNoise3D } from "shader-composer"
import { Color } from "three"

export default function StylizedWater() {
Expand Down
7 changes: 3 additions & 4 deletions apps/shader-composer-examples/src/examples/Textures.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Shader, ShaderMaster, useShader } from "shader-composer/r3f"
import {
$,
$vec2,
Add,
Fresnel,
Mul,
Expand All @@ -10,21 +10,20 @@ import {
UniformUnit,
UV
} from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer-r3f"
import { Color } from "three"
import { useRepeatingTexture } from "./helpers"

export default function Textures() {
const texture = useRepeatingTexture("/textures/hexgrid.jpg")

const shader = useShader(() => {
const offset = $vec2(Mul(Time(), 0.05), 0)
const offset = [Mul(Time(), 0.05), 0]

/* Create a texture sampler */
const sampler2D = UniformUnit("sampler2D", texture)

/* Get the texture information for the current fragment */
const tex2d = Texture2D(sampler2D, ScaleAndOffset(UV, $vec2(2, 1), offset))
const tex2d = Texture2D(sampler2D, ScaleAndOffset(UV, [2, 1], offset))

/* Define a color to tint the texture with */
const color = new Color("hotpink")
Expand Down
20 changes: 11 additions & 9 deletions apps/shader-composer-examples/src/examples/Water.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Environment } from "@react-three/drei"
import { pipe } from "fp-ts/function"
import { GlobalTime, Input, Int, Mul, Remap, Vec2 } from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer-r3f"
import { Displacement, FBMNoise, GerstnerWave } from "shader-composer-toybox"
import { add } from "shader-composer/fun"
import { Add, GlobalTime, Input, Int, Mul, Remap, Vec2 } from "shader-composer"
import { Displacement } from "shader-composer-toybox"
import { FBMNoise, GerstnerWave } from "shader-composer"
import { Shader, ShaderMaster, useShader } from "shader-composer/r3f"
import { Color, DoubleSide } from "three"

const NormalizeNoise = (v: Input<"float">) => Remap(v, -1, 1, 0, 1)
Expand Down Expand Up @@ -38,11 +38,13 @@ function Water() {

return pipe(
v,
add(Mul(GerstnerWave(xy, Vec2([1, 1]), 0.5, 20.0, time), 0.8)),
add(Mul(GerstnerWave(xy, Vec2([0.2, 1]), 0.2, 10, time), 0.8)),
add(Mul(GerstnerWave(xy, Vec2([0, -1]), 0.2, 5, time), 0.5)),
add(Mul(GerstnerWave(xy, Vec2([1, 1]), 0.2, 8, time), 0.3))
// add(Mul(vec3(0, 0.005, 0), fbm))
(v) =>
Add(v, Mul(GerstnerWave(xy, Vec2([1, 1]), 0.5, 20.0, time), 0.8)),
(v) =>
Add(v, Mul(GerstnerWave(xy, Vec2([0.2, 1]), 0.2, 10, time), 0.8)),
(v) => Add(v, Mul(GerstnerWave(xy, Vec2([0, -1]), 0.2, 5, time), 0.5)),
(v) => Add(v, Mul(GerstnerWave(xy, Vec2([1, 1]), 0.2, 8, time), 0.3))
// (v) => Add(v, Mul(vec3(0, 0.005, 0), fbm))
)
})

Expand Down
15 changes: 11 additions & 4 deletions apps/shader-composer-examples/src/examples/useRenderPass.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useFrame, useThree } from "@react-three/fiber"
import { useLayoutEffect, useMemo, useRef } from "react"
import { DepthTexture, WebGLRenderTarget } from "three"
import { useUniformUnit } from "shader-composer-r3f"
import { useUniformUnit } from "shader-composer/r3f"

export type RenderPassOptions = {
resolution?: number
Expand All @@ -20,14 +20,21 @@ export const useRenderPass = ({

const renderTargets = useMemo(
() => [
new WebGLRenderTarget(256, 256, { depthTexture: new DepthTexture(256, 256) }),
new WebGLRenderTarget(256, 256, { depthTexture: new DepthTexture(256, 256) })
new WebGLRenderTarget(256, 256, {
depthTexture: new DepthTexture(256, 256)
}),
new WebGLRenderTarget(256, 256, {
depthTexture: new DepthTexture(256, 256)
})
],
[]
)

const texture = useUniformUnit("sampler2D", renderTargets[0].texture)
const depthTexture = useUniformUnit("sampler2D", renderTargets[0].depthTexture)
const depthTexture = useUniformUnit(
"sampler2D",
renderTargets[0].depthTexture
)
const cursor = useRef(0)

useLayoutEffect(() => {
Expand Down
Loading