Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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
    • Recent
    • Tags
    • Users
    • Register
    • Login

    How to detect Global Illumination state via Python API?

    Scheduled Pinned Locked Moved Cinema 4D SDK
    python2024
    3 Posts 2 Posters 24 Views 2 Watching
    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.
    • mfersaouiM Offline
      mfersaoui
      last edited by

      Hello,

      I'm developing a plugin and need to programmatically detect whether Global Illumination is enabled in the current render settings.

      I've tried several approaches but none seem to work reliably. Some constants like c4d.RDATA_GI or c4d.RDATA_GLOBILLUM_ENABLE don't appear to exist, and accessing VideoPost parameters returns unexpected values.

      My question is: what is the correct and recommended way to detect if Global Illumination is currently enabled? Is there a specific constant, parameter ID, or API method I should be using?

      Any guidance would be greatly appreciated!

      Thank you.

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

        Hey @mfersaoui,

        Thank you for reaching out to us. The question is a bit ambiguous. What it entails when 'Global Illumination is enabled' (or not), differs from render engine to render engine. There is neither an abstracted switch to toggle GI in all render engines, nor a flag which would signal of GI is enabled or not.

        So, the first thing you would have to do, is read RDATA_RENDERENGINE and then branch of based on that. For the standard renderer, you would then check if the GI post effect is loaded and enabled. For Redshift you would get the RS post effect and then check there if has GI enabled.

        You can find the post effect symbols here: VideoPost Types

        Cheers,
        Ferdinand

        Some example code for searching the post effects in some render data.

        # Get the active render data of the document.
        renderData: c4d.documents.RenderData = doc.GetActiveRenderData()
        
        # Set the active render engine to Redshift.
        renderData[c4d.RDATA_RENDERENGINE] = c4d.VPrsrenderer
        
        # Iterate over all video post effects and remove any effect not compatible with the Redshift 
        # render engine and finally make sure the Redshift video post effect itself is present. We do 
        # not remove the effects in place in the loop, as that would mess up the iteration because nodes
        # effectively work as a linked list.
        removeEffects: list[c4d.documents.BaseVideoPost] = []
        foundRedshiftEffect: bool = False
        for effect in mxutils.IterateTree(renderData.GetFirstVideoPost(), True):
            # This is the Redshift video post effect.
            if effect.GetType() == c4d.VPrsrenderer:
                foundRedshiftEffect = True
                continue
            # This is some effect not compatible with Redshift.
            elif not effect.RenderEngineCheck(c4d.VPrsrenderer):
                removeEffects.append(effect)
        
        # Remove all the video post effects we marked for removal.
        for effect in removeEffects:
            effect.Remove()
        
        # And add the Redshift video post effect if it was not found yet. Note that there is no hard
        # guarantee that a render engine uses the same ID for its video post effect as the render 
        # engine ID (VPrsrenderer in this case). But it is a very common convention, check with your
        # render engine vendor for details.
        if not foundRedshiftEffect:
            redshiftEffect: c4d.documents.BaseVideoPost = mxutils.CheckType(
                c4d.documents.BaseVideoPost(c4d.VPrsrenderer))
            renderData.InsertVideoPost(redshiftEffect)
        

        MAXON SDK Specialist
        developers.maxon.net

        mfersaouiM 1 Reply Last reply Reply Quote 0
        • mfersaouiM Offline
          mfersaoui @ferdinand
          last edited by mfersaoui

          @ferdinand
          Hey @ferdinand,

          Thank you again for the clarification — checking the Video Post list was indeed the right direction.

          Just to share what worked on my side (Standard/Physical renderer), I check the presence of the GI Video Post and use its BIT_VPDISABLED state to determine whether it’s enabled.

          Here’s the small helper function I’m using:

          def is_gi_active(doc):
              rd = doc.GetActiveRenderData()
              if not rd:
                  return False
          
              # GI Video Post IDs (verified on C4D 2024)
              GI_IDS = [
                  1021096,    # Global Illumination Video Post (C4D 2024)
                  300001038,  # VPglobalillumination (older versions)
              ]
          
              vp = rd.GetFirstVideoPost()
              while vp:
                  if vp.GetType() in GI_IDS:
                      return not vp.GetBit(c4d.BIT_VPDISABLED)
                  vp = vp.GetNext()
          
              return False
          

          Thanks again for your help.

          Best regards,
          Mustapha

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