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

    GetUniqueIP in a shader [SOLVED]

    SDK Help
    0
    6
    482
    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
      Helper
      last edited by

      On 28/10/2014 at 12:59, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   r14 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      Hi there, 
      can someone point me to what i am doing wrong here?
      Basically i want to use the UniqueIP of different objects within a shader, but it doesn't work. shouldn' this apply different shades of red to each object?

      Vector uniqueIDshader::Output(BaseShader *chn, ChannelData *cd)
      {
      	Vector result = Vector(0.0);
      	if (cd->vd)
      	{
      		RayObject *robj = NULL;
      		robj = cd->vd->op;
      		if (!robj) return 0.0;
      		LONG uniqueID = robj->link->GetUniqueIP();
      		result.x = (uniqueID%255)/255.0;
      		return result;
      	}
      	return result;
      }
      

      edit: generally i'd like to have a random number for each object the shader is assigned to and i thought the unique ip could be used for the random init.

      thanks,
      Ello

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

        On 29/10/2014 at 02:06, xxxxxxxx wrote:

        Hello,

        A RayObject[URL-REMOVED]'s link parameter references to the polygon object that was the base for creating that RayObject. This polygon object way be a virtual object in a generator's cache, so it may not have a valid value for UniqueIP. So you could check the generator object (via GetCacheParent()[URL-REMOVED]) for it's UniqueIP.

        But be sure to understand how GetUniqueIP()[URL-REMOVED] works. This function will not return a unique number for each element in the scene. It will return a number that is unique in the specific hierarchy level. The numbers of all parents / children in a branch create a unique IP.

        If you need a truly unique ID you may take a look at GetGUID()[URL-REMOVED].

        best wishes,
        Sebastian


        [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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

          On 29/10/2014 at 03:07, xxxxxxxx wrote:

          thank you very much! exactly that solved the problem...

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

            On 29/10/2014 at 07:55, xxxxxxxx wrote:

            I'm confused how this code can work?
            Because the shader code that runs inside of: if(cd->vd){  } does not run until the scene is rendered for me.
            So the values are gibberish until the scene is rendered at least once.

                if(cd->vd)  
              {      
                  BaseObject *obj = cd->vd->op->link->GetCacheParent();  
                  if(!obj) return 0.0;   
              
                  GePrint(obj->GetName());            //<--returns "Object" until the scene is rendered  
              
                  Matrix mtx = obj->GetMg();  
                  GePrint(RealToString(mtx.off.x));   //<--returns -1.7 until the scene is rendered  
              }
            

            How are you getting accurate values from this code without rendering the scene?

            -ScottA

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

              On 29/10/2014 at 07:57, xxxxxxxx wrote:

              it is only working when rendered. is it possible to pass colors in the editor view? if so i would be very interested in how 🙂

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

                On 30/10/2014 at 01:30, xxxxxxxx wrote:

                Hello,

                The VoumeData[URL-REMOVED] property of the ChannelData[URL-REMOVED] argument is only set when Cinema uses the shader to render a scene. But a shader is also called in two other situations.

                • When the shader preview image is calculated. Cinema will sample the shader to create this preview image using different UV-coordinates.

                • When the viewport preview texture is calculated. Cinema will bake the shader into a 2D texture to create a preview in the viewport. Also in this situation only the UV-coordinates change during sampling. If you want to define that viewport preview texture yourself you can override InitGLImage()[URL-REMOVED].

                best wishes,
                Sebastian


                [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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