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

    Getting the object it is being rendered, from inside a shader plugin

    Cinema 4D SDK
    python 2024
    2
    2
    243
    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

      I already searched for this in the forum and found some similar questions and answers and thay are all quite old.
      One of then was even asked by me a long time ago, when I was still using COFFEE.
      And some other were asked about PYTHON and the answer was that it was only possible in C++.
      But a lot of time has passed and I would like to know if such a basic thing was already possible in PYTHON.
      So, is there any way to know what object is being rendered inside the Output method of a PYTHON shader plugin?

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

        Hey @rui_mac,

        thank you for reaching out to us. In general only shaders which are volume shaders have access to the object for which they are being called for. In Python (or in COFFEE) you cannot implement volume shaders and therefore cannot access the object which is being rendered.

        When you are implementing a volume shader in C++, you can do this (untested pseudo code):

        cinema::Vector MyShader::Output(cinema::BaseShader* shader, cinema::ChannelData* cd){
          // Get the volume data from the channel data.
          cinema::VolumeData* const vd = cd ? cd->vd : nullptr;
          if (!vd)
            return COLOR_RENDER_ERROR;
        
          // Get the ray objects.
          for (cinema::Int32 i; i < vd->GetObjCount(); i++)
          {
            const cinema::RayObject* const ro = vd->GetObj(i);
            if (!obj)
              continue;
           
            // Attempt to find the object this ray object has been constructed for.
            const cinema::BaseObject* const op = ro._texture_link ? ro._texture_link : ro._link;
            if (!op)
              return COLOR_RENDER_ERROR;
            
            // Do stuff with the object ...
          }
        
          return COLOR_RENDER_ERROR;
        }
        

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

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