THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/06/2009 at 08:26, xxxxxxxx wrote:
I put together a simple turbulence shader which shows how to use the 4 sampling points for a UV based shader.
First it is important to return CHANNEL_BUMP_SUPPORT in GetRenderInfo(). Then you check if you are in the bump channel and check which is the current of the four bump samples with GET_TEX_BUMP_SAMPLE(cd->texflag). Depending on the bump sample you have to shift your UV coordinates for your shader calculation.
> \> #include "c4d.h" \> #include "c4d_symbols.h" \> #include "xmandelbrot.h" \> \> \> class MandelbrotData : public ShaderData \> { \> public: \> virtual Bool Init(GeListNode \*node); \> virtual LONG GetRenderInfo(PluginShader\* sh) { return CHANNEL_BUMP_SUPPORT; } \> virtual Vector Output(PluginShader \*chn, ChannelData \*cd); \> virtual LONG InitRender(PluginShader \*sh, InitRenderStruct \*irs); \> virtual void FreeRender(PluginShader \*sh); \> static NodeData \*Alloc(void) { return gNew MandelbrotData; } \> \> private: \> Real m_rDelta; \> Real m_rScale; \> }; \> \> Bool MandelbrotData::Init(GeListNode \*node) \> { \> BaseContainer \*data = ((PluginShader\* )node)->GetDataInstance(); \> \> data->SetReal(MANDELBROTSHADER_DELTA, 1.0f); \> data->SetReal(MANDELBROTSHADER_SCALE, 1.0f); \> \> m_rDelta = 0.0f; \> m_rScale = 0.0f; \> \> return TRUE; \> } \> \> LONG MandelbrotData::InitRender(PluginShader \*sh, InitRenderStruct \*irs) \> { \> BaseContainer \*data = sh->GetDataInstance(); \> \> m_rDelta = data->GetReal(MANDELBROTSHADER_DELTA, 0.0f) / 100.0f; \> m_rScale = 1.0f / data->GetReal(MANDELBROTSHADER_SCALE, 0.001f); \> \> return LOAD_OK; \> } \> \> void MandelbrotData::FreeRender(PluginShader \*sh) \> { \> } \> \> Vector MandelbrotData::Output(PluginShader \*chn, ChannelData \*cd) \> { \> // Scale the UVs = scaling the turbulence \> Vector uv = cd->p\*m_rScale; \> \> // Is this a bump calculation? \> if (GET_TEX_CHANNEL(cd->texflag) == CHANNEL_BUMP) \> { \> // Which of the four samples are we talking about? \> switch (GET_TEX_BUMP_SAMPLE(cd->texflag)) \> { \> // Shift the UV surface point. \> case 0: uv.x -= m_rDelta; break; \> case 1: uv.x += m_rDelta; break; \> case 2: uv.y -= m_rDelta; break; \> case 3: uv.y += m_rDelta; break; \> } \> } \> \> uv.z = 0.0f; \> \> return Turbulence(uv, 4.0f, TRUE); \> } \> \> \> // be sure to use a unique ID obtained from www.plugincafe.com \> #define ID_MANDELBROT 1001162 \> \> Bool RegisterMandelbrot(void) \> { \> // decide by name if the plugin shall be registered - just for user convenience \> String name=GeLoadString(IDS_MANDELBROT); if (!name.Content()) return TRUE; \> return RegisterShaderPlugin(ID_MANDELBROT,name,0,MandelbrotData::Alloc,"Xmandelbrot",0); \> } \>
Hope this helps.
cheers,
Matthias