Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

DX11 DX11 Multiple Shader Passing

This topic is 2128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!