title: Photoshop's "Screen" mode in DirectX
body: <p>Edit: Problem solved! See end of post.</p>
  
  <p>How to implement "Screen" blending mode from Photoshop in DirectX 8?</p>
  
  <p>Info, i've found on this topic (<a href="http://www.ziggyware.com/readarticle.php?article_id=228" rel="nofollow noreferrer">http://www.ziggyware.com/readarticle.php?article_id=228</a>):</p>
  
  <blockquote>
  <pre><code>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 + source – source * destination
  Result = destination + source * (1 – destination)
  </code></pre>
    
    <p>Now that we have the math worked out,
    we simply have to set the blend modes:</p>
  
  <pre><code>BlendOperation = Add
  DestinationBlend = One
  SourceBlend = InvDestColor
  </code></pre>
  </blockquote>
  
  <p>I assume DirectX blending states must be:</p>
  
  <pre><code>pD3DDevice-&gt;SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
  pD3DDevice-&gt;SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
  pD3DDevice-&gt;SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);
  </code></pre>
  
  <p>Is it correct? (I have a wrong result)</p>
  
  <p>Sample project: <a href="http://www.fileqube.com/shared/cqktZO1459443" rel="nofollow noreferrer">Link</a> <a href="http://rapidshare.com/files/241780033/ScreenBlendTest.zip" rel="nofollow noreferrer">Mirror</a></p>
  
  <p>Photoshop result:</p>
  
  <p><a href="http://img192.imageshack.us/img192/7015/photoshopf.jpg" rel="nofollow noreferrer">http://img192.imageshack.us/img192/7015/photoshopf.jpg</a></p>
  
  <p>My result in DirectX:</p>
  
  <p><a href="http://img193.imageshack.us/img193/2969/directx.jpg" rel="nofollow noreferrer">http://img193.imageshack.us/img193/2969/directx.jpg</a></p>
  
  <p>Problem solving:
  formula doesn't consider image alpha, to fix it you need to make image background solid black with 100% opacity</p>