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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Sampling a Fusion shader

    Cinema 4D SDK
    windows 2024 c++
    2
    3
    435
    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.
    • S
      spedler
      last edited by

      I'm writing a ShaderData plugin and what I want to do is sample a Fusion shader created programatically in the InitRender() function of my plugin.

      I'm not even sure if this is feasible, but it doesn't work as expected. Here is the code to create the Fusion shader:

      m_fusion = BaseShader::Alloc(Xfusion);
      GeData gd;
      if (m_fusion != nullptr)
      {
      	m_fusionBlendShader = BaseShader::Alloc(Xcolor);
      	if (m_fusionBlendShader != nullptr)
      	{
      		m_fusionBlendShader->InitRender(irs);
      		gd.SetBaseList2D(m_fusionBlendShader);
      		const DescID blendID = ConstDescID(DescLevel(SLA_FUSION_BLEND_CHANNEL, DTYPE_BASELISTLINK, 0));
      		m_fusion->SetParameter(blendID, gd, DESCFLAGS_SET::NONE);
      	}
      	m_fusionBaseShader = BaseShader::Alloc(Xcolor);
      	if (m_fusionBaseShader != nullptr)
      	{
      		m_fusionBaseShader->InitRender(irs);
      		gd.SetBaseList2D(m_fusionBaseShader);
      		const DescID baseID = ConstDescID(DescLevel(SLA_FUSION_BASE_CHANNEL, DTYPE_BASELISTLINK, 0));
      		m_fusion->SetParameter(baseID, gd, DESCFLAGS_SET::NONE);
      	}
      	m_fusion->InitRender(irs);
      	m_fusionInitCount++;
      }
      

      I've just used color shaders in the Fusion blend and base channels for convenience; this should cause the Fusion to return pure white.

      Everything seems to work as expected, in that it compiles and runs and the shaders are all allocated, but when I sample the Fusion shader in my shader's Output function, it always returns black. I'm not sure if this is because I haven't set the blend and base channels correctly or if this simply can't work, so any advice would be greatly appreciated.

      Many thanks,
      Steve

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

        Hey @spedler,

        Thank you for reaching out to us. At a glance, the issue seems to be that you do not insert the shaders into the fusion shader. You might want to have a look at Base Shader Manual: Access and Structure which I once added for the very case of you are currently in: Shaders which own shaders.

        In case that this does not solve your issue, I would have to ask for a bit more complete code example, so that we can more easily run your code.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        S 1 Reply Last reply Reply Quote 0
        • S
          spedler @ferdinand
          last edited by

          Hi @ferdinand,

          Thanks for this, inserting the colour shaders uner the Fusion shader and then inserting the Fusion shader under my shader works fine.

          I must admit this is my fault. Because the shaders are all created in the InitRender() of my plugin, I didn't think they needed to be (or could be) inserted under my shader. I figured it would be different if the shaders were going to be added to a link field and stay in the document, but not if they're just created then destroyed when done with. So that's very useful to know.

          Thanks again,
          Steve

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