Open Search
    ShaderData Class Reference

    #include <c4d_shaderdata.h>

    Inheritance diagram for ShaderData:

    Detailed Description

    A data class for creating shader (channel shader) plugins.
    Shader plugins appear in the popup menu of the channels in the Material Manager.

    Use RegisterShaderPlugin() to register a scene hook plugin.

    Here are some general comments on the shader API:

    • Coordinate Systems: if there is no further note, all elements like points, normals etc. are always given in global coordinates.
    • Angle Systems: all angle values are always given in radians. Use maxon::RadToDeg() macro for conversion if needed.
    • Vectors: all normals and ray vectors must be normalized. Also, all normals and ray vectors given by Cinema 4D are normalized.

    Draw

    virtual Bool Draw (BaseShader *sh, BaseObject *op, BaseTag *tag, BaseDraw *bd, BaseDrawHelp *bh)
     

    Init/Free Render

    virtual INITRENDERRESULT InitRender (BaseShader *sh, const InitRenderStruct &irs)
     
    virtual void FreeRender (BaseShader *sh)
     

    Output

    virtual Vector Output (BaseShader *sh, ChannelData *cd)
     

    Miscellaneous

    virtual SHADERINFO GetRenderInfo (BaseShader *sh)
     
    virtual BaseShaderGetSubsurfaceShader (BaseShader *sh, Float &bestmpl)
     

    OpenGl Mode

    virtual UInt32 GlMessageDummy (BaseShader *sh, Int32 type, void *msgdata)
     
    virtual Int32 InitGLImage (BaseShader *sh, BaseDocument *doc, BaseThread *th, BaseBitmap *bmp, Bool alpha, Int32 doccolorspace, Bool linearworkflow)
     
    virtual void DestroyGLImage (BaseShader *sh, BaseDocument *doc)
     
    virtual void InvalidateGLImage (BaseShader *sh, BaseDocument *doc)
     
    virtual Bool GetGLImageSize (BaseShader *sh, BaseDocument *doc, Int32 s, Bool noScale, Int32 &w, Int32 &h)
     

    Additional Inherited Members

    - Public Member Functions inherited from NodeData
     NodeData ()
     
    GeListNodeGet ()
     
    const GeListNodeGet () const
     
    virtual Bool Message (GeListNode *node, Int32 type, void *data)
     
    virtual void GetBubbleHelp (GeListNode *node, maxon::String &str)
     
    virtual const BaseDocumentGetDocument (const GeListNode *node) const
     
    virtual maxon::Result< BoolGetBranchInfo (const GeListNode *node, const maxon::ValueReceiver< const BranchInfo & > &info, GETBRANCHINFO flags) const
     
    virtual Bool IsInstanceOf (const GeListNode *node, Int32 type) const
     
    virtual Bool IsDocumentRelated (const GeListNode *node, Bool &docrelated) const
     
    virtual maxon::Result< BoolGetAccessedObjects (const BaseList2D *node, METHOD_ID method, AccessedObjectsCallback &access) const
     
    virtual maxon::Result< maxon::GenericDataGroupChanges (BaseList2D *node)
     
    virtual Bool Init (GeListNode *node, Bool isCloneInit)
     
    virtual void Free (GeListNode *node)
     
    virtual Bool Read (GeListNode *node, HyperFile *hf, Int32 level)
     
    virtual Bool Write (const GeListNode *node, HyperFile *hf) const
     
    virtual Bool CopyTo (NodeData *dest, const GeListNode *snode, GeListNode *dnode, COPYFLAGS flags, AliasTrans *trn) const
     
    virtual Bool GetDDescription (const GeListNode *node, Description *description, DESCFLAGS_DESC &flags) const
     
    virtual Bool GetDParameter (const GeListNode *node, const DescID &id, GeData &t_data, DESCFLAGS_GET &flags) const
     
    virtual Bool SetDParameter (GeListNode *node, const DescID &id, const GeData &t_data, DESCFLAGS_SET &flags)
     
    virtual Bool GetDEnabling (const GeListNode *node, const DescID &id, const GeData &t_data, DESCFLAGS_ENABLE flags, const BaseContainer *itemdesc) const
     
    virtual Bool TranslateDescID (GeListNode *node, const DescID &id, DescID &res_id, C4DAtom *&res_at)
     
    - Public Member Functions inherited from BaseData
    virtual ~BaseData ()
     
    void Destructor ()
     
    - Protected Attributes inherited from NodeData
    GeListNodeprivate_link
     

    Member Function Documentation

    ◆ Draw()

    virtual Bool Draw ( BaseShader sh,
    BaseObject op,
    BaseTag tag,
    BaseDraw bd,
    BaseDrawHelp bh 
    )
    virtual

    Called to draw additional information for the shader in the editor's view.

    Parameters
    [in]shThe BaseShader connected with the ShaderData instance. Equal to static_cast<ShaderData*>Get(). Provided for speed and convenience. Cinema 4D owns the pointed shader.
    [in]opThe active object. Cinema 4D owns the pointed object.
    [in]tagThe active tag. The caller owns the pointed tag.
    [in]bdThe editor's view. The caller owns the pointed view.
    [in]bhThe helper for the editor's view. The caller owns the pointed base draw helper.
    Returns
    true if successful, otherwise false.

    ◆ InitRender()

    virtual INITRENDERRESULT InitRender ( BaseShader sh,
    const InitRenderStruct irs 
    )
    virtual

    Called to initialize resources for the render.

    Parameters
    [in]shThe BaseShader connected with the ShaderData instance. Equal to static_cast<ShaderData*>Get(). Provided for speed and convenience. Cinema 4D owns the pointed shader.
    [in]irsA struct with information about the upcoming rendering.
    Returns
    The result of the initialization: INITRENDERRESULT

    ◆ FreeRender()

    virtual void FreeRender ( BaseShader sh)
    virtual

    Called to free any resources allocated in InitRender.

    Parameters
    [in]shThe BaseShader connected with the ShaderData instance. Equal to static_cast<ShaderData*>Get(). Provided for speed and convenience. Cinema 4D owns the pointed shader.

    ◆ Output()

    virtual Vector Output ( BaseShader sh,
    ChannelData cd 
    )
    virtual

    Called for each point of the visible surface of a shaded object to calculate and return the channel color for the point cd->p.

    Note
    This function is called in a thread context. See the important information about threading.
    Parameters
    [in]shThe BaseShader connected with the ShaderData instance. Equal to static_cast<ShaderData*>Get(). Provided for speed and convenience. Cinema 4D owns the pointed shader.
    [in]cdThe channel data to use and/or modify. The caller owns the pointed channel data.
    Returns
    The calculated color.

    ◆ GetRenderInfo()

    virtual SHADERINFO GetRenderInfo ( BaseShader sh)
    virtual

    Called to get information about what the shader plugin requires from the render and what it will return.

    Note
    This function is called in a thread context. See the important information about threading.
    Parameters
    [in]shThe BaseShader connected with the ShaderData instance. Equal to static_cast<ShaderData*>Get(). Provided for speed and convenience. Cinema 4D owns the pointed shader.
    Returns
    The shader info: SHADERINFO

    ◆ GetSubsurfaceShader()

    virtual BaseShader* GetSubsurfaceShader ( BaseShader sh,
    Float bestmpl 
    )
    virtual

    Called to return the best SSS sub-shader for the shader.

    Note
    If the shader uses sub-shaders it is crucial that it calls their GetSubsurfaceShader() method override so if any sub-shaders are SSS shaders they are used and initialized properly.
    For example here is the implementation of GetSubsurfaceShader from SLA (which uses 2 sub-shaders: Texture and Distorter):
    BaseShader* CSLADistorter::GetSubsurfaceShader(BaseShader *sh, Float &bestmpl)
    {
    BaseShader *pBestShader = nullptr;
    if (m_pTexture != nullptr)
    {
    BaseShader *pShaderTexture = m_pTexture->GetSubsurfaceShader(bestmpl);
    if (pShaderTexture != nullptr)
    pBestShader = pShaderTexture;
    }
    if (m_pDistorter != nullptr)
    {
    BaseShader *pShaderDistorter = m_pDistorter->GetSubsurfaceShader(bestmpl);
    if (pShaderDistorter != nullptr)
    pBestShader = pShaderDistorter;
    }
    return pBestShader;
    }
    Definition: c4d_basechannel.h:36
    BaseShader * GetSubsurfaceShader(Float &bestmpl)
    Definition: c4d_basechannel.h:180
    maxon::Float Float
    Definition: ge_sys_math.h:66
    Parameters
    [in]shThe BaseShader connected with the ShaderData instance. Equal to static_cast<ShaderData*>Get(). Provided for speed and convenience. Cinema 4D owns the pointed shader.
    [in]bestmplThe current best (smallest) Median Path Length found so far.
    This value should never be changed by the code; it is auto adjusted only by the SSS shader and should be passed directly to the subshaders (see example code above).
    Returns
    The best SSS shader found so far.

    ◆ GlMessageDummy()

    virtual UInt32 GlMessageDummy ( BaseShader sh,
    Int32  type,
    void *  msgdata 
    )
    virtual

    To ensure SDK compatibility Private.

    ◆ InitGLImage()

    virtual Int32 InitGLImage ( BaseShader sh,
    BaseDocument doc,
    BaseThread th,
    BaseBitmap bmp,
    Bool  alpha,
    Int32  doccolorspace,
    Bool  linearworkflow 
    )
    virtual

    Extended OpenGL mode. This mode is not documented. See c4d_gl.h for definitions.

    ◆ DestroyGLImage()

    virtual void DestroyGLImage ( BaseShader sh,
    BaseDocument doc 
    )
    virtual

    Extended OpenGL mode. This mode is not documented. See c4d_gl.h for definitions.

    ◆ InvalidateGLImage()

    virtual void InvalidateGLImage ( BaseShader sh,
    BaseDocument doc 
    )
    virtual

    Extended OpenGL mode. This mode is not documented. See c4d_gl.h for definitions.

    ◆ GetGLImageSize()

    virtual Bool GetGLImageSize ( BaseShader sh,
    BaseDocument doc,
    Int32  s,
    Bool  noScale,
    Int32 w,
    Int32 h 
    )
    virtual

    Called before the preview image for the shader is calculated.

    Parameters
    [in]shThe BaseShader connected with the ShaderData instance. Equal to static_cast<ShaderData*>Get(). Provided for speed and convenience. Cinema 4D owns the pointed shader.
    [in]docThe host document of the shader. Cinema 4D owns the pointed document.
    [in]sThe exponent of the maximum texture size chosen in the Preferences or the Material Editor tab. (2 ^ s = maximum preview size)
    [in]noScaletrue if the user has selected the "No Scaling" option in the material.
    [in]wAssign the width for the preview image.
    [in]hAssign the height for the preview image.
    Returns
    true to set the preview image size to the assigned (w, h).