Skip to content

Commit

Permalink
Magic Well example
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Aug 26, 2022
1 parent 2ce67fb commit be5ca02
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/examples/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "r3f-stage/styles.css"
import FireballExample from "./examples/Fireball"
import { FireflyExample } from "./examples/FireflyExample"
import { FogExample } from "./examples/FogExample"
import MagicWellExample from "./examples/MagicWellExample"
import PlasmaBallExample from "./examples/PlasmaBall"
import PlasmaStormScene from "./examples/PlasmaStormScene"
import Playground from "./examples/Playground"
Expand Down Expand Up @@ -41,6 +42,10 @@ export default () => (
<FireflyExample />
</Example>

<Example path="particles/magic-well" title="Magic Well">
<MagicWellExample />
</Example>

<Example path="particles/vanilla" title="Vanilla Three.js">
<Vanilla />

Expand Down
54 changes: 54 additions & 0 deletions apps/examples/src/examples/MagicWellExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useTexture } from "@react-three/drei"
import { ComposableMaterial, Modules } from "material-composer-r3f"
import { useRenderPipeline } from "r3f-stage"
import { between, plusMinus } from "randomish"
import { OneMinus } from "shader-composer"
import { useUniformUnit } from "shader-composer-r3f"
import { AdditiveBlending, Color, DoubleSide, Euler, Vector3 } from "three"
import { Emitter, Particles, useParticles } from "vfx-composer-r3f"
import { particleUrl } from "./textures"

export default function MagicWellExample() {
const texture = useTexture(particleUrl)
const particles = useParticles()
const depth = useUniformUnit("sampler2D", useRenderPipeline().depth)

return (
<group>
<Particles maxParticles={5_000}>
<planeGeometry args={[0.15, 2]} />

<ComposableMaterial
map={texture}
depthWrite={false}
blending={AdditiveBlending}
side={DoubleSide}
color={new Color(0, 3, 2)}
>
<Modules.Scale scale={OneMinus(particles.progress)} />
<Modules.Acceleration
force={new Vector3(0, 1.2, 0)}
time={particles.age}
/>
<Modules.Lifetime {...particles} />
<Modules.Softness softness={5} depthTexture={depth} />
</ComposableMaterial>

<Emitter
continuous
count={2}
setup={({ position, rotation }) => {
const theta = plusMinus(Math.PI)
const power = Math.pow(Math.random(), 3)
const r = power * 1.2
position.set(Math.cos(theta) * r, -2, Math.sin(theta) * r)

rotation.setFromEuler(new Euler(0, plusMinus(Math.PI), 0))

particles.setLifetime(between(1, 5))
}}
/>
</Particles>
</group>
)
}

0 comments on commit be5ca02

Please sign in to comment.