# A Corner-Highlighting Method for Ambient Occlusion
## 3 Our Algorithm
### Generating Outlines  
Our algorithm is inspired by the _model object outlining technique_[17] which is frequently found in many video games as a highlighter for certain 3D objects. This method introduces generating outlines by creating a scaled replica of the 3D objects in run time. Figure 4 visualizes the approaches we have made. Filled polygons represent model objects and thin edges represent their generated outlines with each method. The first method is a simple scaling. It generates an outline by scaling the model object itself. While it is a simple approach, it mostly ends in generating incorrect outlines as seen in the figure on the left. The next approach is the _Normal Vector Extrusion_. For the illumination purpose, many rendering pipelines require model object files to include per-vertex normal vectors, and the Normal Vector Extrusion method benefits from this. We extrude each vertex with its normal vector to a certain extent. This method guarantees constant outline thickness, but corners are mostly discontinuous, leading to a miscalculation on view ray enter and exit counting. This flaw can be seen on the center in the Figure 4.  
To avoid this issue, we opted for our last approach: _Integrated Normal Vector Extrusion_. Each vertex in the model object is shared among multiple faces, and faces have different normal vector orientations. As shown in Algorithm 2, for each vertex, we generate a new normal vector by integrating (or averaging) all the unique normal vectors of the faces that the vertex takes place. Note that similar face normal vectors are treated as a duplicate, and one among them should be valid for integrating. Since this operation is much to handle in real-time, we pre-compute the model object data and save them as a pre-processed data. The last image in Figure 4 depicts the implementation result of Algorithm 2. Unlike previous methods, you can observe an accurate outline for the model object with consistent thickness and continuous corners. Figure 4: Different outline generation methods. The integrated normal vector extrusion shows the best results. Figure 3: Drawing the intersections. Those intersections are candidates for the ambient occlusion processing. ```
step1. reset vertex normal vectors. for each vertex; reset that vertex's candidate set to be empty. step2. build up candidate normal vectors. for each face; calculate the face normal vector \(\vec{n}\). foreach vertex in that face; if\(\vec{n}\) is not included in the vertex's candidate set, add \(\vec{n}\) to the vertex's candidate set. step3. calculate the integrated normal vectors. for each vertex; calculate the average vector of the vertex's candidate set. set that average vector as the integrated normal vector. ```  
**Algorithm 2**Pseudo-code to generate integrated normal vectors for each vertex. In spite of the preparation, our outline method does not always guarantee a perfect result. There are two major causes to be treated with caution. The first is when the model object is _not_ in the form of a closed polyhedron. Closed polyhedron refers to the model object with no opened faces or corners on the surface. In other words, the back face of the model object should not be visible in the camera view from any possible directions. This can be avoided by either filling the gaps (closing the face) or generating custom outlines solely for the troubling ones. The latter case is about scaling the concave corners. Our outlining mechanism cannot spot concave corners by default. While corners in between two different model objects can be distinguished, the local corner information of a single model object is lost due to integrating vertex normal vectors. The best solution to address this issue is to convexify the outline model object and bake the local ambient occlusion of the model object into its texture, so there is no need for real-time checking the local static concave corners. Another solution is to avoid concave vertex normal vectors.