DX11 Multiple Shader Passing

Started by
3 comments, last by Migi0027 11 years, 2 months ago

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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?

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Is anything wrong with the code above?

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement