Skip to content

Ariadne: physically based materials and the scene's environment - #1503

Merged
transfix merged 5 commits into
masterfrom
scene/pbr-materials
Nov 24, 2026
Merged

transfix merged 5 commits into
masterfrom
scene/pbr-materials

Conversation

@transfix

@transfix transfix commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

A geometry node can now be shaded physically. Until now a scene material was Phong only (color, ambient, diffuse, specular), so a document could not say "brushed metal" or "car paint". This is item 5 of the Ariadne scene-format gap plan.

scene:
  environment:                    # optional: the light from all round
    sky: [0.55, 0.62, 0.75]
    horizon: [0.45, 0.45, 0.45]
    ground: [0.16, 0.14, 0.12]
  nodes:
    - node: body
      source: { file: car.glb }
      material:
        color: [0.75, 0.05, 0.05]
        pbr: { metallic: 0.6, roughness: 0.35, coat: { strength: 1, roughness: 0.05 } }
    - node: lamp
      source: { sphere: 0.2 }
      material: { color: [0, 0, 0], pbr: { emissive: [1.0, 0.85, 0.5] } }

The keys

  • material: { pbr: ... } shades the node with VTK's PBR instead of Phong.
    • metallic is 0 (default) for a dielectric and 1 for a metal.
    • roughness is 0 for a mirror and 1 for matte (default 0.5).
    • emissive: [r, g, b] is a colour the node glows with, lit or not.
    • coat is a clear coat, as a strength or { strength, roughness }.
    • Values are 0..1, clamped with a warning. pbr: true takes the defaults.
  • The base colour is what the node shows when Phong-shaded: its color, texture or mesh colours, read as sRGB.
  • Phong keys (ambient, diffuse, specular, specular_power) do not apply, and warn beside pbr:.
  • scene: environment: is image-based lighting from a gradient: sky straight up, through horizon, to ground straight down, about +z.
    • A scene with a pbr: node and no environment: gets a default, about as bright as Phong's ambient: 0.2.
    • environment: false (or none) uses the lights alone.
    • Phong nodes ignore it.

Three choices to review

VTK's PBR doesn't fit next to Phong nodes as it stands. Each point below is one post-replacement line in the PBR shader, on both VTK mappers (desktop and the low-memory one WebGL uses).

  1. Colours are sRGB. VTK takes a PBR base colour as linear and writes pow(color, 1/2.2), which turned [0.8, 0.2, 0.2] into a pale pink. The shader now linearises the base colour (uniform, texture or per-vertex) first, so a colour means the same on a PBR node as on a Phong one. The emissive colour is linearised the same way.
  2. Lights are multiplied by π. VTK's BRDF divides by π, so under the same rig a PBR surface came out about a third as bright as its Phong neighbour. The lights' sum is multiplied back by π: a light of intensity 1 lights a PBR surface face on as brightly as a Phong surface with diffuse: 1. three.js's legacy (non-physical) light mode did the same.
  3. Emissive works without a texture. VTK only reads its emissive factor through an emissive texture. The shader now reads the factor directly.

Without the environment, VTK's PBR has no ambient term at all, so a side the lights miss is black. That is why a pbr: node gets a default environment.

Changes

  • GeometryNode: setPBR, setMetallic, setRoughness, setEmissive, setCoat. State keys pbr, metallic, roughness, emissive_r/g/b, coat and coat_roughness are made only when first set. Off by default; off again, the node is Phong-shaded as before.
  • SceneGraph: setImageBasedLighting, setEnvironment, resetEnvironment, environment, environmentTexture.
    • The environment is a 128 x 64 equirectangular image, 8-bit sRGB, so WebGL2 filters it without a float extension.
    • It follows the scene onto a new renderer, as the lights do.
    • Off by default.
  • ViewportManager: a mirror viewport copies its source's image-based lighting along with its lights, so viewport widgets are lit the same.
  • Loader and realizer:
    • SceneNode::pbr_* and Scene::environment_*.
    • apply_node_material switches a pbr: node, which covers its mesh, model:, LOD rungs, a dataset's meshes and ribbons. mesh_lab's own copy of the material code takes pbr: too.
    • realize_scene turns the environment on for a scene with environment: or a pbr: node.
  • ARIADNE.md §5.4: a "Physically based materials" paragraph.
  • New example: examples/ariadne/documents/pbr_materials.ari, with rows of paint and gold spheres across roughness, coated car paint, a lamp and a Phong sphere to compare.

Tests

  • New cvcgl_pbr_material, offscreen. A plate faces a light and the camera straight on, so its centre pixel has N = V = L and VTK's BRDF has a closed form.
    • State and property: setPBR switches the actor to VTK_PBR and back (a script's "off" or "True" in state too). Values clamp, a value set before the switch applies, and emissive is made linear.
    • Colour: a base colour of [0.8, 0.2, 0.2] lit at intensity 1 draws (202, 58, 58), exactly the closed form. VTK as it stands would draw (120, 34, 34), and linear with no π, a pale (227, 123, 123).
    • Emissive: (0.5, 0.25, 0), unlit, draws (128, 64, 0).
    • Phong: face on with diffuse 1, Phong shows its colour (204, 51, 51), and setPBR(false) brings exactly that back.
    • Image-based lighting:
      • off, an unlit plate is black;
      • a grey environment lights a white plate (126, 126, 126);
      • the sky lights a face looking up (233) and the ground one looking down (58);
      • a polished metal shows the environment's blue as (51, 102, 204), its exact colour.
    • Renderer switch: the environment follows the scene to a new renderer and leaves the old one.
  • New cvcgl_ariadne_pbr, 17 checks:
    • Through AriRuntime: each pbr: node is PBR with its values and a Phong node stays Phong. The main view and the viewport widget's mirror are lit by the document's environment, and an emissive node glows orange.
    • Through realize_scene alone: a pbr: node gets the default environment, environment: false turns it off, a scene with neither turns nothing on, and an environment: alone turns it on.
  • ariadne_loader_test PbrMaterialAndEnvironment:
    • every key is parsed and defaults are kept;
    • bad values are clamped or left out, with warnings;
    • Phong keys beside pbr: warn;
    • environment: spelled false, none, true and a list.

Verified locally

Windows, MSVC, with cvcGL (no examples, no pycvc). The full ctest suite ran twice.

On the original base (master 5949edc), 8,405 tests:

  • Pass: everything but nine.
  • Already failing here: cvcgl_contour_lab and cvcgl_volume_grid_contours (this build has no cvc::planar), and cvcgl_ari_golden's seven goldens, with the same pixel counts as code without this change.
  • Load: six state and frame timing tests failed under load and pass alone.

Merged with master 7f388fc, 8,541 tests at -j 12:

  • Pass: everything but 18.
  • Already failing here: the same three as above.
  • Load: 12 threading, async, lock and frame tests, and cvcmedia_audio_output, all pass rerun at -j 2.
  • Timeouts: the two plant-convergence tests, which take longer than the 900 s cap.
  • Goldens: contour_tiler and volume_grid_contours changed pixel counts relative to the first run. Master's own changes moved them: master plus Ariadne: a scene node's own on_pick: #1491, with no PBR code, gives the same counts.

pbr_materials.ari loads under ShippedExamplesDeclareWhatTheyNeed.

Not verified: Linux, macOS, wasm (WebGL2's prefilter pass renders to half-float cube maps; the environment image itself is 8-bit for that reason), and pycvc.

Schema

#1464 (the closed schema, which every load checks) merged first, so this PR carries its own keys (c10a837, after merging master in as 3a27560):

  • a material's pbr: a flag, or { metallic, roughness, emissive, coat }, where coat is a number or { strength, roughness };
  • environment in both scene definitions: a flag, none, or { sky, horizon, ground }.

With the validator built in: ariadne_schema_test passes 13 (one skip, the without-validator case) and ariadne_loader_test passes 263. pbr_materials.ari and cvcgl_ariadne_pbr's document validate (ari validate). On the merged code, cvcgl_pbr_material and cvcgl_ariadne_pbr (17/17) pass.

Not done

  • Metallic/roughness, normal and emissive textures.
  • An image as the environment (an HDRI).
  • The materials a glTF model carries (cvc::model::material already has metallic, roughness and emissive).
  • The swarm layers, which take only opacity and specular from material: by design.

A geometry node's `material: { pbr: { metallic, roughness, emissive, coat } }`
shades it with VTK's PBR instead of Phong, and `scene: environment: { sky,
horizon, ground }` lights it from all round (image-based lighting from a
generated gradient). A scene with a pbr: node and no environment: gets a
default one; `environment: false` uses the lights alone. Gap item 5 of the
scene-format plan.

- GeometryNode::setPBR, setMetallic, setRoughness, setEmissive, setCoat
  (state keys pbr, metallic, roughness, emissive_r/g/b, coat, coat_roughness).
  Three post-replacement edits to VTK's PBR shader, on both its poly-data
  mappers: the base colour read as sRGB (made linear) as a Phong surface takes
  it; the lights' sum times pi, so a light lights a PBR surface face on as
  brightly as a Phong one with diffuse 1; emissive without an emissive texture.
- SceneGraph::setImageBasedLighting / setEnvironment / resetEnvironment: an
  8-bit sRGB equirectangular gradient, +z up, following the scene onto a new
  renderer; ViewportManager's mirrors copy it with the lights.
- Loader: SceneNode::pbr_*, Scene::environment_*; realize_scene turns the
  environment on; apply_node_material (and mesh_lab's copy) switch pbr: nodes.
- docs/ARIADNE.md §5.4 "Physically based materials"; example
  examples/ariadne/documents/pbr_materials.ari.
- Tests: cvcgl_pbr_material (pixels against VTK's BRDF in closed form),
  cvcgl_ariadne_pbr, loader PbrMaterialAndEnvironment.
@transfix
transfix enabled auto-merge (squash) November 23, 2026 21:32
The closed schema (#1464, merged into this branch from master) gains a
material's pbr (a flag, or { metallic, roughness, emissive, coat } with coat a
number or { strength, roughness }) and environment in both scene definitions (a
flag, none, or { sky, horizon, ground }). Checked with the validator built in:
ariadne_schema_test 13 (one skip), ariadne_loader_test 263, and
pbr_materials.ari and cvcgl_ariadne_pbr's document validate.
src/cvcGL/CMakeLists.txt conflicted where this branch registers
cvcgl_ariadne_pbr and #1491 cvcgl_ariadne_node_pick at the same place: both
kept. With the validator: ariadne_schema_test 13 (one skip), ariadne_loader_test
264; cvcgl_pbr_material, cvcgl_ariadne_pbr 17/17 and cvcgl_ariadne_node_pick
23/23 on the merge.
@transfix
transfix merged commit f83c8cb into master Nov 24, 2026
31 checks passed
@transfix
transfix deleted the scene/pbr-materials branch November 24, 2026 07:00
transfix added a commit that referenced this pull request Nov 24, 2026
…ment, #1469

# Conflicts:
#	src/cvc/ariadne/loader.cpp
#	src/cvc/tests/ariadne_loader_test.cpp
transfix added a commit that referenced this pull request Nov 24, 2026
…ment

# Conflicts:
#	src/cvc/ariadne/schema/ari.v1.schema.json
#	src/cvc/tests/ariadne_loader_test.cpp
#	src/cvcGL/ariadne/scene_realize.cpp
transfix added a commit that referenced this pull request Nov 24, 2026
…R materials and environment)

# Conflicts:
#	src/cvc/tests/ariadne_loader_test.cpp
transfix added a commit that referenced this pull request Nov 24, 2026
…adow cache)

Conflict in ViewportManager.cpp: master's #1503 copies a scene's image-based
lighting into a mirror; SH2 syncs a mirror's lights only on a change. Both kept,
the lights first, then the environment.
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.

1 participant