World Effects (world.hlsl)
World packs placed and keyed in the scene - the world block, particles / fields / surfaces, HLSL functions, helpers (PackHemiAmbient / PackFieldSample / colliders), determinism and render limits.
What a world effect is
A world effect ("type": "world") is a 3D entity placed in the scene, not on a character. It covers falling
snow, dust, rain, magic circles, grass and ground cover - anything with a position and a place in time - and can carry
a GPU simulation. You place the entity and key it in the studio and live playback, and it renders the same way in
every path: raster, ray tracing, path tracing and offline GI.
Where a surface pack changes a character’s materials and a screen effect pack works on the finished image, a world pack adds geometry and particles that actually exist in the scene.
Folder
my_world_pack/
pack.json manifest ("type": "world", "world": { ... })
world.hlsl entry points (simulate, spawn, update, height, shade)
preview.png optional preview image
textures/ optional pack textures (up to 32 files, 64 MB total)
Implement only the functions the manifest declares. Every world shader compiles with DXC at Shader Model 6.0
(cs_6_0, vs_6_0, ps_6_0), and world_api.hlsli is included automatically.
Manifest
{
"format": 1,
"id": "snow",
"version": "1.0.0",
"apiVersion": 6,
"type": "world",
"name": { "ko": "눈", "en": "Snow", "ja": "雪", "zh": "雪" },
"world": {
"step": 0.0166667,
"rewind": 4.0,
"particles": [
{
"name": "fall",
"count": 24000,
"blend": "alpha",
"simulate": "SimulateFlakes",
"shade": "ShadeFlakes",
"size": [0.02, 0.4]
}
],
"fields": [
{
"name": "cover",
"size": 2048,
"extent": 200.0,
"format": "rg16f",
"persistent": true,
"rate": 20.0,
"update": "UpdateCover"
}
],
"surfaces": [
{ "field": "cover", "grid": 256, "height": "SnowHeight", "shade": "SnowShade" }
]
},
"requires": ["params.ext"]
}
The world block
step: fixed simulation step in seconds. It runs from1/240(0.004167) to1/15(0.066667); the default is1/60(0.0166667).rewind: how many seconds of short-lived state are re-simulated. It runs from0to20; the default is4.particles: up to 8 particle systems.fields: up to 4 2D simulation grids in local space.surfaces: up to 2 procedural heightfield meshes.
World packs cannot use classes. Parameters support up to 128 typed parameters with collapsible groups, and the
params.ext capability is always enabled. Textures are limited to 32 files and 64 MB in total.
Particle systems
name: unique within the pack.count: from1to262144(256K) particles.blend:"alpha"(premultiplied / interpolated alpha) or"add".simulate: stateful simulation function called once per fixed step. It cannot be combined withspawn.spawn: stateless function evaluated from index and time. It cannot be combined withsimulate.shade: function that shades the particles in the pixel shader.size: world-space radius hint[min, max]used for culling.
Fields
name: unique within the pack.size: square resolution in texels,64to2048.extent: world units the field covers on the XZ plane, centred on the entity origin as[-extent/2, +extent/2].format:"r16f","rg16f"or"rgba16f".persistent: whentrue, a timeline seek re-simulates the field fromt = 0at itsrate. Whenfalse, it re-simulates over the entity’srewindwindow.rate: steps per second for a persistent field (default10). A persistent field always steps on its own grid, step k at timek / rate, both after a seek and during playback, so a seek and continuous playback reach the same field at the same time.update: compute function that updates the ping-pong texture.
Surfaces
field: name of a field declared infields.grid: quads per side,16to512, producinggrid * grid * 2triangles.height: function returning the local heightY.shade: function returning the surface attributes (PackSurfaceOut).
HLSL contract
Data structures
struct PackParticle {
float3 pos; // world-space position
float size; // world-space radius
float3 vel; // units per second
float age; // age in seconds; below 0 marks an inactive particle
float4 color; // base colour and alpha
float4 data; // custom attributes owned by the pack
};
struct PackSimInput {
uint id; // particle index (0 .. count - 1)
float dt; // fixed step delta time in seconds
float time; // target time in seconds
float3 posLocal; // entity local-space position
};
struct PackFieldInput {
float2 uv; // normalised UV in [0, 1]
float2 posLocal; // local-space XZ coordinates in world units
float4 prev; // previous ping-pong value (zero on the first step of a re-simulation)
float dt; // step delta time
float time; // current simulation time
uint2 texel; // integer texel coordinate
};
struct PackSurfaceIn {
float2 uv; // grid UV in [0, 1]
float2 posLocal; // local-space XZ coordinates
float time; // current time
};
struct PackSurfaceOut {
float3 albedo; // linear RGB albedo
float alpha; // surface opacity (1.0 for opaque)
float roughness; // material roughness [0, 1]
float3 normal; // world normal (the host computes the gradient when omitted)
float3 emission; // emissive linear RGB
};
struct PackSurfaceShadeIn {
float2 uv; // grid UV
float3 posLocal; // local XYZ
float3 posWorld; // world XYZ
float3 normal; // computed world-space gradient normal
float3 viewDir; // unit vector towards the camera
float time; // current time
};
struct PackParticleShadeIn {
float2 uv; // billboard quad UV [0, 1]
PackParticle particle; // particle state
float3 viewDir; // unit vector towards the camera
float3 posWorld; // world position of the billboard vertex
};
Functions
A stateful particle simulation owns both spawning and updating. Particles start with age = -1.
void SimulateFlakes(inout PackParticle p, PackSimInput s);
A stateless spawn evaluates a particle as a function of index and time.
PackParticle SpawnFlakes(uint id, float t);
A field update computes one texel of the ping-pong texture.
float4 UpdateCover(PackFieldInput f);
Surface height returns the local vertical displacement Y.
float SnowHeight(PackSurfaceIn i);
Surface shading returns albedo, alpha, roughness, normal and emission. The host applies direct scene lighting (sun direction, shadow map visibility, sun colour and ambient light) so the surface matches the scene.
PackSurfaceOut SnowShade(PackSurfaceShadeIn i);
Particle shading returns linear HDR colour and alpha.
float4 ShadeFlakes(PackParticleShadeIn i);
Built-in helpers
- Parameters:
PackParam(i)(float),PackParamInt(i),PackParamBool(i),PackParamColor(i),PackParamVec3(i). Colours arrive as linear values. - Transforms:
PackWorldToLocal(posWorld)/PackLocalToWorld(posLocal)for points andPackWorldToLocalVec(vecWorld)/PackLocalToWorldVec(vecLocal)for vectors. - Colliders:
PackColliderCount()is the number of active scene colliders this frame.PackCollider(i)returns aPackColliderDatawithpos(float3),radius(float),vel(float3) andflags(uint). The flags mark body parts:kColliderFoot = 1,kColliderHand = 2,kColliderLeft = 4. - Fields:
PackFieldSample(fieldIndex, posLocalXZ)bilinearly samples field0..3at local XZ coordinates, andPackFieldLoad(fieldIndex, int2 texel)fetches one texel. - Pack textures:
PackSampleTex(i, uv)/PackSampleTexLevel(i, uv, lod)read textures0..31, andPackTexSize(i)/PackTexCount()report the size and count. - Lighting:
PackSunDir()points towards the sun,PackSunColor()is the sun colour and intensity, andPackAmbient()is the ambient colour.PackHemiAmbient(normal)is the scene’s sky / ground hemisphere light for a world-space normal - ambient that follows the stage lighting (PackAmbient()is only the ground colour).PackSunShadow(worldPos)is the sun shadow visibility in[0, 1], from the cascaded shadow map in raster camera views. - Deterministic hashing:
PackRandom(seed),PackRandom(seed, salt)andPackRandom(seed, salt1, salt2)return a PCG-based deterministic pseudo-random float in[0, 1).PackRandom2/PackRandom3work the same way.
Determinism and rewind
World simulations advance in fixed steps and produce exactly the same result in live playback, timeline scrubbing,
offline rendering and video export. Forward playback steps by step intervals up to the target time. Moving backwards,
or jumping by more than 0.25 seconds, follows these rules.
- Persistent fields: re-simulate from
t = 0to the target time atrate(default 10 Hz). This suits fields that keep accumulating, such as footprints left in snow. - Particles and transient fields: reset and re-simulate from
max(0, target - rewind)to the target time in fixedstepincrements. - Character colliders: read only from the precomputed
WorldColliderTrackwithtrack->Sample(t), so the state is identical regardless of playback speed or frame rate.
Rendering and limits
In raster and real-time ray-traced views, WorldPass runs between ScenePass and ResolvePass. Surfaces are drawn
as opaque geometry with depth into the MSAA scene targets, and particles are drawn after them with depth testing only.
ResolvePass resolves world geometry and motion vectors together, so TAA and upscalers such as DLSS / FSR / XeSS keep
working.
In path tracing and offline GI, surfaces and particles are drawn into the outline layer targets, occluded by the tracer’s depth prepass and composited over the result. World surfaces receive the same direct lighting as the scene.
There are a few limits to know.
- Sun shadows: world surfaces receive sun shadows only in the raster renderer. Ray-traced / path-traced frames and
offline GI have no shadow map there, so
PackSunShadowreturns 1. - Screen-space reflections: particles are not shown in screen-space reflections.
- Casting shadows: world particles and surfaces do not cast shadows into the scene.
- Excluded views: unlit, wireframe and extra quad views skip world simulation and rendering.
- Cost: with no worlds placed,
WorldPassissues no draw calls, dispatches no compute passes and allocates no GPU resources.
Example: Snow
The built-in “Snow” pack combines falling snow, ground snow cover that keeps footprints, and kicked-up snow puffs. Its
manifest holds one field (cover), one surface and two particle systems (fall, kick).
"particles": [
{ "name": "fall", "count": 24000, "blend": "alpha",
"simulate": "SimulateFlakes", "shade": "ShadeFlakes", "size": [0.02, 0.40] }
]
The field update carves where foot colliders touch and raises a small rim.
float4 UpdateCover(PackFieldInput f) {
float4 val = f.prev; // x: carved amount, y: compacted rim
uint colCount = PackColliderCount();
for (uint i = 0; i < colCount; ++i) {
PackColliderData col = PackCollider(i);
if ((col.flags & 1u) == 0u) continue; // foot colliders only
float3 colLocal = PackWorldToLocal(col.pos);
float d = distance(f.posLocal, colLocal.xz);
// ... inside the radius, raise val.x / val.y
}
val.x = max(0.0, val.x - PackParam(10) * f.dt); // refill_rate
return val;
}
The surface height reads the field and carves the snow depth.
float SnowHeight(PackSurfaceIn i) {
float depth = PackParam(7);
float4 f = PackFieldSample(0, i.posLocal);
return depth * (1.0 - saturate(f.x) * PackParam(8)); // footprint_depth
}
Surface shading combines the colour parameter with the scene lighting.
PackSurfaceOut SnowShade(PackSurfaceShadeIn i) {
PackSurfaceOut o;
float3 baseColor = PackParamColor(11);
o.albedo = baseColor;
o.alpha = 1.0;
o.roughness = 0.8;
float3 sun = PackSunColor();
float3 hemi = PackHemiAmbient(float3(0.0, 1.0, 0.0));
o.emission = sun * PackParam(12) * PackSunShadow(i.posWorld);
return o;
}
The particle simulation sets position and size when a flake first appears, then adds wind and turbulence as it falls. When a flake reaches the surface or leaves the area, it respawns above.
void SimulateFlakes(inout PackParticle p, PackSimInput s) {
if (p.age < 0.0) {
float3 rnd = PackRandom3(s.id, 10101u);
p.pos = PackLocalToWorld(float3(rnd.x, rnd.z * PackParam(6), rnd.y));
p.age = 0.0;
return;
}
p.age += s.dt;
p.pos += (PackParamVec3(3) + float3(0.0, -PackParam(1), 0.0)) * s.dt;
}
Verification
pack_check validates the manifest and every entry point.
pack_check <pack folder> --compile
--compile reads pack.json, enforces the limits and compiles every declared simulate / spawn / update /
height / shade function.