Skip to content

OSL render tests: match MaterialXTest's OSL settings - #86

Merged
ppenenko merged 6 commits into
metashade/devfrom
metashade/osl-render-bindings
Oct 27, 2026
Merged

ppenenko merged 6 commits into
metashade/devfrom
metashade/osl-render-bindings

Conversation

@ppenenko

Copy link
Copy Markdown
Member

Makes the pytest OSL backend render exactly like MaterialXTest's [renderosl] tests. All 143 OSL renders under contrib/renders/aswf are now pixel-identical to MaterialXTest's.

Follows up on #85.

Commits

Split so each can be cherry-picked upstream on its own:

  1. Bind remaining OslRenderer and OSL GenOptions settings in Python. Adds setEnvShaderParameterOverrides, setDataLibraryOSOPath, useOslCommandString, setAaLit, setAaUnlit, setOSLCmdStr and GenOptions.oslConnectCiWrapper. This is the only C++ change and a candidate for upstreaming.
  2. Resolve repo-relative test images regardless of working directory. Test documents reference images such as resources/Images/grid.png relative to the repo root, so the search_path fixture now includes the repo root. Before this, testrender rendered those textures as missing.
  3. Render OSL tests with MaterialXTest's OSL settings. Uses the new bindings in place of the previous workarounds (copying the utility shaders and patching the envmap):
    • -aa 2 for lit and 1 for unlit renders
    • envmap_filename as an environment shader override
    • oslConnectCiWrapper
    • no fileTextureVerticalFlip
  4. Update the OSL shader baselines for those settings: adds mx_set_ci and removes the mx_transform_uv V-flip.
  5. Match MaterialXTest's tangent frame. MaterialXTest registers C++ TangentOsl/BitangentOsl node implementations. Python can't register those, so the OSL backend puts the same expressions into the inline source of the stdlib genosl tangent and bitangent implementations. Only those two OSL implementations are affected.
  6. Regenerate the OSL baselines with that tangent frame.

Verification

  • python -m pytest contrib/tests -m osl -n 8: 100 passed.
  • Ran MaterialXTest [renderosl] (Debug) with outputDirectory set in the build copy of _options.mtlx. It writes the same flat <stem>/ layout as contrib/renders/aswf, so tests_to_html.py -i1 contrib/renders/aswf -i2 <MaterialXTest output> -l1 osl -l2 osl -d pairs all 143 images directly, with no adapter.
  • A Pillow pixel diff of all 143 pairs found no differences.

Known limitation

OslRenderer doesn't quote paths in its oslc and testrender command lines, so the backend still rejects paths containing spaces (AcademySoftwareFoundation#3120).

Add Python bindings for OslRenderer.setEnvShaderParameterOverrides,
setDataLibraryOSOPath, useOslCommandString, setAaLit, setAaUnlit and
setOSLCmdStr, and for GenOptions.oslConnectCiWrapper.  These are the
settings MaterialXTest's OSL render tests use, so Python drivers of
OslRenderer can reproduce its renders.
Test documents reference images relative to the repo root, e.g.
"resources/Images/grid.png", which MaterialXTest resolves against its
data root.  The pytest search path didn't include the repo root, so
these only loaded when pytest ran from the repo root: ImageHandler falls
back to the working directory, but OSL's testrender received the bare
relative path and rendered without the texture.
Use the new OslRenderer and GenOptions bindings so OSL renders match
MaterialXTest's [renderosl] output:

- -aa 2 for lit and 1 for unlit outputs, as MaterialXTest's
  non-reference-quality renders.
- The radiance map as an environment shader override, replacing the
  patched copies of the utility shaders, which are now compiled straight
  from the repo.
- oslConnectCiWrapper, so color4 and vector4 alpha renders as
  transparency.
- No fileTextureVerticalFlip, which MaterialXTest doesn't set for OSL;
  with it, textures rendered upside down relative to MaterialXTest.

The tangent and bitangent overrides MaterialXTest registers for
testrender are C++ ShaderNodeImpl subclasses and remain a known
difference.
Regenerated with oslConnectCiWrapper, which adds the mx_set_ci terminal
node, and without fileTextureVerticalFlip, which drops the V flip from
mx_transform_uv.
Substitute MaterialXTest's TangentOsl and BitangentOsl expressions for
the inline source of the stdlib genosl tangent and bitangent
implementations, since Python can't register ShaderNodeImpls. With this,
all 143 OSL renders are pixel-identical to MaterialXTest's.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused bindings and backend changes align with the existing C++ render-test behavior, with consistent regenerated baselines and no unresolved blocking findings.

No open issues 🎉

What changed in this PR

Aligns the pytest OSL backend with MaterialXTest’s render settings, completing the follow-up to #85 and replacing earlier rendering workarounds.

Changes:

  • Exposes additional OSL renderer settings and oslConnectCiWrapper through Python bindings.
  • Matches sampling, environment-map, texture-orientation, and tangent-frame settings; adds repository-root image lookup.
  • Regenerates OSL shader baselines and documents the updated behavior.
File Description
source/​PyMaterialX/​PyMaterialXRenderOsl/​PyOslRenderer.cpp Exposes additional renderer controls to Python.
source/​PyMaterialX/​PyMaterialXGenShader/​PyGenOptions.cpp Exposes the Ci-wrapper generation option.
contrib/​tests/​rendertest/​backends.py Aligns OSL generation and rendering settings.
contrib/​tests/​README.md Documents matching settings and tangent overrides.
contrib/​tests/​conftest.py Adds repository-root image lookup.
contrib/​renders/​aswf/​vertical_layering/​vertical_layering_ex5_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​vertical_layering/​vertical_layering_ex2_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​translucent_bsdf/​translucent_bsdf_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​toon_shade/​surfacematerial.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​subsurface_bsdf/​subsurface_4_forward_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​subsurface_bsdf/​subsurface_4_backward_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​subsurface_bsdf/​subsurface_3_weighted_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​subsurface_bsdf/​subsurface_2_radius_5_0_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​subsurface_bsdf/​subsurface_2_radius_0_025_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​subsurface_bsdf/​subsurface_2_radius_0_01_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​subsurface_bsdf/​subsurface_1_common_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​starfield/​starfield_out.osl Wraps color output as a closure.
contrib/​renders/​aswf/​sheen_bsdf/​zeltner_sheen_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​sheen_bsdf/​conty_kulla_sheen_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​oren_nayar_diffuse/​oren_nayar_diffuse_out5.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​oren_nayar_diffuse/​oren_nayar_diffuse_out4.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​oren_nayar_diffuse/​oren_nayar_diffuse_out3.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​oren_nayar_diffuse/​oren_nayar_diffuse_out2.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​oren_nayar_diffuse/​oren_nayar_diffuse_out1.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​multiply_bsdf/​multiply_bsdf_test_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​mix_bsdf/​mix_bsdf_test3_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​mix_bsdf/​mix_bsdf_test1_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​mix_bsdf/​IMP_substrateshader_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​layer_bsdf/​layer_bsdf_test2_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​heighttonormal/​NG_heighttonormal_vec_out.osl Updates texture orientation and wraps vector output.
contrib/​renders/​aswf/​gooch_shade/​redblue_gooch_material.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​gooch_shade/​default_gooch_material.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​generalized_schlick/​schlick_bsdf_T_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​generalized_schlick/​schlick_bsdf_RT_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​generalized_schlick/​schlick_bsdf_R_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​edge_brighten/​edge_brighten_out.osl Wraps color output as a closure.
contrib/​renders/​aswf/​dielectric/​dielectric_bsdf_T_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​dielectric/​dielectric_bsdf_RT_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​dielectric/​dielectric_bsdf_R_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​dielectric/​dielectric_bsdf_layer_RT_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​conductor/​test_conductor_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​color3_vec3_cm_test/​height_to_normal_cm_out.osl Updates texture orientation and wraps vector output.
contrib/​renders/​aswf/​burley_diffuse/​test_burley_diffuse_out.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​bsdf_graph/​test_mybsdf_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​aswf/​blur/​blur_vector3_out.osl Updates texture orientation and wraps vector output.
contrib/​renders/​aswf/​blur/​blur_vector2_out.osl Updates texture orientation and wraps vector output.
contrib/​renders/​aswf/​blur/​blur_float_out.osl Updates texture orientation and wraps scalar output.
contrib/​renders/​aswf/​blur/​blur_color4_out.osl Updates texture orientation and wraps color output.
contrib/​renders/​aswf/​blur/​blur_color3_out.osl Updates texture orientation and wraps color output.
contrib/​renders/​aswf/​blur/​blur_cellnoise_out.osl Wraps scalar output as a closure.
contrib/​renders/​aswf/​blackbody/​Blackbody.osl Adds Ci-wrapper baseline.
contrib/​renders/​aswf/​add_bsdf/​add_bsdf_test_out.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Revit/​other/​turbulence3d_object_out.osl Wraps scalar output as a closure.
contrib/​renders/​adsk/​Examples/​Revit/​other/​turbulence2d_object_out.osl Wraps scalar output as a closure.
contrib/​renders/​adsk/​Examples/​Revit/​mirror/​M_legacy_mirror.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Revit/​glazing/​M_legacy_glazing.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Fusion/​transparent/​Gemstone_Ruby.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Fusion/​transparent/​Gemstone_Diamond.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Fusion/​metal/​Copper_Polished.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Fusion/​metal/​Anodized_Red_Rough.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Fusion/​metal/​Anodized_Blue_Glossy.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Fusion/​glazing/​Glazing_test.osl Updates Ci wrapper and tangent frame.
contrib/​renders/​adsk/​Examples/​Fusion/​bitmap/​bitmapoutput.osl Updates texture orientation and wraps color output.

Review effort: Balanced

@ppenenko
ppenenko merged commit 5ef75a7 into metashade/dev Oct 27, 2026
34 of 37 checks passed
@ppenenko
ppenenko deleted the metashade/osl-render-bindings branch October 27, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants