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

    get bitmap of shader in r20

    Cineware SDK
    r20 c++
    4
    4
    1.4k
    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,

      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!

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by

        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

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

          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!

          1 Reply Last reply Reply Quote 0
          • r_giganteR
            r_gigante
            last edited by

            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:

            • Sampling a Shader.
            • Creating a VolumeData about using Render::GetInitialVolumeData() or VolumeData::Alloc()
            • Post #8 in Sample a shader thread.

            Best, R.

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