Message 1 of 6
CustomBackground How-To Example from Max SDK Broken in DX11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been trying to get the CustomBackground example working (from maxsdk\howto\Graphics\CustomBackground). But this seems to always give me a black background.
To test, I modified the plugin with some simple additions that hook NOTIFY_ACTIVE_VIEWPORT_CHANGED to toggle the background shader on that viewport (via IFixedViewportPipeline) between the custom and default. This is grungey, but at least allows me to evaluate the shader.
Additions to CustomBackgroundMain.cpp:
#include <notify.h>
#include <Graphics/ViewSystem/IFixedViewportPipeline.h>
#include <Graphics/ViewSystem/IRenderView2.h>
static void OnActiveViewportChanged(void* param, NotifyInfo* info)
{
ViewExp18* vp18 = dynamic_cast<ViewExp18*>(&GetCOREInterface14()->GetActiveViewExp());
if (vp18 && vp18->IsActive())
{
MaxSDK::Graphics::IRenderView2* irv = vp18->GetRenderView();
if (irv)
{
MaxSDK::Graphics::IFixedViewportPipeline* ivp = irv->GetFixedViewportPipeline();
if (!ivp->GetBackgroundFragment())
{
void* ptr = theCustomBackgroundDesc.Create(FALSE);
ivp->SetBackgroundFragment(static_cast<MaxSDK::Graphics::CustomBackground*>(ptr));
}
else
{
ivp->RestoreDefaultBackgroundFragment();
}
}
}
}
__declspec( dllexport ) int LibInitialize()
{
RegisterNotification(OnActiveViewportChanged, NULL, NOTIFY_ACTIVE_VIEWPORT_CHANGED);
return TRUE;
}
__declspec( dllexport ) int LibShutdown()
{
UnRegisterNotification(OnActiveViewportChanged, NULL, NOTIFY_ACTIVE_VIEWPORT_CHANGED);
return TRUE;
}
This also requires exposing the init/shutdown API in CustomBackground.def:
LIBRARY CustomBackground.dlu
EXPORTS
LibDescription @1 PRIVATE
LibNumberClasses @2 PRIVATE
LibClassDesc @3 PRIVATE
LibVersion @4 PRIVATE
LibInitialize @6 PRIVATE
LibShutdown @7 PRIVATE
SECTIONS
.data READ WRITE
I compile this plugin and load it in Max 2023. Here's what I get, when switching a wireframe- and default-shaded viewport to use the custom background:

The overlay for object selection / hit-testing works, as do tooltips, gizmos and wireframes. But the background is always black and the object is not shaded.
I also tried switching the viewport to DX Mode and found that the background is not drawn at all:
... So I tried changing the Nitrous driver to DX9, restarted Max and that seems to work (after loading the plugin manually due to D3D errors at startup relegated the plugin to deferred loading):
However, this is not a solution. I want the DX11 shader to work, but I'm not sure what's causing it to break. I've confirmed the shader compiles, all the handles are valid, and the call to SetBackgroundFragment() succeeds.
Perhaps the howto example is out of date? Some guidance would sure be helpful here!