unity-lighting-vfx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Unity Lighting and Visual Effects

Unity 灯光与视觉效果

Lighting Modes

光照模式

Unity provides three light modes controlling how illumination is calculated.
Unity提供三种光照模式,用于控制光照的计算方式。

Realtime Lights

实时灯光

  • Calculate lighting every frame at runtime
  • Allow dynamic changes to intensity, color, position
  • Cast shadows up to Shadow Distance
  • Contribute only direct lighting by default (no bounced light)
  • Higher runtime cost, especially in complex scenes or low-end hardware
  • Best for: dynamic objects, flickering effects, moving light sources
  • 运行时每帧计算光照
  • 允许动态调整强度、颜色、位置
  • 可投射阴影,阴影范围受Shadow Distance限制
  • 默认仅贡献直接光照(无反弹光)
  • 运行时成本较高,尤其是在复杂场景或低端硬件中
  • 最佳适用场景:动态物体、闪烁效果、移动光源

Baked Lights

烘焙灯光

  • Calculations performed in the Unity Editor and saved as lighting data to disk
  • At runtime, Unity loads pre-computed data instead of calculating dynamically
  • Bake both direct and indirect lighting into lightmaps
  • Store information in Light Probes for moving objects
  • Cannot modify light properties at runtime; do not illuminate dynamic GameObjects
  • No specular contributions
  • Best for: static scenery, complex indirect lighting, performance-critical scenarios
  • 在Unity编辑器中完成计算,并将光照数据保存到磁盘
  • 运行时Unity加载预计算数据,而非动态计算
  • 将直接光照和间接光照烘焙到光照贴图中
  • 为移动物体存储光照探针信息
  • 运行时无法修改灯光属性;不会照亮动态GameObject
  • 无高光贡献
  • 最佳适用场景:静态场景、复杂间接光照、性能优先的场景

Mixed Lights

混合灯光

  • Combine baked indirect lighting with real-time direct lighting
  • Behavior depends on the Lighting Mode setting in the Lighting window
  • Cast real-time shadows (not baked soft shadows)
  • Can change properties at runtime (affects real-time component only)
  • Always more expensive than fully baked lighting
  • Best for: dynamic shadows with baked background lighting
Important: All baked/mixed modes require Baked Global Illumination enabled. Without it, Mixed and Baked lights behave as Realtime.
  • 结合烘焙间接光照实时直接光照
  • 行为取决于Lighting窗口中的Lighting Mode设置
  • 投射实时阴影(非烘焙软阴影)
  • 运行时可修改属性(仅影响实时部分)
  • 成本始终高于完全烘焙的光照
  • 最佳适用场景:需要动态阴影且背景光照为烘焙的场景
重要提示:所有烘焙/混合模式都需要启用Baked Global Illumination。未启用时,混合灯光和烘焙灯光会自动切换为实时灯光模式。

Light Types

灯光类型

Directional Light

方向光

  • Located infinitely far away, emits light in one direction
  • Parallel rays, no distance-based intensity falloff
  • Simulates sun/moon; every new scene includes one by default
  • Links to procedural sky system; rotate to create time-of-day effects
  • 位于无限远处,向单一方向发射光线
  • 光线平行,强度不随距离衰减
  • 模拟太阳/月亮;新建场景默认包含一个方向光
  • 与程序化天空系统关联;旋转可实现昼夜变化效果

Point Light

点光源

  • Located at a point, emits in all directions equally
  • Intensity follows inverse square law (diminishes with distance squared)
  • Use for lamps, explosions, local illumination
  • 位于某一点,向所有方向均匀发射光线
  • 强度遵循平方反比定律(随距离平方衰减)
  • 适用于灯具、爆炸效果、局部照明

Spot Light

聚光灯

  • Located at a point, emits in a cone shape
  • Adjustable cone angle; light diminishes at edges (penumbra)
  • Wider angles create larger fade areas
  • Use for flashlights, headlights, searchlights
  • 位于某一点,以锥形范围发射光线
  • 可调整锥角;光线在边缘衰减(半影区)
  • 角度越宽,衰减区域越大
  • 适用于手电筒、车头灯、探照灯

Area Light

面光源

  • Defined by a rectangle or disc; emits uniformly across surface
  • Follows inverse square law; produces soft, subtle shading
  • Bake-only -- not available at runtime
  • Use for street lights, realistic interior lighting
  • 由矩形或圆形定义,从表面均匀发射光线
  • 遵循平方反比定律;产生柔和、细腻的阴影
  • 仅支持烘焙——运行时不可用
  • 适用于路灯、真实室内照明

Global Illumination

全局光照

Global illumination (GI) simulates how light bounces between surfaces, producing realistic indirect lighting.
全局光照(GI)模拟光线在表面间的反弹,生成真实的间接光照效果。

Baked GI

烘焙GI

  • Pre-computes indirect lighting into lightmaps using the Progressive Lightmapper (CPU or GPU)
  • Results stored in lightmap textures and Light Probes
  • Configure in the Lighting window under Bake settings
  • GPU Progressive Lightmapper offers faster bake times with configurable tile sizes
  • 使用Progressive Lightmapper(CPU或GPU)将间接光照预计算到光照贴图中
  • 结果存储在光照贴图纹理和光照探针中
  • 在Lighting窗口的Bake设置中配置
  • GPU Progressive Lightmapper支持更快的烘焙速度,且可配置 tile 大小

Environment Lighting

环境光照

Three ambient light sources configured in the Lighting window Environment tab:
  • Skybox: Uses skybox material colors for ambient light from different angles
  • Gradient: Separate sky, horizon, and ground colors with smooth blending
  • Color: Uniform ambient light across the scene
Intensity Multiplier (0-8, default 1) controls ambient brightness.
在Lighting窗口的Environment标签中配置三种环境光源:
  • Skybox:使用天空盒材质颜色,从不同角度提供环境光
  • Gradient:分别设置天空、地平线和地面颜色,实现平滑过渡
  • Color:为场景提供统一的环境光
Intensity Multiplier(范围0-8,默认1)控制环境光亮度。

Environment Reflections

环境反射

  • Source: Skybox or custom Cubemap/RenderTexture
  • Configurable resolution, compression, intensity multiplier
  • Bounces setting controls reflection evaluation iterations between objects
  • 来源:Skybox或自定义Cubemap/RenderTexture
  • 可配置分辨率、压缩方式、强度乘数
  • Bounces设置控制物体间反射计算的迭代次数

Light Probes and Adaptive Probe Volumes

光照探针与自适应探针体积

Light Probes

光照探针

  • Capture lighting information in empty space throughout a scene
  • At runtime, indirect lighting for dynamic GameObjects is approximated using nearest probes
  • Provide indirect bounced light for moving objects and LOD system support
  • Must be manually placed using Light Probe Groups
  • Store baked lighting information; work with both direct and indirect lighting
  • 捕获场景中空旷区域的光照信息
  • 运行时,动态GameObject的间接光照通过最近的探针进行近似计算
  • 为移动物体和LOD系统提供间接反弹光支持
  • 需使用Light Probe Groups手动放置
  • 存储烘焙光照信息;支持直接光照和间接光照

Adaptive Probe Volumes (APV)

自适应探针体积(APV)

APV is the modern replacement for manual Light Probe placement in URP:
  • Automated probe placement -- eliminates manual Light Probe Group positioning
  • Per-pixel lighting -- superior quality compared to per-object approaches
  • Scene baking -- bake multiple scenes together using Baking Sets
  • Runtime adjustments -- Lighting Scenarios and sky occlusion for dynamic changes
  • Large-world support -- streaming data for expansive open-world environments
  • Data flexibility -- loading from AssetBundles or Addressables
  • Configurable probe density and volume size with visualization tools
APV是URP中手动放置光照探针的现代化替代方案:
  • 自动探针放置——无需手动定位Light Probe Group
  • 逐像素光照——相比逐物体方案,质量更优
  • 场景烘焙——使用Baking Sets可同时烘焙多个场景
  • 运行时调整——支持Lighting Scenarios和天空遮挡,实现动态变化
  • 大世界支持——为大型开放世界环境提供数据流
  • 数据灵活性——可从AssetBundles或Addressables加载
  • 可配置探针密度和体积大小,并提供可视化工具

Reflection Probes

反射探针

Capture a spherical view of surroundings as a cubemap for reflective materials.
捕获周围环境的球形视图,保存为立方体贴图,用于反射材质。

Types

类型

TypeDescription
BakedCaptures static GameObjects only; best performance
CustomAllows dynamic object capture with custom textures
RealtimeUpdates during gameplay; configurable refresh mode
类型描述
Baked仅捕获静态GameObject;性能最佳
Custom允许使用自定义纹理捕获动态物体
Realtime游戏运行时更新;可配置刷新模式

Key Properties

关键属性

  • Importance: Rendering priority when multiple probes overlap
  • Intensity: Texture brightness in shader calculations
  • Box Projection: Enables projection mapping for interiors (requires URP config)
  • Box Size/Offset: World-space bounding box for reflection contribution
  • Blend Distance: Blending distance for deferred probes
  • Importance:多个探针重叠时的渲染优先级
  • Intensity:着色器计算中的纹理亮度
  • Box Projection:启用室内投影映射(需URP配置)
  • Box Size/Offset:反射贡献的世界空间边界框
  • Blend Distance:延迟探针的混合距离

Realtime Options

实时选项

  • Refresh Mode: On Awake, Every Frame, or Via Scripting
  • Time Slicing: All Faces At Once, Individual Faces, No Time Slicing
  • Refresh Mode:唤醒时刷新、每帧刷新或通过脚本刷新
  • Time Slicing:一次性渲染所有面、逐个渲染面、不使用时间切片

Particle System vs VFX Graph

Particle System vs VFX Graph

FeatureParticle SystemVFX Graph
SimulationCPU-basedGPU-based
Particle countThousandsMillions
Render pipelineAll pipelinesURP/HDRP only
AuthoringInspector modulesNode-based graph editor
PhysicsBuilt-in collisionCustom collision blocks
ScriptingFull C# APIEvent-based C# API
Sub-emittersNative supportGPU Event contexts
Best forSmall/medium effects, mobileLarge-scale effects, high-end
Decision Guide:
  • Use Particle System for mobile targets, simple effects, when you need full CPU-side scripting control, or when targeting the Built-in Render Pipeline
  • Use VFX Graph for massive particle counts, GPU-driven simulations, complex node-based authoring, or high-end platforms with URP/HDRP
特性Particle SystemVFX Graph
模拟方式基于CPU基于GPU
粒子数量数千级数百万级
渲染管线支持所有管线仅支持URP/HDRP
创建方式检查器模块基于节点的图形编辑器
物理系统内置碰撞自定义碰撞模块
脚本控制完整C# API基于事件的C# API
子发射器原生支持GPU Event上下文
最佳场景中小型效果、移动端大规模效果、高端平台
选择指南:
  • 当目标为移动端、需要简单效果、需要完整CPU端脚本控制,或使用Built-in Render Pipeline时,选择Particle System
  • 当需要海量粒子、GPU驱动模拟、复杂节点式创建,或使用URP/HDRP的高端平台时,选择VFX Graph

Particle System Modules

Particle System模块

ModulePurpose
MainInitial state: lifetime, speed, size, gravity, simulation space
EmissionRate and timing of particle spawns
ShapeVolume/surface for emission and start velocity direction
Velocity over LifetimeModify movement over particle age
NoiseTurbulence for organic, chaotic motion
Limit Velocity over LifetimeNatural deceleration
Force over LifetimeSimulated physics forces
Inherit VelocitySub-emitter particles match parent velocity
Lifetime by Emitter SpeedAdjust lifespan based on emitter velocity
Color over Lifetime / by SpeedColor changes based on age or velocity
Size over Lifetime / by SpeedDimension changes based on time or speed
Rotation over Lifetime / by SpeedOrientation changes
CollisionParticle collisions with scene geometry
TriggersDesignate particles as collision triggers
Sub EmittersParticles that emit other particles
Texture Sheet AnimationTexture grid animation frames
TrailsMotion trail rendering
LightsReal-time lights on particles
External ForcesWind zones and force fields
RendererImage/mesh transform, shading, overdraw
Custom DataAttach custom data to particles
模块用途
Main初始状态设置:生命周期、速度、大小、重力、模拟空间
Emission粒子生成的速率和时间控制
Shape粒子发射的体积/表面及初始速度方向
Velocity over Lifetime随粒子生命周期修改运动状态
Noise为粒子添加湍流,实现自然、混乱的运动
Limit Velocity over Lifetime模拟自然减速效果
Force over Lifetime模拟物理作用力
Inherit Velocity子发射器粒子继承父物体速度
Lifetime by Emitter Speed根据发射器速度调整粒子生命周期
Color over Lifetime / by Speed根据粒子年龄或速度改变颜色
Size over Lifetime / by Speed根据时间或速度改变粒子尺寸
Rotation over Lifetime / by Speed改变粒子朝向
Collision粒子与场景几何体的碰撞
Triggers将粒子标记为碰撞触发器
Sub Emitters可发射其他粒子的粒子
Texture Sheet Animation纹理网格动画帧
Trails运动轨迹渲染
Lights粒子上的实时灯光
External Forces风区和力场
Renderer图像/网格变换、着色、过绘制
Custom Data为粒子附加自定义数据

VFX Graph Basics

VFX Graph基础

Systems

系统

  1. Spawn System: Single Spawn Context managing emission
  2. Particle System: Initialize -> Update -> Output succession
  3. Mesh Output System: Single Mesh Output Context
  1. Spawn System:管理粒子发射的单个Spawn Context
  2. Particle System:初始化 -> 更新 -> 输出的流程
  3. Mesh Output System:单个Mesh Output Context

Contexts

上下文

  • Spawn: Executes each frame to calculate spawn amounts. States: Running, Idle, Waiting. Configurable loop duration, count, and delays
  • Initialize: Runs at particle birth, sets initial state. Processes Blocks for newly spawned particles. Configurable bounds and capacity
  • Update: Per-frame for all living particles. Automatic: position integration, rotation integration, aging, reaping
  • Output: Renders particles (Quad, Mesh, etc.). No output ports. Customizable rendering blocks
  • Spawn:每帧执行以计算粒子生成数量。状态:Running、Idle、Waiting。可配置循环时长、数量和延迟
  • Initialize:粒子生成时运行,设置初始状态。处理新生成粒子的Blocks。可配置边界和容量
  • Update:每帧对所有存活粒子执行。自动处理:位置整合、旋转整合、老化、销毁
  • Output:渲染粒子(Quad、Mesh等)。无输出端口。可自定义渲染Blocks

Graph Elements

图形元素

  • Blocks: Stackable nodes within Contexts; each handles one operation; top-to-bottom execution
  • Operators: Low-level property workflow nodes connecting to Block/Context ports
  • Properties: Connectable via property workflow
  • Settings: Non-connectable editable values per Context
  • Blocks:上下文内可堆叠的节点;每个节点处理一项操作;按从上到下顺序执行
  • Operators:连接Block/Context端口的底层属性工作流节点
  • Properties:可通过属性工作流连接
  • Settings:每个上下文的不可连接可编辑值

GPU Events

GPU Events

Experimental feature where GPU computes events (vs CPU for normal events). Cannot be customized with Blocks.
实验性功能,由GPU计算事件(常规事件由CPU计算)。无法用Blocks自定义。

Common Patterns (C#)

常见模式(C#)

Create and Configure a Light

创建并配置灯光

csharp
using UnityEngine;

public class LightSetup : MonoBehaviour
{
    void Start()
    {
        GameObject lightObj = new GameObject("Dynamic Light");
        Light light = lightObj.AddComponent<Light>();
        light.type = LightType.Point;
        light.color = Color.yellow;
        light.intensity = 2.0f;
        light.range = 15f;
        light.shadows = LightShadows.Soft;
        light.shadowResolution = UnityEngine.Rendering.LightShadowResolution.Medium;
    }
}
csharp
using UnityEngine;

public class LightSetup : MonoBehaviour
{
    void Start()
    {
        GameObject lightObj = new GameObject("Dynamic Light");
        Light light = lightObj.AddComponent<Light>();
        light.type = LightType.Point;
        light.color = Color.yellow;
        light.intensity = 2.0f;
        light.range = 15f;
        light.shadows = LightShadows.Soft;
        light.shadowResolution = UnityEngine.Rendering.LightShadowResolution.Medium;
    }
}

Create a Realtime Reflection Probe

创建实时反射探针

csharp
using UnityEngine;
using UnityEngine.Rendering;

public class ProbeSetup : MonoBehaviour
{
    void Start()
    {
        GameObject probeObj = new GameObject("Realtime Reflection Probe");
        ReflectionProbe probe = probeObj.AddComponent<ReflectionProbe>();
        probe.size = new Vector3(10, 10, 10);
        probe.mode = ReflectionProbeMode.Realtime;
        probe.refreshMode = ReflectionProbeRefreshMode.EveryFrame;
        probe.resolution = 256;
        probe.hdr = true;
    }
}
csharp
using UnityEngine;
using UnityEngine.Rendering;

public class ProbeSetup : MonoBehaviour
{
    void Start()
    {
        GameObject probeObj = new GameObject("Realtime Reflection Probe");
        ReflectionProbe probe = probeObj.AddComponent<ReflectionProbe>();
        probe.size = new Vector3(10, 10, 10);
        probe.mode = ReflectionProbeMode.Realtime;
        probe.refreshMode = ReflectionProbeRefreshMode.EveryFrame;
        probe.resolution = 256;
        probe.hdr = true;
    }
}

Control Particle System at Runtime

运行时控制Particle System

csharp
using UnityEngine;

public class ParticleController : MonoBehaviour
{
    ParticleSystem ps;

    void Start()
    {
        ps = GetComponent<ParticleSystem>();

        // Modify emission rate -- cache module in local variable first
        var emission = ps.emission;
        emission.rateOverTimeMultiplier = 50f;

        // Modify main module
        var main = ps.main;
        main.startLifetime = 3f;
        main.startSpeed = 5f;
        main.simulationSpace = ParticleSystemSimulationSpace.World;
    }

    void OnTriggerEnter(Collider other)
    {
        // Burst emit particles
        ps.Emit(100);
    }

    void OnDisable()
    {
        ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
    }
}
csharp
using UnityEngine;

public class ParticleController : MonoBehaviour
{
    ParticleSystem ps;

    void Start()
    {
        ps = GetComponent<ParticleSystem>();

        // 修改发射速率——先将模块缓存到局部变量
        var emission = ps.emission;
        emission.rateOverTimeMultiplier = 50f;

        // 修改主模块
        var main = ps.main;
        main.startLifetime = 3f;
        main.startSpeed = 5f;
        main.simulationSpace = ParticleSystemSimulationSpace.World;
    }

    void OnTriggerEnter(Collider other)
    {
        // 爆发式生成粒子
        ps.Emit(100);
    }

    void OnDisable()
    {
        ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
    }
}

VFX Graph Runtime Control

VFX Graph运行时控制

csharp
using UnityEngine;
using UnityEngine.VFX;

public class VFXController : MonoBehaviour
{
    VisualEffect vfx;
    VFXEventAttribute eventAttr;

    void Start()
    {
        vfx = GetComponent<VisualEffect>();
        eventAttr = vfx.CreateVFXEventAttribute();

        // Set exposed properties
        vfx.SetFloat("SpawnRate", 100f);
        vfx.SetVector3("Direction", Vector3.up);
        vfx.playRate = 1.5f;
    }

    void OnTriggerEnter(Collider other)
    {
        // Send custom event with attributes
        eventAttr.SetVector3("position", other.transform.position);
        vfx.SendEvent("OnHit", eventAttr);
    }

    public void StopEffect()
    {
        vfx.Stop();
    }
}
csharp
using UnityEngine;
using UnityEngine.VFX;

public class VFXController : MonoBehaviour
{
    VisualEffect vfx;
    VFXEventAttribute eventAttr;

    void Start()
    {
        vfx = GetComponent<VisualEffect>();
        eventAttr = vfx.CreateVFXEventAttribute();

        // 设置暴露属性
        vfx.SetFloat("SpawnRate", 100f);
        vfx.SetVector3("Direction", Vector3.up);
        vfx.playRate = 1.5f;
    }

    void OnTriggerEnter(Collider other)
    {
        // 发送带属性的自定义事件
        eventAttr.SetVector3("position", other.transform.position);
        vfx.SendEvent("OnHit", eventAttr);
    }

    public void StopEffect()
    {
        vfx.Stop();
    }
}

Refresh Reflection Probe on Demand

按需刷新反射探针

csharp
using UnityEngine;

public class ProbeRefresher : MonoBehaviour
{
    ReflectionProbe probe;

    void Start()
    {
        probe = GetComponent<ReflectionProbe>();
        probe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.ViaScripting;
    }

    public void RefreshReflections()
    {
        probe.RenderProbe();
    }

    public bool IsReady()
    {
        return probe.IsFinishedRendering(probe.RenderProbe());
    }
}
csharp
using UnityEngine;

public class ProbeRefresher : MonoBehaviour
{
    ReflectionProbe probe;

    void Start()
    {
        probe = GetComponent<ReflectionProbe>();
        probe.refreshMode = UnityEngine.Rendering.ReflectionProbeRefreshMode.ViaScripting;
    }

    public void RefreshReflections()
    {
        probe.RenderProbe();
    }

    public bool IsReady()
    {
        return probe.IsFinishedRendering(probe.RenderProbe());
    }
}

Anti-Patterns

反模式

Lighting Anti-Patterns

光照反模式

  1. Too many Realtime lights: Each realtime light adds per-frame cost. Use Baked or Mixed for static lights
  2. Forgetting to enable Baked Global Illumination: Mixed/Baked lights silently fall back to Realtime without it
  3. Overlapping Reflection Probes without Importance values: Causes flickering; always set Importance to establish priority
  4. Using Area Lights expecting runtime behavior: Area lights are bake-only; they produce no light at runtime
  5. Ignoring Indirect Multiplier: Leaving at default can cause over-bright or too-dark bounced light; tune per light
  6. Not setting Shadow Bias correctly: Too low causes self-shadowing artifacts (shadow acne); too high causes peter-panning (shadows detach from objects)
  7. Manual Light Probe placement in large scenes: Use Adaptive Probe Volumes (APV) in URP instead for automated, per-pixel quality
  1. 过多实时灯光:每个实时灯光都会增加每帧成本。静态灯光应使用烘焙或混合模式
  2. 忘记启用Baked Global Illumination:未启用时,混合/烘焙灯光会自动切换为实时模式
  3. 重叠反射探针未设置Importance值:会导致闪烁;始终需设置Importance来确定优先级
  4. 期望面光源在运行时生效:面光源仅支持烘焙;运行时不会产生光照
  5. 忽略Indirect Multiplier:默认值可能导致反弹光过亮或过暗;需针对每个灯光调整
  6. Shadow Bias设置不当:值过低会导致自阴影 artifacts(阴影 acne);值过高会导致阴影脱离物体(peter-panning)
  7. 在大型场景中手动放置光照探针:在URP中应使用自适应探针体积(APV),实现自动放置和逐像素质量

Particle System Anti-Patterns

Particle System反模式

  1. Not caching module references: Each property access on a module struct immediately writes to native code; cache the module variable
  2. Using World simulation space for attached effects: Particles drift away from moving parents; use Local space for attached FX
  3. Excessive particle counts on CPU: Particle System is CPU-bound; for >10K particles, consider VFX Graph
  4. Forgetting to Stop/Clear: Leaked particle systems consume CPU even when invisible
  1. 未缓存模块引用:每次访问模块结构体属性都会立即写入原生代码;需缓存模块变量
  2. 对附着效果使用World模拟空间:粒子会从移动的父物体漂移;附着效果应使用Local空间
  3. CPU上粒子数量过多:Particle System基于CPU;粒子数量超过10K时,考虑使用VFX Graph
  4. 忘记停止/清除粒子系统:泄漏的粒子系统即使不可见也会消耗CPU

VFX Graph Anti-Patterns

VFX Graph反模式

  1. Using VFX Graph for simple effects on mobile: GPU overhead and URP/HDRP requirement make it overkill for simple mobile effects
  2. Not setting Capacity in Initialize: Default capacity may allocate too much or too little GPU memory
  3. Ignoring Bounds: Incorrect bounds cause effects to be culled when visible; always configure bounds in Initialize context
  4. Sending events every frame without throttling: SendEvent has CPU-GPU sync cost; batch or throttle event dispatch
  1. 在移动端使用VFX Graph实现简单效果:GPU开销和URP/HDRP要求使其在移动端简单效果场景中过于冗余
  2. 未在Initialize中设置Capacity:默认容量可能分配过多或过少GPU内存
  3. 忽略Bounds:错误的Bounds会导致可见效果被剔除;始终需在Initialize上下文中配置Bounds
  4. 无限制地每帧发送事件:SendEvent存在CPU-GPU同步成本;需批量处理或限制事件发送频率

Key API Quick Reference

关键API速查

Light (UnityEngine.Light)

Light(UnityEngine.Light)

MemberTypeDescription
type
PropertyLightType (Directional, Point, Spot, Area)
color
PropertyEmitted light color
intensity
PropertyBrightness multiplier
range
PropertyMax distance (Point/Spot)
spotAngle
/
innerSpotAngle
PropertyOuter/inner cone angles
shadows
PropertyLightShadows (None, Hard, Soft)
shadowResolution
PropertyShadow map quality
shadowBias
/
shadowNormalBias
PropertyShadow artifact reduction
bounceIntensity
PropertyGI bounce strength
cookie
PropertyProjected texture mask
cullingMask
PropertyLayer-based filtering
colorTemperature
PropertyCCT in Kelvin
lightmapBakeType
PropertyBaking configuration
bakingOutput
PropertyLast bake contribution details
AddCommandBuffer()
MethodExecute GPU commands at specified points
成员类型描述
type
属性LightType(Directional、Point、Spot、Area)
color
属性发射光颜色
intensity
属性亮度乘数
range
属性最大距离(点光源/聚光灯)
spotAngle
/
innerSpotAngle
属性外/内锥角
shadows
属性LightShadows(None、Hard、Soft)
shadowResolution
属性阴影贴图质量
shadowBias
/
shadowNormalBias
属性减少阴影 artifacts
bounceIntensity
属性GI反弹强度
cookie
属性投影纹理遮罩
cullingMask
属性基于层的过滤
colorTemperature
属性色温(开尔文)
lightmapBakeType
属性烘焙配置
bakingOutput
属性上次烘焙贡献详情
AddCommandBuffer()
方法在指定阶段执行GPU命令

ParticleSystem (UnityEngine.ParticleSystem)

ParticleSystem(UnityEngine.ParticleSystem)

MemberTypeDescription
main
/
emission
/
shape
PropertyModule access structs
particleCount
PropertyCurrent active particles
isPlaying
/
isPaused
/
isStopped
PropertyPlayback state
Play()
/
Pause()
/
Stop()
MethodPlayback control
Emit(count)
MethodImmediate particle spawn
Simulate(time)
MethodFast-forward simulation
GetParticles()
/
SetParticles()
MethodDirect particle data access
Clear()
MethodRemove all particles
TriggerSubEmitter()
MethodActivate sub-emitters
成员类型描述
main
/
emission
/
shape
属性模块访问结构体
particleCount
属性当前活跃粒子数
isPlaying
/
isPaused
/
isStopped
属性播放状态
Play()
/
Pause()
/
Stop()
方法播放控制
Emit(count)
方法立即生成粒子
Simulate(time)
方法快进模拟
GetParticles()
/
SetParticles()
方法直接访问粒子数据
Clear()
方法移除所有粒子
TriggerSubEmitter()
方法激活子发射器

VisualEffect (UnityEngine.VFX.VisualEffect)

VisualEffect(UnityEngine.VFX.VisualEffect)

MemberTypeDescription
visualEffectAsset
PropertyAssign/change effect graph
playRate
PropertySimulation speed
aliveParticleCount
PropertyActive particle count
Play()
/
Stop()
/
Reinit()
MethodPlayback control
SendEvent(name, attr)
MethodTrigger graph events
CreateVFXEventAttribute()
MethodCreate event payload
SetFloat()
/
SetVector3()
/ etc.
MethodSet exposed properties
GetFloat()
/
GetVector3()
/ etc.
MethodRead exposed properties
HasFloat()
/
HasVector3()
/ etc.
MethodCheck property existence
ResetOverride(property)
MethodRestore original values
成员类型描述
visualEffectAsset
属性分配/更换效果图形
playRate
属性模拟速度
aliveParticleCount
属性活跃粒子数
Play()
/
Stop()
/
Reinit()
方法播放控制
SendEvent(name, attr)
方法触发图形事件
CreateVFXEventAttribute()
方法创建事件负载
SetFloat()
/
SetVector3()
/ etc.
方法设置暴露属性
GetFloat()
/
GetVector3()
/ etc.
方法读取暴露属性
HasFloat()
/
HasVector3()
/ etc.
方法检查属性是否存在
ResetOverride(property)
方法恢复原始值

ReflectionProbe (UnityEngine.ReflectionProbe)

ReflectionProbe(UnityEngine.ReflectionProbe)

MemberTypeDescription
mode
PropertyBaked/Custom/Realtime
size
/
center
PropertyBounding box config
intensity
/
importance
PropertyBrightness and priority
boxProjection
PropertyEnable box projection
refreshMode
/
timeSlicingMode
PropertyRealtime update config
RenderProbe()
MethodForce cubemap refresh
IsFinishedRendering()
MethodCheck time-sliced completion
BlendCubemap()
MethodBlend two cubemaps
成员类型描述
mode
属性Baked/Custom/Realtime
size
/
center
属性边界框配置
intensity
/
importance
属性亮度和优先级
boxProjection
属性启用盒式投影
refreshMode
/
timeSlicingMode
属性实时更新配置
RenderProbe()
方法强制刷新立方体贴图
IsFinishedRendering()
方法检查时间切片渲染是否完成
BlendCubemap()
方法混合两个立方体贴图

Related Skills

相关技能

  • unity-graphics
    -- Render pipelines (URP/HDRP/Built-in), shaders, materials, cameras
  • unity-2d
    -- 2D lighting (URP 2D Renderer), sprite rendering
  • unity-platforms
    -- Platform-specific lighting quality tiers, mobile optimization
  • unity-graphics
    -- 渲染管线(URP/HDRP/Built-in)、着色器、材质、相机
  • unity-2d
    -- 2D光照(URP 2D Renderer)、精灵渲染
  • unity-platforms
    -- 平台特定光照质量层级、移动端优化

Additional Resources

附加资源