Solved How to bake shader into basebitmap?

Hi all,

I'm trying to use BaseShader::BakeShaderIntoBaseBitmap() to get a 2D representation of the shader. However, I couldn't get the correct result.

BaseDocument* bd = GetActiveDocument();
InitRenderStruct irs{ bd };
BaseBitmap* bit = BaseBitmap::Alloc();
BaseShader* shader = mat->GetChannel(CHANNEL_DIFFUSION)->GetShader();
shader->BakeShaderIntoBaseBitmap(*bit, *bd, irs.thread, false, irs.document_colorprofile, irs.linear_workflow, true, 0, 1000, 0, 1000)

I have read 'BaseShader Manual', but I'm not sure where to get a parentThread, so I used irs.thread...

Any ideas or examples?


What do you mean by "get the correct result" ?

in the BaseShader manual, the thread is just the current thread :

BaseThread* const parentThread = GeGetCurrentThread();
if (parentThread == nullptr)
	return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);

You should just have to passe the thread provided to you by a function argument where you are executing your code, retrieve the CurrentThread or use nullptr.

Your bitmap must be initialise :

AutoAlloc<BaseBitmap> bitmap;
if (bitmap == nullptr)
	return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);

const maxon::Int32 sizeX = 256;
const maxon::Int32 sizeY = 256;
const maxon::Int32 bitDepth = 32;

const IMAGERESULT imageResult = bitmap->Init(sizeX, sizeY, bitDepth, INITBITMAPFLAGS::NONE);
if (imageResult != IMAGERESULT::OK)
	return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);

By the way, the bitmap argument pointer passed to BakeShaderIntoBaseBitmap should be passe without the * before it.

hope that help, let us know if you have more questions


MAXON SDK Specialist

MAXON Registered Developer

Thanks a lot!