From 2cb9394f50117c894f0a272a7f0802b17db17940 Mon Sep 17 00:00:00 2001 From: Hendrik Mans Date: Sun, 21 Aug 2022 19:00:49 +0200 Subject: [PATCH] New example (#162) --- apps/examples/src/App.tsx | 10 +- .../src/examples/{Fog.tsx => FogExample.tsx} | 19 +- .../src/examples/PlasmaStormScene.tsx | 210 ++++++++++++++++++ apps/examples/src/examples/Playground.tsx | 22 +- 4 files changed, 233 insertions(+), 28 deletions(-) rename apps/examples/src/examples/{Fog.tsx => FogExample.tsx} (86%) create mode 100644 apps/examples/src/examples/PlasmaStormScene.tsx diff --git a/apps/examples/src/App.tsx b/apps/examples/src/App.tsx index 81dce3d5a..30f021c7f 100644 --- a/apps/examples/src/App.tsx +++ b/apps/examples/src/App.tsx @@ -8,8 +8,9 @@ import { import "r3f-stage/styles.css" import FireballExample from "./examples/Fireball" import { FireflyExample } from "./examples/FireflyExample" -import { Fog } from "./examples/Fog" +import { FogExample } from "./examples/FogExample" import PlasmaBallExample from "./examples/PlasmaBall" +import PlasmaStormScene from "./examples/PlasmaStormScene" import Playground from "./examples/Playground" import { Simple } from "./examples/Simple" import { SoftParticlesExample } from "./examples/SoftParticlesExample" @@ -55,7 +56,7 @@ export default () => ( - + Particle-based fog. Particles use billboarded plane geometries with a @@ -79,6 +80,11 @@ export default () => ( + Scenes + + + + Experiments diff --git a/apps/examples/src/examples/Fog.tsx b/apps/examples/src/examples/FogExample.tsx similarity index 86% rename from apps/examples/src/examples/Fog.tsx rename to apps/examples/src/examples/FogExample.tsx index 6eb4c0bb7..4706e487f 100644 --- a/apps/examples/src/examples/Fog.tsx +++ b/apps/examples/src/examples/FogExample.tsx @@ -14,6 +14,13 @@ import { } from "vfx-composer-r3f" import { smokeUrl } from "./textures" +export const FogExample = () => ( + + + + +) + export const Fog = () => { const texture = useTexture(smokeUrl) @@ -26,11 +33,6 @@ export const Fog = () => { return ( - - - - - { ) } + +const Sculpture = () => ( + + + + +) diff --git a/apps/examples/src/examples/PlasmaStormScene.tsx b/apps/examples/src/examples/PlasmaStormScene.tsx new file mode 100644 index 000000000..d5288e967 --- /dev/null +++ b/apps/examples/src/examples/PlasmaStormScene.tsx @@ -0,0 +1,210 @@ +import { useTexture } from "@react-three/drei" +import { GroupProps } from "@react-three/fiber" +import { Layers, useRenderPipeline } from "r3f-stage" +import { between, plusMinus, random } from "randomish" +import { + Cos, + Mul, + OneMinus, + Rotation3DY, + Rotation3DZ, + Sin, + Time +} from "shader-composer" +import { useUniformUnit } from "shader-composer-r3f" +import { Color, DoubleSide, MeshStandardMaterial, Vector3 } from "three" +import { Repeat } from "three-vfx" +import { + Emitter, + Particles, + useParticleAttribute, + useParticles, + VFX, + VFXMaterial +} from "vfx-composer-r3f" +import { smokeUrl } from "./textures" + +/* TODO: extract into randomish */ +const onCircle = (radius = 1) => { + const theta = plusMinus(Math.PI) + const x = radius * Math.cos(theta) + const y = radius * Math.sin(theta) + + return { x, y } +} + +export default function PlasmaStormScene() { + return ( + + + + + + + ) +} + +const frequency = 5 + +const SuckyParticles = () => { + const particles = useParticles() + const velocity = useParticleAttribute(() => new Vector3()) + + return ( + + + + + + + + + + + + + + { + particles.setLifetime(between(1, 2), random() / frequency) + + const direction = onCircle(between(4, 5)) + + position.set(direction.x, 0, direction.y) + + velocity.value + .set(direction.x, 0, direction.y) + .normalize() + .multiplyScalar(-1) + .multiplyScalar(between(1.5, 2)) + }} + /> + + + ) +} + +const FloorEruption = () => { + const particles = useParticles() + const velocity = useParticleAttribute(() => new Vector3()) + + return ( + + + + + + + + + + + + + { + const s = onCircle(between(3, 3.2)) + position.set(s.x, 0, s.y) + particles.setLifetime(4, random() / frequency) + + velocity.value + .set(position.x, 5, position.z) + .normalize() + .multiplyScalar(2) + }} + /> + + + ) +} + +function PlasmaBall(props: GroupProps) { + const time = Time() + + const depth = useUniformUnit("sampler2D", useRenderPipeline().depth) + + return ( + + + + + + + + + + + + + + ) +} + +export const Fog = () => { + const texture = useTexture(smokeUrl) + + const particles = useParticles() + const velocity = useParticleAttribute(() => new Vector3()) + const rotation = useParticleAttribute(() => 0 as number) + const scale = useParticleAttribute(() => 1 as number) + + const depth = useUniformUnit("sampler2D", useRenderPipeline().depth) + + return ( + + + + + + + + + + + + + + { + particles.setLifetime(6, random() / frequency) + position.set(-10, between(0, 1), plusMinus(10)) + velocity.value.set(between(3, 10), 0, 0) + rotation.value = plusMinus(0.2) + scale.value = between(1, 10) + }} + /> + + + + ) +} diff --git a/apps/examples/src/examples/Playground.tsx b/apps/examples/src/examples/Playground.tsx index 192059351..af5fa477e 100644 --- a/apps/examples/src/examples/Playground.tsx +++ b/apps/examples/src/examples/Playground.tsx @@ -1,23 +1,3 @@ -import { sharedResource } from "@hmans/r3f-shared-resource" - -const SharedMaterial = sharedResource(() => ( - -)) - export default function Playground() { - return ( - - - - - - - - - - - - - - ) + return }