Three Vue3Three Vue3
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
    • Getting Started
    • Scene
    • Parameter Bus
    • SkyBox
    • Model Loader

      • Component Loader
      • Function Loader
    • Popup
    • Callout
    • Movable Element
    • Animation
    • Model Rotator
    • Picker
    • Fit Camera
    • Mesh

      • Wave Circle Mesh
      • Flow Line Mesh
    • Effect

      • Nature

        • Rain
        • Snow
          • Default Usage
          • Props
          • Class usage
        • Water
        • Water Pool
        • Sandy Beach
      • Sky & Atmosphere

        • Sky Dome
        • HeightFog
        • Nebula Galaxy
      • Light

        • Bloom
        • Sweep Light
        • Light Gradient
        • Light Pillar
        • Radar Sweep
        • Signal Wave
        • Force Shield
      • Particles & Sprites

        • Fireworks
        • Text Fireworks
        • Glow Sprite
    • GIS

      • Geographic Reference
      • GeoObject
      • GeoJsonLayer
      • Tile Layer

type

Component

<tv-snow> renders a GPU snow field inside a <tv-scene>. Every flake is a soft snowflake sprite that sways with a per-flake phase while falling, and wraps in a box around the camera. Add accumulate to let snow settle on the scene meshes.

The shader is a TSL node material, so it renders on WebGPURenderer (the default) and on a classic WebGLRenderer. Add renderer-type="webgl" to <tv-scene> to compare the two backends.

The same effect is available as the SnowEffect class when you are not using the scene component.

Default Usage

Click me to view the codes
<template>
  <tv-scene class="scene" bg-color="rgb(40, 42, 54)" @created="created">
    <tv-snow
      :count="1200"
      :speed="0.5"
      :color="0xffffff"
      :range="16"
      :height="14"
      :wind-x="0.2"
      :wind-z="0.08"
      accumulate
      :accumulation-thickness="0.12"
      :accumulation-duration="6"
    />
  </tv-scene>
</template>

<script lang="ts" setup>
import { onBeforeUnmount } from 'vue'
import * as THREE from 'three'

const objects: THREE.Object3D[] = []

const created = (scene, { camera }) => {
  camera.position.set(0, 1.6, 6)
  camera.lookAt(0, -0.2, 0)

  // A few simple meshes give the settling snow something to cover.
  const ground = new THREE.Mesh(
    new THREE.PlaneGeometry(10, 10),
    new THREE.MeshStandardMaterial({ color: '#39404f', roughness: 1 })
  )
  ground.rotation.x = -Math.PI / 2
  ground.position.y = -1.4

  const rock = new THREE.Mesh(
    new THREE.SphereGeometry(0.9, 48, 32),
    new THREE.MeshStandardMaterial({ color: '#4c566a', roughness: 0.85 })
  )
  rock.position.set(-1.6, -0.5, -0.4)
  rock.scale.set(1, 0.8, 1)

  const block = new THREE.Mesh(
    new THREE.BoxGeometry(1.5, 1.5, 1.5),
    new THREE.MeshStandardMaterial({ color: '#434c5e', roughness: 0.9 })
  )
  block.position.set(1.5, -0.65, -0.6)
  block.rotation.y = Math.PI / 6

  const pillar = new THREE.Mesh(
    new THREE.CylinderGeometry(0.35, 0.45, 1.6, 32),
    new THREE.MeshStandardMaterial({ color: '#3f4657', roughness: 0.9 })
  )
  pillar.position.set(0.2, -0.6, -1.8)

  scene.add(ground, rock, block, pillar)
  objects.push(ground, rock, block, pillar)
}

onBeforeUnmount(() => {
  objects.forEach((object) => {
    const mesh = object as THREE.Mesh
    mesh.geometry.dispose()
    ;(mesh.material as THREE.Material).dispose()
    mesh.removeFromParent()
  })
  objects.length = 0
})
</script>

<style>
.scene {
  margin-top: 10px;
  margin-bottom: 16px;
  width: 100%;
  height: 300px;
}
</style>

Props

NameTypeDefaultDescription
countnumber3000optional Number of flakes.
colorstring | number | Color0xffffffoptional Flake color.
speednumber0.5optional Falling speed multiplier.
rangenumber20optional Horizontal size of the wrapping box.
heightnumber15optional Vertical size of the wrapping box.
windXnumber0.2optional Wind drift on the X axis.
windZnumber0.1optional Wind drift on the Z axis.
turbulencenumber0.8optional Strength of the gusty sway.
opacitynumber0.9optional Flake opacity.
sizenumber1optional Flake size multiplier.
accumulatebooleanfalseoptional Let snow settle on the scene meshes.
accumulationTargetsObject3D | Object3D[]-optional Meshes that collect snow; defaults to the whole scene.
accumulationThicknessnumber0.1optional Thickness of the settled snow shell.
accumulationDurationnumber6optional Seconds for the snow to reach full thickness.
accumulationColorstring | number | Color0xffffffoptional Color of the settled snow.

Class usage

The standalone SnowEffect uses the same snowflake sprites, gusts, wrapping, soft fades and optional accumulation as <tv-snow>. It runs on WebGPU and WebGL, follows the camera automatically, and advances its own clock once added to a scene.

import { SnowEffect } from 'three-vue3'

const snow = new SnowEffect({
  count: 1200,
  size: 1,
  accumulate: true,
  accumulationDuration: 6
})
scene.add(snow.mesh)

// No per-frame update is required. Call update(delta) only to drive the
// timeline explicitly, and dispose when tearing down:
snow.dispose()

By default, snow accumulates on every eligible opaque mesh in the scene. Set accumulationTargets to limit accumulation to specific objects; accumulationThickness, accumulationDuration and accumulationColor work exactly like their component props.

Edit this page on GitHub
Last Updated:
Contributors: Shing Rui, ruixinglong
Prev
Rain
Next
Water