Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How to bake shader into basebitmap?

    Cineware SDK
    2
    3
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hazzzel
      last edited by hazzzel

      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)
      ShowBitmap(bit);
      

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

      Any ideas or examples?

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,

        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

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • H
          hazzzel
          last edited by

          Thanks a lot!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post