Default blend state for transparent objects

I've ran into this behavior:

  1. Create object with PBR material
  2. Set HasTransparency to true
  3. Set alpha to 0 (should be invisible).
It can be reproduced by modifying PBRPropertiesSample.CreateSampleScene (skip the texture initialization and the updates and only set the values as described above).

When you rotate around the object, you can see other objects behind it with a color tint that corresponds to the material base color. Is this expected behavior? 

I assume it's caused because the transparent queue uses PremultipliedAlphaBlend (that's just my assumption) and setting the materials blend state to DXDevice.CommonState.NonPremultipliedAlphaBlend resolves this issue.

Is there a way to set it globally? And what possible effects it could have? Just so that I know if I should do it on per-object basis.

Best regards,
Roman Janovsky
You are right - DXEngine is using pre-multiplied alpha because this provides correct results when blending transparent pixels (see internet for advantages of using pre-multiplied alpha).

When creating a PhysicallyBasedMaterial in DXEngine you cannot just set the Alpha value (there is no Alpha property as in the StandardMaterial). So you can only change alpha by updating the BaseCalor property (Color4 type). When doing that you must set the color with premultiplied alpha value otherwise you will get a color blend (as you have described). This means that red, green and blue color values must be multiplied by the alpha value. In your case (alpha = 0) you should set the BaseColor = Color4(0, 0, 0, 0). // the last parameter is alpha

I have updated the XML comment for BaseColor property by adding information that the color needs to be alpha pre-multiplied.

Also, I would recommend you to use IsVisible property to hide the object because this will skip rendering hidden objects, while setting alpha to 0 will still render the object.
Andrej Benedik
Thank you for the explanation and the tip. The change in alpha is related to color animation, so it should be helpful to disable rendering of fully transparent objects to remove some rendering work. I'll do some profiling :)

Forum Jump:

Users browsing this thread:
1 Guest(s)