Repository navigation
Bake untranslatable worlds into an environment map - #157
Open
ishaanshah wants to merge 2 commits into
Open
ishaanshah wants to merge 2 commits into
ishaanshah wants to merge 2 commits into
Conversation
…r fallback The XML export operator now sets export_ctx.strict from scene.mitsuba.export_mode, as the render engine does. Relaxed mode's colour fallback goes through the constant-colour conversion instead of returning a raw RGBA tuple Mitsuba's parser rejects.
A world that ``convert_world`` cannot translate (a Sky Texture, a Mix or Add Shader surface, a procedural chain, an Environment Texture that does not feed the Background directly) is currently dropped with a warning, which costs the scene its main light. It is now rendered once with Cycles through an equirectangular camera and exported as an ``envmap`` instead. The bake runs on a copy of the world, so the user's data is untouched. Its camera lays the map out in the parametrization of an environment texture lookup, so the emitter takes the same ``to_world`` as a translated environment texture, and ``scale`` 1 since the map already holds the strength. The map is written through ``export_image`` like any other texture. The world's ray visibility is put back on the emitter, as for a translated world. A world that switches on a Light Path output is baked with the values an indirect diffuse ray reports. The bake traces camera rays, so a world that shows the camera a backdrop and lights the scene with something else would otherwise bake the backdrop. Node groups holding a Light Path node are copied before they are changed. This is a heuristic: one environment map cannot hold a different answer per ray type. The ``bake_world`` export option (default on) and ``bake_world_resolution`` (map height, default 1024) control it, in relaxed mode only. The bake is lossy: the map has a fixed resolution, so features smaller than a texel (such as a sun disk) are spread out, and a Light Path world keeps only one branch. Strict mode therefore still skips the world. The render engine never bakes: the bake needs an operator, which the render job thread cannot run. Tests: unit tests for Sky Texture and Mix Shader worlds, an indirect environment texture whose bake must reproduce the source image, the option, strict mode, untouched translatable worlds, ray visibility and a Light Path world; and a roundtrip test rendering a direction-encoding world in Mitsuba and in Cycles from six directions, which pins the orientation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A world that
convert_worldcannot translate is currently dropped with a warning, which leaves the scene without its main light. This affects common setups: a Sky Texture, a Mix or Add Shader surface (often used to separate the camera backdrop from the lighting), procedural chains, and Environment Textures that do not feed the Background directly (e.g. through a Gamma or Hue/Saturation node). On a set of about 1000 production scenes, this dropped the world in roughly 40% of them, mostly Sky Textures.This PR bakes such a world into an
envmapinstead, and includes a couple of small fixes to the exporter.Bake untranslatable worlds
When
convert_worldraises,export_worldnow renders the world once with Cycles through an equirectangular camera and exports the result as anenvmap:to_worldas a translated environment texture, andscale = 1since the map already contains the strength.export_image, like any other texture.Light Path. A world that switches on a Light Path output is baked with the values an indirect diffuse ray reports (
Is Camera Ray = 0,Is Diffuse Ray = 1, depth 1, ...). The bake traces camera rays, so otherwise a world that shows the camera a backdrop and lights the scene with an HDRI would bake the backdrop. Node groups containing a Light Path node are copied before they are changed. This is a heuristic: one environment map cannot give a different answer per ray type, so for such worlds the camera backdrop or glossy reflections can differ from Cycles.Options.
bake_world(default on) andbake_world_resolution(map height, width is twice that; default 1024) on the export operator, in relaxed mode only. The bake is lossy: the map has a fixed resolution, so features smaller than a texel (such as a sun disk) are spread out, and a Light Path world keeps only one branch. Strict mode therefore still skips the world with a warning. The render engine never bakes: the bake runs a render operator, which is not available from the render job thread.Export operator: honour the scene's exporting mode
The XML export operator now sets
export_ctx.strictfromscene.mitsuba.export_mode, as the render engine already does. Until now it always exported in strict mode, whatever the scene's setting.Honouring relaxed mode exposed a bug in its colour fallback. When a colour input is driven by something the converter cannot handle,
eval_colorlogs a warning and falls back to the socket's default colour. That fallback returned the bare_to_color(...)tuple, whereas every other branch returns a colour plugin (export_ctx.spectrum(...), or an unboundedsrgbfor values outside [0, 1]); Mitsuba rejects the tuple when the scene is loaded. The path was unreachable from the operator before, since strict mode replaces such a material with the error BSDF instead. The constant-colour conversion now lives in one helper,_color_constant, which both the resolved-constant branch and the fallback use, so the fallback also gets the out-of-range handling.Examples
Tests
tests/unit/test_world_export.py: Sky Texture and Mix Shader worlds are baked into anenvmapwhose file exists and loads in relaxed mode, while strict mode skips the world; an indirectly connected environment texture bakes back to its source image; the option turns baking off; translatable worlds are not baked; ray visibility is preserved; a Light Path world bakes its lighting branch.tests/roundtrip/test_world_roundtrip.py: a world whose colour encodes the view direction is baked, then rendered in Mitsuba and in Cycles from six directions; they agree to within 0.001, which pins the orientation of the map.tests/unit/test_export_warnings.py: the operator honours the exporting mode, and the relaxed colour fallback produces a valid spectrum.