Sign in to follow this  
C0nn

D3D10_BLEND_OP_MAX

Recommended Posts

[font="arial, verdana, tahoma, sans-serif"][size="2"]Hey there,
I have a problem understanding the results of this operation. I have attached an image of my small test.

The red cube is drawn first. Blending is only enabled when rendering the second cube (green). The red cube is solid with an alpha value of 1.0. The green cube is semi-transparent with an alpha value of 0.5.
My blend description looks like this:
[code]D3D10_BLEND_DESC desc = {0};
desc.AlphaToCoverageEnable = 0;
desc.BlendEnable[0] = true;
desc.SrcBlend = D3D10_BLEND_ZERO;
desc.DestBlend = D3D10_BLEND_ZERO;
desc.BlendOp = D3D10_BLEND_OP_MAX;
desc.SrcBlendAlpha = D3D10_BLEND_ONE;
desc.DestBlendAlpha = D3D10_BLEND_ZERO;
desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;[/code]
Since the source factor is zero I would assume that the green cube would be invisible; therefore not blended with the red one. The blending equation looks like this afaik:
Csrc * Fsrc (OP) Cdest * Fdest
where Cscr is the color of the source, Fscr is the blending factor of the source, Cdest and Fdest destination color and factor and (OP) the blending operation.
In this case it should be: Max(ZERO, ZERO) = black, but it's not. It seems as if both factors are ignored.

Can someone enlighten me?
Btw, is this something that belongs rather in the beginner section?[/size][/font]

Share this post


Link to post
Share on other sites
I hate to bump my own thread, but is there really nobody who has an idea? I also tried the reference driver with the same result hence I guess that I don't understand blending in DX. [img]http://public.gamedev.net/public/style_emoticons/default/huh.gif[/img]
Thanks in advance.

Share this post


Link to post
Share on other sites
[source]
desc.SrcBlend = D3D10_BLEND_ZERO;
desc.DestBlend = D3D10_BLEND_ZERO;
desc.BlendOp = D3D10_BLEND_OP_MAX;
[/source]
This says to use ( 0, 0, 0 ) for both source and destination data, and choose the greater. Which doesn't make much sense :D

Share this post


Link to post
Share on other sites
I am not sure I can follow you. I guess that [b]D3D10_BLEND_OP_MAX [/b]does a componentwise comparison in the form of
[code]MAX((Rs, Gs, Bs), (Rd, Gd, Bd)) = (MAX(Rs, Rd), MAX(Gs, Gd), MAX(Bs, Bd))
where MAX(a,b) = a if a>b
b if b>a
a=b else[/code]
Why wouldn't it make sense if D3D10_BLEND_OP_MAX((0,0,0), (0,0,0)) =(0,0,0)? Even if this would be nonsense, why does the similar operation [b]D3D10_BLEND_OP_MIN [/b]yield the expected color, which is black?

Share this post


Link to post
Share on other sites
[quote name='C0nn' timestamp='1318010742' post='4870204']
why does the similar operation [b]D3D10_BLEND_OP_MIN [/b]yield the expected color, which is black?
[/quote]
I don't know why D3D10 isn't producing expected results. Is there an effect you're trying to create, or are you just trying to understand the various blend operations?

Share this post


Link to post
Share on other sites
I am reading atm Frank D. Luna's introduction to DirectX 10. In the chapter about blending is a small example with water. He encouraged to experiment with some blending params, which I did. Everything is logical except this operation. I couldn't explain the appearance of the water, therefore I wrote a small test with just these two cubes. And I still can't explain. So no, I had no intention for a special effect, just trying to understand.

Notice that setting both blending factors to zero was just an example. Replacing it with other values (ONE, ALPHA, BLENDFACTOR etc.) still produces the same image. This behavior seems pointless and even less is it documented, hence I think I found a bug in the reference driver [img]http://public.gamedev.net/public/style_emoticons/default/cool.gif[/img], unless ofc someone explains why I am wrong.

Share this post


Link to post
Share on other sites
Nope, I think you are right. I just did a quick test in DX9 mixing all possible combinations and both min and max behave as if the factors are always one/one, i.e. ignored. I don't seem to find this mentioned in the docs so far and my google-fu doesn't give me anything useful either.

For OpenGL on the other hand it's crystal clear, e.g. here in wiki: [url="http://www.opengl.org/wiki/Blending#Blend_Equations"]Blending equations[/url]. Seems to be the expected behavior and not a bug in the pipeline.

Congrats: You actually demonstrated that docs (and books) can be misleading or even wrong. Won't be the last time, promised ;)

Share this post


Link to post
Share on other sites
Thanks for testing. I also tried finding something on this board and google but couldn't find anything. This operation is obviously not that important so nobody noticed/cared. I am still not sure if this is an error in the docs or in D3D itself. I tend to the latter so I wrote a bug report on Microsoft Connect. Strange that you can't logout from Connect if you don't accept cookies [img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] .

Hm, should have taken a closer look at your link first. It explicitly states that in OpenGL both factors are ignored. So yes, it is most probably intentional in D3D as well. Oh well, then they can use my report to update the MSDN article. Edited by C0nn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this