Skip to content

Commit

Permalink
hdPrman: moving creation of fallback materials to render param base c…
Browse files Browse the repository at this point in the history
…lass. The new fallback materials are based on the interactive mode.

The difference in the materials is the volume albedo and the double-sidedness attributes.

(Internal change: 2197749)
  • Loading branch information
unhyperbolic authored and lkerley committed Jan 7, 2022
1 parent c20b2bd commit 7b85a31
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 232 deletions.
2 changes: 1 addition & 1 deletion third_party/renderman-24/plugin/hdPrman/gprim.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class HdPrman_Gprim : public BASE
virtual riley::MaterialId
_GetFallbackMaterial(HdPrman_RenderParam *renderParam)
{
return renderParam->fallbackMaterial;
return renderParam->GetFallbackMaterialId();
}

// Populate primType and primvars.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,9 @@ HdPrman_InteractiveRenderParam::Begin(HdRenderDelegate *renderDelegate)
// Riley setup
//
static const RtUString us_circle("circle");
static const RtUString us_defaultColor("defaultColor");
static const RtUString us_default("default");
static const RtUString us_density("density");
static const RtUString us_densityFloatPrimVar("densityFloatPrimVar");
static const RtUString us_diffuseColor("diffuseColor");
static const RtUString us_diffuseDoubleSided("diffuseDoubleSided");
static const RtUString us_displayColor("displayColor");
static const RtUString us_lightA("lightA");
static const RtUString us_main_cam("main_cam");
static const RtUString us_main_cam_projection("main_cam_projection");
static const RtUString us_pv_color("pv_color");
static const RtUString us_pv_color_resultRGB("pv_color:resultRGB");
static const RtUString us_PxrDomeLight("PxrDomeLight");
static const RtUString us_PxrPerspective("PxrPerspective");
static const RtUString us_PxrPrimvar("PxrPrimvar");
static const RtUString us_PxrSurface("PxrSurface");
static const RtUString us_PxrVolume("PxrVolume");
static const RtUString us_shadowDistance("shadowDistance");
static const RtUString us_shadowFalloff("shadowFalloff");
static const RtUString us_simpleTestSurface("simpleTestSurface");
static const RtUString us_simpleVolume("simpleVolume");
static const RtUString us_specularDoubleSided("specularDoubleSided");
static const RtUString us_specularEdgeColor("specularEdgeColor");
static const RtUString us_specularFaceColor("specularFaceColor");
static const RtUString us_specularModelType("specularModelType");
static const RtUString us_varname("varname");

riley::CoordinateSystemList const k_NoCoordsys = { 0, nullptr };

Expand Down Expand Up @@ -326,58 +303,7 @@ HdPrman_InteractiveRenderParam::Begin(HdRenderDelegate *renderDelegate)
_fallbackLightAttrs);
}

// Materials
fallbackMaterial = riley::MaterialId::InvalidId();
std::vector<riley::ShadingNode> materialNodes;

riley::ShadingNode pxrPrimvar_node;
pxrPrimvar_node.type = riley::ShadingNode::Type::k_Pattern;
pxrPrimvar_node.name = us_PxrPrimvar;
pxrPrimvar_node.handle = us_pv_color;
pxrPrimvar_node.params.SetString(us_varname, us_displayColor);
// Note: this 0.5 gray is to match UsdImaging's fallback.
pxrPrimvar_node.params.SetColor(us_defaultColor,
RtColorRGB(0.5, 0.5, 0.5));
pxrPrimvar_node.params.SetString(RixStr.k_type, RixStr.k_color);
materialNodes.push_back(pxrPrimvar_node);

riley::ShadingNode pxrSurface_node;
pxrSurface_node.type = riley::ShadingNode::Type::k_Bxdf;
pxrSurface_node.name = us_PxrSurface;
pxrSurface_node.handle = us_simpleTestSurface;
pxrSurface_node.params.SetColorReference(us_diffuseColor,
us_pv_color_resultRGB);
pxrSurface_node.params.SetInteger(us_specularModelType, 1);
pxrSurface_node.params.SetInteger(us_diffuseDoubleSided, 1);
pxrSurface_node.params.SetInteger(us_specularDoubleSided, 1);
pxrSurface_node.params.SetColor(us_specularFaceColor,
RtColorRGB(0.04f));
pxrSurface_node.params.SetColor(us_specularEdgeColor,
RtColorRGB(1.0f));
materialNodes.push_back(pxrSurface_node);

fallbackMaterial = _riley->CreateMaterial(
riley::UserId::DefaultId(),
{static_cast<uint32_t>(materialNodes.size()), &materialNodes[0]},
RtParamList());

fallbackVolumeMaterial = riley::MaterialId::InvalidId();
{
std::vector<riley::ShadingNode> materialNodes;
riley::ShadingNode pxrVolume_node;
pxrVolume_node.type = riley::ShadingNode::Type::k_Bxdf;
pxrVolume_node.name = us_PxrVolume;
pxrVolume_node.handle = us_simpleVolume;
pxrVolume_node.params.SetString(us_densityFloatPrimVar, us_density);
// 18% albedo chosen to match Storm's fallback volume shader.
pxrVolume_node.params.SetColor(us_diffuseColor,
RtColorRGB(0.18, 0.18, 0.18));
materialNodes.push_back(pxrVolume_node);
fallbackVolumeMaterial = _riley->CreateMaterial(
riley::UserId::DefaultId(),
{static_cast<uint32_t>(materialNodes.size()), materialNodes.data()},
RtParamList());
}
_CreateFallbackMaterials();
}

void
Expand Down
86 changes: 3 additions & 83 deletions third_party/renderman-24/plugin/hdPrman/offlineRenderParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ HdPrman_OfflineRenderParam::Initialize(
RtParamList rileyOptions,
riley::ShadingNode integratorNode,
riley::Extent outputFormat, TfToken outputFilename,
std::vector<riley::ShadingNode> const & fallbackMaterialNodes,
std::vector<riley::ShadingNode> const & fallbackVolumeNodes,
std::vector<RenderOutput> const & renderOutputs)
{
_options = rileyOptions;
Expand All @@ -55,8 +53,8 @@ HdPrman_OfflineRenderParam::Initialize(
GetCameraContext().Begin(AcquireRiley());

_SetRenderTargetAndDisplay(outputFormat, outputFilename);
_SetFallbackMaterial(fallbackMaterialNodes);
_SetFallbackVolumeMaterial(fallbackVolumeNodes);

_CreateFallbackMaterials();
}

void
Expand Down Expand Up @@ -105,67 +103,7 @@ HdPrman_OfflineRenderParam::InitializeWithDefaults()
_SetRenderTargetAndDisplay(format, TfToken("default.exr"));
}

// Default material
{
static const RtUString us_PxrPrimvar("PxrPrimvar");
static const RtUString us_PxrSurface("PxrSurface");
static const RtUString us_simpleTestSurface("simpleTestSurface");
static const RtUString us_pv_color("pv_color");
static const RtUString us_pv_color_resultRGB("pv_color:resultRGB");
static const RtUString us_varname("varname");
static const RtUString us_displayColor("displayColor");
static const RtUString us_defaultColor("defaultColor");
static const RtUString us_diffuseColor("diffuseColor");
static const RtUString us_specularEdgeColor("specularEdgeColor");
static const RtUString us_specularFaceColor("specularFaceColor");
static const RtUString us_specularModelType("specularModelType");

std::vector<riley::ShadingNode> materialNodes;
riley::ShadingNode pxrPrimvar_node;
pxrPrimvar_node.type = riley::ShadingNode::Type::k_Pattern;
pxrPrimvar_node.name = us_PxrPrimvar;
pxrPrimvar_node.handle = us_pv_color;
pxrPrimvar_node.params.SetString(us_varname, us_displayColor);
// Note: this 0.5 gray is to match UsdImaging's fallback.
pxrPrimvar_node.params.SetColor(
us_defaultColor,
RtColorRGB(0.5, 0.5, 0.5));
pxrPrimvar_node.params.SetString(RixStr.k_type, RixStr.k_color);
materialNodes.push_back(pxrPrimvar_node);

riley::ShadingNode pxrSurface_node;
pxrSurface_node.type = riley::ShadingNode::Type::k_Bxdf;
pxrSurface_node.name = us_PxrSurface;
pxrSurface_node.handle = us_simpleTestSurface;
pxrSurface_node.params.SetColorReference(
us_diffuseColor,
us_pv_color_resultRGB);
pxrSurface_node.params.SetInteger(us_specularModelType, 1);
pxrSurface_node.params.SetColor(us_specularFaceColor,RtColorRGB(0.04f));
pxrSurface_node.params.SetColor(us_specularEdgeColor, RtColorRGB(1.0f));
materialNodes.push_back(pxrSurface_node);
_SetFallbackMaterial(materialNodes);
}

// Volume default material
{
static const RtUString us_PxrVolume("PxrVolume");
static const RtUString us_simpleVolume("simpleVolume");
static const RtUString us_density("density");
static const RtUString us_densityFloatPrimVar("densityFloatPrimVar");
static const RtUString us_diffuseColor("diffuseColor");
std::vector<riley::ShadingNode> volumeMaterialNodes;
riley::ShadingNode pxrVolume_node;
pxrVolume_node.type = riley::ShadingNode::Type::k_Bxdf;
pxrVolume_node.name = us_PxrVolume;
pxrVolume_node.handle = us_simpleVolume;
pxrVolume_node.params.SetString(us_densityFloatPrimVar, us_density);
// 18% albedo chosen to match Storm's fallback volume shader.
pxrVolume_node.params.SetColor(us_diffuseColor,
RtColorRGB(0.18, 0.18, 0.18));
volumeMaterialNodes.push_back(pxrVolume_node);
_SetFallbackVolumeMaterial(volumeMaterialNodes);
}
_CreateFallbackMaterials();

// Default light
{
Expand Down Expand Up @@ -319,24 +257,6 @@ HdPrman_OfflineRenderParam::SetFallbackLight(
params);
}

void
HdPrman_OfflineRenderParam::_SetFallbackMaterial(
std::vector<riley::ShadingNode> const & materialNodes)
{
fallbackMaterial = _riley->CreateMaterial(riley::UserId::DefaultId(),
{static_cast<uint32_t>(materialNodes.size()), &materialNodes[0]},
RtParamList());
}

void
HdPrman_OfflineRenderParam::_SetFallbackVolumeMaterial(
std::vector<riley::ShadingNode> const & materialNodes)
{
fallbackVolumeMaterial = _riley->CreateMaterial(riley::UserId::DefaultId(),
{static_cast<uint32_t>(materialNodes.size()), &materialNodes[0]},
RtParamList());
}

void
HdPrman_OfflineRenderParam::Render()
{
Expand Down
6 changes: 0 additions & 6 deletions third_party/renderman-24/plugin/hdPrman/offlineRenderParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class HdPrman_OfflineRenderParam: public HdPrman_RenderParam
RtParamList rileyOptions,
riley::ShadingNode integratorNode,
riley::Extent outputFormat, TfToken outputFilename,
std::vector<riley::ShadingNode> const & fallbackMaterialNodes,
std::vector<riley::ShadingNode> const & fallbackVolumeNodes,
std::vector<RenderOutput> const & renderOutputs);

// Optional facility to quickly add a light to Riley
Expand Down Expand Up @@ -103,10 +101,6 @@ class HdPrman_OfflineRenderParam: public HdPrman_RenderParam
RtParamList const& params);
void _SetRenderTargetAndDisplay(
riley::Extent format,TfToken outputFilename);
void _SetFallbackMaterial(
std::vector<riley::ShadingNode> const & materialNodes);
void _SetFallbackVolumeMaterial(
std::vector<riley::ShadingNode> const & materialNodes);

riley::IntegratorId _integratorId;
riley::ShadingNode _activeIntegratorShadingNode;
Expand Down
109 changes: 109 additions & 0 deletions third_party/renderman-24/plugin/hdPrman/renderParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,4 +1479,113 @@ HdPrman_RenderParam::_InitializePrman()
(rileyvariant.find("xpu") != std::string::npos));
}

static
RtParamList
_ComputePrimvarNodeParams()
{
static const RtUString us_varname("varname");
static const RtUString us_displayColor("displayColor");
static const RtUString us_defaultColor("defaultColor");

RtParamList result;
result.SetString(
us_varname, us_displayColor);
// Note: this 0.5 gray is to match UsdImaging's fallback.
result.SetColor(
us_defaultColor, RtColorRGB(0.5, 0.5, 0.5));
result.SetString(
RixStr.k_type, RixStr.k_color);
return result;
}

static
RtParamList
_ComputeSurfaceNodeParams()
{
static const RtUString us_diffuseColor("diffuseColor");
static const RtUString us_pv_color_resultRGB("pv_color:resultRGB");
static const RtUString us_specularModelType("specularModelType");
static const RtUString us_diffuseDoubleSided("diffuseDoubleSided");
static const RtUString us_specularDoubleSided("specularDoubleSided");
static const RtUString us_specularFaceColor("specularFaceColor");
static const RtUString us_specularEdgeColor("specularEdgeColor");

RtParamList result;
result.SetColorReference(
us_diffuseColor, us_pv_color_resultRGB);
result.SetInteger(
us_specularModelType, 1);
result.SetInteger(
us_diffuseDoubleSided, 1);
result.SetInteger(
us_specularDoubleSided, 1);
result.SetColor(
us_specularFaceColor, RtColorRGB(0.04f));
result.SetColor(
us_specularEdgeColor, RtColorRGB(1.0f));
return result;
}

static
RtParamList
_ComputeVolumeNodeParams()
{
static const RtUString us_densityFloatPrimVar("densityFloatPrimVar");
static const RtUString us_density("density");
static const RtUString us_diffuseColor("diffuseColor");

RtParamList result;
result.SetString(
us_densityFloatPrimVar, us_density);
// 18% albedo chosen to match Storm's fallback volume shader.
result.SetColor(
us_diffuseColor, RtColorRGB(0.18, 0.18, 0.18));
return result;
}

void
HdPrman_RenderParam::_CreateFallbackMaterials()
{
// Default material
{
static const RtUString us_PxrPrimvar("PxrPrimvar");
static const RtUString us_pv_color("pv_color");
static const RtUString us_PxrSurface("PxrSurface");
static const RtUString us_simpleTestSurface("simpleTestSurface");

const std::vector<riley::ShadingNode> materialNodes{
riley::ShadingNode{
riley::ShadingNode::Type::k_Pattern,
us_PxrPrimvar,
us_pv_color,
_ComputePrimvarNodeParams()},
riley::ShadingNode{
riley::ShadingNode::Type::k_Bxdf,
us_PxrSurface,
us_simpleTestSurface,
_ComputeSurfaceNodeParams()}};
_fallbackMaterialId = _riley->CreateMaterial(
riley::UserId::DefaultId(),
{static_cast<uint32_t>(materialNodes.size()), materialNodes.data()},
RtParamList());
}

// Volume default material
{
static const RtUString us_PxrVolume("PxrVolume");
static const RtUString us_simpleVolume("simpleVolume");

const std::vector<riley::ShadingNode> materialNodes{
riley::ShadingNode{
riley::ShadingNode::Type::k_Bxdf,
us_PxrVolume,
us_simpleVolume,
_ComputeVolumeNodeParams()}};
_fallbackVolumeMaterialId = _riley->CreateMaterial(
riley::UserId::DefaultId(),
{static_cast<uint32_t>(materialNodes.size()), materialNodes.data()},
RtParamList());
}
}

PXR_NAMESPACE_CLOSE_SCOPE
Loading

0 comments on commit 7b85a31

Please sign in to comment.