-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAYA-108563 - Support default material shading using new SDK APIs #1339
Changes from all commits
5c5da71
33c5f03
92a5541
de41070
d403e2f
f5b63ed
4036ac9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1280,15 +1280,61 @@ void HdVP2Mesh::_InitRepr(const TfToken& reprToken, HdDirtyBits* dirtyBits) | |
|
||
switch (desc.geomStyle) { | ||
case HdMeshGeomStyleHull: | ||
break; // Creating the hull render items requires geom subsets from the topology, and we | ||
// can't access that here. | ||
// Creating the smoothHull hull render items requires geom subsets from the topology, | ||
// and we can't access that here. | ||
#ifdef HAS_DEFAULT_MATERIAL_SUPPORT_API | ||
if (reprToken == HdVP2ReprTokens->defaultMaterial) { | ||
// But default material mode does not use geom subsets, so we create the render item | ||
renderItem = _CreateSmoothHullRenderItem(renderItemName); | ||
renderItem->setDefaultMaterialHandling( | ||
MRenderItem::DrawOnlyWhenDefaultMaterialActive); | ||
renderItem->setShader(_delegate->Get3dDefaultMaterialShader()); | ||
} | ||
#endif | ||
break; | ||
case HdMeshGeomStyleHullEdgeOnly: | ||
// The smoothHull repr uses the wireframe item for selection | ||
// highlight only. | ||
// The smoothHull repr uses the wireframe item for selection highlight only. | ||
#ifdef HAS_DEFAULT_MATERIAL_SUPPORT_API | ||
if (reprToken == HdReprTokens->smoothHull | ||
|| reprToken == HdVP2ReprTokens->defaultMaterial) { | ||
// Share selection highlight render item between smoothHull and defaultMaterial: | ||
bool foundShared = false; | ||
_ReprVector::const_iterator it = std::find_if( | ||
_reprs.begin(), | ||
_reprs.end(), | ||
_ReprComparator( | ||
reprToken == HdReprTokens->smoothHull ? HdVP2ReprTokens->defaultMaterial | ||
: HdReprTokens->smoothHull)); | ||
if (it != _reprs.end()) { | ||
const HdReprSharedPtr& repr = it->second; | ||
const auto& items = repr->GetDrawItems(); | ||
#if HD_API_VERSION < 35 | ||
for (HdDrawItem* item : items) { | ||
HdVP2DrawItem* shDrawItem = static_cast<HdVP2DrawItem*>(item); | ||
#else | ||
for (const HdRepr::DrawItemUniquePtr& item : items) { | ||
HdVP2DrawItem* const shDrawItem = static_cast<HdVP2DrawItem*>(item.get()); | ||
#endif | ||
if (shDrawItem | ||
&& shDrawItem->MatchesUsage(HdVP2DrawItem::kSelectionHighlight)) { | ||
drawItem->SetRenderItem(shDrawItem->GetRenderItem()); | ||
foundShared = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (!foundShared) { | ||
renderItem = _CreateSelectionHighlightRenderItem(renderItemName); | ||
} | ||
drawItem->SetUsage(HdVP2DrawItem::kSelectionHighlight); | ||
} | ||
#else | ||
// The smoothHull repr uses the wireframe item for selection highlight only. | ||
if (reprToken == HdReprTokens->smoothHull) { | ||
renderItem = _CreateSelectionHighlightRenderItem(renderItemName); | ||
drawItem->SetUsage(HdVP2DrawItem::kSelectionHighlight); | ||
} | ||
#endif | ||
// The item is used for wireframe display and selection highlight. | ||
else if (reprToken == HdReprTokens->wire) { | ||
renderItem = _CreateWireframeRenderItem(renderItemName); | ||
|
@@ -1605,7 +1651,8 @@ void HdVP2Mesh::_UpdateDrawItem( | |
} | ||
#endif | ||
|
||
if (desc.geomStyle == HdMeshGeomStyleHull) { | ||
if (desc.geomStyle == HdMeshGeomStyleHull | ||
&& desc.shadingTerminal == HdMeshReprDescTokens->surfaceShader) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaultMaterial repr has a different shading terminal and will skip the shading update. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we modify the real material while in default material mode does it update correctly when we turn off "use default material"? IIRC somewhere we clear all the dirty flags, so we'd forget about the dirty material id and then not update. |
||
bool dirtyMaterialId = (itemDirtyBits & HdChangeTracker::DirtyMaterialId) != 0; | ||
if (dirtyMaterialId) { | ||
SdfPath materialId = GetMaterialId(); // This is an index path | ||
|
@@ -2388,6 +2435,10 @@ MHWRender::MRenderItem* HdVP2Mesh::_CreateSmoothHullRenderItem(const MString& na | |
renderItem->setObjectTypeExclusionFlag(MHWRender::MFrameContext::kExcludeMeshes); | ||
#endif | ||
|
||
#ifdef HAS_DEFAULT_MATERIAL_SUPPORT_API | ||
renderItem->setDefaultMaterialHandling(MRenderItem::SkipWhenDefaultMaterialActive); | ||
#endif | ||
|
||
setWantConsolidation(*renderItem, true); | ||
|
||
return renderItem; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#usda 1.0 | ||
( | ||
defaultPrim = "GEO" | ||
metersPerUnit = 0.01 | ||
upAxis = "Y" | ||
) | ||
|
||
def Xform "GEO" | ||
{ | ||
def Mesh "BILLBOARD" ( | ||
prepend apiSchemas = ["MaterialBindingAPI"] | ||
kind = "component" | ||
) | ||
{ | ||
uniform bool doubleSided = 1 | ||
float3[] extent = [(-1.5, 0, -1.5), (1.5, 0, 1.5)] | ||
int[] faceVertexCounts = [4] | ||
int[] faceVertexIndices = [0, 1, 3, 2] | ||
rel material:binding = </GEO/BILLBOARD/Looks/TEXTUREDA> | ||
point3f[] points = [(-1.5, 0, 1.5), (1.5, 0, 1.5), (-1.5, 0, -1.5), (1.5, 0, -1.5)] | ||
texCoord2f[] primvars:map1 = [(0, 0), (1, 0), (0, 1), (1, 1)] ( | ||
interpolation = "faceVarying" | ||
) | ||
int[] primvars:map1:indices = [0, 1, 3, 2] | ||
|
||
def Scope "Looks" | ||
{ | ||
def Material "TEXTUREDA" | ||
{ | ||
token inputs:file1:varname = "map1" | ||
token outputs:surface.connect = </GEO/BILLBOARD/Looks/TEXTUREDA/TEXTUREDA.outputs:surface> | ||
|
||
def Shader "TEXTUREDA" | ||
{ | ||
uniform token info:id = "UsdPreviewSurface" | ||
color3f inputs:diffuseColor.connect = </GEO/BILLBOARD/Looks/TEXTUREDA/file1.outputs:rgb> | ||
token outputs:displacement | ||
token outputs:surface | ||
} | ||
|
||
def Shader "file1" | ||
{ | ||
uniform token info:id = "UsdUVTexture" | ||
float4 inputs:fallback = (0.5, 0.5, 0.5, 1) | ||
asset inputs:file = @green_A.png@ | ||
float2 inputs:st.connect = </GEO/BILLBOARD/Looks/TEXTUREDA/file1/TexCoordReader.outputs:result> | ||
token inputs:wrapS = "repeat" | ||
token inputs:wrapT = "repeat" | ||
float3 outputs:rgb | ||
|
||
def Shader "TexCoordReader" | ||
{ | ||
uniform token info:id = "UsdPrimvarReader_float2" | ||
token inputs:varname.connect = </GEO/BILLBOARD/Looks/TEXTUREDA.inputs:file1:varname> | ||
float2 outputs:result | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we end up using this pattern to share more render items then this seems like a good candidate to be refactored into a method.