Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Gamasutra: The Art & Business of Making Gamesspacer
Refractive Texture Mapping, Part One
View All     RSS
February 28, 2020
arrowPress Releases
February 28, 2020
Games Press
View All     RSS







If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Refractive Texture Mapping, Part One


November 10, 2000 Article Start Previous Page 3 of 4 Next
 

Ripple Equation

To generate ripples on the mesh, a similar equation is derived from the sine wave equation combined with the circle equation. By looking at the Figure 6, the circle equation can be written as:


Figure 6. Circle on XZ plane.

If the sine wave equation is applied to the radius, ripples are created; therefore the final ripple equation can be written as:

 

y(r) = a * sin(kr - p) (Equation 5)

where
x = X-axis value
y = Y-axis value
a = wave amplitude
k = wave number (frequency)
p = phase shift
r = radius, or

Perturbations Combined

If each perturbation function (ripple or directional wave) is written as wk(x, z), the final mesh perturbation is the sum of all functions such as:


(Equation 6)

 

n = number of perturbations.
y = Y-axis value
p(x,z) = final perturbation function

Implementing of all these equations (4, 5, and 6) together is straightforward. The program just loops though all vertices of the mesh applying equation 4 or 5 (depending on the type of perturbation) to the X and Z mesh values. Then it sums the Y coordinate results of each perturbation and stores the final result back on the mesh vertex data. It is important to note that as the original mesh was created as flat rectangular mesh divided into slices, the finer the mesh (that is, the more polygons), the more accurate the waves are. However, more calculations are necessary. The pseudocode in listing 2 shows how these sums of perturbations can be implemented, as well as the perturbation data structure used in the sample program.

Listing 2. Sums of wave functions applied to the mesh

//pertubation data structure example
typedef struct _water_perturbation
{

long

//ripple info
float
float

//wave info
float
float

//general info
float
float
float


//time counter
float

type;


center_x;
center_z;


vector_x;
vector_z;


amplitude;
frequency;
wave_speed;



current_time;
//ripple or plain sine wave


//directional vector components


}WATER_PERTURBATION;

VERTEX_TEXTURE_LIGHT
WATER_PERTURBATION
float
long
long
float
float
float

*vertex_list;
*current_perturbation;
final_y;
t0;
t1;
x_tmp;
z_tmp;
radius;


vertex_list= (VERTEX_TEXTURE_LIGHT *)water->mesh_info.vertex_list;

for (t0=0; t0mesh_info.vertex_list_count; t0++)
{

//initial mesh y value
final_y = water->initial_parameters.y0;

for (t1=0; t1perturbation_count; t1++)
{

//perturbation list is an array inside the water data structure
//holding amplitude, frequency, current time ripples center values, etc.
current_perturbation = &water->perturbation_list[t1];

if (water->perturbation_list[t1].type == WATER_PERTURBATION_TYPE_RIPPLE)
{

//calculate ripple
x_tmp= vertex_list[t0].x-current_perturbation->center_x;
z_tmp= vertex_list[t0].z-current_perturbation->center_z;

radius= (float)sqrt ((double)(x_tmp*x_tmp+z_tmp*z_tmp));

//deform point
final_y+=current_perturbation->amplitude*

(float)sin((double)(current_perturbation->frequency* radius-current_perturbation->current_time));
}
else
{
//wave calculations
x_tmp= vertex_list[t0].x*current_perturbation->vector_x;
z_tmp= vertex_list[t0].z*current_perturbation->vector_z;

//deform point
final_y+=current_perturbation->amplitude*

(float)sin ((double)(current_perturbation->frequency*
(x_tmp+z_tmp)-current_perturbation->current_time));
}
}

//set vertex
vertex_list[t0].y = final_y;

}// end vertex deformation

 


Article Start Previous Page 3 of 4 Next

Related Jobs

Purdue University
Purdue University — West Lafayette, Indiana, United States
[02.28.20]

Assistant Professor in Game Development and Design
Heart Machine
Heart Machine — Culver City, California, United States
[02.28.20]

Gameplay Engineer
Vicarious Visions / Activision
Vicarious Visions / Activision — Albany, New York, United States
[02.28.20]

Senior Software Engineer
Sucker Punch Productions
Sucker Punch Productions — Bellevue, Washington, United States
[02.28.20]

Gameplay Programmer





Loading Comments

loader image