Sign in to follow this  

blending question

This topic is 1706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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

Oops I forgot to say that too, I can't use alpha

Any other way?

Edited by lomateron

Share this post


Link to post
Share on other sites

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

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
Sign in to follow this