THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/12/2008 at 06:03, xxxxxxxx wrote:
Here a simple example. Basically I allocate buffers in the videopost and store the pointers in the container of the videopost. I read out the container in the shader then and fill the buffer from within ShaderData::Output(). You could also use ExecuteLine() in the videopost to display the buffer on the fly.
the shader
> \> #include "c4d.h" \> #include "c4d_symbols.h" \> #include "xmandelbrot.h" \> \> \> class MandelbrotData : public ShaderData \> { \> public: \> virtual Bool Init (GeListNode \*node); \> 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: \> Vector \*m_varrBuf; \> LONG m_lWidth; \> }; \> \> Bool MandelbrotData::Init(GeListNode \*node) \> { \> BaseContainer \*data = ((PluginShader\* )node)->GetDataInstance(); \> \> m_varrBuf = NULL; \> m_lWidth = 0; \> \> return TRUE; \> } \> \> LONG MandelbrotData::InitRender(PluginShader \*sh, InitRenderStruct \*irs) \> { \> BaseContainer \*data = sh->GetDataInstance(); \> \> if(irs->vd) \> { \> PluginVideoPost \*pvp = NULL; \> pvp = irs->vd->FindVideoPost(1000968); \> \> if(pvp) \> { \> BaseContainer \*pdata = pvp->GetDataInstance(); \> \> BaseContainer \*subbc = pdata->GetContainerInstance(1023441); \> \> VPBuffer \*buf = NULL; \> buf = (VPBuffer\* )subbc->GetVoid(1000); \> \> m_varrBuf = (Vector\* )subbc->GetVoid(1001); \> \> if(buf && m_varrBuf) m_lWidth = buf->GetInfo(VPGETINFO_XRESOLUTION); \> } \> } \> \> return LOAD_OK; \> } \> \> void MandelbrotData::FreeRender(PluginShader \*sh) \> { \> } \> \> Vector MandelbrotData::Output(PluginShader \*chn, ChannelData \*cd) \> { \> if(cd->vd) \> { \> LONG x,y,scale; \> \> cd->vd->GetXY(&x;,&y;,&scale;); \> \> if(m_varrBuf) m_varrBuf[((y/scale)\*m_lWidth)+(x/scale)] = Vector(1.0, 0.0, 0.0); \> } \> \> return 0.0; \> } \> \> // 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); \> } \>
the videopost
> \> #include "c4d.h" \> #include "c4d_symbols.h" \> #include "vpcolorize.h" \> \> \> class ColorizeData : public VideoPostData \> { \> INSTANCEOF(ColorizeData,VideoPostData) \> \> public: \> virtual Bool Init(GeListNode \*node); \> virtual void Free(GeListNode \*node); \> virtual void AllocateBuffers(PluginVideoPost \*node, Render \*render, BaseDocument \*doc); \> virtual LONG Execute(PluginVideoPost \*node, VideoPostStruct \*vps); \> virtual LONG GetRenderInfo(PluginVideoPost \*node) { return VIDEOPOST_REFRESH/\*|VIDEOPOST_EXECUTELINE\*/; } \> \> static NodeData \*Alloc(void) { return gNew ColorizeData; } \> \> private: \> LONG m_lFxId; \> Vector \*m_varrBuf; \> }; \> \> Bool ColorizeData::Init(GeListNode \*node) \> { \> PluginVideoPost \*pp = (PluginVideoPost\* )node; \> BaseContainer \*dat = pp->GetDataInstance(); \> \> m_varrBuf = NULL; \> \> return TRUE; \> } \> \> void ColorizeData::AllocateBuffers(PluginVideoPost \*node, Render \*render, BaseDocument \*doc) \> { \> BaseContainer \*data = node->GetDataInstance(); \> \> LONG needbitdepth = 32; // also 16 and 32 are possible \> \> m_lFxId = render->AllocateBufferFX(VPBUFFER_POSTEFFECT, "Colorize", needbitdepth, TRUE); \> } \> \> LONG ColorizeData::Execute(PluginVideoPost \*node, VideoPostStruct \*vps) \> { \> BaseContainer \*data = node->GetDataInstance(); \> \> if (vps->vp==VP_RENDER && vps->open) \> { \> VPBuffer \*buf = NULL; \> buf = vps->render->GetBuffer(VPBUFFER_POSTEFFECT, m_lFxId); \> if(!buf) return RAY_NOMEM; \> \> BaseContainer subbc; \> subbc.SetVoid(1000,buf); \> \> const LONG w = buf->GetInfo(VPGETINFO_XRESOLUTION); \> const LONG h = buf->GetInfo(VPGETINFO_YRESOLUTION); \> \> m_varrBuf = bNew Vector[w\*h]; \> if(!m_varrBuf) return RAY_NOMEM; \> \> subbc.SetVoid(1001,m_varrBuf); \> \> data->SetContainer(1023441, subbc); \> } \> \> else if (vps->vp==VP_RENDER && !vps->open) \> { \> VPBuffer \*buf = NULL; \> buf = vps->render->GetBuffer(VPBUFFER_POSTEFFECT, m_lFxId); \> if(!buf) return RAY_NOMEM; \> \> if(buf && m_varrBuf) \> { \> const LONG w = buf->GetInfo(VPGETINFO_XRESOLUTION); \> const LONG h = buf->GetInfo(VPGETINFO_YRESOLUTION); \> \> LONG x,y; \> const LONG cpp = buf->GetInfo(VPGETINFO_CPP); \> \> SReal \*b,\*buffer = (SReal\* )GeAlloc(cpp\*w\*sizeof(SReal)); \> if (!buffer) return RAY_NOMEM; \> \> for(y=0; y<h; y++) \> { \> buf->GetLine(0,y,w,buffer,32,TRUE); \> \> for (b=buffer,x=0;x<w;x++,b+=cpp) \> { \> Vector col = m_varrBuf[(y\*w)+x]; \> b[0] = col.x; \> b[1] = col.y; \> b[2] = col.z; \> } \> buf->SetLine(0,y,w,buffer,32,TRUE); \> } \> GeFree(buffer); \> } \> } \> \> return RAY_OK; \> } \> \> void ColorizeData::Free(GeListNode \*node) \> { \> if(m_varrBuf) bDelete(m_varrBuf); \> } \> \> \> // be sure to use a unique ID obtained from www.plugincafe.com \> #define ID_COLORIZEVIDEOPOST 1000968 \> \> Bool RegisterVPTest(void) \> { \> // decide by name if the plugin shall be registered - just for user convenience \> String name=GeLoadString(IDS_VIDEOPOST); if (!name.Content()) return TRUE; \> return RegisterVideoPostPlugin(ID_COLORIZEVIDEOPOST,name,0,ColorizeData::Alloc,"VPcolorize",0,0); \> } \>
cheers,
Matthias