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

    BakeShaderIntoBaseBitmap and Alphas

    Cinema 4D SDK
    c++
    2
    4
    713
    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.
    • R
      rui_mac
      last edited by

      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?

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @rui_mac
        last edited by

        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

        MAXON SDK Specialist
        developers.maxon.net

        R 1 Reply Last reply Reply Quote 0
        • R
          rui_mac
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • R
            rui_mac @i_mazlov
            last edited by

            @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.

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