Hi guys,
I want to enable displacement shading for HdStorm on my material and I am using the following code to achieve that by directly setting up a material network map:
HdMaterialNode previewSurfaceNode;
previewSurfaceNode.identifier = UsdImagingTokens->UsdPreviewSurface;
previewSurfaceNode.path = previewSurfacePath;
HdMaterialNode primVarReaderNode;
primVarReaderNode.identifier = UsdImagingTokens->UsdPrimvarReader_float2;
primVarReaderNode.path = primVarReaderPath;
primVarReaderNode.parameters.insert({_tokens->varname, VtValue(_tokens->st)});
HdMaterialNode textureDisplacementNode;
textureDisplacementNode.identifier = UsdImagingTokens->UsdUVTexture;
textureDisplacementNode.path = textureDisplacementPath;
textureDisplacementNode.parameters.insert(
{_tokens->file,
VtValue(std::string("hydraPOCDisplacement.png"))});
textureDisplacementNode.parameters.insert({_tokens->sourceColorSpace, VtValue(_tokens->raw)});
rel.inputId = textureDisplacementNode.path;
rel.inputName = _tokens->r;
rel.outputId = previewSurfaceNode.path;
rel.outputName = _tokens->displacement;
network.relationships.emplace_back(rel);
rel.inputId = primVarReaderNode.path;
rel.inputName = _tokens->result;
rel.outputId = textureDisplacementNode.path;
rel.outputName = _tokens->st;
network.relationships.emplace_back(rel);
network.nodes.push_back(std::move(primVarReaderNode));
network.nodes.push_back(std::move(textureDiffuseNode));
network.nodes.push_back(std::move(textureNormalNode));
network.nodes.push_back(std::move(textureRoughnessNode));
network.nodes.push_back(std::move(textureAONode));
network.nodes.push_back(std::move(textureDisplacementNode));
network.nodes.push_back(std::move(previewSurfaceNode));
networkMap.map.insert({HdMaterialTerminalTokens->surface, network});
networkMap.map.insert({HdMaterialTerminalTokens->displacement, network});
networkMap.terminals.push_back(previewSurfacePath);
All textures are considered by the preview surface shader except the displacement and I am not sure what is missing to get the geometry shader running and correctly call the displacement shader in previewSurface.glslfx. I was debugging and reading through the code a bit and saw, that HdStMesh::_UpdateDrawItemGeometricShader actually fetches the correct shader source but I wasn’t able to identify the cause of the problem.
Maybe someone has an idea.
Cheers,
Robert