BakeShaderIntoBaseBitmap and Alphas
-
If I have a PNG file in a Link field of a shader, and I use BakeShaderIntoBaseBitmap to get a bitmap that I can read the RGB and alpha values of the pixels, the internal alpha of the PNG file is ignored.
I mean, I create the bitmap with:AutoAlloc<BaseBitmap> bitmap; if (bitmap != nullptr) { const IMAGERESULT imageResult = bitmap->Init(256, 256, 32, INITBITMAPFLAGS::NONE); if (imageResult == IMAGERESULT::OK) { shader->BakeShaderIntoBaseBitmap(*bitmap, *irs.doc, nullptr, true, irs.document_colorprofile, irs.linear_workflow, true, 0, 255, 0, 255); cfdata.bt_middle = BaseBitmap::Alloc(); bitmap->CopyTo(cfdata.bt_middle); } } }
... I get a bitmap without any alpha channel, even if I Init it with 32 bits and set the doAlpha parameter of the BakeShaderIntoBaseBitmap command to true.
How can I get a bitmap from the Link field of a shader that, if it is an image with alpha (a PNG, or a TIFF, or a TGA), it respects its alpha? -
Hi @rui_mac,
Could you please provide a little more context and code, how specifically you run into this issue? How exactly do you check that your baked RGB image has no alpha available? I know there were some issues in Picture Viewer showing alpha channel (which could be the case that your image does have alpha but you cannot see it in the PV).
In general the doAlpha flag should do its job, so if it doesn't - it's likely a bug. Unfortunately, I will be able to check this earliest next week.
Cheers,
Ilia -
I was able to solve it by reading the alpha directly from the image file.
But I will past my previous code here (the one that was not creating any alpha) as soon as I get home. -
@i_mazlov
Here is a snippet of my code:BaseShader* shader; shader = (BaseShader*)dat->GetLink(CUBICFACE_BACK_TEXTURE, irs.doc); if (shader != nullptr) { AutoAlloc<BaseBitmap> bitmap; if (bitmap != nullptr) { const IMAGERESULT imageResult = bitmap->Init(quality, quality, 32, INITBITMAPFLAGS::NONE); if (imageResult == IMAGERESULT::OK) { shader->BakeShaderIntoBaseBitmap(*bitmap, *irs.doc, nullptr, true, irs.document_colorprofile, irs.linear_workflow, true, 0, quality-1, 0, quality-1); cfdata.bt_back = BaseBitmap::Alloc(); bitmap->CopyTo(cfdata.bt_back); } } }
However, even if the texture placed in the link CUBICFACE_BACK_TEXTURE is a PNG with trnasparency or a shader that creates an alpha (like Fire or Flame), the resulting bitmap never gets an alpha.