Jump to content

  • Log In with Google      Sign In   
  • Create Account

Blending Problem to a rendertarget or something else?


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
5 replies to this topic

#1 ankhd   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 09 June 2014 - 08:03 PM

Hi all.

 

I refactored my rendering system to render the scene to a render target so I can do bloom, This all works fine.

 

This is what steps I do, First render all objects to off screen render target, then render bloom objects to there render target

Then the two rendered targets are blended to the final image. This all works.

 

The problem is when I use the final render target to render a blened quad on the screen it makes all the rendered object

turn blue and leaves the background the same and blends with it only,

 

here is the image of the final scene with the quad and the blue mesh.

 

I've set the blend state and the depth and nothing changes. The thing is this all worked Until I used a offscreen renderTarget.

 

Any Ideas on what it could be.

 

Image

BlendingGoneBad.jpg?psid=1



Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2852

Like
0Likes
Like

Posted 09 June 2014 - 08:50 PM

Can you provide some source code? Are you able to narrow down the problem? Ie. disable parts of the code until you can confirm that the program works as intended.

 

Cheers!



#3 ankhd   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 09 June 2014 - 10:43 PM

I turned of bloom and I am rendering to the render target the terrain and I'm still getting the terrain turning blue.

 

so it the same as my other terrain app but im using the new render to texture.

 

Wonder if its got something to do with the fullscreen quad that gets the scene texture applied to it.

the main render target gets a NDC space quad rendered to it then the blened rectangle.

does the NDC quad kill the depth.

 

//my blend state is this.

D3D10_BLEND_DESC blendDesc = {0};
	blendDesc.AlphaToCoverageEnable = false;
	blendDesc.BlendEnable[0] = true;
	blendDesc.SrcBlend       = D3D10_BLEND_SRC_ALPHA;
	blendDesc.DestBlend      = D3D10_BLEND_INV_SRC_ALPHA;
	blendDesc.BlendOp        = D3D10_BLEND_OP_ADD;
	blendDesc.SrcBlendAlpha  = D3D10_BLEND_ONE;
	blendDesc.DestBlendAlpha = D3D10_BLEND_ONE;//D3D10_BLEND_ZERO;
	blendDesc.BlendOpAlpha   = D3D10_BLEND_OP_ADD;
	blendDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;

DepthStencil

 // Create depth stencil texture
    D3D10_TEXTURE2D_DESC descDepth;
    descDepth.Width = width;
    descDepth.Height = height;
    descDepth.MipLevels = 1;
    descDepth.ArraySize = 1;
    descDepth.Format = DXGI_FORMAT_D32_FLOAT;
    descDepth.SampleDesc.Count = MultiSampleAmount;
    descDepth.SampleDesc.Quality = MultiSampleQuality;
    descDepth.Usage = D3D10_USAGE_DEFAULT;
    descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
    descDepth.CPUAccessFlags = 0;
    descDepth.MiscFlags = 0;

before rendering the quad

Device->OMSetRenderTargets( 1, &m_pRenderTargetView, m_pDepthStencilView );

 

//clear the backbuffer

 

float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha

Device->ClearRenderTargetView( m_pRenderTargetView, ClearColor );

 

 

// Clear the depth buffer to 1.0 (max depth)

Device->ClearDepthStencilView(m_pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0 );

 

 

StencilRef = 1;

Device->OMSetDepthStencilState(m_DepthStencilState, m_StencilRef);

//add blending

 

float blendfactor[] = {0.5f, 0.5f, 0.5f, 1.0f};

Device->OMSetBlendState(mTransparentBS, blendfactor, 0xffffffff);

 

 

RenderFullScreenQuad(resourceviewfromscene);

 

shader used to render the fullscreen quad


The quad vertices are
// given in NDC space.
//=============================================================================
 
Texture2D gMap;

 

cbuffer cbPerFrame

 float gUseColour = 0.0;//render black and white default

};

 

SamplerState gTriLinearSam
{
 Filter = MIN_MAG_MIP_LINEAR;
 AddressU = Wrap;
 AddressV = Wrap;
};

struct VS_IN
{
 float3 posL : POSITION;
 float2 texC : TEXCOORD;
};

struct VS_OUT
{
 float4 posH : SV_POSITION;
 float2 texC : TEXCOORD;
};
 
VS_OUT VS(VS_IN vIn)
{
 VS_OUT vOut;

 vOut.posH = float4(vIn.posL, 1.0f);
 
 vOut.texC = vIn.texC;
 
 return vOut;
}

float4 PS(VS_OUT pIn) : SV_Target
{
if(gUseColour == 0.0)
{
 float r = gMap.Sample(gTriLinearSam, pIn.texC).r;
 
 // draw as grayscale
 return float4(r,r,r,1);
}
else
{
float4 colour = gMap.Sample(gTriLinearSam, pIn.texC);
 
 // draw as colour
 return colour ;
}

}
 
technique10 DrawMapTech
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
}

 

//the shader for the blended rectangle parts


//color map texture
//Texture2D colorMap;
DepthStencilState DisableDepth
{
    DepthEnable = FALSE;
    DepthWriteMask = ZERO;
};

DepthStencilState NoDepthWrites
{
    DepthEnable = TRUE;
    DepthWriteMask = ZERO;
};

//texture sampler state
//SamplerState linearSampler
//{
 //   Filter = min_mag_mip_linear;
 //   AddressU = Clamp;
//    AddressV = Clamp;
 //   MaxAnisotropy = 16;
//};

//blend state
BlendState SrcAlphaBlendingAdd
{
 BlendEnable[0] = TRUE;
 SrcBlend = SRC_ALPHA;
 DestBlend = INV_SRC_ALPHA;
 BlendOp = ADD;
 SrcBlendAlpha = ZERO;
 DestBlendAlpha = ZERO;
 BlendOpAlpha = ADD;
 RenderTargetWriteMask[0] = 0x0F;

 

/--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique10 RENDER
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( CompileShader( gs_4_0, GS() ) );  
        SetPixelShader( CompileShader( ps_4_0, PS() ) );
        SetBlendState( SrcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
    }   
    pass P1
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( CompileShader( gs_4_0, GSPass2() ) );  
        SetPixelShader( CompileShader( ps_4_0, PSPass2() ) );
        //SetBlendState( SrcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
         // we must also disable the depth buffer for stream-out only
        SetDepthStencilState( DisableDepth, 0 );
    }   
}



#4 ankhd   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 09 June 2014 - 11:25 PM

sorry for the above that code was pasted in a code block.

 

I notice if I change the colour of the clear screen the terrain is change to the clear colour what does that mean ?????.



#5 ankhd   Members   -  Reputation: 1358

Like
1Likes
Like

Posted 10 June 2014 - 01:13 AM

Ok found the problem.

 

it was in the full screen quad shader the colour value in the pixel shaders alpha value had some value???. I set it

colour.a = 1.0; and It all worked.



#6 kauna   Crossbones+   -  Reputation: 2852

Like
1Likes
Like

Posted 10 June 2014 - 05:21 AM

 Well I'm happy that you resolved the problem by yourself :)

 

Cheers!






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