Compute ABI
Set 0 ABI 1 fixes 15 Vulkan descriptor bindings and a 96-byte Camera push constant in glome_abi.glslinc. GlomeBuffers verifies the size and every field offset of its seven C# structs at startup. Custom shaders share this layout with glome_standard.glsl.
Set 0 descriptors
Section titled “Set 0 descriptors”| Binding | GLSL symbol | Descriptor | Stride / format | Contents |
|---|---|---|---|---|
| 0 | output_image |
writeonly image2D |
rgba8 |
Output pixel image (RGBA8 UNORM) |
| 1 | Faces |
readonly buffer (std430) |
160 B |
Triangle tris[] in BVH order |
| 2 | Tree |
readonly buffer (std430) |
32 B |
CapNode nodes[], flattened spherical-cap BVH |
| 3 | Materials |
readonly buffer (std430) |
48 B |
MaterialRecord material_records[] |
| 4 | Diagnostics |
buffer (std430) |
64 B |
Diagnostic probes[], host input rays and hit outputs |
| 5 | Lights |
readonly buffer (std430) |
16 + 32n B |
16 B uvec4 light_counts header + LightRecord lights[] |
| 6 | Environment |
uniform Environment (std140) |
80 B |
Environment uniform block env |
| 7 | bank0 |
texture2DArray |
sRGB RGBA8 | Albedo texture bank 0 |
| 8 | bank1 |
texture2DArray |
sRGB RGBA8 | Albedo texture bank 1 |
| 9 | bank2 |
texture2DArray |
sRGB RGBA8 | Albedo texture bank 2 |
| 10 | bank3 |
texture2DArray |
sRGB RGBA8 | Albedo texture bank 3 |
| 11 | nearest_repeat |
sampler |
linear mips | Nearest filtering, repeat UV |
| 12 | linear_repeat |
sampler |
linear mips | Linear filtering, repeat UV |
| 13 | nearest_clamp |
sampler |
linear mips | Nearest filtering, clamp to edge |
| 14 | linear_clamp |
sampler |
linear mips | Linear filtering, clamp to edge |
| Push | Camera |
push_constant (std430) |
96 B |
Camera frame, lens, and dispatch dimensions (camera) |
Workgroups are 8 × 8 × 1 (rounded up to cover the viewport, so check camera.dims.xy bounds). Unused texture banks bind a 1×1 white layer.
Record layouts
Section titled “Record layouts”Each row below is 16 bytes (four 32-bit words). C# records use sequential layout with Pack = 4.
CameraPush (96 B)
Section titled “CameraPush (96 B)”| Offset | GLSL | C# |
|---|---|---|
| 0x00 | right vec4 | Right |
| 0x10 | up vec4 | Up |
| 0x20 | back vec4 | Back |
| 0x30 | pos vec4 | Pos |
| 0x40 | lens vec4 | Lens |
| 0x50 | dims ivec4 | Dims |
right, up, back, pos form the unit camera frame in . lens holds (R, tan(fov/2), elapsedSeconds, 0). dims holds (width, height, bvhNodeCount, probeCount); probeCount == 0 selects image rendering.
TriangleRecord (160 B)
Section titled “TriangleRecord (160 B)”| Offset | GLSL | C# |
|---|---|---|
| 0x00 | plane vec4 | Plane |
| 0x10 | dual0 vec4 | Dual0 |
| 0x20 | dual1 vec4 | Dual1 |
| 0x30 | dual2 vec4 | Dual2 |
| 0x40 | inv_k_material vec4 | InvKMaterial |
| 0x50 | uv01 vec4 | Uv01 |
| 0x60 | uv2 vec4 | Uv2 |
| 0x70 | n0 vec4 | N0 |
| 0x80 | n1 vec4 | N1 |
| 0x90 | n2 vec4 | N2 |
plane is the supporting great-sphere normal; dual0..2 evaluate spherical barycentrics. inv_k_material packs (1/K_A, 1/K_B, 1/K_C, materialIndex). uv01 packs A/B UVs; uv2 packs (uC, vC, surfaceId, traversalFlags) as floats. n0..2 are projected vertex normals.
CapRecord (32 B)
Section titled “CapRecord (32 B)”| Offset | GLSL | C# |
|---|---|---|
| 0x00 | center vec4 | Center |
| 0x10 | bounds vec4 | Bounds |
center is the unit spherical-cap center in . bounds packs (\cos\alpha, firstTriangle, triangleCount, escapeIndex) as floats (triangleCount == 0 on interior nodes).
ProbeRecord (64 B)
Section titled “ProbeRecord (64 B)”| Byte | +0…3 | +4…7 | +8…11 | +12…15 |
|---|---|---|---|---|
| 0x00 | p | |||
| 0x10 | d | |||
| 0x20 | ids.x | ids.y | angle | u |
| 0x30 | v | pad0 | pad1 | pad2 |
Host writes ray origin p and tangent d; shader writes ids = (kind, id) (0 miss, 1 ground, 2 triangle; -1 ID for miss/ground), angle (rad), and u, v.
MaterialRecord (48 B)
Section titled “MaterialRecord (48 B)”| Byte | +0…3 | +4…7 | +8…11 | +12…15 |
|---|---|---|---|---|
| 0x00 | base_color | |||
| 0x10 | emission_roughness | |||
| 0x20 | metallic | alpha_cutoff | albedo_ref | flags |
base_color is linear RGBA; emission_roughness is linear emission RGB + roughness. albedo_ref packs texture bank in high 8 bits and layer in low 24 bits (0xffffffffu = no texture).
LightRecord (32 B)
Section titled “LightRecord (32 B)”| Offset | GLSL | C# |
|---|---|---|
| 0x00 | source vec4 | Source |
| 0x10 | radiance_cutoff vec4 | RadianceCutoff |
The Lights SSBO begins with a 16-byte uvec4 light_counts header (Directional, ShadowedDirectional, Omni, ShadowedOmni in order), followed by 32-byte records starting at byte 16 + 32i (so lights[2] starts at byte 80). radiance_cutoff.w is -1 for directional lights or for omni lights.
EnvironmentBlock (80 B)
Section titled “EnvironmentBlock (80 B)”| Offset | GLSL | C# |
|---|---|---|
| 0x00 | background vec4 | Background |
| 0x10 | ambient_energy vec4 | AmbientEnergy |
| 0x20 | fog_density vec4 | FogDensity |
| 0x30 | mode_ground_mat ivec4 | ModeGroundMaterial |
| 0x40 | ground_uv_xform vec4 | GroundUvTransform |
Colors are linear RGB. fog_density.w is density per metre. mode_ground_mat.xy holds (shadingMode, groundMaterialIndex) (< 0 disables equatorial ground). ground_uv_xform packs UV scale XY and offset ZW.
Material and traversal flags
Section titled “Material and traversal flags”| Field | Mask | Bits |
|---|---|---|
MaterialRecord.Flags |
0x01 |
Unshaded |
MaterialRecord.Flags |
0x06 |
CullMode << 1 (0 back, 2 front, 4 disabled; traversal uses triangle flags) |
MaterialRecord.Flags |
0x08 |
Nearest filter (clear = linear) |
MaterialRecord.Flags |
0x10 |
Clamp UV (clear = repeat) |
MaterialRecord.Flags |
0x20 |
DisableMips (force LOD 0) |
TraversalFlags (uv2.w) |
0x03 |
CullMask: CullBack = 0, CullFront = 1, TwoSided = 2 |
TraversalFlags (uv2.w) |
0x04 |
Cutout (alpha-scissor test at mip 0) |
Set 1 and specialization
Section titled “Set 1 and specialization”S3RenderProgram.CaptureSet1 returns ProgramBuffer[] (UniformBuffer or StorageBuffer), bound consecutively at Set 1 binding 0, 1, ... on construction and Rebuild. UpdateProgramBuffer(binding, bytes) overwrites from offset 0 in place.
Each entry in SpecializationValues compiles one pipeline specializing constant ID 0; Draw(..., pipeline: i) selects the 0-based array index.
Shader headers
Section titled “Shader headers”Include in this order:
#[compute]#version 450#include "res://addons/glome/Shaders/glome_abi.glslinc"#include "res://addons/glome/Shaders/glome_camera.glslinc"#include "res://addons/glome/Shaders/glome_intersections.glslinc"#include "res://addons/glome/Shaders/glome_lighting.glslinc"glome_abi.glslinc defines descriptors, structs, PI, TAU, RAY_MIN = 0.00001, and Hit { int kind, id; float t; vec2 uv; vec3 weights; }.
glome_camera.glslinc
Section titled “glome_camera.glslinc”| Function | Purpose |
|---|---|
vec2 screen_uv(ivec2 pixel) |
Pixel center in (-1, 1) |
vec4 pixel_direction(vec2 uv) |
Unit view ray tangent (forward = -back, screen Y down) |
void write_probe(int i, Hit h) |
Write hit kind, ID, angle, and UV into probes[i] |
glome_intersections.glslinc
Section titled “glome_intersections.glslinc”| Function | Purpose |
|---|---|
vec4 sample_bank(texture2DArray bank, vec3 uv, uint flags, float lod) |
Sample array layer uv.z using material sampler flags |
vec4 material_sample(MaterialRecord m, vec2 uv, float footprint) |
base_color × albedo with footprint-derived mip LOD |
ivec2 texel_address(ivec2 p, ivec2 size, bool clamped) |
Clamp or wrap integer texel coordinates |
float base_alpha(texture2DArray bank, int layer, vec2 uv, uint flags) |
Level-0 alpha (nearest or explicit bilinear) |
bool covered(MaterialRecord m, vec2 uv) |
Alpha-scissor coverage test (alpha >= alpha_cutoff) |
vec3 chart_weights(int j, vec3 beta) |
Inverse-K corrected barycentric weights |
vec2 triangle_uv(int j, vec3 w) |
Interpolated triangle UV |
float first_root(float a, float b, float lo) |
Forward root of (10.0 if degenerate) |
bool cap_hits(CapNode node, vec4 start, vec4 tangent, vec2 end_cs) |
Arc vs. spherical-cap intersection test |
Hit trace(vec4 p, vec4 d, float lo, float hi, bool any_hit, int ignore) |
Trace [lo, hi] (); skips triangle ignore (-1 = none) |
float uv_footprint(Triangle tri, vec4 x, vec2 uv, float angular) |
Estimated UV footprint for mip selection |
vec4 bump_from_uv(Triangle tri, vec4 x, vec4 n, vec2 uv, vec2 dh) |
Perturb tangent normal from UV height derivatives |
vec4 smooth_normal(Triangle tri, vec3 weights, vec4 x) |
Interpolated tangent normal (falls back to tri.plane) |
Hit trace_primary(vec4 p, vec4 d) |
Trace [RAY_MIN, π]; if floorless and missed, continues from (-p, -d) up to 2π |
glome_lighting.glslinc
Section titled “glome_lighting.glslinc”| Function | Purpose |
|---|---|
vec4 light_direction(vec4 x, vec4 source, out float angle) |
Unit tangent toward source and geodesic angle (rad) |
bool light_visible(vec4 x, vec4 geometric, vec4 source, int ignore) |
Geodesic shadow ray visibility test |
vec3 direct_light(MaterialRecord m, vec3 albedo, vec4 n, vec4 v, vec4 l) |
Diffuse + GGX/Smith/Schlick direct lighting |
vec3 geodesic_fog(vec3 color, float angle) |
Exponential fog blend with |
Traversal hooks
Section titled “Traversal hooks”Define before #include "glome_intersections.glslinc". trace runs them in this order (for both primary and shadow rays):
| Hook | Call site |
|---|---|
GLOME_GROUND_HOLE(x) |
On equatorial crossing before ground coverage; return true to open a hole (pair with CPU GroundMask(x) = !hole(x)). |
GLOME_OPAQUE_TWO_SIDED |
Skips ground alpha coverage, triangle face culling, and triangle alpha coverage. |
GLOME_ANALYTIC_HIT(p,d,lo,any_hit,h) |
Between ground and BVH; update h respecting [lo, h.t] and any_hit. |
GLOME_EXCLUDE_CANDIDATE(j) |
After triangle containment, before depth/cull/cutout checks; return true to skip triangle j. |
For host-side packing and renderer methods, see Resources and runtime.