Artificial Fish

Reference: X. Tu and D. Terzopoulos, "Artificial Fishes: Physics, Locomotion, Perception, Behavior", Computer Graphics, SIGGRAPH 94 Conference Proceedings, pp. 43-50, July, 1994

1 Introduction

Consider a realistic virtual world of fish. There would be underwater currents, moving plants, unmoving rocks and coral reef that the fish must swim around. There would be food (prey) and predators. Some fish would only be prey, others only predators, some both, and perhaps some none.

When a predator appears, the fish might initially group together for protection, but when the predator gets close, they might scatter. The predator might then choose a victim and chase it. At mating time, the fish might have courtship rituals. This complex behavior is difficult to realistically animate with keyframing techniques.

This paper tries to create realistic fish, fish that not only look realistic, but also move in a realistic fashion, and even behave realistically. This requires the animators to model the form and appearance of the fish, the physics of their movement, their perception of the external world, and their response to these perceptions. Results of this effort are shown in the computer animation "Go Fish", part of the SIGGRAPH 93 electronic theater. Here is a description of the following images from the paper:

"The color plates show stills from our 1994 animation "The Undersea World of Jack Cousto." The detailed motions of the artificial fishes emulate the complexity and unpredictability of movement of their natural counterparts, and this enhances the visual beauty of the animations. "

"Plate1a shows a variety of animated artificial fishes. The reddish fish are engaged in a mating ritual, the greenish fish is a predator hunting for small prey, the remaining fishes are feeding on plankton (white dots). Dynamic seaweeds grow from the ocean bed and sway in the current."

"In Plate 1b, the large male in the foreground is courtship dancing with the female (top). The prey fish in the background are engaging in schooling behavior, a common subterfuge for avoiding predators."

"Plate 1c shows a shark stalking the school."

Here is an animation that was shown at the SIGGRAPH 97 course on Artificial Life. (Quicktime - 14 mbytes)

1.1 Background

This work is an example of physically based modeling that has been extended. The fish model is an extension of the snake and worm dynamics model created by [MILLER88]. The fish model is a spring-mass system with internal contractile muscles. This system uses a more sophisticated implicit Euler simulation. This is needed because the dynamic range of forces created in the simulated aquatic environment is larger than for the snake and worm models. The aquatic plants are also modeled as spring-mass systems. The authors have created a motor-control system to simulate the complex motion of swimming fish.

This is also an example of behavioral simulation, an extension of the work on flocking by [Reynolds87]. The authors achieve the complex behavior in stages: first the primitive reflexive behaviors such as obstacle avoidance, and then more complex ones. The behavior is closely linked to perception. In previous work, authors had simulated a virtual roach that retreated when it perceived a virtual hand. The fish have simulated visual perception and other perceptions, e.g., water temperature.

The combination of perception, behavior, and motor systems create fish that are autonomous and do not need to be keyframed. This is analogous to some work in robotics. As the level of sophistication of the simulation increases, unprogrammed emergent behaviors may be created.

1.2 Overview

Figure 1 shows an overview of the virtual fish. The models used are compromises between realism and computational efficiency. Note that as machines become faster, the models can be moved closer to reality. The motor controllers (MCs) are parameterized procedures with each one assigned to a specific task, e.g., "swim forward", "turn left", etc.

2 Physics-Based Fish Model and Locomotion

Most fish use the caudal fin, powered by the posterior (rear) muscles, to move forward and anterior (front) muscles to turn. To simulate fish motion the authors created a model with 23 point masses and 91 springs. This system allows the fish to flex while it also maintains its structural stability. Twelve of the springs are used as muscles (Figure 3).

2.1 Mechanics

For node i: mass = mi,

position = Xi(t) = [xi(t), yi(t), zi(t)],

velocity = vi(t) = dXi(t)/dt

acceleration = ai(t) = dvi(t)/dt

Spring Sij connects node i to node j. It has a spring force constant cij and equilibrium length lij. The spring deformation is given by eij(t) = | Xj(t) - Xi(t)| - lij. Then the force Sij exerts on node i is fij.

2.2 Swimming Using Muscles and Hydrodynamics

The virtual fish swims by contracting its muscles, i.e., by decreasing the rest length lij. The authors assign a minimum length to a muscle spring and express the contraction factor as a number between 0.0 and 1.0. By contracting the muscles on one side and letting those on the other side relax, the fish tail will swing back and forth, thus propelling the fish forward (Figure 4).

Figure 4: Hydrodynamic locomotion. With tail swinging towards positive X axis, reaction force Fiw at point ni acts along the inward normal. Component Fixw resists the lateral movement, while Fiyw is forward thrust. Aggregate thrust propels fish towards positive Y axis. to control locomotion.

2.3 Motor Controllers

The fish has three motor controllers: Swim-MC (straight ahead), Left-turn-MC, and right turn MC. The MC's prescribe muscle contractions to the appropriate springs.

According to fish research, the swimming speed of a fish is proportional to the amplitude and frequency of the tail oscillations. The authors tests agree with these observations; both swimming speed and turn angles are proportional to the contraction amplitudes and frequencies of the muscle springs.

The Swim-MC converts a swim speed parameter into contraction amplitude and frequency values for the swimming springs. By testing, the set of parameters which produce maximum speed has been determined. So speed settings are given as a fraction (between 0.0 and 1.0) of these values.

A turn is accomplished by quickly contracting the springs on one side of the fish and relaxing those on the other side. Then the contracted springs are slowly restored to their resting state. Experimentation found four sets of parameters that produce turns of 30, 45, 60, and 90 degrees. Interpolation of these parameters can produce any turn up to 90 degrees, greater angle turns are produced by adding turns together.

2.4 Pitching (up and down motion) and Yawing (side to side motion)

The pectoral fins are used to control pitching and yawing. They can be held close to the body, reducing drag, for rapid swimming or extended, increasing drag, to slow down the fish. Reef fish may use these for very delicate motions, even backwards swimming.

The pectoral fins are not modeled in great physical detail but act by applying vector forces to the nodes in the fish midsection (1 <= i <= 12). These fins are similar to airplane wings and control comes from changing their orientations relative to the body.

Figure 5: Pectoral Fins

The fin force is Ff = -A(N*V)N, where A is the fin area, V is the fish velocity, and N is the normal to the fin surface. By varying the angles the fins apply different forces to the nodes. If the leading edges are raised then a lifting or upwards force is generated. If then fins are depressed then a downwards force is generated. If the fin angles are different then the fish yaws and rolls. The fins can also be used for braking, which is useful in maintaining a schooling pattern.

3 Sensory Perception

There are two sensors, a temperature sensor at the center of the body and a visual sensor. The visual sensor has access to the geometries, materials, and illumination, that is in the graphics pipeline for rendering. The vision can also interrogate the object database to identify nearby objects, and can interrogate the physical simulation to obtain information such as the velocity of objects.

The fish vision covers a 300 degree spherical angle that extends out to a radius defined by the waters translucence. An object is "seen" if any part of it is in this view volume and not occluded by another object.

Figure 10: Artificial fish vision sensor. (a) Visual perception is limited to 300 degree solid angle.
Figure 10: Artificial fish vision sensor. (b) Occlusion and distance limits the perception of objects (only the fish towards the left is visible).

A more realistic simulation would be to use computer vision algorithms to extract information from the scene rendered from the viewpoint of the fish.

4. Behavioral Modeling and Simulation

At each time step (animation frame) the intention generator issues an intention based on the fish's habits, mental state, and incoming sensory information. It then chooses and executes a behavior routine that runs the appropriate motor controllers.

4.1 Habits

The animator can choose the innate character of a fish by choosing the set of preferences, i.e., whether it is male or female, likes brightness or darkness, cold, warmth, schooling, etc.

4.2 Mental State

There are three mental state variables: H (hunger), L (libido), and F (fear). The range of each is between 0.0 and 1.0. The higher values correspond to a stronger urge to eat, mate, and avoid danger. The variables are computed as follows:

where t = time

5 Intention Generator

Figure 5 illustrates the intention generator.

The first check is to see if there is immediate danger of a collision. If an object comes into the collision sensitivity region (a bounding volume around the fish) then the intention I is to avoid a collision. A "timid" fish would have a large sensitivity region whereas a "brave" fish would have a small region.

If there is no collision danger then the neighborhood is searched for predators.. The fear state variable, F, and the most dangerous predator M for which Fm >= Fi, is computed. If the total fear F > fo ( a threshold value 0.1 <= fo <= 0.5) then evasive action must be taken. If the most dangerous predator is not too dangerous (Fm < f1 with f1 > f0) and the fish schools then the school intention is generated, else the escape intention is generated.

If fear is below the threshold then hunger and libido variables are computed. If the larger of the two is greater than some threshold r, (0.0 < r < 0.5) then either the eat or mate intentions are generated.

If there is no action from the above tests then the ambient light and temperature are determined from the perception system. If the fish is content with these values then the intention to wander is generated, else to leave is generated.

After an intention is generated then the fish invokes the perceptual focus mechanism. This focuses on just the external information needed to carry out the generated intention. For example, if the intention is escape, then the positions of obstacles and the most dangerous predator are located and these determine the motion. For example, if the predator is to the left, the constraint don't turn left is generated.

Real fish have a persistence of action. To simulate persistence in action, a single item short term memory is used. For example, if the fish has the intention of eat, and a collision danger is generated, then the current intention is stored and retrieved after the obstacle has been avoided.

The focuser can be parameterized by threshold values to vary the fish character. For example, assume the intention is to eat, and the current target prey distance is lc and the distance to another prey is ln (example a new fish swims into view). Then if lc - ln > threshold the fish will go after the new prey. By varying the threshold from 0.0 to a large number, the predator fish can be very persistent or easily distracted.

5.1 Behavior Routines

After an intention is generated it passes control, and the data from the perception focuser, to a behavior routine. The fish has eight behavior routines: avoiding-static-obstacle, avoiding-fish, eating-food, mating, leaving, wandering-about, escaping, and schooling. The behavior routines then choose the appropriate MC and pass it the right parameters. Look at each of these routines.

avoiding-static-obstacle, avoiding-fish: These operate similarly. Given the relative obstacle position an appropriate MC, e.g. turn-left, is chosen, and the control parameters are computed, subject to other constraints. The avoiding-fish routine treats the other fish as a bounding box moving in a certain direction. Adjusting the size of the bounding box can usually avoid collisions.

eating-food: tests the distance, d, of the food from the fish's mouth. If d >= threshold then a subroutine chasing-target, is invoked. When d < threshold then the subroutine suck-in is invoked. This simulates a vacuum force that is exerted on the target and other nearby objects. This force is added to the other external forces on the nodes. This is how many fish actually eat.

mating: invokes four subroutines

wandering-about: This routine invokes the swim-MC and sends random angles to the turn-MCs.

leaving: This is similar to wandering-about except that the fish moves without turning.

escaping: The fish choose the best MC depending upon the relative position and orientation of the predator

6 Artificial Fish Types

There are currently three types: predators, prey, and pacifists.

6.1 Predators

Predators do not prey on other predators so they do no predator detection. Also they do not school, escape, or mate (F = L = 0). All they do is avoid collisions and, if hungry, go after prey. A predator chases prey, k, if the cost Ck = dk(1 + B1Sk + B2Ek/pi) is less than some threshold. dk = distance between the mouth of the predator and the center of the prey's body. Sk = 1 if the prey is in a school, else Sk = 0. Ek is the required turning angle. Current values of the parameters are B1 = 0.5 and B2 = 0.2.

6.2 Prey

Prey fish do not mate. Their main activities are eating and forming schools. The school routine uses rules similar to the Reynolds paper as shown by the set of rules below (collision avoidance is already handled so these look for velocity matching and flock-centering):

test: >= 2 neighbors within one body length to the front ?

if the answer = no then find the closest schoolmate in front and speed up towards it
else, if the answer = yes then
test: >= 2 neighbors within one body length to the sides?

if the answer = no then find the closest schoolmate to the sides and turn to it
else, if the answer = yes then
test: swim in generally same direction as the neighbors?

if the answer = no then match velocity with neighbors
else, if the answer = yes then just swim along.

6.3 Pacifists

In pacifists, escape and school are deactivated and mate is activated. There is a diversity of fish mating habits but there are three main behaviors:

Nuzzling - the male approaches the female from underneath and nudges her abdomen until she is ready to spawn

Spawning ascent - the female swims rapidly towards the surface pursued by the male and releases gametes at the peak of the ascent.

Courtship dancing - there are two common types:

Looping - the male swims up and down in a loop above and in front of the female

Circling - the male and female circle, as if chasing each other's tail

The author's implemented a mating behavior that does the following sequence of behaviors: looping, circling, spawning ascent, and nuzzling. The male selects a female on the following criteria: a female of the same species is more attractive than a female of a different species (from biology this would have to be so) and closer females are more attractive than ones further away.

Once fish i has selected mate j, it sends a signal to j. There are then three possibilities:

j's intention is not to mate - then i approaches j and follows it around using chasing-target with the center of j's body as the target

j's intention is to mate, but not with i - if i is a male then it performs a looping behavior in front of j. If j is impressed then the courtship sequence continues, else i discontinues looping and looks for another partner. If i is female then it just looks for another partner.

If j intends to mate with i then the courtship sequence begins.

The courtship sequence is as follows:

Looping - the female hovers and bobs her head (by motor control of the pectoral fins) while the male invokes chasing-target at a point in front of the females head (which bobs up and down). The male counts the number of times his mouth reaches the vicinity of the moving point and when a threshold is reached begins the next stage.

Circling - both fish invoke chasing-target on each other's tail.

the spawning ascending routine begins after the female has done a fixed number of turns. The male invokes chasing-target to follow the female.

The female stops and the male does the nuzzling routine for a set number of steps.

After the looping routine the female may be attracted to a larger male fish than the original. At the nuzzling stage, if the male comes in at a wrong angle, the avoiding-fish routine may be invoked, so it turns away and tries again. Also, to allow the fish to approach closely, the sensitivity region is set very small.

7 Conclusion and Computation Costs

They were able to produce 4 wireframe frames per second with 10 fish, 15 food particles and 5 static obstacles on an SGI Indigo2 (with the R4400 cpu - probably 100 mhz).

Artificial Life in Computer Graphics
HyperGraph Home page.

Last changed February 16, 1999, G. Scott Owen,