Benoit Leveau
November 10th, 2010, 11:25
[reposting in correct section]
Hi,
I'm trying to update a display shader from mental ray 3.6 to 3.8, and to use the native frame buffers instead of a custom frame buffer plugin.
So far, so good, but I have a problem.
I manage to receive the streams for all the frame buffers, using the socket number written in the stub files, but for some reason the data I receive for the color one is all black.
For all frame buffers, I manage to get the correct data and I can then send it to my display program.
The one for the color is a 4x8bit channel and all I receive are zeros. Anyone else had this problem?
Here is my read tile functions. It's called whenever I receive a "rect_data..." message on the socket, after I issued a stream_begin with all the ids I want to stream.
// read a bucket from ray via the socket, and send it to an external viewer
int read_rect_data(int sockfd, const char *buf, const bool output_shaders)
{
int size, fb_id, fb_type;
int xl, yl, xh, yh;
int width, height, comp, bits;
sscanf(buf, "rect_data: %d, %d %d %d %d, %d %d, %d %d %d %d",
&size,
&xl, &yl, &xh, &yh,
&fb_id, &fb_type,
&width, &height, &comp, &bits);
const int w = xh+1-xl;
const int h = yh+1-yl;
const int wh = w*h*sizeof(miColor);
if ( !tile_data || !packet_data || size > packet_size || wh > tile_size )
{
release_tile_data();
packet_size = size;
tile_size = wh;
packet_data = malloc(packet_size);
tile_data = (miColor*)malloc(tile_size);
}
const int n = get_packet(sockfd, (char*)packet_data, size);
if (n != size)
{
fprintf(stderr, "thing : dropped bucket %d %d %d %d\n", xl, xh, yl, yh);
return 0;
}
// interleave channels
miScalar *out = (miScalar*)tile_data;
if (bits == 32)
{
const unsigned int *in = (unsigned int*)packet_data;
for (int y=yh; y>=yl; --y)
{
for (int c=0; c<comp; ++c)
{
for (int x=0; x<w; ++x)
{
unsigned int i = ntohl(*in);
out[(w*(y-yl)+x)*4+c] = *((float*)&i);
++in;
}
}
}
}
else if (bits == 8)
{
const unsigned char *in = (unsigned char*)packet_data;
for (int y=yh; y>=yl; --y)
{
for (int c=0; c<comp; ++c)
{
for (int x=0; x<w; ++x)
{
out[(w*(y-yl)+x)*4+c] = (*in)/255.0f;
++in;
}
}
}
}
for (int c=comp; c<4; ++c)
{
for (int y=yh; y>=yl; --y)
{
for (int x=0; x<w; ++x)
{
out[(w*(y-yl)+x)*4+c] = 0.0f;
}
}
}
// send data to external viewer
return 0;
}
Any help appreciated,
Best,
Benoit
Hi,
I'm trying to update a display shader from mental ray 3.6 to 3.8, and to use the native frame buffers instead of a custom frame buffer plugin.
So far, so good, but I have a problem.
I manage to receive the streams for all the frame buffers, using the socket number written in the stub files, but for some reason the data I receive for the color one is all black.
For all frame buffers, I manage to get the correct data and I can then send it to my display program.
The one for the color is a 4x8bit channel and all I receive are zeros. Anyone else had this problem?
Here is my read tile functions. It's called whenever I receive a "rect_data..." message on the socket, after I issued a stream_begin with all the ids I want to stream.
// read a bucket from ray via the socket, and send it to an external viewer
int read_rect_data(int sockfd, const char *buf, const bool output_shaders)
{
int size, fb_id, fb_type;
int xl, yl, xh, yh;
int width, height, comp, bits;
sscanf(buf, "rect_data: %d, %d %d %d %d, %d %d, %d %d %d %d",
&size,
&xl, &yl, &xh, &yh,
&fb_id, &fb_type,
&width, &height, &comp, &bits);
const int w = xh+1-xl;
const int h = yh+1-yl;
const int wh = w*h*sizeof(miColor);
if ( !tile_data || !packet_data || size > packet_size || wh > tile_size )
{
release_tile_data();
packet_size = size;
tile_size = wh;
packet_data = malloc(packet_size);
tile_data = (miColor*)malloc(tile_size);
}
const int n = get_packet(sockfd, (char*)packet_data, size);
if (n != size)
{
fprintf(stderr, "thing : dropped bucket %d %d %d %d\n", xl, xh, yl, yh);
return 0;
}
// interleave channels
miScalar *out = (miScalar*)tile_data;
if (bits == 32)
{
const unsigned int *in = (unsigned int*)packet_data;
for (int y=yh; y>=yl; --y)
{
for (int c=0; c<comp; ++c)
{
for (int x=0; x<w; ++x)
{
unsigned int i = ntohl(*in);
out[(w*(y-yl)+x)*4+c] = *((float*)&i);
++in;
}
}
}
}
else if (bits == 8)
{
const unsigned char *in = (unsigned char*)packet_data;
for (int y=yh; y>=yl; --y)
{
for (int c=0; c<comp; ++c)
{
for (int x=0; x<w; ++x)
{
out[(w*(y-yl)+x)*4+c] = (*in)/255.0f;
++in;
}
}
}
}
for (int c=comp; c<4; ++c)
{
for (int y=yh; y>=yl; --y)
{
for (int x=0; x<w; ++x)
{
out[(w*(y-yl)+x)*4+c] = 0.0f;
}
}
}
// send data to external viewer
return 0;
}
Any help appreciated,
Best,
Benoit