GetUniqueIP in a shader [SOLVED]



  • 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



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

    Hello,

    A RayObject'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()) for it's UniqueIP.

    But be sure to understand how GetUniqueIP() 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().

    best wishes,
    Sebastian



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

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



  • 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



  • 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 :)



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

    Hello,

    The VoumeData property of the ChannelData 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().

    best wishes,
    Sebastian


Log in to reply