3D engine that AI agents drive
Commit the cap-order script, keep the sky probe size local, validate --world-property (#1104)
Nguyen Xuan An3505d7fef2d9
diff --git a/bench/cycles-parity/floor-closed-form.py b/bench/cycles-parity/floor-closed-form.pyindex 9dbe8706..68b6fd82 100644--- a/bench/cycles-parity/floor-closed-form.py+++ b/bench/cycles-parity/floor-closed-form.py@@ -7,6 +7,9 @@ The floor is Lambert with albedo 0.8, the camera looks straight down and nothingsky: albedo / pi * the integral of sky radiance times cosine over the upper hemisphere (a flat sky of radiance L gives albedo * L).For the Kloofendal map the integral is taken twice from the Radiance file's own bytes: with the texel decoded as mantissa times2^(exponent-136) (what Cook's parser and the Radiance format give) and as (mantissa + 0.5) times 2^(exponent-136).+ uv run --no-project --with numpy python bench/cycles-parity/floor-closed-form.py --cap-order+needs only the sky file: it prints how many texels exceed the radiance limit and the sky term with the limit applied to the texels before+the bilinear lookup (Cook) and to the interpolated value after it (what render-cycles.py did before #1104), on a 2-D grid.Prints, per tag, the closed forms, each renderer's mean over the seeds with its standard error, and each mean over the closed form."""import glob@@ -108,7 +111,47 @@ def format_channels(values, digits=5):return "[" + ", ".join(f"{value:.{digits}f}" for value in values) + "]"+def decode_uncapped_texels(rgbe):+ scale = numpy.where(rgbe[..., 3] == 0, 0.0, 2.0 ** (rgbe[..., 3].astype(numpy.float64) - 136.0))+ return rgbe[..., :3].astype(numpy.float64) * scale[..., None]+++def hemisphere_term(texels, cap_after_lookup, polar_steps=1024, azimuth_steps=2048):+ """albedo-free E / pi of the upper hemisphere, bilinear in both axes on a polar x azimuth grid, capping the value if asked."""+ height, width, _ = texels.shape+ polar = (numpy.arange(polar_steps) + 0.5) / polar_steps * (math.pi / 2.0)+ texel_x = (numpy.arange(azimuth_steps) + 0.5) / azimuth_steps * width - 0.5+ left = numpy.floor(texel_x).astype(int)+ fraction_x = (texel_x - left)[:, None]+ total = numpy.zeros(3)+ for index in range(polar_steps):+ texel_y = polar[index] / math.pi * height - 0.5+ top = int(math.floor(texel_y))+ fraction_y = texel_y - top+ row = texels[min(max(top, 0), height - 1)] * (1.0 - fraction_y) + texels[min(max(top + 1, 0), height - 1)] * fraction_y+ line = row[left % width] * (1.0 - fraction_x) + row[(left + 1) % width] * fraction_x+ if cap_after_lookup:+ line = numpy.minimum(line, RADIANCE_LIMIT)+ weight = math.cos(polar[index]) * math.sin(polar[index]) * (math.pi / 2.0 / polar_steps)+ total += line.mean(axis=0) * weight+ return 2.0 * total+++def print_cap_order():+ """Sky term with the radiance limit applied to the texels (Cook) and to the interpolated value (the old render-cycles.py)."""+ raw = decode_uncapped_texels(decode_radiance_bytes(SKY_FILE))+ brightest = raw.max(axis=2)+ print(f"{SKY_FILE}: {int((brightest > RADIANCE_LIMIT).sum())} texels above {RADIANCE_LIMIT:g}, largest channel value {raw.max():.0f}")+ cap_before = hemisphere_term(numpy.minimum(raw, RADIANCE_LIMIT), False)+ cap_after = hemisphere_term(raw, True)+ print(f"cap before the lookup {format_channels(cap_before, 6)} cap after the lookup {format_channels(cap_after, 6)}")+ print(f"cap after over cap before {format_channels(cap_after / cap_before)}")++def main():+ if "--cap-order" in sys.argv:+ print_cap_order()+ returndata_directory = sys.argv[1]tags = sys.argv[sys.argv.index("--tags") + 1].split(",") if "--tags" in sys.argv else list(closed_forms())forms = closed_forms()diff --git a/bench/cycles-parity/floor-direct-light-suite.sh b/bench/cycles-parity/floor-direct-light-suite.shindex 237a30ee..d34ea212 100644--- a/bench/cycles-parity/floor-direct-light-suite.sh+++ b/bench/cycles-parity/floor-direct-light-suite.sh@@ -96,8 +96,8 @@ stage_probe() {render_variants cycles td-sky@nosample:8 td-sky@res4096:8 td-sky@nosun:8 td-both@nosun:8 td-sky@capafter:8 td-both@capafter:8# The sky itself: 512 x 288 pictures of the background from level, 45 degrees up and straight up.- width=512- height=288+ local width=512+ local height=288both_sides sk-h:2 sk-45:2 sk-up:2render_variants cycles sk-45@capafter:2}diff --git a/bench/cycles-parity/render-cycles.py b/bench/cycles-parity/render-cycles.pyindex dc4c0160..144a5a86 100644--- a/bench/cycles-parity/render-cycles.py+++ b/bench/cycles-parity/render-cycles.py@@ -637,8 +637,13 @@ def apply_cycles_property(scene, property_assignment):# One --world-property name=value (a diagnostic): sets a property of the world's Cycles settings, such as sampling_method="NONE"# (the sky is then found by BSDF sampling only) or sample_map_resolution=4096. Blender versions keep these on world.cycles or on world.def apply_world_property(world, property_assignment):+ if "=" not in property_assignment:+ raise ValueError(f"--world-property takes name=value, got {property_assignment!r}.")property_name, property_text = property_assignment.split("=", 1)- property_value = json.loads(property_text)+ try:+ property_value = json.loads(property_text)+ except json.JSONDecodeError:+ raise ValueError(f"--world-property {property_name} takes a JSON value such as 0, 0.5, true or \"NAME\", got {property_text!r}.")for owner in (world.cycles, world):if hasattr(owner, property_name):setattr(owner, property_name, property_value)@@ -816,8 +821,11 @@ def main():build_scene_objects(scene, description)build_world_shader(scene, description["world"], repository_root)for index, token in enumerate(sys.argv):- if token == "--world-property":- apply_world_property(scene.world, sys.argv[index + 1])+ if token != "--world-property":+ continue+ if index + 1 >= len(sys.argv):+ raise ValueError("--world-property takes name=value after it.")+ apply_world_property(scene.world, sys.argv[index + 1])build_scene_lights(scene, description["environment"])lens_options = resolve_lens_options(options, description["camera"])build_camera_object(scene, description["camera"], lens_options, options["width"] / options["height"])diff --git a/docs/cycles-parity.md b/docs/cycles-parity.mdindex ecf6b943..ce4c7fbc 100644--- a/docs/cycles-parity.md+++ b/docs/cycles-parity.md@@ -1560,7 +1560,7 @@ On Cycles' side the sky floor stays at 1.00168 / 1.00126 / 1.00064 of the closed### Cause-`bench/cycles-parity/render-cycles.py` limited the sky by a `Minimum` node after the Environment Texture node, so it capped the interpolated value. Cook and the 67js runtime cap the texels (`radianceLimit`, 16) before the map is interpolated and sampled. The Kloofendal map has 244 texels above 16 (the largest is about 59,900) (probably what is left of the sun in the original map `[guessed]`), and bilinear interpolation of the raw texels next to them gives values above 16 that the cap then cuts to 16 where Cook's neighbours stay at their own lower values. Computed from the file with a 2-D hemisphere integral: capping after the lookup raises the floor's sky term by 1.00177 / 1.00132 / 1.00067 against capping before. That is what was measured on Cycles (1.00168 / 1.00126 / 1.00064); the two differ by 0.01 percent, which a 1024 by 2048 grid of the integral can account for `[inferred]`. Cook was right. It is a difference of the comparison, not a defect of the kernel.+`bench/cycles-parity/render-cycles.py` limited the sky by a `Minimum` node after the Environment Texture node, so it capped the interpolated value. Cook and the 67js runtime cap the texels (`radianceLimit`, 16) before the map is interpolated and sampled. The Kloofendal map has 244 texels above 16 (the largest channel value is 61,184; probably what is left of the sun in the original map `[guessed]`), and bilinear interpolation of the raw texels next to them gives values above 16 that the cap then cuts to 16 where Cook's neighbours stay at their own lower values. Computed from the file with `uv run --no-project --with numpy python bench/cycles-parity/floor-closed-form.py --cap-order` (a 1024 by 2048 polar and azimuth grid, bilinear lookup of the raw texels, then the cap; the texel count and the maximum come from the same command): capping after the lookup raises the floor's sky term by 1.00177 / 1.00132 / 1.00067 against capping before. That is what was measured on Cycles (1.00168 / 1.00126 / 1.00064); the two differ by 0.01 percent, which a 1024 by 2048 grid of the integral can account for `[inferred]`. Cook was right. It is a difference of the comparison, not a defect of the kernel.### After the change to the script