Monday, July 27, 2009

The little hacker's busy weekend

Another unruly weekend is gone..
As far as I can remember, I've been home since Friday evening.

Let's see where I did not go. Friday evening a friend invited me to go clubbing and I didn't go, both because Friday is the day where I'm particularly tired and because I wanted to get some code done at home.
Saturday I didn't go out drinking with friends and I also didn't go to a club where another friend invited me. I didn't go also because I wanted to stick around to help my girlfriend to prepare for her trip to the mount Fuji (!)
Clearly, Saturday I didn't go climb the Fuji-san ! Nor I joined some friends that went to some swimming pool (also because I woke up at 4 PM).

That's a lot of inaction !!

I did get busy with code however. Thursday night I got the RenderMan SL compiler to compile a basic shader such as matte.sl into asm code that can run in the virtual machine.

So, now this shader:

surface matte( float Ka = 1; float Kd = 1;)
{
    normal Nf = faceforward(normalize(N), I);
    Oi = Os;
    Ci = Os * Cs * (Ka*ambient() + Kd*diffuse(Nf));
}
..becomes..

.data
    N               global    varying    vector
    I               global    varying    vector
    Oi              global    varying    color
    Os              global    varying    color
    Ci              global    varying    color
    Cs              global    varying    color

    $su1            parameter uniform float   
    $su5            parameter uniform float   

.code
;====================================
surface matte
    movvv    $v2       N     
    normalize    $v3       $v2   

    movvv    $v4       $v3   
    movvv    $v1       $v4   
    movvv    $v5       I     
    faceforward    $v6       $v1       $v5   

    movvv    $v7       $v6   
    movvv    $v0       $v7   
    movvv    Oi        Os    
    mulvv    $v0       Os        Cs    
    ambient  $v2   

    movvv    $v3       $v2   
    mulsv    $v4       $su1      $v3   
    movvv    $v6       $v0   
    diffuse  $v7       $v6   

    movvv    $v8       $v7   
    mulsv    $v9       $su5      $v8   
    addvv    $v10      $v4       $v9   
    mulvv    $v11      $v0       $v10  
    movvv    Ci        $v11  

    ret

..the parameters aren't still quite there as they aren't getting the proper default value and are named as registers (I actually just noticed that 8), but overall the thing works !
The renderer now grabs SL files and compiles them automatically.

Recently a couple of coworkers, while chatting, kind of teamed up for their love for Linux. I've used it in the past, but I'm not so attached to it because I don't really have much of an academic background.. and it's at the university where people get all warm with the Unix stuff.

Still, I decided to look into porting RibTools to Linux.. since the code is rather platform independent.
I installed the latest Ubuntu (it's the popular Linux of the day) under VirtualBox.. all free all the way !

The RibTools projects are fairly simple, but nonetheless I didn't want to write a Makefile.. I will never understand Makefiles !!

At work, one of the Linux buffs, ported the current project's build process from Visual Studio solution & project to Jam.
It was actually a good idea, because projects at some point get so complicated and small changes sometimes require a lot of repetitive manual labour of mouse and copy & paste. The nice thing is that our coworker actually bundled the build system with a script that scans the source dirs and builds VS project files and the solution automatically ! Those of course, being generated automatically, are only good to browse with the IDE and don't allow for changing settings using Visual Studio's interface. In any case, it's a pretty good system.

For RibTools instead I used Code::Blocks. It's a multi-platform IDE that is surprisingly good.. as very close to Visual Studio.
The nicest feature is the ability to import VS's project files. That saved I don't know how much time.. very useful to avoid too much frustrations at first.
Some things still needed manual tweaking. For example, the post-building shell commands that copy resource files into a directory for distribution.. those needed to be translated into the Unix alternative (to avoid copying Subversion's .svn dirs, I resort to using rsync to copy ! While on PC, xcopy wouldn't pick up the hidden .svn stuff).
Another problem is that static libraries in the same solution don't automatically get linked to executables that depend on them. One has to go into the link settings of the project and specify the static libraries names directly.

GCC gave me a few problems, but on the other hand it's nice to run code on a different compiler to bring up issues. I think that VC++ can now be considered a pretty solid C++ compiler, but there was at least one usage of templates that VC++ allowed and apparently doesn't reflect the standard.. and GCC pointed that out.
GCC also got pretty confused with my usage of macros and placement new ..and I must admit that I'm pretty confused too (^^;)
Some things sparked a WTF and it will be interesting to get to the bottom of it some day (in GCC, my "DASSERT" macro works at line 225 but not right below (?!)).

Anyhow, the Linux version of the renderer now builds and runs. The exception is "RibRenderTool" which uses OpenGL and a GLUT clone to do actual screen display. That will require a bit more work, but it shoudln't be too hard (really ?).

I also updated the project page over at Google project hosting.. how do you like the new icon ?! Rather macabre !!

One final note about Linux. Ubuntu comes with the GNOME desktop. It's fairly lean, especially with all the stupid windowing effects removed (don't want those while running the OS virtually !).
Then I installed the kubuntu desktop package, which is based on KDE.. and it was pretty mad. Very overkill looking, rather confusing, and not really visually appealing !
Then I installed to xubuntu and I'm happy with it now.
I wish I installed xubuntu from the start, because removing kubuntu completely, required some work.

Otherwise, things run pretty smoothly. Of course, I'm not one of those that needs Linux to survive.. but I was glad to see that it's possible the have a nice IDE under Linux as well.

And, zzzzzzzzzzz