I'm using a pre-built material of Qt3D:
Qt3DRender::QMaterial *MyClass::createMaterial()
{
Qt3DExtras::QPhongAlphaMaterial *mat = new Qt3DExtras::QPhongAlphaMaterial();
mat->setAmbient(QColor("#576675"));
mat->setDiffuse(QColor("#5F6E7D"));
mat->setSpecular(QColor("#61707F"));
mat->setShininess(0.0f);
mat->setAlpha(0.5f);
return mat;
}
I set alpha to 0.5f
, so I expect the material be semi-transparent. But the model looks mostly white except some regions:
When I check the source code I see this settings for alpha-blending:
m_blendState->setSourceRgb(QBlendEquationArguments::SourceAlpha);
m_blendState->setDestinationRgb(QBlendEquationArguments::OneMinusSourceAlpha);
m_blendEquation->setBlendFunction(QBlendEquation::Add);
I wonder why the model looks white?
As suggested by @Macke, the object on black background looks fine!
When I set alpha
to 1.0
, I observe this:
As pointed out by @Macke, one issue was related to depth test. On the source code, depth mask is disabled by default:
// ...
, m_noDepthMask(new QNoDepthMask())
// ...
m_phongAlphaGL3RenderPass->addRenderState(m_noDepthMask);
m_phongAlphaGL2RenderPass->addRenderState(m_noDepthMask);
m_phongAlphaES2RenderPass->addRenderState(m_noDepthMask);
I enabled depth mask by removing QNoDepthMask
stuff, and now with alpha = 1.0
the rendering result is fine:
Suggested by @EddyAlleman, I added such lines of code:
blendState->setSourceAlpha(Qt3DRender::QBlendEquationArguments::Zero);
blendState->setDestinationAlpha(Qt3DRender::QBlendEquationArguments::One);
Then, the transparency (alpha = 0.4
) is fine even on gray background:
try this to set the blendequation state
set sourceAlphaArg to Qt3DRender::QBlendEquationArguments::Zero
set destinationAlphaArg to Qt3DRender::QBlendEquationArguments::One
info from enum QBlendEquationArguments::Blending
Constant Value OpenGL Qt3DRender::QBlendEquationArguments::Zero 0 GL_ZERO Qt3DRender::QBlendEquationArguments::One 1 GL_ONE
EDIT: a good explanation can be found here: learnopengl.com/Advanced-OpenGL/Blending
Try not using blendequation, seems like the color computed by blendstate is added to the gray background. (maybe good for got particle sparks, less so for objects)
How does it look with black background?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With