Jump to content

  • Log In with Google      Sign In   
  • Create Account

DX11 Multiple Shader Passing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Migi0027   Crossbones+   -  Reputation: 2116

Like
0Likes
Like

Posted 24 January 2013 - 03:33 PM

Hi guys,

 

 

right now I'm having a program which is supposed to render multiple passes. So my theory was as following:

Shader Pass Color Alpha = 1.0f/AmountOfPasses

And this would be true for all shaders. But the problem is that it doesn't really work. It it like e.g. two passes, first.alpha: 0.5 second.alpha:1 or something like that?

Well my method doesn't really seem to work as the second pass isn't visible for some reason. But no matter if my shaders are somehow wrong, what is the correct way to render multiple passes to get one image?

My Shader:

cbuffer ConstantObjectBuffer
{
float4x4 final;
float4x4 rotation;
float4 ambientcol;
float3 space;
float alpha;
}

cbuffer ConstantFrameBuffer
{
float4 lightvec;
float4 lightcol;
}

struct VOut
{
float4 position : SV_POSITION;
float4 normal : NORMAL;
float4 color : COLOR;
};

VOut VShader(float4 position : POSITION, float4 normal : NORMAL)
{
VOut output;

output.position = mul(final, position);

// set the ambient light
output.color = ambientcol;

// calculate the diffuse light and add it to the ambient light
float4 norm = normalize(mul(rotation, normal));
float diffusebrightness = saturate(dot(norm, lightvec));
output.color += lightcol * diffusebrightness;

output.color.a = alpha;

return output;
}

float4 PShader(VOut input) : SV_TARGET
{
return input.color;
}

 

The alpha amount is calculated in c++, like this:

ObjectBuffer.Alpha = 1.0f/(float)(Passes.getAlpha()); // .getAlpha = get all passes except lighting (e.g. texture, bump mapping...)
if (Passes.Lighting)
ObjectBuffer.Alpha += Lights.Directional.size();

 

 

Thank You


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

Sponsor:

#2 TiagoCosta   Crossbones+   -  Reputation: 2446

Like
0Likes
Like

Posted 24 January 2013 - 04:12 PM

Just enable additive blending... No need to play with alpha values if all passes have the same alpha (adding to one).

P.S: I'm not sure if I understood you correctly, are you doing texture mapping, bump mapping, and lighting in different passes?

Edited by TiagoCosta, 24 January 2013 - 04:13 PM.


#3 Migi0027   Crossbones+   -  Reputation: 2116

Like
0Likes
Like

Posted 25 January 2013 - 11:54 AM

I tried to enable additive blending, but nothing seemed to happen, here's how i did it:

 

D3D11_BLEND_DESC alphapassDesc = {0};
	alphapassDesc.AlphaToCoverageEnable = true;
	alphapassDesc.IndependentBlendEnable = true;

	alphapassDesc.RenderTarget[0].BlendEnable = true;
	alphapassDesc.RenderTarget[0].SrcBlend       = D3D11_BLEND_SRC_ALPHA;
	alphapassDesc.RenderTarget[0].DestBlend      = D3D11_BLEND_INV_SRC_ALPHA;
	alphapassDesc.RenderTarget[0].BlendOp        = D3D11_BLEND_OP_ADD;
	alphapassDesc.RenderTarget[0].SrcBlendAlpha  = D3D11_BLEND_ONE;
	alphapassDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
	alphapassDesc.RenderTarget[0].BlendOpAlpha   = D3D11_BLEND_OP_ADD;
	alphapassDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

	dev->CreateBlendState(&alphapassDesc, &AlphaPassBS);

 

 

PS. I know somethings wrong dry.png


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

#4 Migi0027   Crossbones+   -  Reputation: 2116

Like
0Likes
Like

Posted 27 January 2013 - 06:06 AM

Is anything wrong with the code above?


Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

#5 Migi0027   Crossbones+   -  Reputation: 2116

Like
0Likes
Like

Posted 12 February 2013 - 02:50 PM

If anyone is looking for a solution, this will do the trick wink.png

 

SrcBlend = D3D11_BLEND_ONE;
DestBlend = D3D11_BLEND_SRC1_COLOR;

 

From: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205072%28v=vs.85%29.aspx#Blend_Pixel_Shader_Outputs


Edited by Migi0027, 12 February 2013 - 02:51 PM.

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS