Sign in to follow this  
lomateron

blending question

Recommended Posts

lomateron    491

I am rendering to a 2D texture R32G32B32A32 with blending enabled and the blending adds the value the pixel shader returns to the value that render target already has. 

The question is:

Is there an easy and fast way to make the pixel shader reset the value of the render target texel to float4(0.0f,0.0f,0.0f,0.0f), when a condition inside the pixel shader is true?

without having to copy paste the render target values to a shader resource. or making a ping pong render targets.

Edited by lomateron

Share this post


Link to post
Share on other sites
Jason Z    6434

You should be able to use the alpha channel as a sort of mask for both the pixel shader value as well as the value from the render target.  Use the add blend op, but use the D3D10_BLEND_SRC_ALPHA blend mode for both the source and destination.  Then you can set your alpha channel to either be 1.0 (do the additive blend of the pixel shader output and render target contents) or set it to 0.0, which would effectively zero out both the source and destination.

 

I haven't tried this out, but it seems like this could work for you.  That is of course assuming that you don't use the alpha channel already!

Share this post


Link to post
Share on other sites
Jason Z    6434

In that case, I don't think its possible without having a copy of the render target available as a SRV...  I would be happy to see someone come up with a solution, but I don't think you can do it.

Share this post


Link to post
Share on other sites
Tsus    1186

Hi!

Will your float texture ever contain negative values?

It's not strikingly elegant, but: in case you need to clear a pixel, you could write out a large negative value, giving you after the additive blending something that is smaller than zero.

When you use the texture later, you could clamp the value again up to zero: max(0, texture_color).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this