How to setup a zbias and alpha threshold for rendering decals

Hi, i am setting up an HdxRenderTask with the following code:

auto decoRenderTaskId = GetControllerId().AppendChild(TfToken(“renderTask_decorations”));
GetRenderIndex()->InsertTask(&delegate, decoRenderTaskId);

HdxRenderTaskParams renderParams;
renderParams.camera = freeCameraSceneDelegate->GetCameraId();
renderParams.viewport = viewport;
renderParams.framing = framing;
renderParams.overrideWindowPolicy = overrideWindowPolicy;

renderParams.enableLighting = true;
renderParams.depthFunc = HdCmpFuncLEqual;
renderParams.cullStyle = HdCullStyleBack;
renderParams.alphaThreshold = 0.5f;

renderParams.depthBiasUseDefault = false;
renderParams.depthBiasEnable = true;
renderParams.depthBiasConstantFactor = 0.01f;
renderParams.depthBiasSlopeFactor = 1.f;

renderParams.blendEnable = false;
renderParams.depthMaskEnable = true;
renderParams.enableAlphaToCoverage = true;
renderParams.useAovMultiSample = true;

HdRprimCollection coll(HdTokens->geometry,
                       HdReprSelector(HdReprTokens->refined),
                       SdfPath::AbsoluteRootPath().AppendChild(TfToken("DecorationMeshes")));
coll.SetMaterialTag(HdStMaterialTagTokens->masked);

TfTokenVector renderTags = {HdRenderTagTokens->geometry};

delegate.SetParameter(decoRenderTaskId, HdTokens->params, renderParams);
delegate.SetParameter(decoRenderTaskId, HdTokens->collection, coll);
delegate.SetParameter(decoRenderTaskId, HdTokens->renderTags, renderTags

The collection is rendered , but without zbias and alpha masking applied. I debugged through hydra and veryfied that even the gl call is issued:
glPolygonOffset(_depthBiasSlopeFactor, _depthBiasConstantFactor); is called with the correct values.
Maybe i am missing something important to set this up? If i play around with other render task parameters they are reflected in the rendered scene. Only zbias and alpha treshold doesn’t seem to do anything. Why could this be?

Cheers,
Robert

Sorry i found the reason. My fault: i needed negative bias values instead of positive. However the alpha threshold still not seems to do anything. How do i setup alpha masking? I suppose that is done in the preview shader?

1 Like

Alright! I found the reason now why i don’t see alpha. It was because i forgot to connect the alpha texture output to the opacity input of the PreviewSurface shader. The rgb output of the UvTexture node outputs just rgb, not a and so without connecting alpha in addition, it won’t consider texture transparency of course.

1 Like