Solved get bitmap of shader in r20

Hi,

I'm working on r20, and I found I can't use BaseShader::BakeShaderIntoBaseBitmap() because it is a new feature in r21. Trying find a way around, I want to extract the bitmap of the layer shader. However, my code does not work.

BaseBitmap* diffuseBitmap ;
GeData gd;
BaseShader* shader = bm->GetChannel(CHANNEL_DIFFUSION)->GetShader();

if (shader->GetType() == Xlayer) {
    LayerShader* layerShader = static_cast<LayerShader*>(shader); 
    LayerShaderLayer* layerShaderLayer = layerShader->GetFirstLayer();
    while (layerShaderLayer != NULL)
    {
        if (layerShaderLayer->GetType() == LayerType::TypeShader)
	{
	    Bool res = layerShaderLayer->GetParameter(LAYER_S_PARAM_SHADER_LINK, gd);

	    // diffuseBitmap = layerShaderLayer->GetPreview(); // this does not work, too!

	    BaseLink *bl = gd.GetBaseLink(); // program stop here, and I can't see why
	    BaseShader *thisShader = static_cast<BaseShader*>(bl->GetLinkAtom(bd));

	    thisShader->InitRender(irs);
	    diffuseBitmap = thisShader->GetBitmap();
	    thisShader->FreeRender();

            break;
	}
	layerShaderLayer = layerShaderLayer->GetNext();
    }
}
else
{
    // ...
}

ShowBitmap(diffuseBitmap); // can't see anything here when using 'layerShaderLayer->GetPreview()'
diffuseBitmap->Save(fn, FILTER_JPG, nullptr, SAVEBIT::NONE); // fail when using 'GetPreview()'

Could anyone kindly explain where I am doing wrong? Thanks a lot!

Hi,

what is wrong with BaseShader::Sample? BakeShaderIntoBaseBitmap is probably only a convenience wrapper around that method. For your program "stoping" (this is a quite broad description), have you ensured, that your BaseLink is actually populated and does not just return the null pointer?

Cheers,
zipit

MAXON SDK Specialist
developers.maxon.net

Thank you for your reply, the BaseShader::Sample() helps me solve this problem. (Except that when the layer shader use transform layer, scale transformation is not automatically handled.) Anyway, thanks a lot!

Hi @hazzzel thanks for reaching out us.

With regard to your question, please consider that you might have to attach a VolumeData to the InitRenderStruct.

For this scope please have a look at:

Best, R.