Shader Explorer
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

DISPATCH_INDIRECT_STRIDE

#
const DISPATCH_INDIRECT_STRIDE: u32 = 3u

EM_OFFSET_VERTEX_COUNT

#
const EM_OFFSET_VERTEX_COUNT: u32 = 0u

EM_OFFSET_INSTANCE_COUNT

#
const EM_OFFSET_INSTANCE_COUNT: u32 = 1u

EM_OFFSET_FIRST_INDEX_OR_VERTEX_OFFSET

#
const EM_OFFSET_FIRST_INDEX_OR_VERTEX_OFFSET: u32 = 2u

EM_OFFSET_VERTEX_OFFSET_OR_BASE_INSTANCE

#
const EM_OFFSET_VERTEX_OFFSET_OR_BASE_INSTANCE: u32 = 3u

EM_OFFSET_BASE_INSTANCE

#
const EM_OFFSET_BASE_INSTANCE: u32 = 4u

EM_OFFSET_ALIVE_COUNT

#
const EM_OFFSET_ALIVE_COUNT: u32 = 5u

EM_OFFSET_MAX_UPDATE

#
const EM_OFFSET_MAX_UPDATE: u32 = 6u

EM_OFFSET_DEAD_COUNT

#
const EM_OFFSET_DEAD_COUNT: u32 = 7u

EM_OFFSET_MAX_SPAWN

#
const EM_OFFSET_MAX_SPAWN: u32 = 8u

EM_OFFSET_PING

#
const EM_OFFSET_PING: u32 = 9u

EM_OFFSET_INDIRECT_DISPATCH_INDEX

#
const EM_OFFSET_INDIRECT_DISPATCH_INDEX: u32 = 11u

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_pong: u32 ,
effect_metadata_index: u32 ,
}

IndirectBuffer

#
struct IndirectBuffer {
indices: array<u32> ,
}

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_IS_ATOMIC
event_count: i32 , 🔴 CHILD_INFO_IS_ATOMIC
}

ChildInfoBuffer

#

Buffer storing all the ChildInfo structs for several effects.

struct ChildInfoBuffer { }

IndirectDispatch

#

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

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

EffectMetadata

#

Draw indirect parameters for GPU-driven rendering, and additional effect data.

struct EffectMetadata {
vertex_count: u32 ,
instance_count: atomic<u32> ,
first_index_or_vertex_offset: u32 ,
vertex_offset_or_base_instance: i32 ,
base_instance: u32 ,
alive_count: atomic<u32> ,
max_update: u32 ,
dead_count: atomic<u32> ,
max_spawn: atomic<u32> ,
ping: u32 ,
spawner_index: u32 ,
indirect_dispatch_index: u32 ,
indirect_render_index: u32 ,
init_indirect_dispatch_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 () -> f32

frand2

#

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

fn frand2 () -> vec2<f32>

frand3

#

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

fn frand3 () -> vec3<f32>

frand4

#

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

fn frand4 () -> vec4<f32>

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>