On 25/02/2016 at 01:56, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R17
Platform: Windows ;
Language(s) : C++ ;
---------
Hello.
I have to sample a shader and create a bitmap based on that shader.
The problem is that I get a small error in the very first line of pixels.
I send you 2 images with the correct and the wrong version of the result:
correct: https://dl.dropboxusercontent.com/u/432275/correct.png
wrong: https://dl.dropboxusercontent.com/u/432275/wrong.png
These 2 bitmaps are both 100x100 (for testing).
For each pixel, i sample the shader using the corresponding texture coordinates.
Here is the code that I use for sampling:
unsigned int resolution_x = 100; //Testing
unsigned int resolution_y = 100;
BaseBitmap * bitmap = BaseBitmap::Alloc();
IMAGERESULT init_result = bitmap->Init(resolution_x, resolution_y);
if (init_result = IMAGERESULT_OK) {
InitRenderStruct irs;
shader->InitRender(irs);
ChannelData channel_data;
channel_data.off = 0;
channel_data.scale = 0;
channel_data.t = 0;
channel_data.texflag = TEX_TILE;
channel_data.p.z = 0;
channel_data.d = Vector(1,1,1);
channel_data.n = Vector(0,1,0);
channel_data.vd = NULL;
for (unsigned int x = 0; x < resolution_x; ++x ) {
for (unsigned int y = 0; y < resolution_y; ++y ) {
channel_data.p.x = ((LReal)x)/(resolution_x-1) ;
channel_data.p.y = ((LReal)y)/(resolution_y-1) ; //!!!!!!!
assert(channel_data.p.x <= 1 && channel_data.p.y <= 1 );
Vector color = shader->Sample(&channel_data);
bitmap->SetPixel(x, y, 255*color.x , 255*color.y , 255*color.z);
}
}
shader->FreeRender();
if (bitmap->Save(Filename(file.c_str()), FILTER_PNG, NULL, SAVEBIT_0) == IMAGERESULT_OK) {
//image saved
}
}
Now, in the line i have marked with //!!!!! i add a small error correction value 0.001.
That way i get the correct result.
Why is this error correction value needed and why is this needed only in Y texture coordinates ?
Thank you for your time.