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:

// 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 = TransformColor(color, transform).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();

Properties

The settings of InitRenderStruct are:

Further Reading

ChannelData::texflag
Int32 texflag
[READ ONLY] The texture flags: TEX
Definition: c4d_shader.h:969
maxon::Vec3::Clamp01
constexpr Unstrided Clamp01() const
Returns a vector that is clamped to the range [0.0 .. 1.0].
Definition: vec.h:437
SAFEINT32
Int32 SAFEINT32(Float32 x)
Definition: apibasemath.h:266
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
ChannelData::t
Float t
[READ ONLY] The current time in seconds.
Definition: c4d_shader.h:968
ChannelData::p
Vector p
[READ ONLY] The texture position in UVW coordinates.
Definition: c4d_shader.h:965
ChannelData::off
Float off
Definition: c4d_shader.h:971
BaseShader::FreeRender
void FreeRender(void)
Frees all resources used by this shader that were allocated by calling InitRender().
Definition: c4d_basechannel.h:110
BaseShader::InitRender
INITRENDERRESULT InitRender(const InitRenderStruct &is)
Definition: c4d_basechannel.h:105
maxon::Vec3::z
T z
Definition: vec.h:34
BaseTime::Get
Float Get(void) const
Definition: c4d_basetime.h:66
maxon::Vec3< maxon::Float64, 1 >
InitRenderStruct
Definition: c4d_shader.h:179
BaseDocument::GetTime
BaseTime GetTime(void) const
BaseBitmap::SetPixel
Bool SetPixel(Int32 x, Int32 y, Int32 r, Int32 g, Int32 b)
Definition: c4d_basebitmap.h:707
maxon::Vec3::x
T x
Definition: vec.h:32
TransformColor
Vector TransformColor(const Vector &input, COLORSPACETRANSFORMATION colortransformation)
INITRENDERRESULT
INITRENDERRESULT
Definition: ge_prepass.h:398
ChannelData::d
Vector d
[READ ONLY] The MIP sample radius in UVW coordinates.
Definition: c4d_shader.h:967
maxon::Vec3::y
T y
Definition: vec.h:33
Int32
maxon::Int32 Int32
Definition: ge_sys_math.h:60
COLORSPACETRANSFORMATION::LINEAR_TO_SRGB
@ LINEAR_TO_SRGB
Linear to sRGB color space transformation.
COLORTOINT_MULTIPLIER
static const Float COLORTOINT_MULTIPLIER
Constant to convert from vectors color components to integers.
Definition: c4d_tools.h:25
ChannelData::n
Vector n
[READ ONLY] The surface normal.
Definition: c4d_shader.h:966
CALC_TEXINFO
Int32 CALC_TEXINFO(Int32 texflag, Int32 channel)
Definition: c4d_shader.h:52
COLORSPACETRANSFORMATION
COLORSPACETRANSFORMATION
Definition: ge_prepass.h:486
COLORSPACETRANSFORMATION::NONE
@ NONE
None.
ChannelData::scale
Float scale
[READ ONLY] The MIP blur offset.
Definition: c4d_shader.h:971
ChannelData::vd
VolumeData * vd
[READ ONLY] The volume information, can be nullptr.
Definition: c4d_shader.h:970
BaseShader::Sample
Vector Sample(ChannelData *cd)
Definition: c4d_basechannel.h:123
CHANNEL_COLOR
#define CHANNEL_COLOR
The color channel of a material.
Definition: c4d_shader.h:94
INITRENDERRESULT::OK
@ OK
Everything is OK, there was no error.
ChannelData
Definition: c4d_shader.h:952
Float64
maxon::Float64 Float64
Definition: ge_sys_math.h:67