Skip to content

Commit

Permalink
Supporting transparent draws for HdSt.
Browse files Browse the repository at this point in the history
Fix: #2
  • Loading branch information
sirpalee committed Aug 30, 2018
1 parent 8086dc7 commit d96f20e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/hdmaya/adapters/imagePlaneMaterialAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const char* _simpleTexturedSurfaceSource =
vec4 surfaceShader(vec4 Peye, vec3 Neye, vec4 color, vec4 patchCoord)
{
#if defined(HD_HAS_emissiveColor)
return HdGet_emissiveColor();
#if defined(HD_HAS_color)
return HdGet_color();
#else
return vec4(1.0, 0.0, 0.0, 1.0);
#endif
Expand All @@ -86,7 +86,7 @@ static const std::pair<std::string, std::string> _textureShaderSource =
}();

const TfTokenVector _stSamplerCoords = {TfToken("st")};
TF_DEFINE_PRIVATE_TOKENS(_tokens, (emissiveColor));
TF_DEFINE_PRIVATE_TOKENS(_tokens, (color));
const MString _imageName("imageName");

} // namespace
Expand Down Expand Up @@ -144,13 +144,12 @@ class HdMayaImagePlaneMaterialAdapter : public HdMayaMaterialAdapter {
MFnDependencyNode node(_node, &status);
if (ARCH_UNLIKELY(!status)) { return {}; }

if (_RegisterTexture(node, _tokens->emissiveColor)) {
HdMaterialParam emission(
HdMaterialParam::ParamTypeTexture, _tokens->emissiveColor,
if (_RegisterTexture(node, _tokens->color)) {
HdMaterialParam color(
HdMaterialParam::ParamTypeTexture, _tokens->color,
VtValue(GfVec4f(0.0f, 0.0f, 0.0f, 1.0f)),
GetID().AppendProperty(_tokens->emissiveColor),
_stSamplerCoords);
return {emission};
GetID().AppendProperty(_tokens->color), _stSamplerCoords);
return {color};
}
TF_DEBUG(HDMAYA_ADAPTER_IMAGEPLANES)
.Msg("Unexpected failure to register texture\n");
Expand Down
49 changes: 48 additions & 1 deletion src/plugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,45 @@ class HdMayaRender : public MHWRender::MUserRenderOperation {
HdMayaRenderOverride* _override;
};

class SetRenderGLState {
public:
SetRenderGLState(HdGeomStyle geomStyle) :
_geomStyle(geomStyle) {
if (_geomStyle == HdGeomStylePolygons) {
glGetIntegerv(GL_BLEND_SRC_ALPHA, &_oldBlendFunc);
glGetBooleanv(GL_BLEND, &_oldBlend);

if (_oldBlendFunc != _blendFunc) {
glBlendFunc(GL_SRC_ALPHA, _blendFunc);
}

if (_oldBlend != _blend) {
glEnable(GL_BLEND);
}
}
}

~SetRenderGLState() {
if (_geomStyle == HdGeomStylePolygons) {
if (_oldBlend != _blend) {
glDisable(GL_BLEND);
}

if (_oldBlendFunc != _blendFunc) {
glBlendFunc(GL_SRC_ALPHA, _oldBlendFunc);
}
}
}
private:
// non-odr
constexpr static int _blendFunc = GL_ONE_MINUS_SRC_ALPHA;
constexpr static GLboolean _blend = GL_TRUE;

HdGeomStyle _geomStyle = HdGeomStylePolygons;
int _oldBlendFunc = _blendFunc;
GLboolean _oldBlend = _blend;
};

} // namespace

HdMayaRenderOverride::HdMayaRenderOverride()
Expand Down Expand Up @@ -358,7 +397,15 @@ MStatus HdMayaRenderOverride::Render(
_taskController->SetSelectionColor(_colorSelectionHighlightColor);
_taskController->SetEnableSelection(_colorSelectionHighlight);

renderFrame();
// This is required for HdStream to display transparency.
// We should fix this upstream, so HdStream can setup
// all the required states.
if (_rendererName == _tokens->HdStreamRendererPlugin) {
SetRenderGLState state(params.geomStyle);
renderFrame();
} else {
renderFrame();
}

// This causes issues with the embree delegate and potentially others.
if (_wireframeSelectionHighlight &&
Expand Down

0 comments on commit d96f20e

Please sign in to comment.