I'm on a new blending question. I have fog in my scene and when my object goes in the part where it should disappear, it does not.
In front of the fog still visible
As you see, you can still see the object it the part where it should disappear!
I used a multiply blend.
my code
D3D11_BLEND_DESC myblend2 = { 0 };
myblend2.AlphaToCoverageEnable = false;
myblend2.IndependentBlendEnable = false;
myblend2.RenderTarget[0].BlendEnable = true;
myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_ZERO;
myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_SRC_COLOR;
myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
HR(md3dDevice->CreateBlendState(&myblend2, &MULTIPLYBLEND));
For the BlendOp, when I use D3D11_BLEND_OP_MIN or MAX, it will disappear in the fog, but using ADD,SUBTRACT,REV_SUBTRACT, it does not. I also narrowed it down to the DestBlend, when it is set to zero(D3D11_BLEND_ZERO), it will disappear in the fog.
Maybe its my image? maybe the pixel shader?
I also have my HLSL pixel shader code, here it is
float4 PS(VertexOut pin, uniform int gLightCount, uniform bool gUseTexure, uniform bool gAlphaClip, uniform bool gFogEnabled) : SV_Target
{
// Interpolating normal can unnormalize it, so normalize it.
pin.NormalW = normalize(pin.NormalW);
// The toEye vector is used in lighting.
float3 toEye = gEyePosW - pin.PosW;
// Cache the distance to the eye from this surface point.
float distToEye = length(toEye);
// Normalize.
toEye /= distToEye;
// Default to multiplicative identity.
float4 texColor = float4(1, 1, 1, 1);
if (gUseTexure)
{
// Sample texture.
texColor = gDiffuseMap.Sample(samAnisotropic, pin.Tex);
}
//
// Lighting.
//
float4 litColor = texColor;
if (gLightCount > 0)
{
// Start with a sum of zero.
float4 ambient = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 spec = float4(0.0f, 0.0f, 0.0f, 0.0f);
// Sum the light contribution from each light source.
[unroll]
for (int i = 0; i < gLightCount; ++i)
{
float4 A, D, S;
ComputeDirectionalLight(gMaterial, gDirLights[i], pin.NormalW, toEye,
A, D, S);
ambient += A;
diffuse += D;
spec += S;
}
// Modulate with late add.
litColor = texColor*(ambient + diffuse) + spec;
}
//
// Fogging
//
if (gFogEnabled)
{
float fogLerp = saturate((distToEye - gFogStart) / gFogRange);
// Blend the fog color and the lit color.
litColor = lerp(litColor, gFogColor, fogLerp);
}
// Common to take alpha from diffuse material and texture.
litColor.a = gMaterial.Diffuse.a * texColor.a;
return litColor;
}
Maybe something wrong in there?