Real-Time Volume Shadow using Visible-Non Visible Algorithm

: Problem statement: Shadows are most important effect to make realistic games and visually appealing images, but they are poor in frame per second. Silhouette detection is most important phases to create real-time shadow. Approach: Present study describes a real-time shadow generated with volume shadow algorithm using Visible-Non Visible algorithm (VNV) in virtual environment illuminated by a movable light source to improve the frame per second. Silhouette detection that is most expensive part of shadow creation was described. Triangular method and VNV method were compared. An improved algorithm for volume shadow was proposed and volume shadow using both methods in C++ Opengl implemented. Results: The VNV algorithm increases the number of Frame Per Second (FPS) and as a result decreases the cost of implementation. Conclusion: A verified algorithm for volume shadow makes it easy to understand by everyone how to produce real-time shadow in outdoor and indoor virtual environment. It is possible to use it in current commercial games or other virtual reality systems.


INTRODUCTION
Shadows are most important effect to make realistic games and visually appealing images, but they are poor in Frame Per Second (FPS) and difficult to implement in real-time environment (Yaashuwanth and Ramesh 2010). In computer games, shadows can give the best feeling to gamers that they are playing in realistic world. A game with lack of shadow effect cannot be attractive especially in this century that gamers' imagination request more realistic situation.
The idea of volume shadow was proposed when Frank Crow published his ray-casting based shadow volume algorithm. His method explicitly clips shadow geometry to view the frustum (Crow, 1977). Published a paper based on volume shadow using stencil buffer, which is even today the main shadow volume algorithm. Stencil shadows belong to the group of volumetric shadow algorithms, as the shadowed volume in the scene is explicit in the algorithm. He proposed how the original stencil shadow volume technique works.
Another algorithm that Carmack suggested was a bit different from the previous algorithms which includes rays that are traced from infinity towards the eye (Lokovic and Veach, 2000). Shadow Mapping suggested by (Fernando et al., 2001) which are an extension to the traditional shadow mapping technique. In year 2002 Lengyel propose a hybrid algorithm that uses faster Z-pass rendering. Soon et al. (2004) introduced an algorithm that used the spatial coherence and frame coherence to gather. Benichou and Elber (1999) used a method to compute parallel silhouette edges of polyhedral object based on Gaussian sphere, for the normal vectors, which are located on the view direction mapped onto a Gaussian sphere. Olson and Zhang (2006), worked on tangent-space and they focused on tangential distance of objects to be used in polygon mesh silhouette detection. Olson (2010), designed a site that lists all related papers.
Recently, Ulf Assarsson is working on shadow. He has proposed a lot of algorithms and methods to create real-time shadow (Assarsson and Akenine-Moller, 2004).

MATERIALS AND METHODS
To create volume shadow some techniques like silhouette detection, stencil buffer and Z-pass algorithm are needed. Before to spend on shadow it is needed to introduce require methods.

Fig. 1: Triangular mesh
Silhouettes detection: Silhouette is the outline of occluder that is only part of occluder, which contributes in creating shadow. There are some different methods to recognize the silhouette of the occluder. To create real-time shadow using stencil buffer, silhouette detection is needed (Andrea et al., 2010).

Triangular Algorithm:
In triangular algorithm, each face is divided into some triangles and makes a triangular mesh (Fig. 1). It means that each edge should shared by just two triangles. To determine which edge is silhouette, it is need to know each aged is shared between faces toward the light source and faces away to the light source. One of the ways to this is CPU cycle hungry. Figure 1 illustrates how to divide one side of a box, which is consisting of four triangles. To determine silhouette we need just outline of the box. Now we are going to introduce a formula to find a silhouette: Silhouette detection is one of the two most expensive operations in implementation of stencil volume shadow. The other is volume shadow rendering passes to update the stencil buffer.
Stencil Buffer: Stencil buffer is a part of memory in 3-D accelerator that can control the rendering of each pixel. In other word the stencil buffer is a number bits in the frame buffer that use for enable and disable drawing of each pixel of object in rendering and also it can be use to mask color buffer. There is a close relationship between stencil buffer and Z-buffer. Because both buffers are, neighborhood and they are located in the graphics hardware memory. Z-buffer needs to control a selected pixel of stencil value that is increased or decreased when we want to count the time of entering and leaving in the shadow volume. Fortunately, the Z-buffer test is after the stencil buffer tests. To get the main idea of Z-pass algorithm e Fig. 4 is provided. The stencil buffer will increase when eye's ray enter the shadow volume by passing from front face of shadow volume and it will decrease when ray leave the shadow volume by passing of back face of that. This has two phases: Nowadays, Opengl and DiretX support stencil buffer, so we used depth buffer and stencil buffer together. One of the uses of stencil buffer is to limitation of area.

Volume shadow using stencil buffer and VNV algorithm:
After produce the volume, if each object or part of object that is inside of truncated pyramid is in shadow and it should be dark but each object or part of object that is out of truncated pyramid is in lit and it should not be dark. Now we are going to generate volume shadow using stencil buffer and depth buffer together with VNV algorithm. First, in simple word we can say the algorithm in brief: • Render the whole scene without lighting with this the color buffer will be full for all pints of object in shadow and also Z-buffer will be full with depth value • After disable Z-buffer and Color buffer to write, render whole scene with lighting should be done • Subtract of this two depth value provides shadow volume After generate volume shadow, the ray from eye to the each point of object on the shadow receiver is passed. If the ray passes the front face of volume shadow, the stencil buffer will be increased and when the ray passes the back face of shadow volume, the stencil buffer will be decreased. Finally, if the number of stencil buffer is not zero it is in shadow.
We are going to say this as an algorithm or pseudo code in Opengl: 1-Provide the equipment to have stencil buffer 2-Render the all scene without lighting 3-Enable stencil buffer 4 -Disable depth buffer to write and prevent to write in color buffer. 5-VNV algorithm for silhouette detection 6-For Each Plane(P) If DotProduct(P,R)>0 For Each Pixel If (Z-test passes) Increase StencilBuffer 7-For Each Plane (P) If DotProduct(P,R)<0 For Each Pixel If (Z-test passes) Decrease StencilBuffer 8-Render the all scene again with lighting 9-Enable to write in color buffer 10-If (the stencil buffer mod 2=0) The pixel is out of shadow Z-pass algorithm is used when eyes are out of shadow. If eyes are located in shadow Z-fail algorithm is used.
Z-pass algorithm is used when eyes are out of shadow. If eyes are in shadow, we should use Z-fail algorithm that is introduced in following: As a matter of face whole the algorithm is like Zpass algorithm except the step 6 and 7: 6-For Each Plane(P) If

RESULTS
In each algorithm, FPS is the most important factor to implement. The triangular method and VNV methods are used to recognize silhouette. It is amazing that the VNV method has higher FPS than the triangular method (Yusmawati and Yunus, 2007).
According to Fig. 5 and 6 both algorithms are convenient to implement hard shadow in virtual environment. They can be possible to use for commercial games.
Different between FPS when project is rendered without shadow and when is rendered with volume shadow using Triangular algorithm for silhouette detection is not so much. In additional, in this case FPS is acceptable.  The FPS indicates, volume shadow using VNV algorithm for silhouette detection is better than Triangular detection.

DISCUSSION
To have shadow on arbitrary object such as torus or sphere stencil buffer and Z-pass algorithm are used. In following Table 1 the FPS for using triangular algorithm and VNV algorithm are compared.
The result indicates VNV algorithm is very close to the rendering without shadow. It means, it can be use in current commercial games. In addition, the following Table 1 illustrates the proposed algorithm for silhouette detection is appropriate for using in real-time shadow in virtual environment.

CONCLUSION
In this study, we have present two method to create real-time shadow. Volume shadow that was difficult to understand and implement we improve it and make it simple to implement. We have proposed the one of simplest ways to implement volume shadow using stencil buffer and depth buffer. Introduce al. To have a real-time shadow on arbitrary objects, volume shadow is convenient method. Volume shadow is geometry computation and it requires supporting of CPU. Z-pass method is an appropriate tool to check if an object or part of object is located inside the volume shadow or is located in lit.
To increase the FPS a new method to recognize silhouette is proposed. To create volume shadow, triangular algorithm and VNV algorithm are used.
To make easy of the volume shadow, a pseudo code with VNV algorithm to detect the silhouette and two flowcharts are introduced. In comparison, triangular algorithm has low FPS than the VNV algorithm. To create real-time shadow on arbitrary object volume shadow using stencil buffer and VNV algorithm is convenient. The VNV algorithm is suitable for commercial games.