<p>What Direct3D render states should be used to implement Java's Porter-Duff compositing rules (CLEAR, SRC, SRCOVER, etc.)?</p>

[{'answer_id': 67873, 'author': 'Corey Ross', 'author_id': 5927, 'author_profile': 'https://Stackoverflow.com/users/5927', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m haven\'t used Java too much, but based on the <a href="http://keithp.com/~keithp/porterduff/p253-porter.pdf" rel="nofollow noreferrer">white paper from 1984</a>, it should be a fairly straightforward mapping of render state blend modes.</p>\n\n<p>There are of course more that you can do than just these, like normal alpha blending (SourceAlpha, InvSourceAlpha) or additive (One, One) to name a few. <em>(I assume that you are asking about these specifically because you are porting some existing functionality? In that cause you may not care about other combinations...)</em></p>\n\n<p>Anyway, these assume a BlendOperation of Add and that AlphaBlendEnable is true.</p>\n\n<p>Clear</p>\n\n<pre><code>SourceBlend = Zero\nDestinationBlend = Zero\n</code></pre>\n\n<p>A</p>\n\n<pre><code>SourceBlend = One\nDestinationBlend = Zero\n</code></pre>\n\n<p>B</p>\n\n<pre><code>SourceBlend = Zero\nDestinationBlend = One\n</code></pre>\n\n<p>A over B</p>\n\n<pre><code>SourceBlend = One\nDestinationBlend = InvSourceAlpha\n</code></pre>\n\n<p>B over A</p>\n\n<pre><code>SourceBlend = InvDestinationAlpha\nDestinationBlend = One\n</code></pre>\n\n<p>A in B</p>\n\n<pre><code>SourceBlend = DestinationAlpha\nDestinationBlend = One\n</code></pre>\n\n<p>B in A</p>\n\n<pre><code>SourceBlend = Zero\nDestinationBlend = SourceAlpha\n</code></pre>\n\n<p>A out B</p>\n\n<pre><code>SourceBlend = InvDestinationAlpha\nDestinationBlend = Zero\n</code></pre>\n\n<p>B out A</p>\n\n<pre><code>SourceBlend = Zero\nDestinationBlend = InvSourceAlpha\n</code></pre>\n\n<p>A atop B</p>\n\n<pre><code>SourceBlend = DestinationAlpha\nDestinationBlend = InvSourceAlpha\n</code></pre>\n\n<p>B atop A</p>\n\n<pre><code>SourceBlend = InvDestinationAlpha\nDestinationBlend = SourceAlpha\n</code></pre>\n\n<p>A xor B</p>\n\n<pre><code>SourceBlend = InvDestinationAlpha\nDestinationBlend = InvSourceAlpha\n</code></pre>\n\n<p>Chaining these is a little more complex and would require either multiple passes or multiple texture inputs to a shader.</p>\n'}, {'answer_id': 68562, 'author': 'Neal', 'author_id': 7071, 'author_profile': 'https://Stackoverflow.com/users/7071', 'pm_score': 0, 'selected': False, 'text': '<p>When I implement the render states for "A" (that is paint the source pixel color/alpha and ignore the destination pixel color/alpha), Direct3D doesn\'t seem to perform the operation correctly if the source has an alpha value of zero.  Instead of filling the target area with transparency, I\'m seeing the target area remain unchanged.  However, if I change the source alpha value to 1, the target area becomes "virtually" transparent.  This happens even when I disable the alphablending render state, so I would presume this is an attempt at optimization that\'s actually a bug in Direct3D.</p>\n\n<p>Except for this situation, it would appear that Corey\'s render states are correct.  Thanks, Corey!</p>\n'}, {'answer_id': 69665, 'author': 'Corey Ross', 'author_id': 5927, 'author_profile': 'https://Stackoverflow.com/users/5927', 'pm_score': 0, 'selected': False, 'text': '<p>One thing to check, make sure alpha test is off with</p>\n\n<pre><code>AlphaTestEnable = false\n</code></pre>\n\n<p>If that is on (along with something like AlphaFunction = Greater and ReferenceAlpha = 0), clear pixels could be thrown away regardless of the AlphaBlendEnable setting.</p>\n'}, {'answer_id': 8620911, 'author': 'benbuck', 'author_id': 716058, 'author_profile': 'https://Stackoverflow.com/users/716058', 'pm_score': 1, 'selected': False, 'text': '<p>For the "A in B" case, shouldn\'t DestinationBlend be Zero?</p>\n\n<p>A in B</p>\n\n<pre><code>SourceBlend = DestinationAlpha\nDestinationBlend = Zero\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/62661', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7071/']