Sharing Shader Code Between the C++ Vulkan Engine and the Rust WebGPU Renderer#
Slang is the single source of truth. One
.slang source compiles to SPIR-V (Vulkan/C++) and WGSL (WebGPU/Rust),
including shared entry points where the two renderers’ passes coincide.
The pipeline (current)#
shader-build-pipeline.md owns the build wiring,
compile commands, output directories, staleness rules and fast iteration. On
the Rust side its combined WGSL emit replaces the crates’ hand-written WGSL;
their include_str! calls are unchanged and now read Slang-emitted text,
histogram.wgsl included since 2026-11-23.
Ownership: OxidANT’s shaders/ owns all WebGPU Slang entry points and the
shared modules under shaders/common/: aces, brdf, brdf_energy_fit,
camera_ray, cascade_visibility, cloud_upsample, constants, drawn_sky,
fullscreen, gbuffer, hdr_safe, noise, path_estimator,
path_integrator, punctual_light, punctual_shadow, shadow_pcf,
sky_model, surface_lighting, tonemappers, trace_constants and volumetric_clouds. This repo
consumes them through third_party/OxidANT/shaders; Vulkan entry points and
Vulkan-specific material modules stay in Resources/ShadersSlang/. OxidANT
can compile and check its generated WGSL without a superproject checkout.
Why Slang (not GLSL, not naga/WGSL-as-source)#
WGSL used to be the shared-math source, translated by naga into GLSL the C++
engine #included (Historical note below). That shared functions but not
entry points: the generated SPIR-V/GLSL carried WebGPU binding decorations
that do not match the Vulkan engine’s descriptor layout.
Slang’s parameter binding ([vk::binding(i,s)] → @binding(i) @group(s) in
WGSL) aligns the two binding models, so entry points are shareable too. Slang
also targets SPIR-V directly, ray tracing pipeline and ray query included.
WebGPU/WGSL has neither, so those shaders are Slang only for language unity on
the C++ side and emit one target.
Target status (verified against slangc in VulkanSDK 1.4.350.0)#
Target |
Status |
Notes |
|---|---|---|
SPIR-V (Vulkan) |
stable |
Rasterization, compute, ray tracing pipeline, ray query, descriptor sets, push constants |
WGSL (WebGPU) |
experimental |
Functional (official |
WGSL fallback policy: a shared shader that Slang cannot express for the
WGSL target at all (not merely emit) gets hand-written WGSL and no Slang
source, rather than a Slang source nothing on the C++ side consumes that would
still have to be kept in sync. No shader needs it today: the last one,
histogram.wgsl, is Slang since its workgroup atomics became Atomic<uint>
(shader-build-pipeline.md).
Architecture: Slang-native, not #include#
Slang is module- and entry-point-centric: a no-entry-point math module cannot
be emitted to GLSL/WGSL text, and imported functions are name-mangled in the
emit, so sharing goes through Slang’s module system, not textual #include:
Shared math lives under
third_party/OxidANT/shaders/common/. All of its modules are imported on both targets. The C++-only modules sit underResources/ShadersSlang/common/, shared across the raster, deferred, shadow-map, ray tracing and path tracing paths. The shared-module-targets table below is the exact, gated mapping.Entry points
importthe math modules and compile to the target(s) their renderer needs. Slang links modules internally, so mangling is a non-issue.Where the passes genuinely differ (they composite differently), each renderer keeps its own entry points over the same imported math.
Target-local modules sit beside their entry points, not under
common/:forward/forward_lighting.slang(the WebGPU forward and G-buffer lighting) andtracer/bvh_traverse.slang,tracer/trace_shading.slang(the WebGPU compute ray and path tracer). Slang finds them in the importer’s own directory; they compile to WGSL only, and the reachable-function gate follows those imports as it doescommon/.
What is wired today#
Shared math modules (imported by entry points, never emitted directly):
common/aces.slang— ACES filmic tonemap (Narkowicz 2015), its inverseaces_tonemap_inverse(the sky’s photo faces enter as the radiance whose tonemap shows them) and the exact IEC 61966-2-1 sRGB encode. The five coefficients areACES_AtoACES_E;CloudAmbient.hpp’s CPU pair takeskAcesCoefficients, whichBuildIntegrity.CloudAmbientAcesCurveIsAcesSlangsholds to them.common/tonemappers.slang(plan N2) — the tonemapper both post passes pick,apply_tonemapperover ACES, Khronos PBR Neutral and AgX (TONEMAPPER_*, the editors’ order), andencode_display, the sRGB encode with the 8x8 Bayer dither after it;srgb_to_linearundoes it for the Rust renderer’s sRGB targets. The photo sky staysaces_tonemap_inverse’s under every pick (post-processing.md).common/ambient.slang(OxidANT’s, 2026-11-23) — the sky’s share of a surface’s light:ambient_split_sum(an irradiance and a reflection bybrdf_direct’s compensated albedo) andanalytic_ambient(sky_model’s hemisphere irradiance and its reflected gradient, blurred towards it by roughness squared; no sun disk, sincebrdf_direct’s lobe carries the sun and must stay in its shadow), andsky_ambient<M : IAmbientMaps>, which takes the split sum from a renderer’s baked maps when it has them, elseanalytic_ambient. Hererasterizer,deferredandraytrace.rchitadd it after the sun’s shadow throughcommon/ambient_maps.slang’sscene_sky_ambientoverAmbientMaps’s bake of the drawn skybox (OxidANT’sibl.slang, itsfs_skybox_to_cubeuntonemapping the faces assky.slangdraws them, without the sunfs_find_sunfinds in them: OxidANT’scommon/sun_mask.slangcaps 10 degrees around it at the 12-degree ring and fades the cap out by the ring, so the directional Sun alone lights with it), scaled bydirLight.direction.w(the Sky tab’s Ambient slider) and the occlusion map; a switched-off skybox lights with the analytic sky. In OxidANTforward_lighting.slangand the tracer’strace_shading.slangcall it over their own maps. The path tracers get the sky through their bounces’ misses. Both.common/constants.slang—PIandMIN_ROUGHNESS(0.045), forbrdf,path_estimator,volumetric_clouds,material_rules.slangand the path tracer’s furnace card. Both.common/camera_ray.slang— the camera’s ray:camera_ray(clip_to_world, ndc)unprojects the near and far plane, so a traced camera ray starts on the near plane, where raster clips (owner 2026-11-19), with the far plane as its length;camera_ray_through_pixeltakes a pixel throughfullscreen_uv_to_ndc. Hereraytrace.rgen,path_tracing(the camera and cloud-depth rays) andcompute/clouds(its direction; the march starts at the eye), overscene_types.slang’sclip_to_world(GlobalUBO), the product of the two inverses the UBO carries; in OxidANT the tracer, the sky and the cloud march. Both.common/trace_constants.slang— every secondary ray’s bounds:TRACE_TMIN0.001,TRACE_TMAX10000,TRACE_SURFACE_OFFSET0.0001 along the face normal, andTRACE_LIGHT_SPAN(1 - 1e-4), where a punctual light’s shadow ray stops.raytrace.rgen,raytrace.rchit,path_tracingand OxidANT’s tracer. Both.common/brdf.slang— the Epic Games / Unreal 4 microfacet PBR model (distribution_ggx,geometry_smith_k,fresnel_schlick,brdf_direct), used by both renderers’ forward/RT shading and next-event estimation, andbrdf_sampled, the same BRDF with Epic’s Smith remap for sampled light (k = alpha / 2instead of the analytic(r + 1)^2 / 8), which both path tracers’ bounces weight by. Both compensate the GGX lobe’s lost multiple scattering (Turquin 2019):multiscatter_gainscales the specular term by1 + f0 (1 / E_ss - 1), and the diffuse term takes1 - specular_albedo(E_spec(mu)) instead of1 - F, times1 - metallic, so a white surface returns all of a uniform sky.ggx_energyreads E_ss, split by Fresnel, fromcommon/brdf_energy_fit.slang, a generated 14 x 14 cubic B-spline fitted tobrdf_sampled’s single-scatter albedo; both remaps take it. A shading point evaluates it once,ggx_energy(dot(n, v), roughness), and hands it tobrdf_direct,brdf_sampled,brdf_smith_kandsample_bounceasenergy, so a light costs no fit of its own.common/path_estimator.slang— both path tracers’ estimator: the PCG RNG and per-pixel seed (rng_next,path_rng_seed), Russian roulette (russian_roulette_survives) andsample_bounce, the one-sample MIS over the GGX visible-normal and cosine lobes. The C++path_tracing.slangimports it; OxidANT’stracer/traced.slangtoo, andtests/path_estimator_test.slangemits every function to both targets.common/shadow_pcf.slang— the PCF kernel over a cascaded shadow map with a receiver-plane depth bias (receiver_plane_depth_slope,pcf_visibility): each tap compares at the depth of the receiver’s plane beneath it, the slope taken from the shading normal and the affine light matrix, so no derivatives are needed. Taps go through theIShadowTapsinterface, whose implementations bounds-check in the sampling statement:cascaded_shadow.slang’sCombinedTaps(the C++ forward and deferred paths) and OxidANT’sforward/forward_lighting.slang. Both.common/punctual_light.slang—KHR_lights_punctualas both renderers shade it. The C++ engine reads it throughcommon/punctual_lights.slang, which owns set 0’sPUNCTUAL_LIGHTS_BINDING(a count row, then the four rows per light) andPUNCTUAL_SHADOW_MAP_BINDING(one depth cube per shadowed light): forward and deferred shadow the first four point and spot lights by their cubes and add the rest unshadowed, the closest-hit shader traces one shadow ray per light, and the path tracer samples one light per bounce. Both.common/punctual_shadow.slang— both renderers’ cube shadows: the row-3 unpack, the depth formula andpunctual_shadow_visibility, five taps through theIPunctualShadowTapsinterface. This engine taps its cube array (punctual_lights.slang’sCubeTaps); the WebGPU renderer keeps its cubes as layers of one 2D depth array (slot * 6 + face) and taps them through the face selection andpunctual_shadow_face_coord. A face-picked uv cannot leave [0,1], so neither tap needs a range check. Both.common/cascade_visibility.slang— the sun’s cascades for both: the split selection, a cascade’s hit (map uv throughfullscreen_ndc_to_uv, depth and whether its box holds the point),find_cascade’s search (the selected cascade, else the first coarser box that holds the point, through each renderer’sICascadeSpaces), the slope bias andcascade_visibility’s PCF overshadow_pcf.slang. A point no box holds counts as lit. Both fit the cascades to the scene rect’s frustum, not the whole image’s: the docks are opaque, and the image’s would cost every shown pixel 1.6-1.7x the texel size (the default docks at 1200x768), so only ground under them is retried.common/surface_lighting.slangandcommon/gbuffer.slang— theSurfacePoint, its f0, how a lit point combines the shadowed sun with the punctual, ambient and emissive terms, and the G-buffer both deferred paths write and read: rgba16f normal and metallic, whose sign -1 marks unlit; rgba8 sRGB albedo and occlusion; rgba16f roughness and emissive. Both.common/cloud_upsample.slang— the half-resolution cloud march’s nearest half-texel depth and its depth-weighted four-texel upsample, behindICloudUpsampleTexels, which each renderer’s pass implements. Both.common/noise.slang— 3D simplex noise + fractal Brownian motion, checked on both targets by OxidANT’stests/noise_test.slang; no production shader imports it yet.common/fullscreen.slang— the fullscreen-triangle vertex trick (vid/2*4-1), used by every fullscreen pass on both sides. Itsuvis the one per-target difference in shared code: uv (0,0) is always the target’s top-left texel, but clip-space y = -1 is the top row in Vulkan and the bottom row in WebGPU, sofullscreen_vspicks the V formula with__target_switch(spirv:v = (y + 1) / 2; every other target:v = 1 - (y + 1) / 2). The WGSL emit is byte-identical to the single formula it replaced.fullscreen_uv_to_ndcis its exact inverse, switched the same way, for the passes that reconstruct a position from the uv (deferred.slangon SPIR-V,ssao.slangon WGSL), andfullscreen_ndc_to_uvthe reverse, for a projected point’s texel (ssao.slang,gpu_cull.slang).BuildIntegrity.NoShaderRedeclaresTheFullscreenUvMappingfails on a hand-written copy in afullscreenimporter. A wrong V mirrors the frame about its horizontal centre line, which a vertically symmetric test scene cannot show;GoldenRender.WorldUpIsScreenUp(C++) andworld_up_is_screen_up(OxidANTtests/headless.rs) pin it.common/material_fetch.slang— theobjectDescriptionbinding and thefetch_object_description/fetch_materiallookups on it. Spirv only: the raster (rasterizer.slang,deferred.slang,shadow_map.slang), closest-hit/any-hit ray tracing (raytrace.rchit.slang,raytrace.rahit.slang) and path tracing (path_tracing.slang) entry points.common/material_rules.slang— the binding-free glue from the fetchedObjMaterialto OxidANT’scommon/gltf_material.slang(below):roughness_factor(the OBJ shininess fallback),material_metallic_roughness(glTF SS3.9.2 G=roughness/B=metallic channel swizzle),material_masked_out(alphaMode MASK, decided byObjMaterial::alphaMode) andblend_coverage. Split out ofmaterial_fetch.slangsopath_tracing.slangcan call them, as withbase_color.slangbelow. Spirv only, every C++ shading path (raster, deferred, shadow map, ray tracing, path tracing).common/material_textures.slang— the one declaration of thetextures[]/textureSamplers[]arrays (TEXTURES_BINDING/SAMPLER_BINDING), plus explicit-LOD (SampleLevel) and implicit-LOD (Sample) helpers for the alpha (map_d), normal, metallic-roughness and emissive slots. Both LOD shapes share one module because an implicit-LOD helper an entry point does not call is dead-code-eliminated before Slang’s capability checking, so a compute/ray-tracing importer that calls only the explicit-LOD half never picks up a fragment-only capability. The base-colour slot is not here: its sampling stays inline at each call site, next to the per-shader control flow (albedo assembly, discard, G-buffer packing). Spirv only:rasterizer.slang,deferred.slang,rasterizer/shadows/shadow_map.slang,common/traced_hit.slangandalpha_test.slang;raytrace.rchit.slangandpath_tracing.slangget it throughtraced_hit.slang, the traced modes’ one hit fetch.common/path_integrator.slang— both renderers’ path tracer:trace_pathwalks one path over anITracedScene, which gives the closest hit, the shadow ray, the camera and bounce skies, the sun, the punctual lights and the furnace.path_tracing.slangimplements it over ray queries (EnginePathScene), OxidANT’stracer/trace_shading.slangoverbvh_traverse(TracerScene). One closest-hit and one shadow-ray call site per kernel, because SwiftShader inlines a whole traversal per site; the clouds’ depth ray takes the path loop’s first pass (PathDepth). Both.common/drawn_sky.slang— the sky both renderers draw per direction:sky/sky.slang’s fragment and both path tracers’ camera misses read it, with the disabled sky’s navy (SKYBOX_DISABLED), whichBuildIntegrity.CloudAmbientNavyIsTheDisabledSkyRadianceholds toCloudAmbient.hpp’s. Both.common/traced_hit.slang— this engine’s ray-traced hit:traced_surfacefetches a committed triangle’s vertices and material at level 0 for bothraytrace.rchit.slangandpath_tracing.slang, andcommit_unmasked_candidatesis the ray queries’ MASK test, which an any-hit stage does for the ray-tracing pipeline. Spirv only;BuildIntegrity.TracedModesShareOneHitFetchAndOneIntegratorkeeps both callers on it.common/cascaded_shadow.slang— this engine’s map binding andcalc_cascaded_shadowover OxidANT’scascade_visibility.slang. Spirv only: the raster and deferred lighting paths (rasterizer.slang,deferred.slang).common/base_color.slang—base_color(glTF base colour =baseColorFactor * sampled texture) and the per-slot UV accessors overgltf_material.slang’stransform_uv(KHR_texture_transform), in a bindingless module so every spirv shading path can import it. It keepsrasterizer/rasterizer.slang,deferred/deferred.slang,raytracing/raytrace.rchit.slangandpath_tracing/path_tracing.slangin agreement with the referenceprim.base_color * baseSampleinforward/forward.slang(wgsl, not an importer); before it, those four droppedbaseColorFactorwhenever a material also had a texture. The alpha half travels separately: the glTF loader putsbaseColorFactor[0..2]indiffuseandbaseColorFactor[3]indissolve, whichmaterial_masked_out()multiplies into the sampled alpha (theObjMaterialtable inmodel-loading.md). Spirv only.common/emission.slang— the glTF emissive rule (material_emission:emissiveFactor* sampledemissiveTexture, or the factor alone without a texture). Spirv only, all four raster/RT shading paths (rasterizer.slang,deferred.slang,raytrace.rchit.slang,path_tracing.slang).OxidANT’s
common/gltf_material.slang(both targets) — the material rules both renderers sample with, once:transform_uv(KHR_texture_transform),tangent_space_normal(the texel to tangent space, z rebuilt from xy for a two-channel BC5 map) andapply_normal_map(glTF SS3.9.3; on a doubleSided back face it negates the mapped normal as a whole, which reverses tangent, bitangent and normal together, SS3.9.2),mirror_signandnormal_transform(the cofactor the raster vertex stages take the normal transform from, so the push constants carry only the model matrix),material_metallic(held in [0, 1]),material_roughness(floored) andalpha_masked_out(an explicit alpha mode plus cutoff,common/alpha_mode.slang’sALPHA_OPAQUE/ALPHA_MASK/ALPHA_BLEND, whichObjMaterial.hppincludes). Its vector kernel checks every function on both targets. The C++ shading paths reach it throughmaterial_rules.slang,material_textures.slang,base_color.slangandraster_geometry.slang; the Rust renderer’sforward.slangand tracer call it directly.common/hdr_safe.slang(OxidANT’s since 2026-11-23) —hdr_safe, the clamp every write to an RGBA16F HDR target ends in: radiance to[0, HDR_MAX]withHDR_MAX = 65000, under fp16’s 65504, and NaN to 0, found by its bits because WGSL may assume floats are finite. Here: the forward and deferred outputs and the deferred G-buffer’s emission, the ray-generation store, and the path tracer’s per-sample sum and output store; in OxidANT the forward pass, the sky, bloom and the tracer. Both.common/alpha_test.slang— the glTF MASK alpha test for ray queries:raytrace.rahit.slang’s any-hit shader andtraced_hit.slang’scommit_unmasked_candidates, the ray-query candidate loop the path tracer runs for want of an any-hit stage. Spirv only.common/volumetric_clouds.slang— the volumetric clouds: the noise volume’s texel (noise_volume_texel),cloud_unpackof the SceneUBO’s four cloudvec4s, the axis-aligned box test, density, the light’s optical depth (light_optical_depth), the sun’s multiple-scattering octaves, the sky ambient (CloudAmbient) andmarch_clouds, which stops at the scene depth (cloud_scene_distance) and steps a long path more often. Every caller passes the ambient its host averaged from the sky it draws (C++:compute/clouds.slang, from theSceneUBO’scloudAmbientTop/cloudAmbientBottom). The noise comes in through theICloudNoiseinterface, which Slang specializes per caller: the C++compute/clouds.slangpasses its combinedSampler3D, OxidANT’sclouds/cloud_march.slanga texture plus a sampler. Both.clouds.mdowns the behaviour.common/sky_model.slang— the analytic sky’s horizon/zenith/ground gradient (sky_gradient), sun disk (sun_disk) and diffuse hemisphere irradiance approximation (hemisphere_irradiance), shared bysky/sky.slang(both renderers’ background),common/ambient.slang(the analytic ambient, whose reflections and irradiance must agree with the background) and the WebGPU tracer’s miss shading (tracer/trace_shading.slang). The C++ engine never drawssky.slang’s procedural mode: without faces its cube map holds the same gradient, baked byscene/sky_box/AnalyticSky.hpp, which copies the three coloursBuildIntegrity.AnalyticSkyMatchesOxidantsSkyModelpins. There is deliberately no combinedsky_radiance: each caller takes its light direction and intensity from its own uniform block or, inanalytic_ambient, as arguments, oversky_gradient+sun_disk.tests/sky_constants.rspins the three gradient constants a third time on the Rust CPU side (render::ibl::SKY_ZENITH/SKY_HORIZON/SKY_GROUND, consumed byEnvironmentImage::sky’s panorama).
Entry-point shader targets: five entry-point sources serve both renderers.
sky/sky.slang is the sky each draws into its HDR target: the C++ engine
compiles its vs_vulkan_main (SV_VulkanVertexID, since SV_VertexID needs
draw parameters a Raspberry Pi 5’s v3dv lacks) and fs_main to SPIR-V through
OxidANT’s manifest rows, which build them in its CI too, and fills
SkyUniforms from scene/sky_box/SkyUniforms.hpp; the combined
sky.wgsl carries the extra entry unused. fxaa/fxaa.slang is FXAA after the
tonemap: the C++ engine compiles only its fs_main, behind post.slang’s
SV_VulkanVertexID vertex, and fills FxaaUniforms from
renderer/FxaaUniforms.hpp (z 0: post’s intermediate holds sRGB-encoded
bytes). histogram/histogram.slang is auto exposure: the C++ engine dispatches its three kernels as they are,
over the same two-float exposure buffer post.slang reads, and bloom/bloom.slang is bloom, whose three fragment
entries the C++ engine compiles behind post.slang’s vertex, as ssao/ssao.slang’s occlusion and blur
(post-processing.md). Every other source compiles to one target. tonemap/tonemap.slang (WGSL) and post/post.slang (SPIR-V) look
like one pass but are separate sources: the C++ side’s post/post.slang
also composites clouds via push constants, so it never merged with the Rust
tonemap shader.
File |
Target |
|---|---|
|
both |
|
wgsl |
|
wgsl |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
wgsl |
|
wgsl |
|
wgsl |
|
both |
|
wgsl |
|
both |
|
both |
|
wgsl |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
both |
|
both |
|
wgsl |
|
wgsl |
|
wgsl |
|
wgsl |
|
wgsl |
CI guards: OxidANT’s vector kernels, tests/<module>_test.slang for
brdf, noise, path_estimator, hdr_safe, aces, fullscreen,
camera_ray, ambient, gltf_material, cascade_visibility,
punctual_shadow, surface_lighting, gbuffer, cloud_upsample, drawn_sky,
path_integrator, sun_mask, exposure, bloom_filter and tonemappers, run every
public function of their common/ module once per case of
tests/vectors/<module>.json (inputs, f64 references, a tolerance per output;
OxidANT’s docs/shaders.md § Vector kernels). Both targets are checked on a
device: OxidANT’s shader_vectors.rs dispatches the WGSL, and
Integration.SharedSlangKernelsMeetTheirVectors
(Test/commit/VulkanEngine/sharedShaderVectorsSuite.cpp) the SPIR-V this
engine’s build emits from the imported manifest rows, on a headless Vulkan
device, naming module, case and component of every miss. It loops over every
vector file, so the next module’s kernel needs no edit here. The first two
were this engine’s compile-only guards until 2026-11-21. The table above
excludes them (see its gating test). A spirv-only module has nothing to guard until it gains a real wgsl
consumer, which the table below makes checkable. OxidANT’s
tests/volumetric_clouds_test.slang and tests/shadow_pcf_test.slang are the
reverse guards: SPIR-V only, they import volumetric_clouds with a
Sampler3D and shadow_pcf with a Sampler2DArrayShadow the way the C++
engine does, so OxidANT’s own CI proves both still emit for this engine;
tests/constants_test.slang does the same for constants and
trace_constants. BuildIntegrity.NoShaderCopiesASharedLeafModule fails a
file in either tree that keeps a private copy of a leaf module’s constant,
literal or function (OxidANT’s scripts/check-shared-shader-copies.py holds
its own tree to the same rules).
The local cloud-volume shader is compute/noise_volume.slang so Slang’s
import noise; resolves OxidANT’s common/noise.slang. A local file named
noise.slang shadowed that shared module in the compiler’s include order;
the dual-target test then failed with E30015 undefined identifier on
snoise and fbm before it could test the shared math.
BuildIntegrity.NoVulkanShaderShadowsASharedModule now fails on any local
.slang named like a file in OxidANT’s shaders/, which is why this repo’s
common/hdr_safe.slang went in the pin bump that brought OxidANT’s.
Shared-module targets: the per-common/-module counterpart of the table
above, computed the same way (an import-graph walk over shader-manifest.json)
and gated by the same kind of test. tests/*.slang count as real consumers,
which is why brdf and noise show both although noise has no production
wgsl consumer yet. (unused) would mark a module under common/ that nothing
imports.
Module |
Target |
|---|---|
|
both |
|
both |
|
spirv |
|
both |
|
spirv |
|
spirv |
|
both |
|
both |
|
both |
|
both |
|
both |
|
spirv |
|
both |
|
both |
|
both |
|
spirv |
|
both |
|
both |
|
both |
|
both |
|
both |
|
both |
|
spirv |
|
spirv |
|
spirv |
|
both |
|
both |
|
both |
|
both |
|
both |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
spirv |
|
both |
|
both |
|
both |
|
both |
|
both |
|
both |
|
spirv |
|
spirv |
|
both |
Status: all C++ shaders are on Slang SPIR-V (all 8 loading sites), and all
Rust shaders on Slang-emitted WGSL, every WebGPU pass written target-neutral
(OxidANT’s docs/shaders.md); a pass gains its SPIR-V row with the C++ change
that binds it.
Which C++ shading path reads which ObjMaterial field#
A new ObjMaterial field is not done when one shading path reads it:
BuildIntegrity.EveryObjMaterialFieldIsReadByAShader only asks whether some
.slang source mentions material.<field>, so a field read by
rasterizer.slang and silently dropped by path_tracing.slang still passes.
This table is the per-path answer: one row per ObjMaterial member
(common/scene_types.slang), one column per C++ shading path
(deferred.slang’s is geometry_fs_main, raytrace.rchit.slang’s
rchit_main, path_tracing.slang’s path_tracing_main); the two alpha-only
consumers shadow_map.slang/alpha_test.slang share a column, since neither
shades a colour. A cell names the expression or helper that reads the field on
that path, or says “not read” and why. The asymmetries it pins, so they stop
being rediscovered one field at a time:
metallicandroughnessare a full factor-or-texture read on all four paths. Until 2026-11path_tracing.slangread metallic on the texture branch alone, so an untextured factor (metallic_card.gltf’s 0.75) was ignored, and had no specular lobe to use roughness with.shininessis only reachable throughroughness_factor()’s negative-roughnessfallback (“(fallback)” in its row).dissolveis read only insidematerial_masked_out(), so a path with no MASK alpha test of its own (raytrace.rchit.slang,path_tracing.slang’s own shading; their MASK test runs earlier, inalpha_test.slang’sray_hit_masked_out()) never touches it.
Member |
|
|
|
|
|
|---|---|---|---|---|---|
|
|
|
|
|
not read — alpha testing only discards a fragment, never shades a colour |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no lighting |
|
|
|
not read — the MASK cut-out for ray-traced hits runs in the any-hit shader ( |
not read — candidates are alpha-tested earlier, by |
|
|
|
|
|
|
|
|
|
|
not read — see |
not read — see |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no normal mapping |
|
|
|
|
|
not read — no normal mapping |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no normal mapping |
|
|
|
|
|
not read — no normal mapping |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — no lighting |
|
|
|
|
|
not read — MASK alpha testing runs regardless of |
|
|
|
not read — see |
not read — see |
|
|
|
|
|
|
|
|
|
|
not read — see |
not read — see |
|
|
|
|
|
not read — the path tracer gathers its own indirect light |
not read — no lighting |
|
|
|
|
not read — see |
not read — no lighting |
|
|
|
|
not read — see |
not read — no lighting |
|
|
|
|
not read — see |
not read — no lighting |
Beyond shaders#
The larger cross-renderer items on the roadmap
(OxidANT’s third_party/OxidANT/crates/webgpu_renderer/docs/webgpu-renderer-roadmap.md, Phase G):
Shared assets — OBJ→glTF conversion, so both renderers load the same scenes (the C++ engine’s
Resources/Modelsbecomes directly usable).Side-by-side comparison harness — same scene, same camera, diff the Vulkan and WebGPU screenshots. With shared BRDF math the images should match closely, so the diff becomes a regression net for both renderers.
Historical note: the retired naga/WGSL-export route (2026-07-20 to 2026-07-30)#
Before Slang, WGSL was to stay the source of truth:
cargo run -p kataglyphis_webgpu_renderer --example export_shaders (naga)
translated the Rust renderer’s hand-written WGSL into SPIR-V/GLSL for the C++
side, opt-in via a -ExportWgslShaders flag on Build-Windows.ps1 /
Build-Windows-Container.ps1, output to the gitignored
Resources/Shaders/generated/. It shared functions (a
Resources/Shaders/generated/aces.glsl/brdf.glsl #include POC worked) but
never entry points, for the binding-model mismatch above; that limit
motivated the Slang migration.
Retired 2026-07-30: nothing in the C++ engine consumed the exported output
(grep -rn "\.spv" Src/ shows every SPIR-V load coming from
Resources/ShadersSlang/build/spirv/), so the flag, its build-script plumbing
and the Resources/Shaders/generated/ gitignore entry were removed. The
export_shaders naga example stays in the Rust crate upstream, harmless and
still useful for inspecting naga’s WGSL→SPIR-V output; this repo no longer
treats it as the sharing route.