THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 03/11/2009 at 10:16, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10.1/11
Platform: Windows ; Mac OSX ;
Language(s) : C++ ;
---------
Hi,
I have a problem when sampling a Shader ( class PluginShader ). First of all, here's a piece of code:
> // Declare Material, Channel and a Shader \> BaseMaterial \*Mat = NULL; \> BaseChannel \*Chan = NULL; \> PluginShader \*Shader = NULL; \> \> // Get a material linked in the descriptions of my plugin \> if (bc->GetLink(ID_MATLINK, doc)) { \> Mat = (BaseMaterial\* )bc->GetLink(ID_MATLINK, doc); \> } \> else return FALSE; \> \> // Get Color Channel from Material \> if (Mat) Chan = Mat->GetChannel(CHANNEL_COLOR); \> \> // Get Shader from Channel \> if (Chan) Shader = Chan->GetShader(); \> \> // Evaluate Shader \> if (Shader) { \> // Init ChannelData (I calculated the UVW position \> // and Polygon Normal earlier in my plugin, don't \> // worry about that) \> ChannelData cd; \> cd.p = UVWpos; \> cd.d = delta; \> cd.n = PolyNormal; \> cd.scale = C_FLOATZERO; \> cd.off = C_FLOATZERO; \> cd.texflag = TEX_TILE; \> cd.vd = NULL; \> \> InitRenderStruct is; \> \> Shader->InitRender(&is;); \> Vector col = Shader->Sample(&cd;); \> Shader->FreeRender(); \> }
OK, this whole code works pretty well with almost all channel shaders available in CINEMA 4D, and also with 3rd party channel shaders.
The problem is, it does not always work with bitmap textures. A bitmap texture (BMP, JPEG, TIFF, etc) is also represented by a PluginShader, so I can evaluate it.
If the user uses a material with a texture in the color channel, it gives me correct results. But when the user saves his scene and loads it again later, the Sample() function always returns a zero vector. This can just be pr evented by keeping the used texture in a directory that is one of the Texture Path (set up in the CINEMA 4D preferences).
Question(s) :
-
How can I make this work, even when the texture is not in one of the standard texture paths?
Do I have to call some kind of PleaseRememberYourTexture() method in the PluginShader? -
Why does it work before the scene is saved?
Thanks a thousand times for any help!
Cheers,
Jack