Photoshop Screen Mode in DirectX

Edit: The problem is resolved! See End of Post.

How to implement the "Screen" blending mode from Photoshop to DirectX 8?

The information I found on this topic ( http://www.ziggyware.com/readarticle.php?article_id=228 ):

Result = 1 – (1 – destination) * (1 – source) Result = 1 – (1 – source – destination + destination * source) Result = 1 – 1 + source + destination – destination * source Result = source + destination – destination * source Result = destination + sourcesource * destination Result = destination + source * (1 – destination) 

Now that we have developed the math, we just need to set the blending modes:

 BlendOperation = Add DestinationBlend = One SourceBlend = InvDestColor 

I assume that DirectX mix states should be:

 pD3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR); 

Is it correct? (I have the wrong result)

Project Example: Mirror Link

Photoshop Result:

http://img192.imageshack.us/img192/7015/photoshopf.jpg

My result in DirectX:

http://img193.imageshack.us/img193/2969/directx.jpg

Problem solving: the formula does not consider the image alpha, to fix this, you need to make the image a solid black background with 100% opacity

+4
source share
2 answers

Invalid line:

 pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD); 

Your intention is probably that the alpha blender should do ADD, but the D3DTSS_COLOROP parameter does not affect the final blender, instead it installs a texture compiler. You set it to add something (the result of the previous / next stage or something like that) to the color you selected from the texture, which is incorrect. D3DTOP_SELECTARG1 or, by default, D3DTOP_MODULATE should complete the task.

Instead, you need to write:

 pD3DDevice->SetRenderState(D3DBLENDOP, D3DBLENDOP_ADD); 
+2
source

The math seems right, and the way you install DirectX features should work.

My advice:

  • Use the same images that you use in Photoshop, so you know that this is not doing pure white correctly (maybe).
  • Make sure you can perform other blending modes and that they generate the correct output.

    • apologies if you have already done this.
0
source

Source: https://habr.com/ru/post/1285851/


All Articles