Particle

package
v0.0.0-...-5dcec5f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package Particle provides a particle shader pipeline used for shading 2D and 3D particles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Process

type Process State

func (Process) AttractorForce

func (state Process) AttractorForce() vec3.XYZ

AttractorForce is the combined force of the attractors at the moment on that particle.

func (Process) Collided

func (state Process) Collided() bool.X

Collided is true when the particle has collided with a particle collider.

func (Process) CollisionDepth

func (state Process) CollisionDepth() float.X

CollisionDepth is the length of the normal of the last collision. If there is no collision detected it is equal to 0.0.

func (Process) CollisionNormal

func (state Process) CollisionNormal() vec3.XYZ

CollisionNormal of the last collision. If there is no collision detected it is equal to (0.0, 0.0, 0.0).

func (Process) Restart

func (state Process) Restart() bool.X

Restart is true if the current process frame is first for the particle.

type RenderMode

type RenderMode string
const (
	KeepData          RenderMode = "keep_data"           // Do not clear previous data on restart.
	DisableForce      RenderMode = "disable_force"       // Disable attractor force.
	DisableVelocity   RenderMode = "disable_velocity"    // Ignore VELOCITY value.
	CollisionUseScale RenderMode = "collision_use_scale" // Scale the particle's size for collisions.
)

type Shader

type Shader[T gdclass.Interface] struct {
	ShaderMaterial.Extension[T]
}

Shader that runs before the object is drawn. They are used for calculating material properties such as color, position, and rotation. They are drawn with any regular material for CanvasItem or Spatial, depending on whether they are 2D or 3D.

Particle shaders are unique because they are not used to draw the object itself; they are used to calculate particle properties, which are then used by a CanvasItem or Spatial shader. They contain two processor functions: start() and process().

Unlike other shader types, particle shaders keep the data that was output the previous frame. Therefore, particle shaders can be used for complex effects that take place over multiple frames.

func (*Shader[T]) Fragment

func (*Shader[T]) Fragment(state Startup) Process

func (*Shader[T]) Lighting

func (*Shader[T]) Lighting(Process) struct{}

func (*Shader[T]) Material

func (*Shader[T]) Material(state Process) State

func (*Shader[T]) OnCreate

func (s *Shader[T]) OnCreate(value reflect.Value)

func (*Shader[T]) Pipeline

func (*Shader[T]) Pipeline() [3]string

func (*Shader[T]) RenderMode

func (*Shader[T]) RenderMode() []RenderMode

func (*Shader[T]) ShaderType

func (*Shader[T]) ShaderType() string

type Startup

type Startup State

func (Startup) RestartColor

func (state Startup) RestartColor() bool.X

RestartColor is true if particle is restarted, or emitted without a custom color (i.e. this particle was created by emit_subparticle() without the FLAG_EMIT_COLOR flag).

func (Startup) RestartCustom

func (state Startup) RestartCustom() bool.X

RestartCustom is true if particle is restarted, or emitted without a custom property (i.e. this particle was created by emit_subparticle() without the FLAG_EMIT_CUSTOM flag).

func (Startup) RestartPosition

func (state Startup) RestartPosition() bool.X

RestartPosition is true if particle is restarted, or emitted without a custom position (i.e. this particle was created by emit_subparticle() without the FLAG_EMIT_POSITION flag).

func (Startup) RestartRotScale

func (state Startup) RestartRotScale() bool.X

RestartRotScale is true if particle is restarted, or emitted without a custom rotation or scale (i.e. this particle was created by emit_subparticle() without the FLAG_EMIT_ROT_SCALE flag).

func (Startup) RestartVelocity

func (state Startup) RestartVelocity() bool.X

RestartVelocity is true if particle is restarted, or emitted without a custom velocity (i.e. this particle was created by emit_subparticle() without the FLAG_EMIT_VELOCITY flag).

type State

type State struct {
	Active    bool.X           `gd:"ACTIVE"`    // true when the particle is active, can be set false.
	Color     vec4.RGBA        `gd:"COLOR"`     // Particle color, can be written to and accessed in mesh's vertex function.
	Velocity  vec3.XYZ         `gd:"VELOCITY"`  // Particle velocity, can be modified.
	Transform mat4.ColumnMajor `gd:"TRANSFORM"` // Particle transform.
	Custom    vec4.XYZW        `gd:"CUSTOM"`    // Custom particle data. Accessible from shader of mesh as INSTANCE_CUSTOM.
	Mass      float.X          `gd:"MASS"`      // Particle mass, intended to be used with attractors. Equals 1.0 by default.

	EmitSubParticle func(xform mat4.ColumnMajor, velocity vec3.XYZ, color vec4.RGBA, custom vec4.XYZW, flags uint.X) bool.X `gd:"emit_subparticle"`
}

func (State) AmountRatio

func (State) AmountRatio() float.X

AmountRatio value of amount_ratio (3D) property of Particles node.

func (State) Delta

func (State) Delta() float.X

Delta process time.

func (State) EmissionTransform

func (State) EmissionTransform() mat4.ColumnMajor

EmissionTransform (used for non-local systems).

func (State) EmitterVelocity

func (State) EmitterVelocity() vec3.XYZ

EmitterVelocity is the Velocity of the Particles2D (3D) node.

func (State) FlagEmitColor

func (State) FlagEmitColor() uint.X

FlagEmitColor for using on the last argument of emit_subparticle() function to assign a color to a new particle.

func (State) FlagEmitCustom

func (State) FlagEmitCustom() uint.X

FlagEmitCustom for using on the last argument of emit_subparticle() function to assign a custom value to a new particle.

func (State) FlagEmitPosition

func (State) FlagEmitPosition() uint.X

FlagEmitPosition for using on the last argument of emit_subparticle() function to assign a position to a new particle's transform.

func (State) FlagEmitRotScale

func (State) FlagEmitRotScale() uint.X

FlagEmitRotScale for using on the last argument of emit_subparticle() function to assign a rotation and scale to a new particle's transform.

func (State) FlagEmitVelocity

func (State) FlagEmitVelocity() uint.X

FlagEmitVelocity for using on the last argument of emit_subparticle() function to assign a velocity to a new particle.

func (State) Index

func (State) Index() float.X

Index (from total particles).

func (State) InterpolateToEnd

func (State) InterpolateToEnd() float.X

InterpolateToEnd Value of interp_to_end (3D) property of Particles node.

func (State) Lifetime

func (State) Lifetime() float.X

Lifetime of the particle

func (State) Number

func (State) Number() float.X

Number is a unique number since emission start.

func (State) RandomSeed

func (State) RandomSeed() float.X

RandomSeed used as base for random.

func (State) UserData

func (State) UserData() [6]vec4.XYZW

UserData is user data passed to the shader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL