PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
5.99k stars 1.18k forks source link

Storm: Shader compile error with mx::heighttonormal nodes #2281

Open ashwinbhat opened 1 year ago

ashwinbhat commented 1 year ago

Description of Issue

When we use MaterialX heighttonormal node to convert a height map to normal map, Storm reports a shader error. error C7522: OpenGL requires constants to be initialized

Steps to Reproduce

  1. Extract contents of zip file
  2. Open testPreviewSurfaceNormalMap_mtlx.usda.
  3. It should render 4 planes, one of them is missing the texture and bump mapping testBumpMapping.zip image

System Information (OS, Hardware)

Windows x64

Package Versions

USD Dev at 1d2f18b

Build Flags

--tests --openimageio --opencolorio --materialx

ashwinbhat commented 1 year ago

Attached is the shader dump. program27_shader0_FRAGMENT_SHADER.glsl.txt

The filter kernels are uninitialized

const float c_box_filter_weights[84];
const float c_gaussian_filter_weights[84];

Adding a quick fix locally to initialize variables on emitVariableDeclarations seems to do it. https://github.com/PixarAnimationStudios/USD/blob/5c5ebddff35012461a2b0ba773c47f05730cbab4/pxr/imaging/hdSt/materialXShaderGen.cpp#L294-L296

image

tallytalwar commented 1 year ago

Filed as internal issue #USD-8019

ashwinbhat commented 1 year ago

To clarify:

 emitVariableDeclarations(constants, _syntax->getConstantQualifier(), 
                          mx::Syntax::SEMICOLON,  
                          mxContext, mxStage, true); 

Works, but I'm not sure if this will break others use cases.