Sunday, December 21, 2008

Recent home coding: ribparser

I've been spending some time at home writing a very basic RIB parser. RIB being the RenderMan scene description format.
The goal is to be able to read in input simple files and someday maybe even render them. But the real point is to get RIB files in input, because that's a well established standard in the world of production rendering and that's where my focus is right now.

RIB files are text files with commands and parameters which pretty much translate to the RenderMan Interface (or RI) that is also available for C programming (provided a RenderMan license..).
RIB files being so close to an API also give an insight into a state machine for the REYES pipeline ..something that I think is worth looking at, though I'm not sure that it's going to translate well for real-time 3D.

I've looked before into the RenderMan interface with the book The RenderMan Companion by Steve Upstill. The book actually only covers the C interface, but it shows many simple examples on how to create things "procedurally" and how to handle a scene, including creating shadow maps.
An important book to learn about RenderMan, but not too explicit about the actual internal structure of a renderer.

Recently, another book refreshed my interest for the RenderMan interface and off-line rendering in general. The book is called Production Rendering: Design and Implementation. Edited by Ian Stephenson in collaboration with 6 other experts in the field.
The book explains what happens behind the scenes of a production renderer and it goes straight into the RenderMan + REYES pipeline approach. From the state machine to the way primitives are processed and converted into micro-polygons, to how the micro-polygons grids are "shaded" using custom shaders that can run on massive multi-core architectures (as I write, the latest NVidia card has 540 cores 8).
Production Rendering got me really excited and made me realize how close are modern real-time shaders to those meant for off-line renderers. I also like the C++ code snippets that show things like are meant to be explained (show me the code !!) reminds me a bit of my long lost Advanced Animation and Rendering Techniques
by A.Watt and M.Watt (15+ years ago !!).

Then, recently I found this a basic RenderMan implementation in Shell script !! It's called RenSH and it's written by Ian Stephenson (see some of his other RenderMan-related works, like the PS2 implementation).
RenSH clearly very cool and it was also an inspiration for me to go ahead and try to write my own RIB parser... if someone can write a parser and a renderer in shell script, surely I can write something in C/C++ 8)
As it turns out, shell script actually makes it easier to write a parser, because it is a parser itself, and the guy clearly knows the RenderMan interface inside out. But still, it's quite humbling to see the whole state machine, the transformations and the quadratic primitives becoming actual ASCII art 8)

Anyhow, my project is over at the Google code repository. It currently really only gets one test .rib file in input and parses it validating the arguments of a small subset of commands. It will hopefully grow.. but that really depends on many things (like, time 8).
The project is also an excuse to get acquainted with XCode, so the actual project file is in XCode format, while the source is pretty much plain C++ using printf() and std::vector.

Have fun !

Note: The book links are by my Amazon Associates account just because. But, I really suggest, if possible, to shop around and maybe have a look at the actual books. I bought mine at GDC and Siggraph (it was $100 for Production Rendering !!).