![]() Los Angeles mental ray® User Group |
![]() | ||||||||||||
| |||||||||||||
Resources Sections General Install/Setup Options Settings Performance Optimizations mi Scene File FG/AO/GI Subsurface Scattering Shiny Stuff mrfm (Maya) Shader Writing Hair and Geometry Shaders | Stub TipsEver notice that at the beginning of a render, you have a stub image written in place of the rendered output image? That stub has readable text that can be used to connect to streaming tile data. This offers you some alternatives to In a recent email on the mentalray mailing list forum, Thomas Driemeyer suggested we repost this here. In addition, we address the follow up question on how to access floating point framebuffer data below. Basic Stub DataExcerpted from the "Realtime Image Display (DISP)" section 5.3.2 of Programming mental ray ... "[Stub data is written] to a socket whose number is written to files. If there are file output statements in the camera, the specified image files are written as 128-byte files containing an ascii line such as:
imf_disp can connect to the given socket on the given host to obtain RGBA tiles. [...] The 128-byte file is overwritten with the final image when rendering completes and the output statements in the camera are executed."The 128-byte file contains -1 as port numbers in mental ray 3.3.3 or higher if firewall mode was enabled by the package that mental ray is integrated in. This mode attempts to circumvent defective Windows ``firewalls'' that consider any attempt to create a socket an Internet access, and block it. mental ray tries to limp along in such a case by avoiding all socket creates. This is a Windows-specific problem, Linux and Unix are fine. "The protocol used to send data to a file descriptor or to a socket are identical. Data is sent in packets. Each packet consists of a header, followed by optional image data. The header consists of five integers in network byte order (big-endian, high byte first): one packet type code followed by four parameters. The following packets are defined:
"Image size packets (type 5) are sent only to file descriptors and not to sockets because socket readers have obtained that information from the 128-byte file already. The gamma value is a floating-point value, not an integer. mental ray 2.1 and 3.0, but not 3.1 and later, refuse connections (type 3) if there is already another connection; this can happen only during socket connection attempts. Packets with types not listed in the table above should be quietly ignored, they will consist of only the header. "Only image data packets (type 2) have data after the header. Data is sent in RGBARGBA... order, with eight bits per pixel component, beginning with the lower left corner of each tile. The coordinates of the lower left tile pixel (xl, yl) and of the upper right tile pixel (xh, yh) are in absolute image coordinates. If output shaders run, the image may be sent multiple times, once as rectangular tiles during rendering and then once per output shader in blocks of scanlines. The order of tile and scanline packets is undefined. Framebuffer access (floating point or whatever you define)Thomas notes .. "... with mental ray 3.3 you get a second port listed at the end of the 128-byte stub file line. If you open that, you can list available frame buffers, and request raw frame buffer data. Conversion is up to you. I am afraid this isn't documented; try starting a long-running render and connect to the port with telnet (or the browser of your choice, using telnet://renderhost:port), and ask for help. It's very brief but complete. We'll walk through an example of this in the next section. But before that, let's make a documetnation attempt, derived from protocol information I got from Thomas... The socket connection protocol for the second port allows access to the data streaming out from any defined framebuffer. (Note that this is framebuffer image pixel data, after the samples have been filtered/collected into pixels.) These commands are sent to the thread handling image display, which replies to the socket using the packet protocol defined above. Here are the commands available for sending to the second port:
If you send a stream_begin command, the stream replies with frame and rectangle packets as previously described, in other words:
The following interaction demonstrates the protocol when connecting to the second port. Green indicates socket reply. The red number is our port. Note how the help and fb_list replies end with an empty line after the colon. % ray33-o -samples 4 4 -o x.pic cube.miFramebuffer Access Example (aka, Fun With Sockets)OK. Let's learn by doing. For this example, we use a standalone ray on a Linux machine and an mi file that renders long enough for us to poke around on telnet (the SSS mi file of grapes submitted by Dominika Waclawski soon to be seen on the SSS tips page). As above, green indicates socket reply. Now let's render to a file called foo.jpg: If we were to telnet to the first port, we'd just see a bunch of streaming data. The secondary port gives us a little more interactivity. So, let's telnet to it (that last number): Here's some data streaming fun. Try opening an |