Files
test/tests/python/cycles_render_tests.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

294 lines
10 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2015-2023 Blender Authors
#
# SPDX-License-Identifier: Apache-2.0
import argparse
import platform
import os
import shlex
import sys
from pathlib import Path
from modules import render_report
# List of .blend files that are known to be failing and are not ready to be
# tested, or that only make sense on some devices. Accepts regular expressions.
BLOCKLIST_ALL = [
# Blocked due to overlapping object differences between platforms.
"hair_geom_reflection.blend",
"hair_geom_transmission.blend",
"hair_instancer_uv.blend",
"principled_hair_directcoloring.blend",
"visibility_particles.blend",
# Temporarily blocked for 4.4 lib upgrade, due to PNG alpha minor difference.
"image_log_osl.blend",
]
# Blocklist for device + build configuration that does not support OSL at all.
BLOCKLIST_OSL_NONE = [
'.*_osl.blend',
'osl_.*.blend',
]
# Blocklist for OSL with limited OSL tests for fast test execution.
BLOCKLIST_OSL_LIMITED = []
# Blocklist for tests that fail when running all tests with OSL backend.
# Most of these tests are blocked due to expected differences between SVM and OSL.
# Due to the expected differences there are usually a SVM and OSL version of the test.
# So blocking these tests doesn't lose any test permutations.
BLOCKLIST_OSL_ALL = BLOCKLIST_OSL_LIMITED + [
# AOVs are not supported. See 73266
'aov_.*.blend',
'render_passes_aov.*.blend',
# Image sampling is different from SVM. There are OSL variants of these tests
'image_byte.*.blend',
'image_float.*.blend',
'image_half.*.blend',
'image_mapping_.*_closest.blend',
'image_mapping_.*_cubic.blend',
'image_mapping_.*_linear.blend',
'image_alpha_blend.blend',
'image_alpha_channel_packed.blend',
'image_alpha_ignore.blend',
'image_log.blend',
'image_non_color.blend',
'image_mapping_udim.blend',
# Tests that need investigating into why they're failing:
# Noise differences due to Principled BSDF mixing/layering used in some of these scenes
'render_passes_.*.blend',
]
BLOCKLIST_OPTIX = [
# Ray intersection precision issues
'big_triangles_50164.blend',
'big_plane_43865.blend',
]
# Blocklist for OSL tests that fail with the OptiX OSL backend.
BLOCKLIST_OPTIX_OSL_LIMITED = [
'image_.*_osl.blend',
# OptiX OSL doesn't support the trace function
'osl_trace_shader.blend',
# Noise functions do not return color with OptiX OSL
'osl_camera_advanced.blend',
]
# Blocklist for SVM tests that fail when forced to run with OptiX OSL
BLOCKLIST_OPTIX_OSL_ALL = BLOCKLIST_OPTIX_OSL_LIMITED + [
# OptiX OSL does support AO or Bevel
'ambient_occlusion.*.blend',
'bake_bevel.blend',
'bevel.blend',
'principled_bsdf_bevel_emission_137420.blend',
# Dicing tests use wireframe node which doesn't appear to be supported with OptiX OSL
'dicing_camera.blend',
'offscreen_dicing.blend',
'panorama_dicing.blend',
# The mapping of the UDIM texture is incorrect. Need to investigate why.
'image_mapping_udim_packed.blend',
# Error during rendering. Need to investigate why.
'points_volume.blend',
]
BLOCKLIST_METAL = []
if platform.system() == "Darwin":
version, _, _ = platform.mac_ver()
major_version = version.split(".")[0]
if int(major_version) < 13:
BLOCKLIST_METAL += [
# MNEE only works on Metal with macOS >= 13
"underwater_caustics.blend",
]
Cycles: approximate shadow caustics using manifold next event estimation This adds support for selective rendering of caustics in shadows of refractive objects. Example uses are rendering of underwater caustics and eye caustics. This is based on "Manifold Next Event Estimation", a method developed for production rendering. The idea is to selectively enable shadow caustics on a few objects in the scene where they have a big visual impact, without impacting render performance for the rest of the scene. The Shadow Caustic option must be manually enabled on light, caustic receiver and caster objects. For such light paths, the Filter Glossy option will be ignored and replaced by sharp caustics. Currently this method has a various limitations: * Only caustics in shadows of refractive objects work, which means no caustics from reflection or caustics that outside shadows. Only up to 4 refractive caustic bounces are supported. * Caustic caster objects should have smooth normals. * Not currently support for Metal GPU rendering. In the future this method may be extended for more general caustics. TECHNICAL DETAILS This code adds manifold next event estimation through refractive surface(s) as a new sampling technique for direct lighting, i.e. finding the point on the refractive surface(s) along the path to a light sample, which satisfies Fermat's principle for a given microfacet normal and the path's end points. This technique involves walking on the "specular manifold" using a pseudo newton solver. Such a manifold is defined by the specular constraint matrix from the manifold exploration framework [2]. For each refractive interface, this constraint is defined by enforcing that the generalized half-vector projection onto the interface local tangent plane is null. The newton solver guides the walk by linearizing the manifold locally before reprojecting the linear solution onto the refractive surface. See paper [1] for more details about the technique itself and [3] for the half-vector light transport formulation, from which it is derived. [1] Manifold Next Event Estimation Johannes Hanika, Marc Droske, and Luca Fascione. 2015. Comput. Graph. Forum 34, 4 (July 2015), 87–97. https://jo.dreggn.org/home/2015_mnee.pdf [2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering scenes with difficult specular transport Wenzel Jakob and Steve Marschner. 2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages. https://www.cs.cornell.edu/projects/manifolds-sg12/ [3] The Natural-Constraint Representation of the Path Space for Efficient Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages. https://cg.ivd.kit.edu/english/HSLT.php The code for this samping technique was inserted at the light sampling stage (direct lighting). If the walk is successful, it turns off path regularization using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells the integrator not to blur the brdf roughness further down the path (in a child ray created from BSDF sampling). In addition, using a cascading mechanism of flag values, we cull connections to caustic lights for this and children rays, which should be resolved through MNEE. This mechanism also cancels the MIS bsdf counter part at the casutic receiver depth, in essence leaving MNEE as the only sampling technique from receivers through refractive casters to caustic lights. This choice might not be optimal when the light gets large wrt to the receiver, though this is usually not when you want to use MNEE. This connection culling strategy removes a fair amount of fireflies, at the cost of introducing a slight bias. Because of the selective nature of the culling mechanism, reflective caustics still benefit from the native path regularization, which further removes fireflies on other surfaces (bouncing light off casters). Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
BLOCKLIST_GPU = [
# Uninvestigated differences with GPU.
'image_log.blend',
'glass_mix_40964.blend',
'filter_glossy_refraction_45609.blend',
'bevel_mblur.blend',
# Inconsistency between Embree and Hair primitive on GPU.
'denoise_hair.blend',
'hair_basemesh_intercept.blend',
'hair_instancer_uv.blend',
'hair_info.blend',
'hair_particle_random.blend',
"hair_transmission.blend",
'principled_hair_.*.blend',
'transparent_shadow_hair.*.blend',
"microfacet_hair_orientation.blend",
# Inconsistent handling of overlapping objects.
"sobol_uniform_41143.blend",
"visibility_particles.blend",
# No path guiding on GPU.
"guiding*.blend",
]
2021-07-06 12:05:27 +10:00
class CyclesReport(render_report.Report):
def __init__(self, title, output_dir, oiiotool, device=None, blocklist=[], osl=False):
# Split device name in format "<device_type>[-<RT>]" into individual
# tokens, setting the RT suffix to an empty string if its not specified.
self.device, suffix = (device.split("-") + [""])[:2]
self.use_hwrt = (suffix == "RT")
self.osl = osl
variation = self.device
if suffix:
variation += ' ' + suffix
if self.osl:
variation += ' OSL'
super().__init__(title, output_dir, oiiotool, variation, blocklist)
def _get_render_arguments(self, arguments_cb, filepath, base_output_filepath):
return arguments_cb(filepath, base_output_filepath, self.use_hwrt, self.osl)
def _get_arguments_suffix(self):
return ['--', '--cycles-device', self.device] if self.device else []
2024-09-12 13:01:34 -04:00
def get_arguments(filepath, output_filepath, use_hwrt=False, osl=False):
dirname = os.path.dirname(filepath)
basedir = os.path.dirname(dirname)
subject = os.path.basename(dirname)
args = [
"--background",
"--factory-startup",
"--enable-autoexec",
"--debug-memory",
"--debug-exit-on-error",
filepath,
"-E", "CYCLES",
"-o", output_filepath,
"-F", "PNG"]
# OSL and GPU examples
# custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.shading_system = True"]
# custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.device = 'GPU'"]
custom_args = os.getenv('CYCLESTEST_ARGS')
if custom_args:
args.extend(shlex.split(custom_args))
spp_multiplier = os.getenv('CYCLESTEST_SPP_MULTIPLIER')
if spp_multiplier:
args.extend(["--python-expr", f"import bpy; bpy.context.scene.cycles.samples *= {spp_multiplier}"])
cycles_pref = "bpy.context.preferences.addons['cycles'].preferences"
use_hwrt_bool_value = "True" if use_hwrt else "False"
use_hwrt_on_off_value = "'ON'" if use_hwrt else "'OFF'"
args.extend([
"--python-expr",
(f"import bpy;"
f"{cycles_pref}.use_hiprt = {use_hwrt_bool_value};"
f"{cycles_pref}.use_oneapirt = {use_hwrt_bool_value};"
f"{cycles_pref}.metalrt = {use_hwrt_on_off_value}")
])
if osl:
args.extend(["--python-expr", "import bpy; bpy.context.scene.cycles.shading_system = True"])
if subject == 'bake':
args.extend(['--python', os.path.join(basedir, "util", "render_bake.py")])
elif subject == 'denoise_animation':
args.extend(['--python', os.path.join(basedir, "util", "render_denoise.py")])
else:
args.extend(["-f", "1"])
return args
2020-10-02 10:10:01 +10:00
def create_argparse():
parser = argparse.ArgumentParser(
description="Run test script for each blend file in TESTDIR, comparing the render result with known output."
)
parser.add_argument("--blender", required=True)
parser.add_argument("--testdir", required=True)
parser.add_argument("--outdir", required=True)
parser.add_argument("--oiiotool", required=True)
parser.add_argument("--device", required=True)
parser.add_argument("--osl", default='none', type=str, choices=["none", "limited", "all"])
parser.add_argument('--batch', default=False, action='store_true')
return parser
def main():
parser = create_argparse()
args = parser.parse_args()
device = args.device
blocklist = BLOCKLIST_ALL
if args.osl == 'none':
blocklist += BLOCKLIST_OSL_NONE
elif args.osl == "limited":
blocklist += BLOCKLIST_OSL_LIMITED
else:
blocklist += BLOCKLIST_OSL_ALL
if device != 'CPU':
blocklist += BLOCKLIST_GPU
if device == 'OPTIX':
blocklist += BLOCKLIST_OPTIX
if args.osl == 'limited':
blocklist += BLOCKLIST_OPTIX_OSL_LIMITED
elif args.osl == 'all':
blocklist += BLOCKLIST_OPTIX_OSL_ALL
Cycles: approximate shadow caustics using manifold next event estimation This adds support for selective rendering of caustics in shadows of refractive objects. Example uses are rendering of underwater caustics and eye caustics. This is based on "Manifold Next Event Estimation", a method developed for production rendering. The idea is to selectively enable shadow caustics on a few objects in the scene where they have a big visual impact, without impacting render performance for the rest of the scene. The Shadow Caustic option must be manually enabled on light, caustic receiver and caster objects. For such light paths, the Filter Glossy option will be ignored and replaced by sharp caustics. Currently this method has a various limitations: * Only caustics in shadows of refractive objects work, which means no caustics from reflection or caustics that outside shadows. Only up to 4 refractive caustic bounces are supported. * Caustic caster objects should have smooth normals. * Not currently support for Metal GPU rendering. In the future this method may be extended for more general caustics. TECHNICAL DETAILS This code adds manifold next event estimation through refractive surface(s) as a new sampling technique for direct lighting, i.e. finding the point on the refractive surface(s) along the path to a light sample, which satisfies Fermat's principle for a given microfacet normal and the path's end points. This technique involves walking on the "specular manifold" using a pseudo newton solver. Such a manifold is defined by the specular constraint matrix from the manifold exploration framework [2]. For each refractive interface, this constraint is defined by enforcing that the generalized half-vector projection onto the interface local tangent plane is null. The newton solver guides the walk by linearizing the manifold locally before reprojecting the linear solution onto the refractive surface. See paper [1] for more details about the technique itself and [3] for the half-vector light transport formulation, from which it is derived. [1] Manifold Next Event Estimation Johannes Hanika, Marc Droske, and Luca Fascione. 2015. Comput. Graph. Forum 34, 4 (July 2015), 87–97. https://jo.dreggn.org/home/2015_mnee.pdf [2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering scenes with difficult specular transport Wenzel Jakob and Steve Marschner. 2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages. https://www.cs.cornell.edu/projects/manifolds-sg12/ [3] The Natural-Constraint Representation of the Path Space for Efficient Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages. https://cg.ivd.kit.edu/english/HSLT.php The code for this samping technique was inserted at the light sampling stage (direct lighting). If the walk is successful, it turns off path regularization using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells the integrator not to blur the brdf roughness further down the path (in a child ray created from BSDF sampling). In addition, using a cascading mechanism of flag values, we cull connections to caustic lights for this and children rays, which should be resolved through MNEE. This mechanism also cancels the MIS bsdf counter part at the casutic receiver depth, in essence leaving MNEE as the only sampling technique from receivers through refractive casters to caustic lights. This choice might not be optimal when the light gets large wrt to the receiver, though this is usually not when you want to use MNEE. This connection culling strategy removes a fair amount of fireflies, at the cost of introducing a slight bias. Because of the selective nature of the culling mechanism, reflective caustics still benefit from the native path regularization, which further removes fireflies on other surfaces (bouncing light off casters). Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
if device == 'METAL':
blocklist += BLOCKLIST_METAL
report = CyclesReport('Cycles', args.outdir, args.oiiotool, device, blocklist, args.osl == 'all')
report.set_pixelated(True)
report.set_reference_dir("cycles_renders")
if device == 'CPU':
report.set_compare_engine('eevee')
else:
report.set_compare_engine('cycles', 'CPU')
# Increase threshold for motion blur, see #78777.
#
# underwater_caustics.blend gives quite different results on Linux and Intel macOS compared to
# Windows and Arm macOS.
#
# OSL tests:
# Blackbody is slightly different between SVM and OSL.
# Microfacet hair renders slightly differently, and fails on Windows and Linux with OSL
#
# both_displacement.blend has slight differences between Linux and other platforms.
test_dir_name = Path(args.testdir).name
if (test_dir_name in {'motion_blur', 'integrator', "displacement"}) or \
((args.osl == 'all') and (test_dir_name in {'shader', 'hair'})):
report.set_fail_threshold(0.032)
# Layer mixing is different between SVM and OSL, so a few tests have
# noticably different noise causing OSL Principled BSDF tests to fail.
if ((args.osl == 'all') and (test_dir_name == 'principled_bsdf')):
report.set_fail_threshold(0.06)
# Volume scattering probability guiding renders differently on different platforms
if (test_dir_name in {'shadow_catcher', 'light'}):
report.set_fail_threshold(0.038)
if (test_dir_name in {'light', 'camera'}):
report.set_fail_threshold(0.02)
report.set_fail_percent(4)
if (test_dir_name in {'volume', 'openvdb'}):
report.set_fail_threshold(0.048)
report.set_fail_percent(3)
Color Management: Add working color space for blend files * Store scene linear to XYZ conversion matrix in each blend file, along with the colorspace name. The matrix is the source of truth. The name is currently only used for error logging about unknown color spaces. * Add Working Space option in color management panel, to change the working space for the entire blend file. Changing this will pop up a dialog, with a default enabled option to convert all colors in the blend file to the new working space. Note this is necessarily only an approximation. * Link and append automatically converts to the color space of the main open blend file. * There is builtin support for Rec.709, Rec.2020 and ACEScg working spaces, in addition to the working space of custom OpenColorIO configs. * Undo of working space for linked datablocks isn't quite correct when going to a smaller gamut working space. This can be fixed by reloading the file so the linked datablocks are reloaded. Compatibility with blend files saved with a custom OpenColorIO config is tricky, as we can not detect this. * We assume that if the blend file has no information about the scene linear color space, it is the default one from the active OCIO config. And the same for any blend files linked or appended. This is effectively the same behavior as before. * Now that there is a warning when color spaces are missing, it is more likely that a user will notice something is wrong and only save the blend file with the correct config active. * As no automatic working space conversion happens on file load, there is an opportunity to correct things by changing the working space with "Convert Colors" disabled. This can also be scripted for all blend files in a project. Ref #144911 Pull Request: https://projects.blender.org/blender/blender/pulls/145476
2025-08-31 02:58:12 +02:00
# OSL blackbody output is a little different.
if (test_dir_name in {'colorspace'}):
report.set_fail_threshold(0.05)
ok = report.run(args.testdir, args.blender, get_arguments, batch=args.batch)
sys.exit(not ok)
if __name__ == "__main__":
main()