Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Correctly sampling a Shader

    Scheduled Pinned Locked Moved SDK Help
    2 Posts 0 Posters 232 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

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

      1. 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?

      2. Why does it work before the scene is saved?

      Thanks a thousand times for any help!

      Cheers,
      Jack

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 03/11/2009 at 12:41, xxxxxxxx wrote:

        It works here. I can use a texture, save the file, close cinema, reopen it and it still does what it is supposed to. I used a texture in my project file. or did i understand something wrong?

        maybe the problem lays elsewhere?? maybe where you link the material?

        cheers,
        ello

        1 Reply Last reply Reply Quote 0
        • First post
          Last post