InitRenderStruct Manual

About

A InitRenderStruct element is used to initialize materials and shaders for rendering. It is typically created by Cinema 4D but it can be created on demand to sample materials or shaders. See Sampling a Shader.

Functionality

A InitRenderStruct element can be initiated and used with these functions:

  • InitRenderStruct::InitRenderStruct(): Constructor, accepts a BaseDocument argument.
  • InitRenderStruct::Init(): Initiates the render structure with the given argument.
  • InitRenderStruct::GetThreadCount(): Returns the thread count by accessing the stored VolumeData pointer.
  • InitRenderStruct::TransformColor(): Transforms a color based on the internally stored color profile and linear workflow settings.
// This example samples the given shader in UV space.
// init the shader
InitRenderStruct irs { doc };
// check if linear workflow is enabled
if (irs.linear_workflow)
const INITRENDERRESULT res = shader->InitRender(irs);
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// sample the shader in UV space
ChannelData channelData;
channelData.off = 0;
channelData.scale = 0;
channelData.t = doc->GetTime().Get();
channelData.texflag = CALC_TEXINFO(0, CHANNEL_COLOR);
channelData.d = Vector { 1, 1, 1 };
channelData.n = Vector { 0, 1, 0 };
channelData.vd = nullptr; // VolumeData is nullptr
for (Int32 y = 0; y < height; ++y)
{
for (Int32 x = 0; x < width; ++x)
{
// generate UV coordinates
const Float64 xFloat = (Float64)x;
const Float64 yFloat = (Float64)y;
const Float64 u = xFloat / widthFloat;
const Float64 v = yFloat / heightFloat;
channelData.p.x = u;
channelData.p.y = v;
channelData.p.z = 0.0f;
const Vector color = shader->Sample(&channelData);
const Vector transformedColor = irs.TransformColor(color).Clamp01();
// write into the given BaseBitmap
const Int32 r = SAFEINT32(transformedColor.x * COLORTOINT_MULTIPLIER);
const Int32 g = SAFEINT32(transformedColor.y * COLORTOINT_MULTIPLIER);
const Int32 b = SAFEINT32(transformedColor.z * COLORTOINT_MULTIPLIER);
bitmap->SetPixel(x, y, r, g, b);
}
}
// free shader resources
shader->FreeRender();
PyObject PyObject * v
Definition: abstract.h:297
NONE
Definition: asset_browser.h:1
PyObject * x
Definition: bytesobject.h:38
Py_UCS4 * res
Definition: unicodeobject.h:1113
OK
User has selected a font.
Definition: customgui_fontchooser.h:0
LINEAR_TO_SRGB
Linear to sRGB color space transformation.
Definition: ge_prepass.h:1
#define CHANNEL_COLOR
The color channel of a material.
Definition: c4d_shader.h:94
COLORSPACETRANSFORMATION
Definition: ge_prepass.h:502
INITRENDERRESULT
Definition: ge_prepass.h:412
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:69
Int32 SAFEINT32(Float32 x)
Definition: apibasemath.h:275
static const Float COLORTOINT_MULTIPLIER
Constant to convert from vectors color components to integers.
Definition: c4d_tools.h:26
maxon::Float64 Float64
Definition: ge_sys_math.h:58
maxon::Int32 Int32
Definition: ge_sys_math.h:51
Int32 CALC_TEXINFO(Int32 texflag, Int32 channel)
Definition: c4d_shader.h:52
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:140
const char const char grammar * g
Definition: parsetok.h:52
unsigned long Py_ssize_t width
Definition: pycore_traceback.h:88
const char * doc
Definition: pyerrors.h:226
constexpr Unstrided Clamp01() const
Returns a vector that is clamped to the range [0.0 .. 1.0].
Definition: vec.h:454

Properties

The settings of InitRenderStruct are:

  • InitRenderStruct::version: The Cinema 4D version.
  • InitRenderStruct::time: The current time.
  • InitRenderStruct::fps: The framerate.
  • InitRenderStruct::docpath: The path for the document.
  • InitRenderStruct::matname: The material name.
  • InitRenderStruct::errorlist: A private error list.
  • InitRenderStruct::vd: The volume data. Can be nullptr, always check.
  • InitRenderStruct::doc: The document to render.
  • InitRenderStruct::thread: The current thread or nullptr for the main Cinema 4D thread.
  • InitRenderStruct::flags: The flags, see ::INITRENDERFLAG.
  • InitRenderStruct::linear_workflow: True if Linear workflow is enabled.
  • InitRenderStruct::document_colorprofile: The document color profile.

Further Reading