godot-particles

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Particle Systems

粒子系统

GPU-accelerated rendering, material-based configuration, and sub-emitters define performant VFX.
GPU加速渲染、基于材质的配置以及子发射器是实现高性能视觉特效(VFX)的核心。

Available Scripts

可用脚本

vfx_shader_manager.gd

vfx_shader_manager.gd

Expert custom shader integration for advanced particle VFX.
用于高级粒子视觉特效的专业自定义着色器集成工具。

particle_burst_emitter.gd

particle_burst_emitter.gd

One-shot particle bursts with auto-cleanup - essential for VFX systems.
带自动清理功能的一次性粒子爆发发射器——是视觉特效系统的必备组件。

NEVER Do in Particle Systems

粒子系统绝对禁忌

  • NEVER use CPUParticles2D for performance-critical effects — 100+ godot-particles with CPU = lag spike. Use GPUParticles2D unless targeting mobile with no GPU support.
  • NEVER forget to set
    emitting = false
    for one-shot godot-particles
    — Explosion scene with
    emitting = true
    by default = godot-particles emit immediately on instantiate(), before positioning. Set false, position, THEN emit.
  • NEVER use high
    amount
    without testing on target platform
    — 1000 godot-particles = fine on desktop, mobile melts. Test early,scale
    amount
    based on
    OS.get_name()
    .
  • NEVER forget to
    queue_free()
    one-shot godot-particles
    — Explosion lasts 1 second but node stays in tree forever = memory leak.
    await create_timer(lifetime).timeout
    then
    queue_free()
    .
  • NEVER use
    emission_shape = POINT
    for explosions
    — All godot-particles spawn at same position = looks flat. Use
    EMISSION_SHAPE_SPHERE
    with radius for 3D spread.
  • NEVER forget alpha in color gradients — Particles fade suddenly at end = harsh. Add gradient point at 1.0 with
    Color(r, g, b, 0.0)
    for smooth fadeout.

  • 绝对不要在性能关键型特效中使用CPUParticles2D —— 100+个CPU驱动的Godot粒子会导致卡顿。除非目标平台是无GPU支持的移动设备,否则请使用GPUParticles2D。
  • 绝对不要忘记为一次性Godot粒子设置
    emitting = false
    —— 默认
    emitting = true
    的爆炸场景会在调用instantiate()后立即发射粒子,甚至在完成定位前。应先设为false,完成定位后再启动发射。
  • 绝对不要在未测试目标平台的情况下设置高
    amount
    —— 1000个Godot粒子在桌面平台运行流畅,但会让移动设备过载。尽早测试,根据
    OS.get_name()
    调整
    amount
    值。
  • 绝对不要忘记对一次性Godot粒子调用
    queue_free()
    —— 爆炸特效仅持续1秒,但节点会永久留在场景树中,造成内存泄漏。应在
    await create_timer(lifetime).timeout
    后调用
    queue_free()
  • 绝对不要为爆炸特效使用
    emission_shape = POINT
    —— 所有Godot粒子都在同一位置生成,视觉效果扁平。对于3D扩散效果,请使用带半径的
    EMISSION_SHAPE_SPHERE
  • 绝对不要在颜色渐变中忽略透明度设置 —— 粒子在生命周期结束时突然消失会显得生硬。应在1.0位置添加一个
    Color(r, g, b, 0.0)
    的渐变点,实现平滑淡出。

Basic Setup

基础设置

gdscript
undefined
gdscript
undefined

Add GPUParticles2D node

Add GPUParticles2D node

Set Amount: 32

Set Amount: 32

Set Lifetime: 1.0

Set Lifetime: 1.0

Set One Shot: true (for explosions)

Set One Shot: true (for explosions)

undefined
undefined

Particle Material

粒子材质

gdscript
undefined
gdscript
undefined

Create ParticleProcessMaterial

Create ParticleProcessMaterial

var material := ParticleProcessMaterial.new()
var material := ParticleProcessMaterial.new()

Emission shape

Emission shape

material.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_SPHERE material.emission_sphere_radius = 10.0
material.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_SPHERE material.emission_sphere_radius = 10.0

Gravity

Gravity

material.gravity = Vector3(0, 98, 0)
material.gravity = Vector3(0, 98, 0)

Velocity

Velocity

material.initial_velocity_min = 50.0 material.initial_velocity_max = 100.0
material.initial_velocity_min = 50.0 material.initial_velocity_max = 100.0

Color

Color

material.color = Color.ORANGE_RED
material.color = Color.ORANGE_RED

Apply to godot-particles

Apply to godot-particles

$GPUParticles2D.process_material = material
undefined
$GPUParticles2D.process_material = material
undefined

Common Effects

常见特效

Explosion

爆炸特效

gdscript
extends GPUParticles2D

func _ready() -> void:
    one_shot = true
    amount = 64
    lifetime = 0.8
    explosiveness = 0.9
    
    var mat := ParticleProcessMaterial.new()
    mat.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_SPHERE
    mat.emission_sphere_radius = 5.0
    mat.initial_velocity_min = 100.0
    mat.initial_velocity_max = 200.0
    mat.gravity = Vector3(0, 200, 0)
    mat.scale_min = 0.5
    mat.scale_max = 1.5
    
    process_material = mat
    emitting = true
gdscript
extends GPUParticles2D

func _ready() -> void:
    one_shot = true
    amount = 64
    lifetime = 0.8
    explosiveness = 0.9
    
    var mat := ParticleProcessMaterial.new()
    mat.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_SPHERE
    mat.emission_sphere_radius = 5.0
    mat.initial_velocity_min = 100.0
    mat.initial_velocity_max = 200.0
    mat.gravity = Vector3(0, 200, 0)
    mat.scale_min = 0.5
    mat.scale_max = 1.5
    
    process_material = mat
    emitting = true

Smoke Trail

烟雾轨迹

gdscript
extends GPUParticles2D

func _ready() -> void:
    amount = 16
    lifetime = 2.0
    
    var mat := ParticleProcessMaterial.new()
    mat.direction = Vector3(0, -1, 0)
    mat.initial_velocity_min = 20.0
    mat.initial_velocity_max = 40.0
    mat.scale_min = 0.5
    mat.scale_max = 1.0
    mat.color = Color(0.5, 0.5, 0.5, 0.5)
    
    process_material = mat
gdscript
extends GPUParticles2D

func _ready() -> void:
    amount = 16
    lifetime = 2.0
    
    var mat := ParticleProcessMaterial.new()
    mat.direction = Vector3(0, -1, 0)
    mat.initial_velocity_min = 20.0
    mat.initial_velocity_max = 40.0
    mat.scale_min = 0.5
    mat.scale_max = 1.0
    mat.color = Color(0.5, 0.5, 0.5, 0.5)
    
    process_material = mat

Sparkles/Stars

闪光/星星特效

gdscript
var mat := ParticleProcessMaterial.new()
mat.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_BOX
mat.emission_box_extents = Vector3(100, 100, 0)
mat.gravity = Vector3.ZERO
mat.angular_velocity_min = -180
mat.angular_velocity_max = 180
mat.scale_min = 0.1
mat.scale_max = 0.5
gdscript
var mat := ParticleProcessMaterial.new()
mat.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_BOX
mat.emission_box_extents = Vector3(100, 100, 0)
mat.gravity = Vector3.ZERO
mat.angular_velocity_min = -180
mat.angular_velocity_max = 180
mat.scale_min = 0.1
mat.scale_max = 0.5

Use star texture

Use star texture

$GPUParticles2D.texture = load("res://textures/star.png") $GPUParticles2D.process_material = mat
undefined
$GPUParticles2D.texture = load("res://textures/star.png") $GPUParticles2D.process_material = mat
undefined

Spawn Particles on Demand

按需生成粒子

gdscript
undefined
gdscript
undefined

player.gd

player.gd

const EXPLOSION_EFFECT := preload("res://effects/explosion.tscn")
func die() -> void: var explosion := EXPLOSION_EFFECT.instantiate() get_parent().add_child(explosion) explosion.global_position = global_position explosion.emitting = true queue_free()
undefined
const EXPLOSION_EFFECT := preload("res://effects/explosion.tscn")
func die() -> void: var explosion := EXPLOSION_EFFECT.instantiate() get_parent().add_child(explosion) explosion.global_position = global_position explosion.emitting = true queue_free()
undefined

3D Particles

3D粒子

gdscript
extends GPUParticles3D

func _ready() -> void:
    amount = 100
    lifetime = 3.0
    
    var mat := ParticleProcessMaterial.new()
    mat.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_BOX
    mat.emission_box_extents = Vector3(10, 0.1, 10)
    mat.direction = Vector3.UP
    mat.initial_velocity_min = 2.0
    mat.initial_velocity_max = 5.0
    mat.gravity = Vector3(0, -9.8, 0)
    
    process_material = mat
gdscript
extends GPUParticles3D

func _ready() -> void:
    amount = 100
    lifetime = 3.0
    
    var mat := ParticleProcessMaterial.new()
    mat.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_BOX
    mat.emission_box_extents = Vector3(10, 0.1, 10)
    mat.direction = Vector3.UP
    mat.initial_velocity_min = 2.0
    mat.initial_velocity_max = 5.0
    mat.gravity = Vector3(0, -9.8, 0)
    
    process_material = mat

Color Gradients

颜色渐变

gdscript
var mat := ParticleProcessMaterial.new()
gdscript
var mat := ParticleProcessMaterial.new()

Create gradient

Create gradient

var gradient := Gradient.new() gradient.add_point(0.0, Color.YELLOW) gradient.add_point(0.5, Color.ORANGE) gradient.add_point(1.0, Color(0.5, 0.0, 0.0, 0.0)) # Fade to transparent red
var gradient_texture := GradientTexture1D.new() gradient_texture.gradient = gradient
mat.color_ramp = gradient_texture
undefined
var gradient := Gradient.new() gradient.add_point(0.0, Color.YELLOW) gradient.add_point(0.5, Color.ORANGE) gradient.add_point(1.0, Color(0.5, 0.0, 0.0, 0.0)) # Fade to transparent red
var gradient_texture := GradientTexture1D.new() gradient_texture.gradient = gradient
mat.color_ramp = gradient_texture
undefined

Sub-Emitters

子发射器

gdscript
undefined
gdscript
undefined

Particles that spawn godot-particles (fireworks)

Particles that spawn godot-particles (fireworks)

$ParentParticles.sub_emitter = $ChildParticles.get_path() $ParentParticles.sub_emitter_mode = GPUParticles2D.SUB_EMITTER_AT_END
undefined
$ParentParticles.sub_emitter = $ChildParticles.get_path() $ParentParticles.sub_emitter_mode = GPUParticles2D.SUB_EMITTER_AT_END
undefined

Best Practices

最佳实践

1. Use Texture for Shapes

1. 使用纹理定义形状

gdscript
undefined
gdscript
undefined

Add texture to godot-particles

Add texture to godot-particles

$GPUParticles2D.texture = load("res://textures/particle.png")
undefined
$GPUParticles2D.texture = load("res://textures/particle.png")
undefined

2. Lifetime Management

2. 生命周期管理

gdscript
undefined
gdscript
undefined

Auto-delete one-shot godot-particles

Auto-delete one-shot godot-particles

if one_shot: await get_tree().create_timer(lifetime).timeout queue_free()
undefined
if one_shot: await get_tree().create_timer(lifetime).timeout queue_free()
undefined

3. Performance

3. 性能优化

gdscript
undefined
gdscript
undefined

Reduce amount for mobile

Reduce amount for mobile

if OS.get_name() == "Android": amount = amount / 2
undefined
if OS.get_name() == "Android": amount = amount / 2
undefined

Reference

参考资料

Related

相关技能

  • Master Skill: godot-master
  • 主技能:godot-master