c4d.BaseShader

class c4d.BaseShader

Represents a shader in the shader tree of a channel.

Methods Signatures

BaseShader.__init__(self, type)

Initialize a new BaseShader in memory.

BaseShader.Sample(self, cd)

Calls ShaderData.Output() for the corresponding shader plugin.

BaseShader.SampleBump(self, cd, bumpflags)

Calculates the bump mapping for a shader (and its children) with the same algorithm as Cinema 4D does.

BaseShader.GetBitmap(self)

Returns the bitmap of shaders of type Xbitmap, otherwise None.

BaseShader.GetRenderInfo(self)

Calls ShaderData.GetRenderInfo() for the corresponding shader plugin.

BaseShader.InitRender(self, is_)

Calls ShaderData.InitRender() for the corresponding shader plugin.

BaseShader.FreeRender(self)

Frees all resources used by this shader, allocated by calling InitRender().

BaseShader.IsColorManagementOff(self, doc)

It checks if color management is disabled for shaders within bump, alpha, displacement or normal channels when linear workflow is enabled.

BaseShader.Compare(self, dst)

Checks if this shader is similar to dst.

BaseShader.HasGPURendererSupport(self)

Checks if the shader is supported by the GPU Renderer.

Inheritance

Parent Class:

Child Class:

Methods Documentation

BaseShader.__init__(self, type)

Initialize a new BaseShader in memory.

Parameters

type (int) – The shader type : Shader Types.

Return type

c4d.BaseShader

Returns

The new shader.

BaseShader.Sample(self, cd)
Calls ShaderData.Output() for the corresponding shader plugin.
The channel color for the point cd.p is calculated.

Note

This has to be done within a pair of InitRender() / FreeRender() calls.

Parameters

cd (c4d.modules.render.ChannelData) – The channel data to use.

Return type

c4d.Vector

Returns

The calculated color.

BaseShader.SampleBump(self, cd, bumpflags)
Calculates the bump mapping for a shader (and its children) with the same algorithm as Cinema 4D does.

The function returns the delta vector that is added to the normal.
The resulting normal is calculated by:
n_dst =  not(n_src + SampleBump(SAMPLEBUMP_NONE))

where n_src is the original normal and n_dst is the bumped normal.

Note

This has to be done within a pair of InitRender() / FreeRender() calls.
Also the BaseVolumeData.ddu and BaseVolumeData.ddv vectors have to be initialized.
Parameters
  • cd (c4d.modules.render.ChannelData) – The channel data to use.

  • bumpflags (int) –

    Flags:

    SAMPLEBUMP_NONE

    None.

    SAMPLEBUMP_MIPFALLOFF

    Additional bump change over distance is considered.

Return type

c4d.Vector

Returns

The delta normal.

BaseShader.GetBitmap(self)

Returns the bitmap of shaders of type Xbitmap, otherwise None.

Note

This has to be done within a pair of InitRender() / FreeRender() calls.

Here is an example.

# Get the first material in the document.
material = doc.GetFirstMaterial()
if material is None:
    raise RuntimeError("Could not find material.")

# Retrieve the shader linked in the color channel.
shader = material[c4d.MATERIAL_COLOR_SHADER]
if shader is None:
    raise RuntimeError("Material has no shader.")

# Initialize an InitRenderStruct.
irs = render.InitRenderStruct()
if irs and shader.InitRender(irs) == c4d.INITRENDERRESULT_OK:
    # Get the bitmap.
    bitmap = shader.GetBitmap()
    # Free the renderer so that that its memory can be freed.
    shader.FreeRender()
    # Show the bitmap in the Picture Viewer.
    if bitmap is not None:
        bitmaps.ShowBitmap(bitmap)
Return type

c4d.bitmaps.BaseBitmap

Returns

The bitmap.

Note

The returned bitmap must be accessed as read-only.

BaseShader.GetRenderInfo(self)
Calls ShaderData.GetRenderInfo() for the corresponding shader plugin.
This retrieves information about what the plugin requires from the raytracer and what it will return.
Return type

int

Returns

The return values are:

SHADERINFO_NONE

None.

SHADERINFO_TRANSFORM

Channel needs back-transformed data. (Required for BaseVolumeData.back_p.)

SHADERINFO_BUMP_SUPPORT

Channel shader supports bump. This is strongly recommended for all shaders except simple 2D (UV) samplers.

SHADERINFO_ALPHA_SUPPORT

Channel shader supports alpha output.

SHADERINFO_REFLECTIONS

Channel shader computes reflections.

SHADERINFO_DUDVREQUIRED

Channel shader needs du/dv bump mapping data. See BaseVolumeData.ddu and BaseVolumeData.ddv.

SHADERINFO_DYNAMICSUBSHADERS

Channel shader has a dynamic list of sub-shaders in its description.

BaseShader.InitRender(self, is_)
Calls ShaderData.InitRender() for the corresponding shader plugin.
You have to do this before you can use the Sample(), SampleBump() or GetBitmap() functions.

Note

Remember to call FreeRender() afterwards.
You aren’t allowed to call InitRender() multiple times without calling FreeRender() in between, even from multiple threads!
Parameters

is (c4d.modules.render.InitRenderStruct) – Information about the upcoming rendering.

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.

BaseShader.FreeRender(self)

Frees all resources used by this shader, allocated by calling InitRender().

BaseShader.IsColorManagementOff(self, doc)

It checks if color management is disabled for shaders within bump, alpha, displacement or normal channels when linear workflow is enabled.

Parameters

doc (c4d.documents.BaseDocument) – The document containing the shader to check if linear workflow is disabled in it.

Return type

bool

Returns

True if color managment is disabled, otherwise False.

BaseShader.Compare(self, dst)

Checks if this shader is similar to dst.

Parameters

dst (c4d.BaseShader) – The shader to compare to.

Return type

bool

Returns

True if the plugin shaders are the same, otherwise False.

BaseShader.HasGPURendererSupport(self)

Checks if the shader is supported by the GPU Renderer.

New in version R19.024.

Return type

bool

Returns

True if the shader is natively supported by the GPU Renderer, otherwise False.