Initialising Gradient



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/11/2010 at 07:31, xxxxxxxx wrote:

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

    ---------
    Hi,

    in pre R12 I used to initialise a gradient element like this in a shader::Init() :

       AutoAlloc<Gradient> gradient1;  
      if (!gradient1) return FALSE;  
      
      GradientKnot k1;  
      k1.col =Vector(1.0,1.0,1.0);  
      k1.pos =1.0;  
      gradient1->InsertKnot(k1);  
      k1.col =Vector(0.0,0.0,0.0);  
      k1.pos =0.0;  
      gradient1->InsertKnot(k1);  
      gradient1->SetData(GRADIENT_INTERPOLATION,GRADIENT_INTERPOLATION_LINEAR);  
         data->SetData(DPIT_SMOKE_NOISE_GRADIENT,GeData(CUSTOMDATATYPE_GRADIENT,gradient1));
    

    In R12 however this doesn´t work anymore (the gradient is initialised completely white). How does it work in R12?

    Thanks



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/11/2010 at 07:50, xxxxxxxx wrote:

    Ok, it seems the gradient IS correctly initialised but it anyway shows all the knots as white. And as soon as you touch the knots it indeed gets white. So is this a bug or am I doing anything wrong? It worked just fine before R12. :-/



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/11/2010 at 07:56, xxxxxxxx wrote:

    Hm, looks ok to me.

    This is the code from the SDKGradient example:

      
    Bool SDKGradientClass::Init(GeListNode *node)  
    {  
      BaseContainer *data = ((BaseShader* )node)->GetDataInstance();  
      
      AutoAlloc<Gradient> gradient;  
      if (!gradient) return FALSE;  
      
      GradientKnot k1,k2;  
      k1.col =Vector(0.0,0.0,1.0);  
      k1.pos =0.0;  
      
      k2.col =1.0;  
      k2.pos =1.0;  
      
      gradient->InsertKnot(k1);  
      gradient->InsertKnot(k2);  
      
      data->SetData(SDKGRADIENTSHADER_COLOR,GeData(CUSTOMDATATYPE_GRADIENT,gradient));  
      data->SetBool(SDKGRADIENTSHADER_CYCLE,FALSE);  
      data->SetLong(SDKGRADIENTSHADER_MODE,0);  
      data->SetReal(SDKGRADIENTSHADER_ANGLE,0.0);  
      
      data->SetReal(SDKGRADIENTSHADER_TURBULENCE,0.0);  
      data->SetReal(SDKGRADIENTSHADER_OCTAVES,5.0);  
      data->SetReal(SDKGRADIENTSHADER_SCALE,1.0);  
      data->SetReal(SDKGRADIENTSHADER_FREQ,1.0);  
      data->SetBool(SDKGRADIENTSHADER_ABSOLUTE,FALSE);  
        
      return TRUE;  
    }  
    

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/11/2010 at 08:05, xxxxxxxx wrote:

    yeah, I also found this in the sdk and it seems to work in the sdk example. Any idea what might be the problem? It´s the same for all my gradients so it seems strange. I also looked up the resources and beside having the ICC_BASEDOCUMENT; flag (which I added now to mine too but didn´t change anything) there´s nothing new to it.

    Also in InitRender I call InitRender(irs) as in the sdk example but this doesn´t seem to change anything (well, how should it, it´s just the new call to pass irs). Could it be because I am in a MaterialData and not a ShaderData? Because in my ChannelShaders it works just fine!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/11/2010 at 08:10, xxxxxxxx wrote:

    hmm, no. I just added it to the simplematerial example and it works there. Argh, what could it be? I mean it worked before just fine and now in R12 it doesn´t. Did anything concerning resources convention change or similar? I am also using a custom material preview, could that be it? Also I am using the Obaselist for the material manager and the gradient is in a different GROUP.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/11/2010 at 08:28, xxxxxxxx wrote:

    Ah! It happens with the ALPHA flag only! This also happens in the simplematerial. So is this to be considered a bug?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/11/2010 at 08:31, xxxxxxxx wrote:

    Here is the changed code I used for testing in simplematerial:

      
    class SimpleMaterial : public MaterialData  
    {  
      INSTANCEOF(SimpleMaterial,MaterialData)  
      
      private:  
          Vector color;  
          Gradient* grad;  
      public:  
          virtual Bool Init        (GeListNode *node);  
          virtual    void CalcSurface            (BaseMaterial *mat, VolumeData *vd);  
          virtual    INITRENDERRESULT InitRender(BaseMaterial *mat, const InitRenderStruct &irs);  
          virtual    void FreeRender(BaseMaterial *mat)  
          {  
              if(grad) grad->FreeRender();  
          }  
      virtual Bool GetDParameter(GeListNode *node, const DescID &id,GeData &t_data,DESCFLAGS_GET &flags);  
      virtual Bool SetDParameter(GeListNode *node, const DescID &id,const GeData &t_data,DESCFLAGS_SET &flags);  
      virtual Bool Message(GeListNode* node, LONG type, void* data);  
      virtual Bool CopyTo(NodeData *dest, GeListNode *snode, GeListNode *dnode, COPYFLAGS flags, AliasTrans *trn);  
      
          static NodeData *Alloc(void) { return gNew SimpleMaterial; }  
      
      LONG updatecount;  
    };  
      
    Bool SimpleMaterial::Init(GeListNode *node)  
    {  
      BaseContainer *data=((BaseMaterial* )node)->GetDataInstance();  
      data->SetVector(SIMPLEMATERIAL_COLOR,1.0);  
      updatecount = 0;  
      
      GeData previewData(CUSTOMDATATYPE_MATPREVIEW, DEFAULTVALUE);  
      MaterialPreviewData* preview = (MaterialPreviewData* )previewData.GetCustomDataType(CUSTOMDATATYPE_MATPREVIEW);  
      if (!preview)  
      return FALSE;  
      data->SetData(SIMPLEMATERIAL_MAT_PREVIEW, previewData);  
      
      AutoAlloc<Gradient> gradient;  
      if (!gradient) return FALSE;  
      
      GradientKnot k1,k2;  
      k1.col =Vector(1.0,1.0,1.0);  
      k1.pos =0.0;  
      
      k2.col =1.0;  
      k2.pos =1.0;  
      
      gradient->InsertKnot(k1);  
      gradient->InsertKnot(k2);  
      
      data->SetData(SIMPLEMATERIAL_COLORG,GeData(CUSTOMDATATYPE_GRADIENT,gradient));  
      return TRUE;  
    }  
      
    INITRENDERRESULT SimpleMaterial::InitRender(BaseMaterial *mat, const InitRenderStruct &irs)  
    {  
      BaseContainer *data=mat->GetDataInstance();  
      color = data->GetVector(SIMPLEMATERIAL_COLOR);  
      grad     = (Gradient* )data->GetCustomDataType(SIMPLEMATERIAL_COLORG,CUSTOMDATATYPE_GRADIENT);   
      if (!grad || !grad->InitRender(irs)) return INITRENDERRESULT_OUTOFMEMORY;  
      return INITRENDERRESULT_OK;  
    }
    

    .h

    enum  
    {  
      ID_TESTGROUP = 3000,  
      SIMPLEMATERIAL_COLOR        = 1000,  
      SIMPLEMATERIAL_MAT_PREVIEW  = 1001,  
          SIMPLEMATERIAL_COLORG,  
    };
    

    .res

      
      GROUP ID_MATERIALPROPERTIES  
      {  
          DEFAULT 1;  
          COLOR     SIMPLEMATERIAL_COLOR {}  
      }  
      GROUP ID_TESTGROUP  
      {  
          GRADIENT SIMPLEMATERIAL_COLORG {ALPHA;}          
      }
    

    .str

      
      SIMPLEMATERIAL_COLOR    "Color";  
      SIMPLEMATERIAL_COLORG "Testgradient";  
      
      ID_TESTGROUP "Test";
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/02/2011 at 02:42, xxxxxxxx wrote:

    Alpha gradients have to be set their mode before any knot is set.

    Example:

      
    Bool SDKGradientClass::Init(GeListNode *node)  
    {  
      BaseContainer *data = ((BaseShader* )node)->GetDataInstance();  
      
      AutoAlloc<Gradient> gradient;  
      if (!gradient) return FALSE;  
      
      //ust be set before any knot is set  
      gradient->SetData(GRADIENT_MODE, GeData(GRADIENTMODE_ALPHA));  
        
      GradientKnot k1,k2;  
      k1.col =Vector(0.0,0.0,1.0);  
      k1.pos =0.0;  
      
      k2.col =1.0;  
      k2.pos =1.0;  
      
      gradient->InsertKnot(k1);  
      gradient->InsertKnot(k2);  
      
      data->SetData(SDKGRADIENTSHADER_COLOR,GeData(CUSTOMDATATYPE_GRADIENT,gradient));  
        
      return TRUE;  
    }  
    

    I will update the docs accordingly.

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/02/2011 at 02:54, xxxxxxxx wrote:

    thank you Matthias. I confirm it's working fine now. super.


Log in to reply