Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .agents/skills/mirai-rendering/references/materials.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ stages.
continues, so it is evaluated inside the traversal, like an any-hit, from
`surface_coverage.slang`; nothing is traced again. The stages that trace depend on that compiled
alpha, not on the rest of the program ([programs and stages](shaders.md#programs-and-stages)).
Its samples record no texture feedback (`texture_feedback_quiet`): a write of each would keep
the whole program, colors and normals too, in every traversal of every stage that traces.
- **Deferred filters.** A ray that crosses glass with a program does not wait for its filter: it
takes the [medium filter](#medium-filter) of the instance and adds the crossing as a filter
point, chained to the others of its owner (a pixel, a probe ray). The program's stage writes in
Expand Down
6 changes: 6 additions & 0 deletions shaders/include/scene.slang
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,17 @@ void material_parameters(uint row, uint block, out float4 parameters[16]) {
[[vk::binding(TEXTURE_FEEDBACK_SLOT, 0)]] RWStructuredBuffer<uint> texture_feedback_words : register(MIRAI_REGISTER(u, TEXTURE_FEEDBACK_SLOT), space0);
#endif

// While true, samples record nothing: the alpha of a program inside a
// traversal (hit_alpha) reads its maps for whether a ray goes on, and a
// write of each of them would keep the whole program in every traversal of
// the stage, its colors and normals too, which no ray reads there.
static bool texture_feedback_quiet = false;
// That a texture was sampled at `level`: log2 of the texels across its width
// a sample spans at the level it reads, less log2 of that width, which no
// level held changes; -FLT_MAX for every level.
void texture_feedback(uint texture_index, float level) {
#ifdef MIRAI_TEXTURE_FEEDBACK
if (texture_feedback_quiet) return;
uint entry = texture_index - TEXTURE_TABLE_RESERVED;
if (entry >= texture_feedback_words[0] || isnan(level)) return;
uint code = uint(clamp(floor((level - TEXTURE_FEEDBACK_LOW) * TEXTURE_FEEDBACK_STEPS), 0.0, float(TEXTURE_FEEDBACK_CODES - 1u)));
Expand Down
8 changes: 7 additions & 1 deletion shaders/include/trace.slang
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ bool hit_mean(Instance inst, float t) {
// The alpha a masked material gives a ray at a point: its maps, or the alpha
// of its program (surface_coverage.slang), which is that of the default
// material when the program does not change it.
// The program records no texture feedback (texture_feedback_quiet), so only
// what its alpha reads stays of it; the hit the ray stops at is shaded, and
// samples, as it is.
float hit_alpha(Instance inst, Material m, Mesh_Triangle tri, float3 weights, float2 uv, float2 uv1, float2 lod, float t) {
if (m.program_id == 0u) return material_base_color(m, uv, uv1, lod, float3(1), true).a;
float3 normal = transform_normal(inst.world_inv, tri.a.normal * weights.x + tri.b.normal * weights.y + tri.c.normal * weights.z);
Expand All @@ -160,7 +163,10 @@ float hit_alpha(Instance inst, Material m, Mesh_Triangle tri, float3 weights, fl
float alpha;
float4 parameters[16];
material_parameters(m.row, inst.material_values, parameters);
return mirai_program_alpha(m.program_id, parameters, ctx, alpha) ? alpha : MATERIAL_DEFAULT_OPACITY;
texture_feedback_quiet = true;
bool given = mirai_program_alpha(m.program_id, parameters, ctx, alpha);
texture_feedback_quiet = false;
return given ? alpha : MATERIAL_DEFAULT_OPACITY;
}

// What a ray that finds this triangle at distance t does: stop, or go through
Expand Down
Loading