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);
Access
Shaders are owned by the object that uses them. The shaders owned by a given object are organized in a list:
Shaders are typically organized in a list but can also be organized in a tree:
while (shader != nullptr )
{
}
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 )
Read-Only Properties
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 )
if (irs.linear_workflow)
channelData.
d =
Vector { 1, 1, 1 };
channelData.
n =
Vector { 0, 1, 0 };
channelData.
vd =
nullptr ;
for (
Int32 y = 0; y < height; ++y)
{
for (
Int32 x = 0; x < width; ++x)
{
const Float64 u = xFloat / widthFloat;
const Float64 v = yFloat / heightFloat;
}
}
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
Definition: c4d_basechannel.h:35
Int32 texflag
[READ ONLY] The texture flags: TEX
Definition: c4d_shader.h:969
#define Xbitmap
Bitmap.
Definition: ge_prepass.h:1173
@ MATERIAL_COLOR_SHADER
Definition: mmaterial.h:272
static void Free(Material *&bl)
Definition: c4d_basetag.h:646
Definition: lib_description.h:328
constexpr Unstrided Clamp01() const
Returns a vector that is clamped to the range [0.0 .. 1.0].
Definition: vec.h:437
@ MATERIAL_BUMP_SHADER
Definition: mmaterial.h:278
static void Free(BaseShader *&ps)
@ BITMAPSHADER_FILENAME
Definition: xbitmap.h:6
Bool AddUndo(UNDOTYPE type, void *data, Bool allowFromThread=false)
Manages file and path names.
Definition: c4d_file.h:93
return OK
Definition: apibase.h:2546
Int32 SAFEINT32(Float32 x)
Definition: apibasemath.h:266
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:179
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
Float t
[READ ONLY] The current time in seconds.
Definition: c4d_shader.h:968
Vector p
[READ ONLY] The texture position in UVW coordinates.
Definition: c4d_shader.h:965
Float off
Definition: c4d_shader.h:971
@ TEXTURETAG_PROJECTION
Definition: ttexture.h:10
void FreeRender(void)
Frees all resources used by this shader that were allocated by calling InitRender().
Definition: c4d_basechannel.h:110
#define Xnoise
Noise.
Definition: ge_prepass.h:1209
INITRENDERRESULT InitRender(const InitRenderStruct &is)
Definition: c4d_basechannel.h:105
void InsertMaterial(BaseMaterial *mat, BaseMaterial *pred=nullptr, Bool checknames=false)
Float Get(void) const
Definition: c4d_basetime.h:66
void SetMaterial(BaseMaterial *mat)
Bool SetParameter(const DescID &id, const GeData &t_data, DESCFLAGS_SET flags)
Definition: c4d_basematerial.h:240
Definition: c4d_shader.h:179
BaseTime GetTime(void) const
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:174
Bool SetPixel(Int32 x, Int32 y, Int32 r, Int32 g, Int32 b)
Definition: c4d_basebitmap.h:707
static Material * Alloc()
static BaseShader * Alloc(Int32 type)
Vector TransformColor(const Vector &input, COLORSPACETRANSFORMATION colortransformation)
INITRENDERRESULT
Definition: ge_prepass.h:398
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:186
Vector d
[READ ONLY] The MIP sample radius in UVW coordinates.
Definition: c4d_shader.h:967
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:205
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:208
@ LINEAR_TO_SRGB
Linear to sRGB color space transformation.
Bool ShowBitmap(const Filename &fn)
static TextureTag * Alloc()
Vector n
[READ ONLY] The surface normal.
Definition: c4d_shader.h:966
BaseShader * GetNext(void)
Definition: c4d_basechannel.h:68
@ TEXTURETAG_PROJECTION_UVW
Definition: ttexture.h:17
@ NEWOBJ
New object/material/tag etc. was created. (Needs to be called after action.)
Int32 CALC_TEXINFO(Int32 texflag, Int32 channel)
Definition: c4d_shader.h:52
maxon::Bool Bool
Definition: ge_sys_math.h:55
COLORSPACETRANSFORMATION
Definition: ge_prepass.h:488
BaseShader * GetFirstShader() const
Definition: c4d_baselist.h:2529
String GetName() const
Definition: c4d_baselist.h:2347
Float scale
[READ ONLY] The MIP blur offset.
Definition: c4d_shader.h:971
VolumeData * vd
[READ ONLY] The volume information, can be nullptr.
Definition: c4d_shader.h:970
Vector Sample(ChannelData *cd)
Definition: c4d_basechannel.h:123
#define CHANNEL_COLOR
The color channel of a material.
Definition: c4d_shader.h:94
@ OK
Everything is OK, there was no error.
Definition: c4d_shader.h:952
static void Free(TextureTag *&bl)
maxon::Float64 Float64
Definition: ge_sys_math.h:67
void InsertShader(BaseShader *shader, BaseShader *pred=nullptr)
Definition: c4d_baselist.h:2557
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())