0

I can use a pixel shader in WPF to remove a specific color, but there are alpha pixels layered over the background. I want to remove a background color, but keep alpha pixels.

For example, I have Image 1. It is a red rectangle with opacity 50% overlaid on a solid black background. I want to remove the black background so that the red rectangle stays alpha 50% and then I can overlay the resulted image on blue background like on Image 2-3 (left).

But by using a pixel shader to remove a specific color, I get Image 2-3 (right), which is not what I want.

Image 2-3.

  1. Is it possible?
  2. How is this process called?
  3. What pixel shader can I use to do it in WPF?
Ziya Jafarov
  • 41
  • 1
  • 6
  • Can you attach existing code and describe the problem with it more clearly (e.g. by adding screenshots)? See [my question](http://stackoverflow.com/q/26216904/1997232) (simply one with shaders). – Sinatr Aug 11 '16 at 09:06
  • @Sinatr I updated the question by adding an example with images. Let me know, if something needs a clarification. – Ziya Jafarov Aug 11 '16 at 10:12
  • Keep in mind what graphicscard is doing. It renders from back to front. If you render the red rectangle on top, there is no black background anymore, Just the blended pixels of the red rectangle. All you can do is, change the blending funktion to keep opacity alive for the red rectangle, then you can blend the blue "background" on top. – kaiser Aug 28 '16 at 17:51
  • @kaiser, You are right, I know there is no background, only pixels. But you don't get a point. The point is to calculate an equivalent alpha channel color on a black background and apply it instead of a pixel. I can verify it is possible to do in math, but I am not sure about possibility to do it in a pixel shader. I need a pixel shader to do it. – Ziya Jafarov Aug 29 '16 at 09:47
  • Set the background alpha the alpha value of your red rectangle (and not to 1). When you render the blue background on top, you can again blend the background with the alpha of your current backbuffer (in your case the alpha value of the red rectangle) – kaiser Aug 29 '16 at 22:19
  • @kaiser, I didn't get your idea, but I think it can not be fixed so easy, because I can't set alpha of background, it is only solid black. In the same way, I could set the background alpha to 0. I need it, because I have semi transparent videos, but MediaElement draws semi transparent areas on black background. I want to remove the background so that semi transparent pixels should be left as they are. – Ziya Jafarov Aug 30 '16 at 12:31

0 Answers0