OpenUSD icon indicating copy to clipboard operation
OpenUSD copied to clipboard

shader variant selection causes new mesh instantiation

Open carsonbrownlee opened this issue 9 months ago • 1 comments

Description of Issue

It seems that changing variant sets over shader params causes meshes connected to that material to be re-instantiated and thus rebuilt as dirty bits are then reset. This works, but adds uneccesary time to reload the mesh. Is this expected behavior with the way I am specifying the variant sets? How can I get around this? Changing the connectToSource of the material's shader implementation appears to have the same behavior. Changing the param values in code manually during runtime appears to work as expected, where Material::Sync() is called but not for the mesh.

Steps to Reproduce

  1. put traces into hdEmbreeMesh::new().
  2. run usdview --renderer hdEmbree
  3. swap variant sets on the shader

simple test scene:

#usda 1.0 ()

def Xform "root" ( apiSchemas = ["MaterialBindingAPI"] ) { def Cube "cube" ( apiSchemas = ["MaterialBindingAPI"] ) { rel material:binding = </root/cube/mat/material1> def "mat" { def Material "material1" { token outputs:surface.connect = </root/cube/mat/material1/shader1.outputs:surface> def Shader "shader1" ( variants = { string shading = "blue" } prepend variantSets = "shading" ) { uniform token info:id = "UsdPreviewSurface" token outputs:surface variantSet "shading" = { "red" { color3f inputs:diffuseColor = (1, 0, 0) } "blue" { color3f inputs:diffuseColor = (0, 0, 1) } } } } } } }

System Information (OS, Hardware)

Ubuntu 22.04

Package Versions

tested on USD 23.08 and 24.05

Build Flags

USD/build_scripts/build_usd.py --usd-imaging --embree --openvdb --openimageio

carsonbrownlee avatar May 02 '24 07:05 carsonbrownlee

Filed as internal issue #USD-9611

jesschimein avatar May 02 '24 16:05 jesschimein