Freestyle integration into Blender

May 28, 2008

First render !

Filed under: Notes, Update — The dev team @ 9:19 PM

I managed to get a little bit further. I corrected the GLStrokeRenderer::preparePaper function to properly load the paper texture (it took me a while to understand that ImBuf has a 32 bit image structure). I also set up the viewer to fixed dimensions 640×640, finally allowing the strokes to be rendered.

When I render the scene, the object shows up very quickly (I recognize the teapot’s shape) but is automatically erased by a gray background. I tried to grab a screenshot or a screencast of it, but it’s unfortunately impossible to do so. Since I did not make any change to the way things are rendered, I am guessing that when the render frame window is instantiated, its OpenGL context is selected for rendering. I have to analyze a little bit closer what’s going on to keep the result on display.

Update:
By studying Yafray’s code in more detail, I understood why the result was not kept on display. I first needed to correctly initialize the freestyleRender function in the rendering pipeline (creating a RenderResult structure to hold the image result and passing the Render variable to Freestyle’s execution function). In Freestyle’s rendering function, after having drawn the strokes, I copy the rendered strokes from the back buffer into a float array and use that data to load up the RenderResult‘s image. The result is then drawn into the render window.

Even though this revision is a big improvement over the past steps, phase 1 is still not over with. I am currently experiencing a few notable issues:

  • the paper texture is apparently not displayed (even though it is loaded) and the brush stroke color is inverted. Is that a Freestyle feature ? I do not know yet.
  • the view map computation may crash for some models (simpleScene.3DS for example) and other style modules (not tested yet).
  • Freestyle’s initialization is called each time the RENDER button is pressed, which could cause some memory leakage (the paper texture is reloaded each time without being deallocated at the end of the render).

After removing the fixed file references, I will need to change the UI to display a list of selectable style modules. Then, I will need to export the model data in 3DS format and the camera information to the viewer to finish up the first phase.

Here is a screenshot of what the first render looks like (the teapot is also upside-down in the original 3DS file):

4 Comments »

  1. cant see the image myself (too fast) but something happens indeed.
    Nice progress.

    I think (not checked in code) that the render result imb is automatically selected in the render window when it comes front.
    So you need either to copy your own imb struct in it, or simply open your imb as image in the image editor.

    small remark :

    GLStrokeRenderer.cpp line 516 : qim->depth = 32

    this is a potential crasher if a wrong filename is passed. put it after the test for qim is null

    Comment by jean-luc — May 28, 2008 @ 10:39 PM

  2. Way to go Maxime, it’s quite exciting to see this first render!
    Don’t bother too much about some 3DS models crashing, lib3ds is known to be unstable (back in the days, I remember having to correct some stuff for it to work okayish, and I’m not even sure this version is shipped with freestyle sources); anyway, 3ds will be bypassed completely in further steps, so, no big deal. Now, if the crashes occur in the actual viewmap computation, that’s an issue (…alas, I’m quite sure this will happen too :/ ).
    About the colors being suspicious, we had a special way of drawing the strokes, so that strokes darken their overlaps instead of making them brighter, as they would in “real life”: If I’m not wrong, we first inverted the background, then drew the strokes additively with inverted colors as well, and then re-inverted the final result (Stéphane?). I suspect this to be the reason of your color inversion.
    Again, bravo for your progress! ;)

    Comment by emmanuel — May 29, 2008 @ 8:14 AM

  3. Actually, Freestyle crashed for the simpleScene.3DS file during view map calculation. Maybe it is due to lib3ds, of course I have no clue.

    Regarding the color issue, I figured out what you said a few hours later. The color was inverted because it would only display the strokes, like you said.

    I would like you to test the revision too as soon as possible. Right now, we still have issues with cross-platform compilation and linking (especially with swig) so as soon as that’s resolved, please continue letting me know how it is working on your system.

    Comment by maxime — May 29, 2008 @ 2:42 PM

  4. About the color inversion: as Emmanuel mentioned, the strokes are drawn in complement colors, mostly to simulate the subtractive nature of wet media using OpenGL additive blending mode. The whole buffer is then inverted in AppCanvas::Render().

    lib3ds has some limitations, but the simpleScene.3DS should work fine (I just tried to compute the ViewMap of that scene using the Freestyle binaries and that works fine, so I don’t think the problem is in the ViewMap computation itself).

    Comment by stephane — May 30, 2008 @ 10:05 PM


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: