CustomBackground How-To Example from Max SDK Broken in DX11

CustomBackground How-To Example from Max SDK Broken in DX11

geoff
Contributor Contributor
779 Views
5 Replies
Message 1 of 6

CustomBackground How-To Example from Max SDK Broken in DX11

geoff
Contributor
Contributor
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:
3dsmax_2022-05-05_13-22-19.png

 

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:
3dsmax_2022-05-05_13-22-53.png

 

... 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):
3dsmax_2022-05-05_13-56-54.png

 

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!
0 Likes
780 Views
5 Replies
Replies (5)
Message 2 of 6

davidlanier
Autodesk
Autodesk

Hi,

I looked at this code and found a problem in the DirectX 11 shader. 

Can you please try to update the DX11 shader maxsdk/howto/Graphics/CustomBackground/shaders/dx11_Draw.fx which uses old semantics from DX9.
What is strikethrough in the following sample should be replaced with the line in bold :

struct AMG_VertexOut
{
    float4 hpos : POSITION;
    float4 hpos : SV_POSITION;
    float3 amg_positionWorld : TEXCOORD0;
float3 amg_uvw : TEXCOORD2;
};struct AMG_PixelIn
{
    float4 hpos : POSITION;
    float4 hpos : SV_POSITION;
    float3 amg_positionWorld : TEXCOORD0;
float3 amg_uvw : TEXCOORD2;
};

 

I am afraid this is not enough to make it work, but please try and tell me if it works for you ?
Regards,



David Lanier
Principal Software Engineer
3ds Max Rendering Team
0 Likes
Message 3 of 6

geoff
Contributor
Contributor

Hi David,

 

Thanks for the reply. These changes do not fix the issue, unfortunately. It seems that something changed though. I still get a black background, but if I rapidly click between two viewports (i.e. repeatedly changing active viewport), I sometimes see a brief flash of the yellow/green gradient that this shader outputs. So it does appear to be rendering, but something else is stomping over it.

 

Do you implement the built-in background gradient as a DX11 shader? Is it possible to send this so I can examine it with my same test plugin?

 

If it's helpful, I'm attaching the plugin here, which is adapted from the HowTo as per the original post. It uses the plugin package system, so it can just be dropped in the ApplicationPlugins directory. It contains plugins for 2017 through 2023 (there's some link errors related to a missing Optimesh.lib in 2015 or 2016 and I haven't tracked down where that stuff lives yet).

 

I did update the mechanism for (re)loading and enabling the shader on the active viewport, which is now a MAXScript call: `ToggleCustomBackground()`. The shaders are stored in the plugin package directory, so you can modify a shader and then toggle off/on to reload.

 

This at least lets you see what's going on. Fingers crossed it's just a shader issue, which means you would be able to use this plugin as-is to fix the shader.

 

Also attaching the source, in case it's something else. And of course so you can see what this is doing. The project is hacked around to fit in my local development environment which fairly different to Autodesk. So you'll need to mess around with the project SDK directories etc if you want to build it locally, or just copy the glue into your own preferred plugin project.

 

Side-note: I did not receive notification of your reply, despite being subscribed and having all email notification settings enabled. So I have to check back here periodically to see if there's any response. I also never heard back from Kevin after submitting this issue (and link to the forum) via ADN technical support. So I dunno what's going on there.

 

Cheers,

Geoff

 

0 Likes
Message 4 of 6

geoff
Contributor
Contributor

Oops, I apparently hit the wrong "reply" button and replied to myself. Please see above post.

0 Likes
Message 5 of 6

waqasziachaudhry
Contributor
Contributor

What is the update on this? A lot of us are waiting for things like this to be fixed.

0 Likes
Message 6 of 6

geoff
Contributor
Contributor

I can confirm the issue is fixed as of 3ds Max 2023.2 but not in any other major releases at the time of writing.

 

This is a particular problem in Max 2022, because that's the version when other established viewport drawing techniques stopped working forever. It's the main reason I investigated HLSL as an alternative, before discovering it basically never worked.

 

Can the fix please be applied to Max 2022, as well as earlier versions that you still maintain?

0 Likes