About
A BaseShader is the base class for shaders in Cinema 4D. Shaders are typically used with materials to define various surface properties. But shaders can also be used in other situations for example in combination with generator objects. BaseShader objects are not stored with the BaseDocument directly but must be inserted into the object that uses them.
BaseShader objects are an instance of Xbase
.
const Bool materialFailure = material ==
nullptr;
const Bool shaderFailure = bitmapShader ==
nullptr;
const Bool tagFailure = textureTag ==
nullptr;
if (materialFailure || shaderFailure || tagFailure)
{
}
object->InsertTag(textureTag);
doc->InsertMaterial(material);
void InsertShader(BaseShader *shader, BaseShader *pred=nullptr)
Definition: c4d_baselist.h:2759
Definition: c4d_basechannel.h:36
static BaseShader * Alloc(Int32 type)
static void Free(BaseShader *&ps)
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
Definition: lib_description.h:355
Manages file and path names.
Definition: c4d_file.h:94
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())
Definition: c4d_basematerial.h:241
static void Free(Material *&bl)
static Material * Alloc()
Definition: c4d_basetag.h:704
void SetMaterial(BaseMaterial *mat)
static TextureTag * Alloc()
static void Free(TextureTag *&bl)
maxon::Bool Bool
Definition: ge_sys_math.h:51
maxon::Int32 Int32
Definition: ge_sys_math.h:56
return OK
Definition: apibase.h:2735
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define Xbitmap
Bitmap.
Definition: ge_prepass.h:1324
@ NEWOBJ
A new object, material, tag, or other classic API node instance has been inserted into the document....
#define ConstDescID(...)
Definition: lib_description.h:594
@ MATERIAL_COLOR_SHADER
Definition: mmaterial.h:294
const char * doc
Definition: pyerrors.h:226
Represents a level within a DescID.
Definition: lib_description.h:298
@ TEXTURETAG_PROJECTION
Definition: ttexture.h:10
@ TEXTURETAG_PROJECTION_UVW
Definition: ttexture.h:17
@ BITMAPSHADER_FILENAME
Definition: xbitmap.h:6
Access and Structure
Shaders are stored in a special shader
branching relation of the nodes who own them. The first shader in the shader branch of a node can be retrieved with BaseList2D::GetFirstShader and inserted with BaseList2D::InsertShader . This primarily applies to BaseList2D shader owners such as BaseObject or BaseMaterial .
BaseShader instances which own shaders themselves tend to not insert shaders into their shader branch but as direct children although they are also BaseList2D instances. An example for this behaviour would be the type LayerShader which carries its owned shaders as direct children. When constructing such nested shader setups, one must call therefore GeListNode::InsertUnder on the root shader to insert child shaders, and not BaseList2D::InsertShader (Fig I).
- Note
- This behaviour is a rule of thumb, but there is no guarantee that all shader types who own shader dependencies handle their owned shaders in this manner. For native Cinema 4D shaders as the Layer or Fusion Shader this holds true, but one must always check how a specific shader handles its owned shaders when dealing with a specific type.
Traversing shaders therefore depends on the context:
With either the list of shaders owned by a material or object, or within a hierarchy level of a set of nested shaders, one can navigate with the common GeListNode functions:
while (shader != nullptr)
{
}
String GetName() const
Definition: c4d_baselist.h:2544
BaseShader * GetFirstShader() const
Definition: c4d_baselist.h:2733
BaseShader * GetNext()
Definition: c4d_basechannel.h:68
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
Allocation/Deallocation
Shaders are created with the usual tools.
Newly created shaders are typically handed over to the object that uses them:
For a list of shader IDs see Shader Types.
if (noiseShader == nullptr)
#define Xnoise
Noise.
Definition: ge_prepass.h:1360
@ MATERIAL_BUMP_SHADER
Definition: mmaterial.h:300
Read-Only Properties
- BaseShader::GetRenderInfo(): Returns information about what the plugin requires from the raytracer and what it will return.
- BaseShader::IsColorManagementOff(): Returns true if color management is disabled for shaders within reflectance, bump, alpha, displacement or normal channels when linear workflow is enabled.
- BaseShader::GetSubsurfaceShader(): Returns the best SSS shader.
- BaseShader::HasGPURendererSupport(): Returns true if the shader is supported natively by the Cinema 4D GPU Renderer. If the shader is not supported, it will be baked into a texture.
- Note
- Also supported shaders may be baked into a texture, depending on the used material channel and shader context.
Sampling a Shader
A shader returns a color value for a given point. This point can be a point in world or object space or a set of UV-coordinates. A shader is sampled this way typically in the rendering pipeline.
A shader has to be initiated:
After the shader has been initiated these functions can be used:
In the end the resources of the shader must be released:
- Warning
- Without properly initiated InitRenderStruct::vd argument it is not safe to sample a shader multi-threaded.
A shader can sipmply be baked into a BaseBitmap using:
const maxon::Int32 colorProfile = irs.document_colorprofile;
const maxon::Bool linearWorkflow = irs.linear_workflow;
const Bool bakeResult = shader->
BakeShaderIntoBaseBitmap(bitmap, *
doc, parentThread, alpha, colorProfile, linearWorkflow, hdr, xmin, xmax, ymin, ymax);
if (bakeResult == false)
Bool ShowBitmap(const Filename &fn)
Bool BakeShaderIntoBaseBitmap(BaseBitmap &outBmp, BaseDocument &doc, BaseThread *parentThread, Bool doAlpha, Int32 colorSpace, Bool linearworkflow, Bool useHDR, Int xmin, Int xmax, Int ymin, Int ymax)
Definition: c4d_basechannel.h:198
Definition: c4d_shader.h:375
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:202
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:195
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:190
if (irs.linear_workflow)
channelData.
t =
doc->GetTime().Get();
channelData.
d =
Vector { 1, 1, 1 };
channelData.
n =
Vector { 0, 1, 0 };
channelData.
vd =
nullptr;
for (
Int32 y = 0; y < height; ++y)
{
{
const Float64 u = xFloat / widthFloat;
const Vector transformedColor = irs.TransformColor(color).
Clamp01();
bitmap->SetPixel(
x, y, r,
g, b);
}
}
PyObject PyObject * v
Definition: abstract.h:297
Int32 CALC_TEXINFO(Int32 texflag, Int32 channel)
Definition: c4d_shader.h:53
INITRENDERRESULT InitRender(const InitRenderStruct &is)
Definition: c4d_basechannel.h:105
Vector Sample(ChannelData *cd)
Definition: c4d_basechannel.h:123
void FreeRender()
Frees all resources used by this shader that were allocated by calling InitRender().
Definition: c4d_basechannel.h:110
PyObject * x
Definition: bytesobject.h:38
Py_UCS4 * res
Definition: unicodeobject.h:1113
maxon::Float64 Float64
Definition: ge_sys_math.h:63
#define CHANNEL_COLOR
The color channel of a material.
Definition: c4d_shader.h:95
COLORSPACETRANSFORMATION
Definition: ge_prepass.h:503
@ LINEAR_TO_SRGB
Linear to sRGB color space transformation.
INITRENDERRESULT
Definition: ge_prepass.h:413
@ OK
Everything is OK, there was no error.
Int32 SAFEINT32(Float32 x)
Definition: apibasemath.h:275
const char const char grammar * g
Definition: parsetok.h:52
unsigned long Py_ssize_t width
Definition: pycore_traceback.h:88
Definition: c4d_shader.h:1176
Vector n
[READ ONLY] The surface normal.
Definition: c4d_shader.h:1189
Float scale
[READ ONLY] The MIP blur offset.
Definition: c4d_shader.h:1194
Float t
[READ ONLY] The current time in seconds.
Definition: c4d_shader.h:1191
Vector d
[READ ONLY] The MIP sample radius in UVW coordinates.
Definition: c4d_shader.h:1190
Int32 texflag
[READ ONLY] The texture flags: TEX
Definition: c4d_shader.h:1192
VolumeData * vd
[READ ONLY] The volume information, can be nullptr.
Definition: c4d_shader.h:1193
Float off
Definition: c4d_shader.h:1194
Vector p
[READ ONLY] The texture position in UVW coordinates.
Definition: c4d_shader.h:1188
constexpr Unstrided Clamp01() const
Returns a vector that is clamped to the range [0.0 .. 1.0].
Definition: vec.h:454
Compare
Two BaseShader elements can be compared with:
- Note
- The comparison is mostly based on the shader's BaseContainer. Other internal data may not be compared.
Further Reading