CS580: Advanced Graphics

Non-Photoreal Rendering with Shaders

Lukas Lepicovsky

Problem Definition:

Though the usual goal of graphics is photorealistic rendering, non-photorealistic effects are also important to simulate artistic drawing styles.

Method & Implementation:

I implemented a system similar to Inspire.
The basic idea is to pick a set of points on the model and use the screen space position(x,y) of these points to render strokes(2d textured patches).

Pseudocode

Generating Feature Points(method 1):

Randomly sort the list of the vertex positions, store a random number rand1 for each vertex. (this number will be used to randomly reject points to get rid of the uniformity that could arrise if we used all vertices).

Generating Feature Points(method 2): (my method)

Randomly cast rays into the scene using a raytrace and record up to N intersection points, store the intersection position, the normal and rand1.

Rendering

Rendered all triangles in the model using a pixel shader that puts the camera space x component of the normal into the red buffer, the camera space y component into the green buffer, and the dot product of the camera direction with the vertex normal into the blue buffer.

Perform edge dectection onto the blue buffer (with a pixel shader).

Render all up to the desired number of feature points into the alpha buffer, store 1/255+dot(pointNormal,lightDir) if (rand1>Rthres) 0 otherwize.

Now read back all the buffers and find all the pixels with an alpha value larger than 0. These are the strokes to be rendered, what style depends on the edge value at that pixel (blue channel) and the illumination of the pixel(alpha value), its orientation red and green channel. I also allow the direct rendering of strong edges regardless of feature points, but this is slow so it should sometimes be disabled.

My implementation allows the buffer that is read to be a lower resolution that the output buffer, this also improves speed.

 

Experimental Results:

Source Code & Excecutable:

My source code either needs the nvidia cg toolkit to be installed along with opengl/glut, or it needs these library files to be placed in the include and lib directories.

The executable is in a subdirectory of the zip called Project 4, along with the cg runtime files, the stroke images, and 3d models.

Here is a link to it all.

The program was tested and works on an Nvidia 7800 gtx.

Conclusion:

One of the main issues with the method described in the paper was that there would not be enough feature points if the mesh had a low vertex count, I addressed this with my ray casting solution, thought it requires more memory it allows for proper rendering of low res models. I also had some problems with feature points popping in and out that is likely due to a problem with my depth test.

 

References / Credit:

Non-Photorealistic Rendering System, Nguyen et. al. http://www.dtc.umn.edu/~xyuan/research/publication/inspire/inspire_IEEE.pdf

Vertex Shader Tutorial: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=47

Pixel Shader Tutorial / 9-tap Laplacian Filter, Mark J. Harris
www.GPGPU.org

TGA Loader, Lev Povalahev
http://www.levp.de/3d/index.html

Ascii File Loader / OpenGL Renderer: Ronny André Reierstad , www.morrowland.com

Ray Triangle Interseption: www.softsurfer.com