PT / GI Packs
pt_surface.hlsl - applying a pack in path tracing and offline GI. PackEvaluate, PtPackIn / PtPackOut, PT_PACK_HAS_LIGHTING lighting separation, extended parameters, textures and limitations.
What a PT / GI pack is
A surface shader pack (surface.hlsl) shades raster and ray-traced camera views with PackShade. The path tracer
(--render pt, the PT video renderer) and the offline GI renderer (GI stills and video) trace all rays inside one
compute shader, so PackShade cannot run there. A pack takes part through a second file, pt_surface.hlsl, which
describes the material at hit points. Light transport such as sun shadows, indirect light, the irradiance cache and
the denoiser stays with the renderer.
Packs without that file use the default shading in PT and GI. Real-time raster and RT use only surface.hlsl.
Files
my_pack/
pack.json manifest
surface.hlsl raster / real-time RT (PackShade)
pt_surface.hlsl path tracing / offline GI (PackEvaluate)
shared.hlsli optional: maths shared by both files
Both files can #include "shared.hlsli" from the pack folder, so the look is written only once. There is no need to
raise apiVersion in pack.json; new features are declared with requires.
PackEvaluate
PtPackOut PackEvaluate(PtPackIn i);
PtPackIn
| Field | Meaning |
|---|---|
pos, normal, V, uv | World position, shading normal, camera direction, texture coordinates |
uv1, uv2 (float4) | PMX extra UV1 / UV2 (0 for models without them, detected with PT_PACK_API_ADDUV) |
L, sunVis | Sun direction, sun visibility 0..1 from the traced shadow ray (0 for diffuse bounces) |
baseColor | Linear texture colour × material colour, unlit |
materialClass | PACK_BODY / SKIN / FACE / EYE / HAIR / WEAPON (disabled materials never reach the pack) |
params[16] | Slider values in pack.json order |
headPos, headScale, headRight, headUp, headForward, headValid | The same head-bone frame as PackSurface |
PtPackOut
| Field | Meaning |
|---|---|
albedo | Linear surface colour. What diffuse bounces and reflections see |
shadowTint | Linear multiplier applied on the shadow side |
shadowBias | Shifts the terminator in N.L units (smoothed face normal: dot(Nsmooth, L) - dot(normal, L)) |
specular | Added linear radiance (rim, gloss, matcap). Multiplied by sunVis |
terminator | The N.L endpoints (lo, hi) of the boundary smoothstep. hi <= lo (e.g. (0, 0)) uses the engine default (-0.12, 0.22) |
flatFace | Use the engine’s flat face treatment (no indirect light gradient on this surface) |
Declaring surface.output adds:
| Field | Meaning |
|---|---|
normal | Custom shading normal used for later ray bounces and reflections |
emission | Linear emission added to ray throughput |
tag | 0..15, written to bits 0-3 of the ID image for primary ray hits |
Assign every field. Unassigned fields are undefined, and pack_check warns about them.
PtPackOut PackEvaluate(PtPackIn i) {
PtPackOut o;
o.albedo = i.baseColor;
o.shadowTint = float3(1, 1, 1);
o.shadowBias = 0.0;
o.terminator = float2(-0.12, 0.22);
o.specular = 0;
o.flatFace = false;
return o;
}
Separating lighting: PT_PACK_HAS_LIGHTING
flatFace ties two things together: flattening indirect light and using the material’s own boundary. It also offers no
way to soften the traced sun shadow. API 1.9.1 and later can separate these with PackEvaluateLighting.
#ifdef PT_PACK_API_LIGHTING
#define PT_PACK_HAS_LIGHTING 1
#endif
...
#ifdef PT_PACK_HAS_LIGHTING
PtPackLighting PackEvaluateLighting(PtPackIn i, PtPackOut o) {
PtPackLighting l;
l.flatIndirect = 1.0; // flatten indirect light, the pack owns the boundary
l.sunShadow = 0.0; // this surface ignores traced shadow
l.lit = -1.0; // use terminator / shadowBias
return l;
}
#endif
PtPackLighting fields:
flatIndirect(0..1): above 0.5, indirect light is gathered flat relative to the view direction (surrounding geometry ignored). The pack keeps its ownterminator/shadowBias. Without this field,flatFace = truedoes the same job.sunShadow(0..1): how much traced sun visibility (sunVis) affects the direct-light boundary and specular. 0 ignores this surface’s shadow, 1 is the previous behaviour.lit(0..1,-1= unused): the direct-light brightness (SDF / ramp result). At 0 or above it replaces theterminator/shadowBiascombination. WithsunShadow = 1it matches the oldterm = smoothstep(edge, N.L + shadowBias) * sunVis, and the pack can avoid the bias round trip.
Packs that do not define PT_PACK_HAS_LIGHTING keep the previous behaviour (flatIndirect follows flatFace,
sunShadow = 1, no lit). A file that defines the macro must assign every field.
How the renderer uses this
- Camera / specular chain:
lerp(albedo * shadowTint, albedo, term * sunVis) * sunIntensity + specular * sunVis, wheretermis the smoothstep ofterminatorshifted byshadowBias. WithPT_PACK_HAS_LIGHTING,litreplacesterminator/shadowBias,sunShadowscalessunVis, andflatIndirectflattens only indirect light while keeping the pack’s boundary. - Diffuse bounces (light gathered by other surfaces): uses only
albedo. Toon terms do not run for gather rays. - Do not add an ambient term. The path tracer traces real indirect light.
- A half-Lambert ramp
threshold ± softnessmaps toterminator = (2 * (threshold - softness) - 1, 2 * (threshold + softness) - 1). - Hits with Ray-MMD PBR records still let an active pack (
materialClass != PACK_CLASS_OFF) win. - The irradiance cache warm-up pass keeps the default albedo.
Textures and slot helpers
Textures declared in pack.json are available (explicit LOD only, no implicit derivatives):
float4 PtPackSampleTex(uint i, float2 uv); // level 0
float4 PtPackSampleTexLevel(uint i, float2 uv, float lod);
uint PtPackTexCount();
float2 PtPackTexSize(uint i);
Out-of-range indices or missing files are (1, 1, 1, 1) / size (1, 1). sRGB textures sample as linear values.
API v6 Sekai slots (mesh UVs, LOD 0, wrap, morphs applied):
bool PtPackHasSphereTex(); // a real sphere slot texture exists
float4 PtPackSampleSphereUv(float2 uv); // _H parameter mask
bool PtPackHasToonMap(); // the toon slot is a UV-mapped _S
float4 PtPackSampleToonUv(float2 uv); // _S shadow colour
Detect uv1 / uv2 and the helpers above with PT_PACK_API_ADDUV.
Extended parameters (params.ext)
Declaring "requires": ["params.ext"] makes the 128 extended parameters available in PT / GI too. Shaders receive
them via a per-geometry offset into gPackExtSlots (t3, space1), and PACK_CAP_PARAMS_EXT is defined.
float PtPackParam(uint i); // slot i.x
int PtPackParamInt(uint i);
bool PtPackParamBool(uint i);
float3 PtPackParamColor(uint i); // linear
float4 PtPackParamColor4(uint i);
float3 PtPackParamVec3(uint i);
uint PtPackParamCount();
The aliases PackParam / PackParamInt / PackParamBool / PackParamColor / PackParamColor4 / PackParamVec3 /
PackParamCount return the same values. Without params.ext, use i.params[16].
#ifdef PACK_CAP_PARAMS_EXT
float rim = PtPackParam(0);
#else
float rim = i.params[0];
#endif
Limitations
- Characters only. Stages and props do not receive packs.
- If several different PT packs appear in one scene, the first is used (a warning is logged).
- Offline GI outlines: packs using
PACK_HAS_EDGE+PackEdgedraw their outlines in GI too. Packs without them use the app’s default outlines. - The denoiser treats the pack’s direct light like the default toon lighting. In still tests hard
step()highlight boundaries remained crisp, but fast motion was not checked. - Avoid loops with an unbounded end in
PackEvaluate. If the GPU hangs, the app terminates. - Check with
pack_check <folder> --compile. It compiles the raster, offline GI and path tracer variants. The template isshaders/pack_template/pt_surface.hlsl.