Optimizing DirectX Shader for 3ds Max

We have created a custom DX shader for max, its kind of ubershader for our game engine. The issue that we are running in to is that after a certain amount of nodes get in the scene with the shader applied the viewport starts to get extemely slow, and eventually gets so painful its too hard to even work.

This article i found in gamasutra pretty much confirms what we are seeing and it mentions that there is a way to optimize the viewports for dx shaders to display, but doesnt actually say how to do it.

Does anyone know how to optimize the scene to help them display better? Or perhaps have another solution to avoid the whole issue?

edit-> the weird thing is that even if we hide all but one node the scene still chugs, but it is my understanding that it shouldnt be trying to render anything that isnt visible, is this true?

Are you changing the textures the shaders are using? Max has a problem cleaning up texture memory when a DX texture is no longer used.

Im not sure what you mean, currently we create a png out of any tif that has alpha because max doesn’t handle tifs very well.

There are two things that I’ve seen work to improve viewport performance in the past. The first thing is to convert your textures to DDS format, and the second is to not use multi-subobject materials. I recommend that you do a test where you apply those two techniques to a scene that’s currently really chuggy for you and see if it makes a difference.

another one is to try and use as few objects as possible.
So, if you can, attach objects that use the same shader together.

That is a bit nasty of course, but 3dsMax is very poor at handling even a moderate number of objects with directX shaders on them.

I tried applying one material without a map to everything, it sped up very little.

It would appear the the number of nodes is the primary culprit. If there isnt much we can do on the shader side we may just have to adjust how we work in max, which is slightly disappointing.

Max has always had a problem with multisubs, but since hardware has speeded up it has got a little better - they might of even improved it. Then along comes DX shaders and it gets worse again …

Tried turning off the hardware shaders in the material editor options?
Ok you loose your nice shaders but you can see the max rendering material instead which could contain your diffuse textures. Add a toggle button to switch between render modes. You could use a script to automate copying your shader textures to your max render material

Yeah i think the route we are going to have to go with is to have the artists work in either shader, then have a “Material Swapper” which will convert from on to the other, the only thing that will get hairy is trying to store all the platform specific options over so we dont lose them when swapping over to standard material.

Time to put the headphones on and write some maxscripts!

You dont have to swap over to a normal material, DX materials have a rendermaterial at the bottom if you look in the material editor, this extra material is used for rendering only. All you need to do is copy the diffuse say to the diffuse of the render material and in the material editor options set to draw software in the viewports.

unless you are using dreaded scripted materials not sure if they have an alternate material, cant remember

One extra thing I noticed is the max file size does increase if you have software and dx materials,
so I have in the past written a script to remove the software materials