Saturday, October 25, 2014

Dev Test - Using GLU Quadrics for Drawing Grease Pencil Strokes

While playing around with ways of implementing stroke-filling, a thought occurred to try experimenting with using GLU Quadrics (specifically, the disc primitive) for drawing the 3D points too (and perhaps for the strokes themselves).

Without further ado, here's a little demo vid showing what the effect looks like:



If you want to get your hands on this to play with it, you can find this on my GitHub Blender Repo:
https://github.com/Aligorith/blender/tree/GPencil_FillStrokes

(Just to clarify things: the main branch for Grease Pencil stroke editing tools is still on developer.blender.org - https://developer.blender.org/diffusion/B/browse/GPencil_EditStrokes/
The GitHub branch is purely for experimental hacks at this stage)


GLU Quadrics are already used to draw the dots in the 2D case, while strokes are drawn using a triangle-strip tesselation technique. But for 3D, we had to fall back to plain old OpenGL point drawing. While the current technique is simpler and lets us do 3D points ok, it does come with limitations on how big/thick we can make the strokes/points (i.e. basically, on Windows, the drivers are limited to doing 10px strokes, and points have a similar limit; technically, the spec even says that only 1.0 thickness needs to be supported!)

For a long time, I've been thinking about enhancing the stroke drawing quality - since, let's face it, the thick-line support in native OpenGL is frankly quite shoddy and ugly (i.e. it has clearly visible segments for a start!). The main problem though was not being able to figure out a good way of doing this in 3D! Most of all the other high quality line drawing attempts out there are only for 2D lines... and so, don't solve the problems we have when lines get shown side-on, and at weird angles. Perhaps a GLSL vert + fragment + geom? shader solution will finally do the trick, but at this stage, I'm not sure how these would integrate with the rest of our drawing system (or even some of the viewport upgrade stuff under way), so in the meantime, that will stay on the backburner.

So, back to today's hack: I was refamiliarising myself with the stroke drawing code, when I noticed that GLU Quadrics weren't being used for drawing simple 3D points, despite the obvious opportunity here for some neat improvements.

In this screenshot, all the points have the same thickness, but are shown larger and smaller based on their distance to the viewport camera. Whether it's a good thing or not depends on what you're using it for, though fixing it is a lot more of a challenge!


One thing lead to another, and I just had to try it for stroke drawing too... 
Ooh... funky...

Although this is a rather funky effect, it wasn't actually what I had in mind originally. Instead, I had considered using GLU Cylinders for the body of the strokes here instead too (i.e. filling in the gaps between each stroke point), but was a bit too lazy to try figuring out the math for getting those rotated and aligned with the stroke segments. This was after all supposed to be just a quick test to get it all out of the system :P


There were some epic fails though...
The result of a bug, which caused the strokes-file above to get rendered flattened and in the wrong places.

Some more overpainting with the bugged code, playing with what interesting effects we could get. Seeing how it was like a cloudscape was quite interesting...


But seeing these gave me inspiration for something that I forgot to try (and which wouldn't have worked anyway) when I still had the first one of the fails still available: Why not try to draw some foliage with this? :)




Wish Granted! And that is how the short screencast above came to be!

2 comments:

  1. That looks great, I've used grease pencil quite a lot to make three dimensional sketches by converting to polys but this looks really interesting, 3D paint - I have been holding off asking you if there was any thoughts about using the new curve based paint system in conjunction with the grease pencil strokes, especially as the animation / onion skinning is so much better now...

    ReplyDelete
    Replies
    1. In my studio we always use grease pencil for different purposes. I hope to see this addon in Blender 2.73! And I want to ask. How this result looks in render?

      Delete