Hey all,
I’m trying to create some directX shaders for 3ds max that control the objects render order. I want the freedom to have some objects always drawn in front of others.
Added below is the shader I have so far. It is a DirectX 11 shader. It “works” but is incomplete. object render order (the “layerNum” property) currently isn’t doing anything.
I have a feeling that the key is in the DepthStencilState or in the tags before the Pass (IE “Draw=Buffer”), but no matter what I do to mess around with these options, I can’t seem to get the results i want.
Help would be greatly appreciated!
string ParamID = "0x0003";
float4x4 WvpXf : WorldViewProjection < string UIWidget="None"; >;
float alpha < string UIName = "alpha"; > = 0.5f;
float4 Color <
string UIName = "Color";
string UIWidget = "Color";
> = float4( 0.0f, 0.0f, 0.0f, 1.0f ); // ambient
//Layer Number
int layerNum <
string UIName = "Layer Number";
string UIWidget = "slider";
float UIMin = 0.0f;
float UIMax = 1000.0f;
float UIStep = 1.0f;
> = 0;
float4 gClearColor <
string UIWidget = "Color";
string UIName = "Background";
> = {0.1, 0.1, 0.1, 0.0};
float gClearDepth <string UIWidget = "none";> = 1.0;
struct appdata
{
float4 Position : POSITION;
};
float4 std_VS(appdata IN) : SV_Position
{
return mul(float4(IN.Position.xyz,1), WvpXf);;
}
float4 std_PS() : SV_Target
{
return float4(Color.rgb,alpha);
}
BlendState noBlend
{
BlendEnable[0] = false;
};
RasterizerState DisableCulling { CullMode = NONE; };
DepthStencilState DepthOn
{
DepthEnable = FALSE;
//DepthWriteMask = ALL; //Original
DepthWriteMask = ZERO;
DepthFunc = LESS; //Original
//DepthFunc = 4;
StencilEnable = FALSE;
//FrontFace = KEEP;
};//And use this in your pass: SetDepthStencilState( DepthOn, 0 );
BlendState alphaBlend
{
//AlphaToCoverageEnable = TRUE; //acts as an Alpha Test, clipping pixels with alpha<0.5
//IndependentBlendEnable = TRUE; //no worky
BlendEnable[0] = TRUE;
SrcBlend = SRC_ALPHA;
DestBlend = INV_SRC_ALPHA;
BlendOp = ADD;
SrcBlendAlpha = ZERO;
DestBlendAlpha = ZERO;
BlendOpAlpha = ADD;
RenderTargetWriteMask[0] = 0x0F;
};
technique11 NoBlend
{
pass p0< string Script =
"Draw=10;";
>
{
SetDepthStencilState( DepthOn, layerNum ); //Attempting to set Draw Order. I'm sure i'm doing it wrong.
SetBlendState(noBlend, float4(1.0f,1.0f,1.0f,1.0f), 0xffffffff);
SetRasterizerState(DisableCulling);
SetVertexShader(CompileShader(vs_5_0,std_VS()));
SetPixelShader(CompileShader(ps_5_0,std_PS()));
}
}
technique11 AlphaBlend < string Script =
"ClearSetColor=gClearColor;"
"ClearSetDepth=gClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"Pass=PostP0;";
>
{
pass PostP0 < string Script =
"RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
"Draw=Buffer;";
> {
SetDepthStencilState( DepthOn, layerNum ); //Attempting to set Draw Order. I'm sure i'm doing it wrong.
SetBlendState(alphaBlend, float4(1.0f,1.0f,1.0f,1.0f), 0xffffffff);
SetRasterizerState(DisableCulling);
SetVertexShader(CompileShader(vs_5_0,std_VS()));
SetPixelShader(CompileShader(ps_5_0,std_PS()));
}
}