Inserting an image into the alpha channel

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

On 17/11/2009 at 15:54, xxxxxxxx wrote:

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

---------
Hello again,

I am trying to insert in image in to the alpha channel of a material that my plugin created.

Here's the code I am attempting to use which is not working.

  
  
PluginShader* cloudMap = PluginShader::Alloc(Xbitmap);   
if (!cloudMap)   
   return FALSE;   
  
          atmosphereMat->GetDataInstance()->SetLink(MATERIAL_ALPHA_SHADER, cloudMap);   
cloudMap->SetParameter(BITMAPSHADER_FILENAME,"..\presets\earthCloud_Map.jpg",0);   
cloudsMat->InsertShader(cloudMap, NULL);   
  
  
  
  

Could someone help me figure out how to insert an image into the alpha channel?

Thanks,

~Shawn

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

On 17/11/2009 at 16:25, xxxxxxxx wrote:

Relative paths like that won't work. It needs to be either a filename (local to the document file) or a full path. Here are two functions that I use to set and clear the Texture link of a channel using an image. Note that this also sets the related values - you can ignore these if only interested in setting the image file. Also note that this is for a standard Material and not for a shader attached to a Material. Finally, don't forget to do a mat->Update(TRUE, TRUE) after changing all of the material's settings.

// Set Material's Channel Texture Image and other   
//*---------------------------------------------------------------------------*   
void PoserMaterial::SetChannelTexture(BaseChannel* bchan, ChannelSampling* samp, const String& map, LONG mix, LONG strength)   
//*---------------------------------------------------------------------------*   
{   
     if (!bchan)          return;   
     BaseContainer     bdata;   
     Filename          mapFN = Filename(map);   
  
     bdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, mapFN.GetDirectory());   
     bchan->SetData(bdata);   
     bdata.SetString(BASECHANNEL_TEXTURE, mapFN.GetFileString());   
     bchan->SetData(bdata);   
     if (samp->use)   
     {   
          bdata.SetLong(BASECHANNEL_INTERPOLATION, samp->sampling);   
          bchan->SetData(bdata);   
          bdata.SetReal(BASECHANNEL_BLUR_OFFSET, samp->blurOffset*0.1f);   
          bchan->SetData(bdata);   
          Real     scale = 1.0f + (Abs(samp->blurScale) * 2.0f);   
          if (samp->blurScale < 0.0f) scale = 1.0f / scale;   
          bdata.SetReal(BASECHANNEL_BLUR_STRENGTH, scale);   
          bchan->SetData(bdata);   
     }   
     else   
     {   
          bdata.SetLong(BASECHANNEL_INTERPOLATION, BITMAPSHADER_INTERPOLATION_ALIAS1);   
          bchan->SetData(bdata);   
     }   
     if (mix)          mat->SetParameter(DescID(mix), GeData(MATERIAL_TEXTUREMIXING_MULTIPLY), DESCFLAGS_DONTCHECKMINMAX);   
     if (strength)     mat->SetParameter(DescID(strength), GeData(1.0f), DESCFLAGS_DONTCHECKMINMAX);   
}   
// Unset Material's Channel Texture Image   
//*---------------------------------------------------------------------------*   
void PoserMaterial::UnsetChannelTexture(BaseChannel* bchan, LONG mix, LONG strength)   
//*---------------------------------------------------------------------------*   
{   
     if (!bchan)          return;   
     BaseContainer     bdata;   
  
     bdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, Filename());   
     bchan->SetData(bdata);   
     bdata.SetString(BASECHANNEL_TEXTURE, "");   
     bchan->SetData(bdata);   
     if (mix)          mat->SetParameter(DescID(mix), GeData(MATERIAL_TEXTUREMIXING_NORMAL), DESCFLAGS_DONTCHECKMINMAX);   
     if (strength)     mat->SetParameter(DescID(strength), GeData(1.0f), DESCFLAGS_DONTCHECKMINMAX);   
}

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

On 17/11/2009 at 16:45, xxxxxxxx wrote:

so is this the part that sets the filename?

  
     Filename          mapFN = Filename(map);   
  
  
  
     bdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, mapFN.GetDirectory());   

so would I then do this?

cloudMap->SetParameter(BITMAPSHADER_FILENAME,mapFN,0);

of course I would change the name to meet my own needs but you get teh idea..

Thanks,

~Shawn

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

On 18/11/2009 at 04:03, xxxxxxxx wrote:

The recommended way is to insert the Bitmap shader into the material and then set the texture link. The use of BaseChannels is not recommended anymore, although still working.

  
BaseMaterial *mat = NULL;  
mat = doc->GetFirstMaterial();  
if(!mat) return FALSE;  
  
BaseContainer *data = mat->GetDataInstance();  
  
PluginShader *shd = NULL;  
shd = PluginShader::Alloc(Xbitmap);  
if(!shd) return FALSE;  
  
BaseContainer *shddata = shd->GetDataInstance();  
  
shddata->SetFilename(BITMAPSHADER_FILENAME, Filename("3punkt.jpg")); //Set here your texture path, relative or absolute doesn't matter  
shd->Message(MSG_UPDATE);  
  
data->SetLink(MATERIAL_ALPHA_SHADER, shd);  
mat->InsertShader(shd, NULL);  
mat->Message(MSG_UPDATE);  
mat->Update(TRUE, TRUE);  
  
EventAdd();  

cheers,
Matthias

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

On 18/11/2009 at 09:36, xxxxxxxx wrote:

Awesome. Thanks Matthias.. You are the man!

~Shawn

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

On 18/11/2009 at 13:37, xxxxxxxx wrote:

for a relative path for example lets say the image I want to cal is in "\presets\earth\Cloud_Map.jpg" of the plugin folder   would I type it like I did in quotes or a different way?

~Shawn

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

On 18/11/2009 at 13:43, xxxxxxxx wrote:

nevermind..   I just used "Cloud_Map.jpg" and it worked fine. Thanks again!

~Shawn