Stylistic Rendering Using an Arbitrary Texture Set


Second Project Update

Goals

The goal for this update was to get the basic texture selection mechanism build. That is given any triangle in the scene I needed a way to choose a texture for the triangle that best matched the color you would see on that triangle if it was rendered in the standard way. As the work on this progressed I realized that there were issues in the way the textures were mapped to the triangles. Specifically, that there was perspective distortion. This prompted a more advanced texture technique that uses the stencil buffer to get a flat texture appearence.

Implementation 1: Texture Selection

To implement texture selection I used some code that I developed for the COMP236 Homework 5b. In this homework assignment we added lighting calculations to our SoftGL (software implementation of OpenGL ) System. I used my implementation of the OpenGL lighting equations to calculate the lighting at one point on each rendered triangle. I then make some simplifying assumptions. Since I don't, as yet, do any image analysis of the texture set provided, I assume that they are given in darkest to lightest order and that their intensities are approximately evenly distributed across the entire intensity range. Given these assumptions, I choose the texture to map to a triangle, by looking at the intensity of the lighting on that triangle, and choosing the texture that covers that intensity interval. These simplifications work well for texture sets that vary mostly in intensity, and do so evenly across the entire range. So for the examples I'll be showing, I generated textures in Adobe Photoshop that fit these criteria.

source code: Renderer_lighting.cpp

Implementation 2: Better Texture Rendering

As mentioned earlier, the initial results using the lighting-based texture mapping showed perspecive distortion as the texture's were mapped onto triangles that had large depth variance. This distortion is usually a desired effect, for example on a wall mapped with a brick texture, the bricks in the distance should appear smaller than the bricks closer to the viewer. But for non-photorealistic effects, espectially drawing style effects, we want the size and orientation of the strokes to be constant regardless of depth. The solution to this problem was to use the stencil buffer in OpenGL. For each texture in the texture set, I render the triangles that I want mapped with that texture and set a bit in the stencil buffer. Then I render a quad that covers the entire screen that is mapped with the desired texture, only writing over pixels that has their stencil bit set. This gives the textures the flat appearence we want. I also believe that we are getting a slight benefit to the performance as the actualy triangles in the model can be rendered without texture or lighting, just to set the stencil bit, and the only things rendered with texture one quad per texture in the texture set.

soure code: Renderer.cpp, Renderer.hpp

Screen Shots

Style
OpenGL Rendering
NPR Rendering
Crosshatch OpenGL Crosshatch
Speckle Traced
OpenGL
Speckle Traced
Noise
OpenGL
Noise

Next Step

I have two major goals for the final update. First I want to implement some image analysis on the texture set, so that textures can be given in any order and the program will analyse the textures to gain some overall color information about each texture. I will also explore different ways of matching lighting colors to textures to allow more flexible and visually apealing results. The second goal is to look at blending of textures. I want to evaluate the lighting equations at least at the vertices of each triangle and then use some alpha blending to either blend multiple textures across one triangle.