CultMath: a Blender ramp table has 257 entries (size + 1 at i / 256); the oracle samples it so, and the oracle test leaves unread operands unread

Builds. Fixtures and CultMath.Cycles.glsl are still to come.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-12 06:14:44 +02:00
commit ddca0252e6
6 changed files with 10 additions and 6 deletions

View file

@ -342,7 +342,7 @@ float cultmath_cycles_rgb_to_bw(float3 color)
// Where a ramp of `size` table entries is read at t: (index, weight), the lower entry and the weight of the
// next one. The colour is table[index] when weight is 0 and (1 - weight) table[index] + weight table[index + 1]
// otherwise. The ramp table itself is the caller's.
// otherwise. The ramp table itself is the caller's; Blender's holds 257 entries, the ramp sampled at i / 256.
float2 cultmath_cycles_ramp_index(float t, int size)
{
float f = (t > 0.0 ? (t < 1.0 ? t : 1.0) : 0.0) * (float)(size - 1);

View file

@ -368,7 +368,8 @@ public static partial class math
/// <summary>
/// Where a Color Ramp of `size` table entries is read at t: (index, weight), the lower entry and the
/// weight of the next one. The colour is table[index] when weight is 0 and
/// (1 - weight) table[index] + weight table[index + 1] otherwise. The ramp table itself is the caller's.
/// (1 - weight) table[index] + weight table[index + 1] otherwise. The ramp table itself is the caller's;
/// Blender's holds 257 entries, the ramp sampled at i / 256.
/// </summary>
public static float2 cycles_ramp_index(float t, int size)
{

View file

@ -53,7 +53,8 @@ public sealed class CyclesOracleTests
throw new InvalidOperationException($"{method.Name}: parameter type {parameter.ParameterType.Name} is not a fixture operand");
}
Assert.Equal(tokens.Length, next);
// The operands a function does not take (Map Range's Steps, for the three kinds that ignore it) are left unread.
Assert.True(next <= tokens.Length, $"{method.Name}: {next} operands wanted, {tokens.Length} in the case");
return values.ToArray();
}

View file

@ -621,7 +621,7 @@ public sealed class GlslMirrorTests
new("vec3 cultmath_cycles_rgb_to_hsv(vec3)", "ulp-bounded", r => new object[] { CyclesColor(r) }),
new("vec3 cultmath_cycles_hsv_to_rgb(vec3)", "ulp-bounded", r => new object[] { new float3(r.NextSingle(), r.NextSingle(), Uniform(r, 0.0f, 2.0f)) }),
new("float cultmath_cycles_rgb_to_bw(vec3)", "ulp-bounded", r => new object[] { CyclesColor(r) }),
new("vec2 cultmath_cycles_ramp_index(float, int)", "ulp-bounded", r => new object[] { Uniform(r, -0.25f, 1.25f), 256 }),
new("vec2 cultmath_cycles_ramp_index(float, int)", "ulp-bounded", r => new object[] { Uniform(r, -0.25f, 1.25f), 257 }),
}.Concat(new[]
{
"blend", "add", "mul", "screen", "overlay", "sub", "div", "diff", "exclusion", "dark", "light", "dodge", "burn", "hue", "sat", "val", "color", "soft", "linear",

View file

@ -438,7 +438,9 @@ def family_rgb_to_bw():
return [{"function": "cycles_rgb_to_bw", "node": "ShaderNodeRGBToBW", "cases": encode_cases(columns, bake("rgb_to_bw", images, build, 1))}]
RAMP_SIZE = 256
# A Blender ramp is sampled at 256 intervals into a table of 257 entries (colorramp_to_array: size + 1 entries
# at i / size), and the kernel reads that table with table_size 257.
RAMP_SIZE = 257
# A constant ramp whose 32 stops sit half an entry past an entry boundary: its table is the stops' values, so
# a lookup's result names the entry it read.
CONSTANT_STOPS = [((8 * j + 3.5) / (RAMP_SIZE - 1), (j + 1) / 32.0) for j in range(32)]

View file

@ -342,7 +342,7 @@ float cultmath_cycles_rgb_to_bw(float3 color)
// Where a ramp of `size` table entries is read at t: (index, weight), the lower entry and the weight of the
// next one. The colour is table[index] when weight is 0 and (1 - weight) table[index] + weight table[index + 1]
// otherwise. The ramp table itself is the caller's.
// otherwise. The ramp table itself is the caller's; Blender's holds 257 entries, the ramp sampled at i / 256.
float2 cultmath_cycles_ramp_index(float t, int size)
{
float f = (t > 0.0 ? (t < 1.0 ? t : 1.0) : 0.0) * (float)(size - 1);