On 25/05/2016 at 07:46, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 14+
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;
---------
Hello,
I must be missing something very obvious. I cannot get proper bitmap pixels sampled from a shaderlink. I am running this from GetVritualObjects.
For example, I have a generator plugin that generates a plane.
I have a shader link in the description that lets the user input a shader, like a bitmap or a noise shader.
I need to sample this shader into a bitmap that I can use later to do some calculations, based on the plane UVs.
This would be done from inside GetVirtualObjects. Or is there a better place to do it?
Here is the code I am using:
AutoAlloc<BaseBitmap> bmp;
BaseShader* shaderLink = (BaseShader* )bc->GetLink(MYSHADERLINK,doc);
if (shaderLink)
{
InitRenderStruct irs;
shaderLink->InitRender(irs);
LONG bitmapWidth = 100;
LONG bitmapHeight = 100;
IMAGERESULT res = bmp->Init(bitmapWidth, bitmapHeight);
if (res == IMAGERESULT_OK)
{
ChannelData chD;
chD.p = Vector(0, 0, 0);
chD.n = Vector(0, 1, 0);
chD.d = Vector(0, 0, 0);
chD.t = 0.0;
chD.texflag = TEX_TILE;
chD.vd = NULL;
chD.off = 0.0;
chD.scale = 0.0;
for (LONG x=0; x < bitmapWidth; x++)
{
for (LONG y=0; y < bitmapHeight; y++)
{
chD.p.x = (Real) x ;
chD.p.y = (Real) y ;
Vector pixel = shaderLink->Sample(&chD);
LONG r1 = pixel.x * 255;
LONG g1 = pixel.y * 255;
LONG b1 = pixel.z * 255;
bmp->SetPixel(x, y, r1, g1, b1);
}
}
}
}
Any help would be greatly appreciated.
Edited for a better explanation.