c4d.plugins.ShaderData

class c4d.plugins.ShaderData
A data class for creating shader (channel shader) plugins.
Use RegisterShaderPlugin() to register the plugin.
A registered shader will appear in the popup menu of the channels in the Materials Manager in Cinema 4D.

Here are some general comments on the shader API:

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

See also

Py-Fresnel plugin example.

Methods Signatures

ShaderData.InitRender(self, sh, irs) Override - Pre-calculate any data for rendering.
ShaderData.FreeRender(self, sh) Override - Free any resources used for the precalculated data from InitRender().
ShaderData.Output(self, sh, cd)
Override - Called for each point of the visible surface of a shaded object.
ShaderData.SetExceptionColor(self, col) Set the exception color.

Inheritance

Parent Class:

Methods Documentation

ShaderData.InitRender(self, sh, irs)

Override - Pre-calculate any data for rendering.

Parameters:
Return type:

int

Returns:

Result of the initialisation:

INITRENDERRESULT_OK Everything is OK, there was no error.
INITRENDERRESULT_OUTOFMEMORY Not enough memory.
INITRENDERRESULT_ASSETMISSING Assets (textures etc.) are missing.
INITRENDERRESULT_UNKNOWNERROR Unknown error.
INITRENDERRESULT_USERBREAK

Changed in version R17.032: Was INITRENDERRESULT_THREADEDLOCK. Thread has been canceled.

ShaderData.FreeRender(self, sh)

Override - Free any resources used for the precalculated data from InitRender().

Parameters:sh (c4d.BaseShader) – The shader node connected with this instance.
ShaderData.Output(self, sh, cd)
Override - Called for each point of the visible surface of a shaded object.
Here you should calculate and return the channel color for the point cd.p.

Important:

No OS calls are allowed during this function.
Doing so could cause a crash, since it can be called in a multi-processor context.
Parameters:
Return type:

c4d.Vector

Returns:

The calculated color.

ShaderData.SetExceptionColor(self, col)

Set the exception color.

Parameters:col (c4d.Vector) – The exception color.