BaseChannel Sample() w/o Shader



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

    On 22/03/2005 at 22:34, xxxxxxxx wrote:

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

    ---------
    I'll try to make this as simple as possible. I have a Shader plugin (ShaderData) which contains a list of 'shader nodes'. The shader nodes are connected in a tree structure which is fed through to the Shader (i.e.: Output()). Some of the shader nodes represent Bitmap texture images. In order to make sampling during calls to Output() conformal to Cinema4D, a BaseChannel is allocated for these type of shader nodes (the other shader nodes are procedural). The BaseChannel is InitTexture()'d in the shader's InitRender() and FreeTexture()'d in FreeRender. All of the pertinent BaseContainer settings are made, including the texture image filename. And I'm assured that it is working to a degree since the correct results appear in the TextureGroup, but they do not appear anywhere else. A call to material->Update(TRUE, TRUE) is being made with an EventAdd() thrown in for good measure.

    Is the BaseChannel information too disconnected from the Material's BaseChannel to get the Output() out to the Material Manager, Texture Tag, and Editor View? I will post code if necessary to show what I have done so far.

    Thanks,



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

    On 23/03/2005 at 12:05, xxxxxxxx wrote:

    Okay, I'll post some code and maybe give someone something to pick apart. ;)

    This is from the ShaderData derived class, showing InitRender(), Output(), and FreeRender(). Note that I'm going through the list looking for ImageMap nodes with a BaseChannel allocated to each one. In Output(), chanSNode is the root node that all other nodes connect to - the nodes are processed stack-recursively (the calls stack until a leaf and are then unwound back for propagating the nodes interactions forward to the root node).

      
    // ShaderData.InitRender  
    LONG iShader::InitRender(PluginShader* chn, InitRenderStruct* irs)  
    {  
         LONG load = LOAD_OK;  
         for (ShaderNode* sn = firstSNode; sn; sn = (ShaderNode* )sn->GetNext())  
         {  
              if (sn->IsInstanceOf(SHADERNODETYPE_IMAGEMAP))  
              {  
                   if ((load = (static_cast<ImageMap_Node*>(sn))->GetChannel()->InitTexture(irs)) != LOAD_OK)  
                   {  
                        MessageDialog("Error: iShader.InitRender.InitTexture");  
                        break;  
                   }  
              }  
         }  
         return load;  
    }  
    // ShaderData.FreeRender  
    void iShader::FreeRender(PluginShader* chn)  
    {  
         for (ShaderNode* sn = firstSNode; sn; sn = (ShaderNode* )sn->GetNext())  
         {  
              if (sn->IsInstanceOf(SHADERNODETYPE_IMAGEMAP))  
                   (static_cast<ImageMap_Node*>(sn))->GetChannel()->FreeTexture();  
         }  
    }  
    // ShaderData.Output  
    Vector iShader::Output(PluginShader* chn, ChannelData* cd)  
    {  
         return chanSNode.Output(chn, cd);  
    }  
    

    And here is the ImageMap_Node class (I've removed some nonrelevant code) :

      
    // Initialize ImageMap_Node Bitmap  
    BOOL ImageMap_Node::InitBitmap(const LONG& t_pDim)  
    {  
         // Alloc and Init BaseChannel  
         if (!(channel = BaseChannel::Alloc()))  
         {  
              MessageDialog(GeLoadString(ERROR_MEMORY_TEXT)+": ImageMap_Node.Init.channel");  
              return FALSE;  
         }  
         BaseContainer bdata;  
         bdata.SetVector(BASECHANNEL_COLOR_EX, Vector(1.0));  
         channel->SetData(bdata);  
         bdata.SetReal(BASECHANNEL_BRIGHTNESS_EX, 1.0);  
         channel->SetData(bdata);  
         bdata.SetLong(BASECHANNEL_INTERPOLATION, BITMAPSHADER_INTERPOLATION_NONE);  
         channel->SetData(bdata);  
         bdata.SetLong(BASECHANNEL_MIXMODE_EX, MATERIAL_TEXTUREMIXING_NORMAL);  
         channel->SetData(bdata);  
         bdata.SetReal(BASECHANNEL_MIXSTRENGTH_EX, 1.0);  
         channel->SetData(bdata);  
         bdata.SetLong(BASECHANNEL_SHADERID, 0);  
         channel->SetData(bdata);  
      
         return TRUE;  
    }  
    // Set BaseChannel* channel  
    void ImageMap_Node::SetChannel(String fileString)  
    {  
         BaseContainer bdata;  
         if (GetC4DVersion() >= 8200)  
         {  
              bdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, Filename(fileString).GetDirectory());  
              channel->SetData(bdata);  
              bdata.SetString(BASECHANNEL_TEXTURE, Filename(fileString).GetFileString());  
         }  
         else bdata.SetString(BASECHANNEL_TEXTURE, fileString);  
         channel->SetData(bdata);  
    }  
    // Get BaseChannel* channel  
    BaseChannel* ImageMap_Node::GetChannel()  
    {  
         return channel;  
    }  
    Vector ImageMap_Node::Output(PluginShader* chn, ChannelData* cd)  
    {  
         if (sn = GetNodeInput(0)->GetNode()) return Mix(channel->Sample(cd->vd, &cd-;>p, &cd-;>d, &cd-;>n, cd->t, cd->texflag, cd->off, cd->scale), sn->Output(chn, cd), 0.5);  
         return channel->Sample(cd->vd, &cd-;>p, &cd-;>d, &cd-;>n, cd->t, cd->texflag, cd->off, cd->scale);  
    }  
    

    Thanks,



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

    On 23/03/2005 at 14:27, xxxxxxxx wrote:

    Okay, I've decided to go back to using a straight BaseBitmap for the ImageMap node texture image. No anti-aliasing in Output() yet, but it displays in the node editor, A.M. Material TextureGroup preview, and renders.

    But still no update of the Editor, Material, and TextureTag previews. I can get colors (from procedural nodes), but not the image (?). I'm assuming UVW coordinates here in cd->p. Anything different needed for these previews?

    Thanks,



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

    On 25/03/2005 at 06:18, xxxxxxxx wrote:

    No, I think the previews should work automatically. Can you see if your shader is sampled when previews are rebuilt?



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

    On 25/03/2005 at 12:01, xxxxxxxx wrote:

    Does the BaseChannel need to be plugged directly into a Shader or Material for sampling to work? Currently they are allocated and maintained within my own shader node class - which is attached to a ShaderData. The BaseChannels' InitTexture and FreeTexture are called before and after Output, respectively.

    The UVW coordinates are always between 0.0 and 1.0?



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

    On 25/03/2005 at 12:44, xxxxxxxx wrote:

    Looking in the BitmapDistortionShader.cpp example of 8.207 there seems to be something with BaseChannel::Attach() going on. Perhaps this is the reason that function was added.
    Yeah, I believe that's the usual range.



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

    On 25/03/2005 at 15:25, xxxxxxxx wrote:

    Ah. And there is no BaseChannel::Attach() in 8.012 as far as I can determine. Might need to move the SDK version up a notch no matter how disagreable for users. :)

    Thanks, Mikael


Log in to reply