First Simulation Using Sphere Mapping
Contents |
|
If sphere mapping is applied to a perturbed polygonal mesh, a very interesting effect can be achieved (Figures 7 and 8 show the results, Figure 9 shows the textures used). The implementation is a combination of the two techniques explained before, plus the vertex normal calculations, because the mesh deforms each frame. Finally, when the perturbation values are tuned (amplitude, frequency, velocity, and so on), it's important to use small amplitudes for the waves. In tall waves the textures stretch too much, creating undesirable effects. The code for the render function is shown in Listing 3.
Listing 3. Render function using sphere mapping
result water_render (WATER *water)
{
resulterror_code;//check param
if (!water)
{return (WATER_ERROR_PARAM_IS_NULL);}//apply perturbations
water_compute_perturbations (water);//compute vertex normals
water_compute_normals (water);//mapping technique (sphere mapping)
water_compute_reflection (water);//this sends all the polygons to the hardware to be transformed and rendered
error_code = polyd3d_render (&water->mesh_info);
if (error_code < 0)
{return (WATER_ERROR_CANNOT_RENDER);}return (WATER_OK);
}
![]() ![]() |
Figures 7 and
8. Sphere mapping and perturbations. |
![]() |
Figure 9.
Textures used in |
Next time, in part two of this article, I will dive into refractive texture mapping for simulating water refraction. I'll also provide a second simulation as well as some optimizations and the sample application.
References
Möller, Tomas, and Eric Haines.
Real-Time Rendering. A.K. Peteres, 1999. pp 131-133.
Direct X 7 SDK Help (Microsoft Corp.)
Serway, R. Physics for Scientists and Engineers with Modern Phyisics, 4th ed. HBJ, 1996. pp. 1023-1036.
Ts'o, Pauline, and Brian Barsky. "Modeling and Rendering Waves: Wave-Tracing Using Beta-Splines and Reflective and Refractive Texture Mapping." SIGGRAPH 1987. pp. 191-214.
Watt, Alan, and Fabio Policarpo. The Computer Image. Addison-Wesley, 1997. pp. 447-448.
Watt, Alan, and Mark Watt. Advanced Animation and Rendering Techniques: Theory and Practice. Addison-Wesley, 1992. pp. 189-190
Harris, John W., and Horst Stocker. Handbook of Mathematics and Computational Science. Springer Verlag, 1998.
PlayStation Technical Reference Release 2.2, August 1998 (Sony Computer Entertainment)
Elias, Hugo. http://freespace.virgin.net/hugo.elias/graphics/x_water.htm
Lander, Jeff. "A Clean Start: Washing Away the New Millennium." Game Developer (December 1999) pp. 23-28.
Haberman, Richard. Elementary Applied Partial Differential Equations, 3rd ed. Prentice Hall, 1997. pp. 130-150.
Graff, Karl F. Wave Motion In Elastic Solids. Dover Publications, 1991. pp. 213-272.
Discuss this article in Gamasutra's discussion forums