Basic Max Viewport Shader Issue

Hey all,

I’ve been following along with Ben Cloward’s HLSL Shader Creation DVD. I’ve come to the point where it goes over the diffuse lighting model. When I was done, my object went fully transparent. I figured I did something wrong, so I checked my work against Ben’s example, but even his shader disappeared! I think this is a max issue, as FX Composer renders the shaders just fine. Anyone else run into this?

code can be found here: http://pastebin.com/FhXw8R1K

What version of Max?

2009 x64

Out.diffuse = brightnessClamped * light1Color;

If brightnessClamped < 1, then you are multiplying your alpha by that value. That means that your alpha is less than 1, which may be interpreted by Max as transparent. Or if your light1Color is greater than 1, you might end up with alpha greater than 1. Which might also get interpreted badly. It depends on what the default blend mode is in max. Since you haven’t set it explicitly in your shader, Max might default to one, zero / alpha test, which will end up transparent.

Try this:

Out.diffuse = float4(light1Color.rgb * brightnessClamped, 1);

or if you want the light to control the alpha:

Out.diffuse = float4(light1Color.rgb * brightnessClamped, light1Color.a);

Or you could do this in your technique:
technique Complete
{
pass simple
{
AlphaBlendEnable = false;
ZWriteEnable = true;
AlphaTestEnable = false;
CullMode = cw;
DestBlend = 2;
SrcBlend = 1;
VertexShader = compile vs_1_1 vertex();
PixelShader = compile ps_2_0 pixel();
}
}

Generally, when I am doing shaders in Max, I include the following in my headers so I can control all of this stuff in the material editor:

//Drawing parameters
bool bBlendAlpha < string UIName = “Alpha Blend Enable”; > = false;
bool bZWrite < string UIName = “Z Write Enable”; > = true;
bool bAlphaTest < string UIName = “Alpha Test Enable”; > = false;
int iAlphaTestFunc < string UIName = “Alpha Test Function”; string UIType = “IntSpinner”; int UIMin = 0; int UIMax = 7; > = 5;
int iAlphaTestThreshold < string UIName = “Alpha Test Thrershold”; string UIType = “IntSpinner”; float UIMin = 0.0; float UIMax = 256.0; > = 128;
int iCullMode < string UIName = “Cull Mode”; string UIType = “IntSpinner”; int UIMin = 0; int UIMax = 7; > = 2;
int iDestBlend < string UIName = “Dest Blend”; string UIType = “IntSpinner”; int UIMin = 0; int UIMax = 7; > = 2;
int iSrcBlend < string UIName = “Src Blend”; string UIType = “IntSpinner”; int UIMin = 0; int UIMax = 7; > = 1;

And then my techniques look like this:

technique Default
<
string script = “Pass=p0;”;
>
{
pass p0 <
string script = “Draw=Geometry;”;
>
{
AlphaBlendEnable = bBlendAlpha;
ZWriteEnable = bZWrite;
AlphaTestEnable = bAlphaTest;
AlphaFunc = iAlphaTestFunc;
AlphaRef = iAlphaTestThreshold;
CullMode = iCullMode;
DestBlend = iDestBlend;
SrcBlend = iSrcBlend;
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_3_0 PsMain();
}
}

In more recent versions of 3ds Max, you have to explicitly tell it to turn alpha blending off if you don’t want it. So in the technique area of the shader you need this line:

AlphaBlendEnable = false;

When I made the DVD, the version of 3ds Max I was using didn’t require that, but in the more recent versions, it does.

Thanks all. Forcing the alpha to 1.0 fixed it, as did turing off both AlphaBlend and AlphaTest