![]() |
|
Default blend state for transparent objects - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: Ab3d.DXEngine (https://forum.ab4d.com/forumdisplay.php?fid=11) +--- Thread: Default blend state for transparent objects (/showthread.php?tid=4329) |
Default blend state for transparent objects - janovrom - 05-26-2022 Hi, I've ran into this behavior:
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 RE: Default blend state for transparent objects - abenedik - 05-27-2022 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. RE: Default blend state for transparent objects - janovrom - 05-27-2022 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 :) |