DirectX 11 shader render order

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  04 April 2013
DirectX 11 shader render order

I'm working on a custom DirectX 11 shader for Nitrous in max2014 and I have an issue in Shaded mode:


EDIT: never mind I just had to set the DepthStencilState

But now I'm having transparency issues... Does anybody know how to set a BlendState properly?

Last edited by Chipicao : 04 April 2013 at 12:54 AM.
 
  06 June 2013
Angry

Hello,

Directx 11 material is completely bugged for me in 2014. Setting a custom blendState give unpredictable results. It even make other objects with standard materials bugs !

Here an example of a custom blendstate with blend disabled. Normally changing the alpha shouldn't change anything here, but that not the case. And applying it to an object make other objects (without materials) lighter and transparent to the grid !


string ParamID = "0x0003";

float4x4 WvpXf : WorldViewProjection < string UIWidget="None"; >;

float alpha < string UIName = "alpha"; > = 0.5;

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(1,0,0,alpha);
}

BlendState noBlend
{
	BlendEnable[0] = false;
};

technique11 NoBlend
{
	pass p0
	{
		SetBlendState(noBlend, float4(1,1,1,1), 0xffffffff);
		SetVertexShader(CompileShader(vs_5_0,std_VS()));
		SetPixelShader(CompileShader(ps_5_0,std_PS()));
	}
}


If i try the default 'StandardFX11.fx' shader provided by autodesk, it doesn't work too. In shaded mode it render like there were no z buffer (objects pop in front of each other without intersection), and in realistic mode the transparency simply doesn't work. Setting a custom blendstate does not help.
 
  07 July 2013
Originally Posted by nico33: Hello,

Directx 11 material is completely bugged for me in 2014. Setting a custom blendState give unpredictable results. It even make other objects with standard materials bugs !

Here an example of a custom blendstate with blend disabled. Normally changing the alpha shouldn't change anything here, but that not the case. And applying it to an object make other objects (without materials) lighter and transparent to the grid !
I think that's because you're supposed to enable it, not disable. If I set BlendEnable[0] to false I get the same problem you describe.
Try this instead:

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;
};




Originally Posted by nico33: If i try the default 'StandardFX11.fx' shader provided by autodesk, it doesn't work too. In shaded mode it render like there were no z buffer (objects pop in front of each other without intersection), and in realistic mode the transparency simply doesn't work. Setting a custom blendstate does not help.
Yes, even the DX11 shader "bundled" with max is broken. You have to set the depth state:
DepthStencilState DepthOn
{
	DepthEnable = TRUE;
	DepthWriteMask = ALL;
	DepthFunc = LESS; //default
	//StencilEnable = TRUE;
	//FrontFace = KEEP;
};
And use this in your pass: SetDepthStencilState( DepthOn, 0 );


The only problem I still have is that objects behind transparent materials tend to disappear depending on the camera angle.
 
  07 July 2013
Hello Chipicao,

Thanks for your answer.

About blendstate, sure i can enable it an make sure the pixel shader output is always one. That ok.

For the depth, i had to use "Less_Equal" instead of "Less", if not the object would disappear in "realistic mode".

For transparent materials it is normal that objects pop in front of each other depending on camera angle/distance (in shaded mode), because it depend on the rendering order. We often deactivate depth write when rendering transparent objects.

What is strange is that i get black instead of background color if using zero for SrcBlendAlpha and DestBlendAlpha. Using SrcBlendAlpha = zero and DestBlendAlpha = INV_SRC_ALPHA seems to work.

	BlendEnable[0] = TRUE;
	SrcBlend = SRC_ALPHA;
	DestBlend = INV_SRC_ALPHA;
	BlendOp = ADD;
	SrcBlendAlpha = ZERO;
	DestBlendAlpha = INV_SRC_ALPHA;
	BlendOpAlpha = ADD;
	RenderTargetWriteMask[0] = 0x0F;


Still all other objects not using a directx material are broken when using one directx material with SetBlendState and/or SetDepthStencilState.
 
  07 July 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:13 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.