Getting data from SHADERLINK

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

On 13/05/2007 at 14:10, xxxxxxxx wrote:

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

---------
Hi,
i can't find any tutorials about introduction about writing sdk plugins, and i have (propably) realy basics problems.

I created a simple SHADERLINK in gui,
(like that: SHADERLINK MATERIAL_ALPHA_SHADER2 { } ), and i'm trying, and trying, and trying to read data and everything gone for nothing.

example:
BaseDocument *doc;
BaseLink *tekstura;
BaseList2D *bl;

// in InitRender
PluginShader *shader = NULL;
tekstura = data->GetBaseLink(MATERIAL_ALPHA_SHADER2);
     if(tekstura!=NULL){
          bl = tekstura->ForceGetLink(); // when i trying to use tekstura- >GetLink(doc);, the methon returns null
          shader = bl->GetFirstShader(); // < --- here i always get null -- why??
          PluginShader *ge = (PluginShader * )bl; // < -- is this correct?
}

// in CalcSurface
     if(tekstura!=NULL){
          PluginShader *shader = NULL;
          bl = tekstura->ForceGetLink();
          shader = bl->GetFirstShader(); // always null
          
          PluginShader *ge = (PluginShader * )bl;
          
          Vector btm = ge->Sample((ChannelData * )vd); // always null

GePrint("Name: "+ge- >GetName()); // functions works fine, that's why i thing that at least some of this code is correct ;)

I would be very gratefull for any help, or pice of good code.

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

On 19/05/2007 at 06:37, xxxxxxxx wrote:

Can somebody help me?
This is very important for me.

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

On 21/05/2007 at 01:45, xxxxxxxx wrote:

What are you trying to achieve, simply loading a shader in your own shader? Take a look at the Bitmapdistortion Shader in the SDK examples. It shows how to initialize and use a ShaderLink.

cheers,
Matthias

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

On 21/05/2007 at 23:45, xxxxxxxx wrote:

Hi,

What I'm trying to achieve is to load a shader in SHADERLINK, and use it as a color of object or as a bump texture - it doesn't matter.

Bitmapdistortion Shader inherit from ShaderData, my plugin inherts from MaterialData - that's why Bitmapdistortion Shader isn't very helpfull example.

i found this
but this is too all about ShaderData.

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

On 22/05/2007 at 02:08, xxxxxxxx wrote:

Here is a complete example for MaterialData plugin which loads a shader and uses it in CalcSurface

  
/////////////////////////////////////////////////////////////  
// CINEMA 4D SDK                                           //  
/////////////////////////////////////////////////////////////  
// (c) 1989-2004 MAXON Computer GmbH, all rights reserved //  
/////////////////////////////////////////////////////////////  
  
// example for an easy implementation of a volume (surface) shader  
// It modifies the preview scenes and adds its own scene  
  
#include "c4d.h"  
#include "c4d_symbols.h"  
#include "msimplematerial.h"  
  
// be sure to use a unique ID obtained from www.plugincafe.com  
#define ID_SIMPLEMAT 1001164  
  
class SimpleMaterial : public MaterialData  
{  
     INSTANCEOF(SimpleMaterial,MaterialData)  
  
     private:  
          PluginShader *shader;  
     public:  
          virtual Bool Init          (GeListNode *node);  
          virtual     void CalcSurface               (PluginMaterial *mat, VolumeData *vd);  
          virtual     LONG InitRender(PluginMaterial *mat, InitRenderStruct *irs);  
          virtual void FreeRender(PluginMaterial* mat);  
          virtual Bool Message(GeListNode* node, LONG type, void* data);  
  
          static NodeData *Alloc(void) { return gNew SimpleMaterial; }  
};  
  
Bool SimpleMaterial::Init(GeListNode *node)  
{  
     shader = NULL;  
     BaseContainer *data=((PluginMaterial* )node)->GetDataInstance();  
     data->SetLink(SIMPLEMATERIAL_TEXTURE,NULL);  
  
     return TRUE;  
}  
  
LONG SimpleMaterial::InitRender(PluginMaterial *mat, InitRenderStruct *irs)  
{  
     BaseContainer *data=mat->GetDataInstance();  
     shader = (PluginShader* )data->GetLink(SIMPLEMATERIAL_TEXTURE,irs->doc,Xbase);  
     if (shader)   
          return shader->InitRender(irs);  
  
     return LOAD_OK;  
}  
  
void SimpleMaterial::FreeRender(PluginMaterial *mat)  
{  
     if (shader)  
      shader->FreeRender();  
     shader=NULL;  
}  
  
void SimpleMaterial::CalcSurface(PluginMaterial *mat, VolumeData *vd)  
{  
     if(shader)  
     {  
          ChannelData cd;  
          cd.vd = vd;  
          cd.d = 0;  
          cd.n = vd->n;  
          cd.off = 0;  
          cd.p = vd->uvw;  
          cd.scale = 0;  
          cd.t = 0;  
          cd.texflag = TEX_TILE;  
  
          Vector col = shader->Sample(&cd;);  
          vd->col = col;  
  
          Multipass *buf = vd->multipass;  
          if (!buf) return;  
  
          // process multipass data  
          *buf->vp_mat_color = col;  
     }  
     else  
     {  
          vd->col = 1.0;  
  
          Multipass *buf = vd->multipass;  
          if (!buf) return;  
  
          // process multipass data  
          *buf->vp_mat_color = 1.0;  
     }  
}  
  
Bool SimpleMaterial::Message(GeListNode* node, LONG type, void* data)  
{  
     BaseContainer *dat = ((PluginShader* )node)->GetDataInstance();  
  
     HandleInitialChannel(node,SIMPLEMATERIAL_TEXTURE,type,data);  
     HandleShaderMessage(node,(PluginShader* )dat->GetLink(SIMPLEMATERIAL_TEXTURE,node->GetDocument(),Xbase),type,data);  
  
     return TRUE;  
}  
  
  
Bool RegisterSimpleMaterial(void)  
{  
     // decide by name if the plugin shall be registered - just for user convenience  
     String name=GeLoadString(IDS_SIMPLEMATERIAL); if (!name.Content()) return TRUE;  
     return RegisterMaterialPlugin(ID_SIMPLEMAT,name,0,SimpleMaterial::Alloc,"Msimplematerial",0);  
}  

here the description resource

  
CONTAINER Msimplematerial  
{  
     NAME Msimplematerial;  
  
     INCLUDE Mpreview;  
     INCLUDE Mbase;  
  
     GROUP ID_MATERIALPROPERTIES  
     {  
          SHADERLINK SIMPLEMATERIAL_TEXTURE { }  
     }  
}  

also take a look a look at the material examples in the sdk

cheers,
Matthias

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

On 22/05/2007 at 02:44, xxxxxxxx wrote:

Thank you for help. I was looking sth like this example.

I have last question, only for sure.

there is no difrents between this

ChannelData cd;
          cd.vd = vd;
          cd.d = 0;
          cd.n = vd->n;
          cd.off = 0;
          cd.p = vd->uvw;
          cd.scale = 0;
          cd.t = 0;
          cd.texflag = TEX_TILE;
          Vector col = shader->Sample(&cd;);

and this:

ChannelData *cd = new ChannelData(vd);
          Vector col = shader->Sample(cd);

right?

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

On 22/05/2007 at 02:50, xxxxxxxx wrote:

Quote: there is no difrents between this
>
> * * *
>
>
> ChannelData cd;
>           cd.vd = vd;
>           cd.d = 0;
>           cd.n = vd->n;
>           cd.off = 0;
>           cd.p = vd->uvw;
>           cd.scale = 0;
>           cd.t = 0;
>           cd.texflag = TEX_TILE;
>           Vector col = shader->Sample(&cd;);
>
> and this:
>
>           ChannelData *cd = new ChannelData(vd);
>           Vector col = shader->Sample(cd);
>
> right?
>
>
>
> * * *

no, but still you have to fill the ChanndelData first, like cd->vd = vd etc. also don't forget to free your ChannelData with delete after using it.

cheers,
Matthias

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

On 22/05/2007 at 03:16, xxxxxxxx wrote:

Thanks, i'm appreciate for your help.