Three Vue3Three Vue3
指南
在线演示
AI 智能体
  • English
  • 简体中文
GitHub
指南
在线演示
AI 智能体
  • English
  • 简体中文
GitHub
    • 快速开始
    • 场景
    • 参数总线
    • 天空盒
    • 模型加载器

      • 组件加载器
      • 函数加载器
    • 弹出窗口
    • 标注
    • 动态元素
    • 动画
    • 模型旋转器
    • 拾取
    • 相机自适应
    • 网格模型

      • 波动圆
      • 流动线网格
    • 效果

      • 自然

        • 雨
        • 雪
        • 海洋水面
        • 互动水池
        • 沙滩漫步
      • 天空与大气

        • 天空穹顶
        • 高度雾
          • 默认用法
          • 属性
            • 雾体
            • 流动噪声
            • 方向性内散射
        • 星云星系
      • 光照

        • 泛光
        • 扫光
        • 灯光渐变
        • 光柱
        • 雷达扫描
        • 信号波
        • 力场护盾
      • 粒子与精灵

        • 烟花
        • 文字烟花
        • 光晕精灵
    • 地理

      • 地理参考系
      • GeoObject 地理对象
      • GeoJsonLayer 图层
      • 瓦片图层

type

Component

<tv-height-fog> 是一个屏幕空间后处理特效。场景会先渲染到带深度纹理的半浮点渲染目标,然后用一个全屏四边形根据深度缓冲重建每个片元的世界坐标,合成带流动噪声和方向性内散射的指数高度雾。

由于高度雾接管了渲染帧,请不要在同一个场景中同时使用 <tv-bloom>。

该特效在 WebGPURenderer(默认)与传统的 WebGLRenderer 上都能运行;给 <tv-scene> 加上 renderer-type="webgl" 即可对比两种后端。

默认用法

点击我查看代码
<template>
  <tv-scene
    class="scene"
    bg-color="rgb(40, 42, 54)"
    :grid-helper="gridHelper"
    @created="created"
  >
    <tv-height-fog />
  </tv-scene>
</template>

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

// 向远处延伸的柱子:[x, z, 宽度, 高度]。
const pillars: [number, number, number, number][] = [
  [-5, 5, 2.8, 13],
  [6, 2, 3.2, 17],
  [-2, -4, 2.6, 11],
  [8, -9, 3.4, 21],
  [-9, -15, 3.0, 15],
  [3, -22, 2.8, 19],
  [-6, -30, 3.4, 23]
]

const gridHelper = {
  size: 400,
  divisions: 40,
  colorGrid: 0x3a4050,
  colorCenterLine: 0x4d5570,
  y: 0.02
}

const meshes: THREE.Mesh[] = []

const created = (scene, { camera }) => {
  camera.position.set(0, 5, 14)
  camera.lookAt(0, 7, -12)

  // 与原 lightAzimuth 30° / lightElevation 25° 相同的方向。
  globalParameterBus.set('sunDirection', new THREE.Vector3(0.453, 0.423, 0.785))

  const ground = new THREE.Mesh(
    new THREE.PlaneGeometry(400, 400),
    new THREE.MeshStandardMaterial({ color: 0x2f3440, roughness: 1 })
  )
  ground.rotation.x = -Math.PI / 2

  const geometry = new THREE.BoxGeometry(1, 1, 1)
  const material = new THREE.MeshStandardMaterial({ color: 0x5c6579, roughness: 0.85 })
  const columns = pillars.map(([x, z, width, height]) => {
    const column = new THREE.Mesh(geometry, material)
    column.position.set(x, height / 2, z)
    column.scale.set(width, height, width)
    return column
  })

  meshes.push(ground, ...columns)
  scene.add(...meshes)
}

onBeforeUnmount(() => {
  meshes.forEach((mesh) => {
    mesh.parent?.remove(mesh)
    mesh.geometry.dispose()
    const meshMaterial = mesh.material as THREE.Material
    meshMaterial.dispose()
  })
  meshes.length = 0
})
</script>

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

属性

雾体

名称类型默认值描述
fogColorstring | number | Color'#c9d4cc'可选 雾的颜色。
fogDensitynumber0.02可选 雾平面处的雾浓度。
fogHeightnumber10可选 雾平面的世界高度。
fogHeightFalloffnumber0.25可选 每升高 1 / falloff 单位密度减半。
fogMaxOpacitynumber1可选 雾能够遮挡场景的最大不透明度。
fogStartDistancenumber0可选 从相机多远处开始累积雾。

流动噪声

名称类型默认值描述
noiseStrengthnumber0可选 雾平面的垂直位移(0 为关闭)。
noiseScalenumber0.012可选 噪声图案的世界单位缩放。
noiseSpeedXnumber0可选 噪声沿 X 轴的流动速度。
noiseSpeedZnumber0可选 噪声沿 Z 轴的流动速度。

方向性内散射

名称类型默认值描述
inscatteringColorstring | number | Color'#ffe2b0'可选 内散射光的颜色。
inscatteringIntensitynumber1可选 内散射强度。
inscatteringExponentnumber5可选 光照方向附近的衰减锐度。
inscatteringStartDistancenumber0可选 从相机多远处开始内散射。

光方向不是属性而是共享参数:雾会跟随存储在参数总线中的太阳方向,从而与天空保持一致。

globalParameterBus.set('sunDirection', new THREE.Vector3(0.453, 0.423, 0.785))
在 GitHub 上编辑此页
Last Updated:
Contributors: Shing Rui
Prev
天空穹顶
Next
星云星系