0

My Problem is, that when I render to a rendertarget, which has a texture binded to it, the rendered information cannot be seen, because the alpha is 0. If I turn the alpha value within the shader to 1 when displaying the rendertarget, then I can see it clear.

If I save the texture to a file, everywhere where there is nothing rendered, it is the clearcolor. Everywhere, where something is rendered, there's alpha = 0. enter image description here

My blendstate:

            D3D10_BLEND_DESC BlendState;
            ZeroMemory(&BlendState, sizeof(D3D10_BLEND_DESC));
            BlendState.AlphaToCoverageEnable = FALSE;
            for (int32 i=0;i<this->m_TextureCount;i++)
                BlendState.BlendEnable[i] = TRUE;
            BlendState.SrcBlend = D3D10_BLEND_SRC_ALPHA;
            BlendState.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
            BlendState.BlendOp = D3D10_BLEND_OP_ADD;
            BlendState.SrcBlendAlpha = D3D10_BLEND_ZERO;
            BlendState.DestBlendAlpha = D3D10_BLEND_ZERO;
            BlendState.BlendOpAlpha = D3D10_BLEND_OP_ADD;
            for (int32 i = 0; i<this->m_TextureCount; i++)
                BlendState.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;

            this->m_pDevice->CreateBlendState(&BlendState, &this->m_pBlendState);

Before rendering:

        this->m_pDevice->OMSetBlendState(this->m_pBlendState, 0, 0xffffffff);

Shadercode to draw the bricks:

    float4x4 View;
float4x4 Projection;

Texture2D Diffuse;

SamplerState TextureSampler
{
  Filter = MIN_MAG_MIP_Linear;
  AddressU = WRAP;
  AddressV = WRAP;
};
struct VertexShaderInput
{
  float3 Position : POSITION0;
  float2 UV       : TEXCOORD0;
  float3 Color    : COLOR0;
  float3 Normal   : NORMAL0;
  row_major float4x4 Offset   : MATRIX;
};

struct VertexShaderOutput
{
  float4 PositionOut : SV_POSITION;
  float4 Position : POSITION0;
  float2 UV       : TEXCOORD0;
  float3 Color    : COLOR0;
  float3 Normal   : NORMAL0;
};

struct PixelShaderOutput
{
  float4 colorMap: SV_TARGET0;
  float4 normalMap: SV_TARGET1;
  float4 positionMap: SV_TARGET2;
};


VertexShaderOutput VS_MAIN(VertexShaderInput input)
{
  VertexShaderOutput Output = (VertexShaderOutput)0;

  float4 pos = float4(input.Position.xyz, 1);

  float4x4 Model = input.Offset;

  float4x4 MVP = mul(mul(Model,View),Projection);

  Output.Position = mul(pos,MVP);
  Output.PositionOut = mul(pos,MVP);

  Output.UV = input.UV;

  Output.Color = input.Color;

  Output.Normal = normalize(mul(input.Normal,(float3x3)Model));

  return Output;
}

PixelShaderOutput PS_MAIN(VertexShaderOutput input)
{
  PixelShaderOutput output;

  output.colorMap = float4(1,0,0,1); // This is the texture above
  output.normalMap = float4(input.Normal,1);
  output.positionMap = float4(input.Position.xyz,1);

  return output;
}


technique10 Main
{
  pass p0
  {
    SetVertexShader(CompileShader(vs_4_0, VS_MAIN()));
    SetGeometryShader(NULL);
    SetPixelShader(CompileShader(ps_4_0, PS_MAIN()));
   }
};
PuRe
  • 179
  • 2
  • 13

1 Answers1

0

changed Rendertarget's Blendstate to

        D3D10_BLEND_DESC BlendState;
        ZeroMemory(&BlendState, sizeof(D3D10_BLEND_DESC));
        BlendState.AlphaToCoverageEnable = true;
        for (int32 i=0;i<this->m_TextureCount;i++)
            BlendState.BlendEnable[i] = TRUE;
        BlendState.SrcBlend = D3D10_BLEND_SRC_ALPHA;
        BlendState.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
        BlendState.BlendOp = D3D10_BLEND_OP_ADD;
        BlendState.SrcBlendAlpha = D3D10_BLEND_SRC_ALPHA;
        BlendState.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA;
        BlendState.BlendOpAlpha = D3D10_BLEND_OP_ADD;
        for (int32 i = 0; i<this->m_TextureCount; i++)
            BlendState.RenderTargetWriteMask[i] = D3D10_COLOR_WRITE_ENABLE_ALL;

        this->m_pDevice->CreateBlendState(&BlendState, &this->m_pBlendState);

And it works now.

PuRe
  • 179
  • 2
  • 13