Advanced search tips: use spaces to require multiple terms (AND), | for alternatives (OR), wrap phrases in quotes (="a b"), =term for exact match, 'term to include, !term to exclude, ^term to match prefix, !^term to exclude prefix, .ext$ to match suffix, and !.ext$ to exclude suffix.

vfx_common.wgsl

Import path

Constants

SPAWNER_OFFSET_PONG

#
const SPAWNER_OFFSET_PONG: u32 = 27u

DRAW_INDIRECT_STRIDE

#
const DRAW_INDIRECT_STRIDE: u32 = 4u

DRAW_INDEXED_INDIRECT_STRIDE

#
const DRAW_INDEXED_INDIRECT_STRIDE: u32 = 5u

EM_OFFSET_CAPACITY

#
const EM_OFFSET_CAPACITY: u32 = 0u

EM_OFFSET_ALIVE_COUNT

#
const EM_OFFSET_ALIVE_COUNT: u32 = 1u

EM_OFFSET_MAX_UPDATE

#
const EM_OFFSET_MAX_UPDATE: u32 = 2u

EM_OFFSET_MAX_SPAWN

#
const EM_OFFSET_MAX_SPAWN: u32 = 3u

EM_OFFSET_INDIRECT_WRITE_INDEX

#
const EM_OFFSET_INDIRECT_WRITE_INDEX: u32 = 4u

EM_OFFSET_INDIRECT_DISPATCH_INDEX

#
const EM_OFFSET_INDIRECT_DISPATCH_INDEX: u32 = 5u

EFFECT_METADATA_STRIDE

#
const EFFECT_METADATA_STRIDE: u32 = {{EFFECT_METADATA_STRIDE}} / 4u

tau

#
const tau: f32 = 6.283185307179586476925286766559

Structures

SimParams

#
struct SimParams {
delta_time: f32 ,
time: f32 ,
virtual_delta_time: f32 ,
virtual_time: f32 ,
real_delta_time: f32 ,
real_time: f32 ,
num_effects: u32 ,
}

Spawner

#
struct Spawner {
transform: mat3x4<f32> ,
inverse_transform: mat3x4<f32> ,
spawn: i32 ,
seed: u32 ,
render_indirect_read_index: u32 ,
effect_metadata_index: u32 ,
draw_indirect_index: u32 ,
slab_offset: u32 ,
parent_slab_offset: u32 ,
unused: u32 ,
}

IndirectEntry

#

Each row corresponds to one row in the ParticleBuffer. The total number of rows in the IndirectBuffer is the capacity of the ParticleBuffer itself (that is, they have the same number of rows).

struct IndirectEntry {
particle_index: array<u32, 2> ,
dead_index: u32 ,
}

IndirectBuffer

#

Indirection buffer storing the indices of alive and dead particles as a contiguous range, to ensure we can dispatch a tight number of workgroups only for alive particles, and can find a dead one to recycle quickly.

struct IndirectBuffer { }

SpawnEvent

#

A event emitted by another effect during its update pass, to trigger the spawning of one or more particle in this effect.

struct SpawnEvent {
particle_index: u32 ,
}

EventBuffer

#

Append buffer populated during the Update pass of the previous frame by a parent effect, and read back by its child effect(s) during the Init pass of the next frame.

struct EventBuffer {
spawn_events: array<SpawnEvent> ,
}

ChildInfo

#

Info about a single child of a parent effect.

struct ChildInfo {
init_indirect_dispatch_index: u32 ,
event_count: atomic<i32> , 🟢 CHILD_INFO_EVENT_COUNT_IS_ATOMIC
event_count: i32 , šŸ”“ CHILD_INFO_EVENT_COUNT_IS_ATOMIC
}

ChildInfoBuffer

#

Buffer storing all the ChildInfo structs for several effects.

struct ChildInfoBuffer { }

DispatchIndirectArgs

#

Indirect compute dispatch struct for GPU-driven passes. The layout of this struct is dictated by WGSL.

struct DispatchIndirectArgs {
x: u32 ,
y: u32 ,
z: u32 ,
}

DrawIndirectArgs

#

Indirect draw (non-indexed) dispatch struct for GPU-driven passes. The layout of this struct is dictated by WGSL. See https://docs.rs/wgpu/latest/wgpu/util/struct.DrawIndirectArgs.html.

struct DrawIndirectArgs {
vertex_count: u32 ,
instance_count: atomic<u32> ,
first_vertex: u32 ,
first_instance: u32 ,
}

DrawIndexedIndirectArgs

#

Indirect draw (non-indexed) dispatch struct for GPU-driven passes. The layout of this struct is dictated by WGSL. See https://docs.rs/wgpu/latest/wgpu/util/struct.DrawIndexedIndirectArgs.html.

struct DrawIndexedIndirectArgs {
index_count: u32 ,
instance_count: atomic<u32> ,
first_index: u32 ,
base_vertex: i32 ,
first_instance: u32 ,
}

BatchInfo

#

Shared info for a single batch (single shader invocation).

struct BatchInfo {
total_spawn_count: u32 ,
total_update_count: u32 ,
base_effect: u32 ,
base_particle: u32 ,
prefix_sum_offset: u32 ,
prefix_sum_count: u32 ,
}

EffectMetadata

#

The metadata describes various effect settings, as well we the location in GPU buffers of the piece of data associated with that instance.

struct EffectMetadata {
capacity: u32 ,
alive_count: atomic<u32> ,
max_update: u32 ,
max_spawn: atomic<u32> ,
indirect_write_index: u32 ,
indirect_render_index: u32 ,
init_indirect_dispatch_index: u32 ,
properties_array_index: u32 ,
local_child_index: u32 ,
global_child_index: u32 ,
base_child_index: u32 ,
particle_stride: u32 ,
sort_key_offset: u32 ,
sort_key2_offset: u32 ,
particle_counter: atomic<u32> ,
}

Functions

pcg_hash

#
fn pcg_hash (
input: u32
) -> u32

to_float01

#
fn to_float01 ( ) -> f32

frand

#

Random floating-point number in [0:1]

fn frand ()

frand2

#

Random floating-point number in [0:1]^2

fn frand2 ()

frand3

#

Random floating-point number in [0:1]^3

fn frand3 ()

frand4

#

Random floating-point number in [0:1]^4

fn frand4 ()

rand_uniform_f

#
fn rand_uniform_f ( ) -> f32

rand_uniform_vec2

#
fn rand_uniform_vec2 ( ) -> vec2<f32>

rand_uniform_vec3

#
fn rand_uniform_vec3 ( ) -> vec3<f32>

rand_uniform_vec4

#
fn rand_uniform_vec4 ( ) -> vec4<f32>

rand_normal_f

#

Normal distribution computed using Box-Muller transform

fn rand_normal_f (
mean: f32
std_dev: f32
) -> f32

rand_normal_vec2

#
fn rand_normal_vec2 (
mean: vec2f
std_dev: vec2f
) -> vec2f

rand_normal_vec3

#
fn rand_normal_vec3 (
mean: vec3f
std_dev: vec3f
) -> vec3f

rand_normal_vec4

#
fn rand_normal_vec4 (
mean: vec4f
std_dev: vec4f
) -> vec4f

proj

#
fn proj ( ) -> vec3<f32>