Under the current

Submerged green plants and soft reflections in a dark water scene.

This is an interactive 3D experiment depicting plants in a calm stream. The goal is to showcase water’s beautiful materiality.

I’ve always loved water. The urban stream about 10 minutes from where I live is my favorite place to stroll. There, I often zone out watching the plants swaying beneath the golden glints, with small fish zooming by.

This project is also inspired by the opening scene in Tarkovsky’s Solaris. The scene’s textures, colors and sounds seemed so simple yet set the tone so perfectly for the rest of the film. I’ve kept thinking about the scene ever since I first saw it, and now I finally get to make my own version of it.

As a novice in 3D and physical modeling, I had a lot to overcome. To achieve high levels of physical realism and visual beauty, I built all mechanical and optical rules in this scene from scratch — from modeling the plants’ movements to finding the right parameters for the film effect. Here’s the detailed technical walkthrough of the main challenges I faced.

Making the plants feel alive

What I want

The plants' movement underwater needs both uniformity and variation. Finding the right balance was hard. Too much uniformity made the plants look like copies of one animation. Too much independence made them look as though they are in separate streams. The scene's movement as a whole is determined by how each leaf moves individually. So there were two linked questions. How could I model water that gives the plants a common direction and rhythm, with enough variation? And how could I model leaves to respond to that water?

Using one image

The first build used a transparent image containing three separate plant-cluster designs. Each design depicted several overlapping leaves. The program selected from those designs to place four clusters in the scene, reusing one design. Each placement had its own position, size and angle.

There were no individual leaf objects yet. To animate a cluster, a shader changed where it read colors from the image. For each screen pixel inside the cluster, it calculated a position in the source image. Moving that lookup position over time made the image appear to sway and bend, a little like viewing a photograph through a shifting distortion.

The displacement varied along the image: it was small near the base and stronger toward the ends. Two sine waves, changing at different rates, supplied the sway. Each cluster had a different starting phase, meaning it began at a different point in those oscillations.

The essential operation was:

for each screen pixel covered by a cluster:
    image_position = map_screen_position_into_cluster_image(pixel)
    image_position += changing_offset(image_position, time)
    color = read_image(image_position)

This moved the picture of the plants. It did not give the leaves separate bodies. Two leaves painted across each other remained part of the same picture, so one could not bend away from the other. The cluster moved, but it felt too much like one object.

The first version: whole plant images move as clusters.

Modeling each leaf as on strip

The next version built each leaf as a narrow, flat strip, with a leaf image applied to it for color and detail. The program could now change one leaf's shape without moving the others.

To construct a strip, I defined a line running down its middle—the centerline. At several positions along that line, I placed an edge point on either side. Joining those pairs produced the strip's surface. A curved centerline therefore produced a curved leaf.

Its initial centerline was a hand-chosen curve. The animation added changing offsets to that curve. In shortened pseudocode:

for each sampled position s along a leaf:
    center = resting_curve(s)
    center.y += movement_weight(s) * wave_offset(s, time)
    center.y += extra_tip_offset(s, time)
construct_the_leaf_strip_around_these_centers()

Here, ss measures distance along the leaf as a fraction of its length: zero at the base, one at the tip. wave_offset combined several sine waves. Each depended on both position and time, allowing different parts of a leaf to move by different amounts.

The movement weight increases towards the tip:

w(s)=s1.5+k,w(s)=s^{1.5+k},

kk controls stiffness. Increasing kk reduced movement through most of the body while keeping the weight at the tip equal to one. For example, if the exponent is three, halfway along the leaf the weight is 0.53=0.1250.5^3=0.125: only one eighth of its value at the tip.

That weighting kept the base still, but it also weakened the movement through much of the body. A leaf's tip could move noticeably while the original bend in its middle barely changed.

At this stage, I drew each strip as forty short sections joined together. Those subdivisions made its outline smooth, but every section still followed the offset formula above. A smooth outline could therefore reproduce the same unconvincing movement.

Individual strips give each leaf its own shape and movement.

Changing the leaves with three controls

I next tested a model that changed a leaf's curvature directly. I used a separate page with plain strips, so texture and water reflections would not hide the movement.

Each leaf had three changing numbers: aa controlled a broad bow, bb added an opposing bend through the body, and cc adjusted the end. Together, they determined the direction of each short section along the leaf. I joined those sections end to end to make its centerline.

A simplified version of the direction formula was:

θ(s,t)=θ0+[A0+a(t)]B1(s)+b(t)B2(s)+c(t)s2.\theta(s,t)=\theta_0+[A_0+a(t)]B_1(s)+b(t)B_2(s)+c(t)s^2.

Here, ss runs from base to tip and tt is time. θ\theta is the section's angle from the horizontal. θ0\theta_0 sets the starting direction, and A0A_0 supplies an initial arch. The fixed functions B1B_1 and B2B_2 determine where the first two controls act:

B1(s)=sin⁡(πs)+0.5s3,B2(s)=sin⁡(2πs)−0.65s3.B_1(s)=\sin(\pi s)+0.5s^3, \qquad B_2(s)=\sin(2\pi s)-0.65s^3.

The first sine pattern has one broad rise along the leaf. The second changes sign halfway along, allowing the two halves to turn in opposing directions. Multiplying them by aa and bb changes the amount and direction of those bends. The cs2c s^2 term acts more strongly toward the tip.

The cubic terms keep these patterns from returning to zero at the tip. That lets changes in the body also change the end's direction. The actual implementation also uses cc to shift the bend patterns slightly along the leaf; that position adjustment is omitted from this simplified equation.

The program built the curve from those directions:

point = attachment
for each section from base to tip:
    angle = direction_formula(section_position, time)
    next_point = point + section_length * [cos(angle), sin(angle)]
    add next_point to the centerline
    point = next_point

The pair [cos(angle), sin(angle)] gives a direction of length one. Multiplying it by section_length makes every step the same length. Changing the angles therefore changes the curve without stretching the leaf. I drew the textured strip around this new centerline just as before.

To animate it, I generated a target for each of aa, bb and cc using smooth noise: numbers that change irregularly but gradually. Each control approached its target through a damped update, which both pulled it toward the target and slowed its rate of change. Stronger targets produced deeper bends; a faster response made the leaf follow sooner.

This produced changing body curves and more freedom in the tip's direction. When I arranged the leaves into three overlapping groups in the scene, however, the groups did not move convincingly together.

Giving nearby leaves related movement

The problem was in the target generator. It chose different parts of its noise pattern according to a leaf's group, with additional timing offsets based on leaf length. Two leaves could overlap on screen yet follow unrelated signals. Their visual proximity had no say in how their movements were linked.

I changed the generator to use actual scene positions. For each leaf, I chose the average position of the middle part of its resting centerline. All leaves used the same time. At that position, each bend control received a blend of shared and local variation:

F(x,y,t)=E(t) [0.82Ncommon(t)+0.18Nlocal(x,y,t)].F(x,y,t)=E(t)\,[0.82N_{\mathrm{common}}(t) +0.18N_{\mathrm{local}}(x,y,t)].

xx and yy are scene coordinates. NcommonN_{\mathrm{common}} gives every leaf the same changing number. NlocalN_{\mathrm{local}} varies smoothly across the scene, so nearby leaves receive similar numbers. E(t)E(t) raises and lowers the overall strength slowly. This construction is repeated for all three bend controls, using a different noise pattern for each.

The 82% common part gave the groups a shared push and release. The 18% local part let them differ without separating into unrelated rhythms. Increasing the common share made the targets more alike; increasing the local share gave position more influence. The size of the local noise features also mattered: broad features affected several leaves together, while smaller features created differences over shorter distances.

These signals set bend targets, not water velocities. The program scaled them by the overall Current setting and small per-leaf strength differences, then used the same damped update and curve construction as before.

The groups now moved together more convincingly. Yet each leaf was still controlled by only three numbers. A changing target reshaped the whole curve; it did not describe a local push on the middle of a leaf and the resulting movement of its neighbors.

Letting connected sections respond to water

I gave each leaf a centerline made of 18 points, each with its own position and velocity. Adjacent points were connected by segments that resisted stretching, and adjacent segments resisted changes in their angle. This is a simple flexible rod.

18 simulation points, first two fixed, connecting segments and surrounding strip
The connected-point model. The strip width is enlarged to show its construction.

I had tested connected-point models during the earlier motion study. This time, I used them to preserve the common movement while allowing a push on one section to affect the rest of the leaf.

The important change was what the program stored between updates. In the three-control model, the point positions were calculated from aa, bb and cc. In the rod model, the positions and velocities of the points were the changing state. Their interactions determined the curve.

The water model changed with it. I replaced the bend-target signals with a function u(x,y,t)\mathbf{u}(x,y,t) that returned a horizontal and vertical water velocity at any position and time. Every moving point sampled that same underlying function at its current location. Points at the same location sampled identical velocities, and nearby points sampled related ones.

This was a prescribed current in the two-dimensional plane of the leaves. It did not calculate a volume of fluid or the leaves' effect on the water. The visible water surface was rendered separately. Initially, repeating waves varied the prescribed velocities; I refined that pattern after testing the leaf response.

How the water moves a point

Water resistance, or drag, brings a point's velocity closer to the water velocity around it. For one direction, the code used:

vnext=v+Δt r u1+Δt r.v_{\mathrm{next}}=\frac{v+\Delta t\,r\,u}{1+\Delta t\,r}.

vv is the point's current velocity, uu is the water velocity, Δt\Delta t is the time step, and rr is the response rate. The result is a weighted average of the old point velocity and the water velocity. A larger rr makes the point follow the water sooner; a smaller one retains more of its previous motion.

I applied this update separately along and across the leaf's local direction, with much stronger drag across it. This lets a sideways current bend a leaf more strongly than a current running along its length. After updating velocity, the program moves the point by velocity * dt.

Current now controlled the strength of the water velocity rather than a bend target. The separate Response control scaled drag. Increasing Response made a leaf follow moving water more closely, but also made still water slow it more strongly. Setting u=0u=0 leaves the update as v/(1+Δtr)v/(1+\Delta t r): stopping the current does not remove resistance.

How the points stay connected

Drag alone would let every point drift on its own and the leaf come apart. After the drag step, I corrected their positions using two rules.

First, neighboring points should remain one segment length apart. If they moved too far apart, the solver brought them closer; if too close, it separated them. Lighter points received more of the correction. The first two points were fixed in this version, holding the attachment and the first segment's direction.

Second, a joint should resist bending away from its resting angle. Three points define two segments and the angle between them. The model assigned a bending energy to changes in that angle:

Ebend=B2ℓ(ϕ−ϕ0)2.E_{\mathrm{bend}}=\frac{B}{2\ell}(\phi-\phi_0)^2.

ϕ\phi is the current joint angle, ϕ0\phi_0 is its initial angle, ℓ\ell is the segment length, and BB is bending rigidity. Larger departures have a higher cost. Increasing BB makes a joint harder to bend under the same loading.

The code uses this relationship through compliance, α=ℓ/B\alpha=\ell/B, which describes how much a joint yields. A constraint solver repeatedly adjusts the three points to reduce the angle error while allowing some bend according to that compliance. High compliance permits more bending; low compliance keeps the joint closer to its resting angle. The solver note gives the exact correction formula.

One simulation step is therefore:

save previous positions
for each free point:
    sample the shared water velocity at its position
    update the point's velocity through drag
    move it by velocity * dt
repeat corrections along the leaf:
    bring segment lengths back toward their original lengths
    resist changes in joint angles according to bending rigidity
for each free point:
    velocity = (corrected_position - previous_position) / dt

A correction to one point affects both segments connected to it. Repeating the process lets a local disturbance affect neighboring sections. The last line carries the corrected movement into the next step, so the leaf retains momentum. The simulation uses a fixed step of 1/1201/120 second, independently of the browser's drawing rate.

The leaf now had sections that influenced one another. It still needed the right water pattern and material settings to look convincing.

Balancing shared motion and local differences

The first candidate in this round was too stiff. Stronger repeating water-velocity waves made the bends visible, but many leaves followed the same S-shaped gesture. The movement had gone from disconnected groups to excessive uniformity.

In the Solaris reference clip, straighter spans, changing bows and active tips coexist within the same broad flow. I adjusted both the leaves' material properties and the water pattern to reproduce that mixture.

Different leaves can yield differently

I varied relative thickness along and between leaves. Thickness here was a simulation parameter, separate from the visible strip's width. Some profiles had a flexible base and a stiffer body; others made the tip softer than the middle.

Holding other factors fixed, mass scaled with thickness hh, the base drag rate with 1/h1/h, and bending rigidity with h3h^3. A section made 20% thinner therefore had 80% of the mass, 1.25 times the base drag rate and about half the bending rigidity: 0.83=0.5120.8^3=0.512.

These relationships let similar water movement produce different bends. A stiff span could move mostly as a unit, while a softer section changed curvature more readily. The parameters were tuned for the scene, not measured from real plants.

The same water can vary across space

I also replaced the repeating velocity waves with curl noise, which builds circulating flow from a smooth irregular pattern.

Start with a function ψ(x,y,t)\psi(x,y,t) that returns one number at each location and time. Imagine those numbers as the heights of a landscape. This is only a way to construct the current; it is not the visible water surface. The slopes of that landscape give a velocity through:

ueddy=(∂ψ∂y,−∂ψ∂x).\mathbf{u}_{\mathrm{eddy}} =\left(\frac{\partial\psi}{\partial y}, -\frac{\partial\psi}{\partial x}\right).

The derivatives describe how quickly the number changes vertically and horizontally. Swapping those slopes and reversing one sign turns the direction along the landscape's contours. The pair gives the horizontal and vertical velocity of a local swirling pattern, or eddy.

To move the pattern through the scene, the program evaluates the noise at a shifted position such as x - drift_speed * time. The shift moves the arrangement of eddies; the local slopes and their amplitude determine the water velocity returned at a point. Those are two different speeds.

The final velocity combines two sizes of eddies with a shared directional flow:

water_velocity = downstream_push(time) + sideways_change(time)
water_velocity += large_drifting_eddies(position, time)
water_velocity += smaller_weaker_eddies(position, time)
water_velocity *= current

The directional terms and larger eddies give several leaves related movement. The smaller eddies vary the push along and between them. Every point samples the same combined function; no leaf gets a private random current.

Pattern size controls how broadly a change is shared. Drift speed controls how quickly the pattern passes, and amplitude controls how strong its velocity contribution is. The first noise-based candidate was too quiet. Increasing eddy strength to 2.75 times that candidate restored visible movement while keeping the mean downstream component unchanged.

Together, the varied material response and shared irregular current gave the leaves different bends and timing within a recognizable common movement. It remained more orderly than the reference footage.

Earlier periodic movement (left) and the refined result (right). Both the water-current and leaf-material models changed.

Moving the plants with our cursor

With the shared-current movement working, I added plant brushing on September 22. Surface ripples already responded to the cursor; holding the left mouse button and sweeping over the plants now bent them too.

The leaf model already responded to water velocity. I added the stroke as a local movement of water, letting the existing drag and connections determine how the leaves reacted.

I tracked the cursor's positions over time and mapped them into the scene's coordinates. Each movement created a short trail of disturbances along the path between the previous and new positions. Sampling along that path let a fast stroke affect a narrow leaf even if the cursor crossed it between browser updates.

Each disturbance pushed in the direction of the stroke. Its influence was strongest near its center and faded to zero within a small radius, so nearby sections could move while distant leaves continued with the current. Faster strokes produced stronger pushes. I capped the speed used to calculate the push, and the resulting water speed, to avoid abrupt flinging. I accumulated the push from the distance the cursor traveled, rather than adding a fixed kick for every input event. That kept a mouse reporting more events from automatically producing a stronger effect.

At each leaf point, the added velocity entered the existing model as:

utotal=ucurrent+ucursor.\mathbf{u}_{\mathrm{total}} =\mathbf{u}_{\mathrm{current}}+\mathbf{u}_{\mathrm{cursor}}.

The two terms are the background water velocity and the local velocity produced by recent cursor movement, both sampled at that point. I used their sum in the drag update described earlier. The leaf's bending resistance, momentum and connections then shaped the response. Push strength and interaction radius controlled how strongly and how widely a stroke affected the plants.

The disturbances rose briefly and then faded away within one second. Releasing the button stopped new input, but left that short wake and the plants' existing motion intact. Holding the cursor still added nothing. I tested a stroke with the background current turned off to check that it produced a local bend followed by settling.

Realistic water

The surface of had to suggest a close view of relatively calm water, with plants moving underneath. The first versions had movement and reflections, but the materiality feels wrong.

From moving texture to surface direction

The first renderer read a texture containing surface slopes—numbers describing how much a small patch tilts horizontally and vertically. It sampled that texture at two moving scales and combined the results. Changing the lookup positions animated the slopes. Those slopes distorted the underwater image and determined the reflections.

This was inexpensive, but the initial pattern produced dense, fragmented highlights. Moving the texture did not by itself give the bright shapes the scale or evolution I wanted. I moved toward formula-defined waves, where I could adjust spacing, height and travel independently and see which change affected the result.

Fixed stored slopes sampled twice at moving scales, combined into normals
Two moving samples of a stored slope texture combine to determine surface direction.
The early texture-based surface in its original scene.

The later model describes a height at each position and time. It does not need a detailed moving mesh in this fixed view. The shader calculates how quickly height changes along each of the two water-plane axes. Those slopes determine the direction perpendicular to the local surface, called its normal. A flat patch has an upward normal; a sloping patch has a tilted one.

Local slope determines normal; heights combine
A schematic cross-section: changing height produces slopes, which determine surface direction. The renderer evaluates a two-dimensional field.
The later formula-based surface. The plants and appearance also evolved between these two scenes.

A normal determines which direction reflects toward the camera. A bright mark appears when that reflected direction meets the light source. The mark's outline therefore depends on the surface slopes as well as the source's shape.

I represented the bright source as a small angular disk: it occupies a finite patch of directions rather than one infinitely small direction. Increasing its diameter allows a wider range of surface tilts to reflect it. Increasing its brightness strengthens the existing reflection. These changes do different things, so making a glint brighter could not repair its outline.

Building large and small changes in tilt

One travelling wave can be written as:

h(x,t)=Asin⁡(k⋅x−ωt+ϕ).h(\mathbf{x},t)=A\sin(\mathbf{k}\cdot\mathbf{x}-\omega t+\phi).

x=(x,y)\mathbf{x}=(x,y) is position along the water plane, tt is time, and hh is height. AA sets height amplitude, k\mathbf{k} sets direction and spacing, ω\omega controls change over time, and ϕ\phi sets the starting phase. The dot product measures position along the wave's direction. The wavelength is λ=2π/∣k∣\lambda=2\pi/|\mathbf{k}|.

The surface combines a broad, shallow swell with four shorter waves. The broad swell changes the tilt over a large region. The shorter waves break that region into smaller patches whose directions can catch the light.

This gave me a useful way to separate overall shape from detail. Excessive short-wave detail could produce many tiny reflections even when the larger movement looked calm. Changing the broad swell affected where a larger bright passage appeared.

There is an important distinction in how the two scales were tuned. For the broad swell, I compared wavelengths while holding height amplitude fixed. A longer wave then has gentler slopes. For the shorter waves, the implementation stores a slope amplitude SS and derives height:

A=S∣k∣.A=\frac{S}{|\mathbf{k}|}.

This follows because differentiating the sine introduces a factor of ∣k∣|\mathbf{k}|. Increasing wavelength at fixed slope also increases height amplitude. It spreads the tilts farther apart without simply weakening them.

The short waves also have their own phase speeds, calculated using a gravity-and-surface-tension relation. A separate moving coordinate offset carries their pattern with the broad current. A wave's own travel and the transport of its pattern are separate contributions; this is an authored wave field, not a simulation of an entire river.

Making bright passages arrive and fade

Continuously distributed waves could leave activity spread too evenly across the image. I tested a moving region that strengthens waves as it passes, like a gust affecting one patch of water.

The region has a smooth bell shape, strongest near its moving center and weaker farther away. It multiplies the height of both the broad swell and the shorter waves. This changes their slopes too: the renderer accounts for both the amplified wave and the gradual change in strength around the region's edges.

The combined slopes create bright passages that arrive, develop and fade. The gust changes the surface itself, so reflections respond to its changing shape.

Technical note: calculating slopes under a gust

Let w(x,y,t)w(x,y,t) be a wave's height and E(x,y,t)E(x,y,t) the gust's strength. Here xx and yy lie along the water plane and tt is time. Multiplying height by the gust gives:

h=Ew,∇h=E∇w+w∇E.h=Ew,\qquad \nabla h=E\nabla w+w\nabla E.

The symbol ∇\nabla means the pair of slopes along the water-plane axes. The product rule gives two contributions: the original wave's slopes scaled by the gust, and the wave's height multiplied by the gust's own spatial change. Omitting the second contribution would make the calculated surface direction inconsistent with its height.

The implementation accumulates these contributions for each wave. In simplified pseudocode, omitting other amplitude controls:

for each wave:
    height, slope = evaluate_wave(position, time)
    strength, strength_slope = evaluate_moving_gust(position, time)
    total_height += strength * height
    total_slope += strength * slope + height * strength_slope

The accumulated slopes then determine the surface normal used for reflections.

Choosing the reflection shapes

I compared changes in wave direction, spacing and source size. Spreading the wave directions too widely fragmented the highlights; keeping them narrow could produce lines. Enlarging the light source could thicken unwanted hooked shapes. That made it clear that source size alone would not fix the surface pattern.

I then lengthened the broad swell while keeping its height fixed, making its slopes gentler. Lengthening the shorter waves while preserving their slope amplitudes spread the reflective patches farther apart without weakening their tilts. In the shape comparison, the important change is the balance between the highlights and the open water around them: the selected combination leaves more quiet space between distinct reflections, making the surface feel calmer at the scale of the nearby plants.

Earlier directions and selected gentler/longer waves
Comparing wave shapes. The selected version lowers the broad swell and lengthens both broad and short waves, leaving more open water between reflections.

Adding cursor ripples

Cursor movement already created surface disturbances early in the project. In the formula-based surface, each disturbance is stored with a center, start time and strength. Its age determines the radius of an expanding ring. A smooth envelope confines the wave around that ring and reduces its strength over time.

The renderer evaluates each active ripple's height and slopes, then adds them to the background surface. The resulting normal drives both reflection and distortion of the underwater image. A ripple can therefore change a highlight and displace a leaf's apparent edge through the same surface calculation.

The input stores a bounded trail of events; at most 24 remain active, each expiring after three seconds. The plant brushing described in Part 1 uses a separate local water-velocity trail. The two effects share cursor input, but an expanding surface ripple is not the force calculation that bends a leaf.

Later, I reduced the cost of evaluating the surface by storing its slopes in an intermediate image at half the final width and height. The final image still computes its optical appearance at full resolution, using those stored slopes. This evaluates the wave field at one quarter as many pixels while retaining the selected pattern, with small differences in the finest glints. The next part follows those surface directions into what we see beneath and reflected above the water.

Making the plants look submerged

Moving leaves and surface reflections were not enough to establish that the plants were submerged. Some versions left the leaves too bright and distinct, as though there were transparent air above them. I needed the image to communicate the water between the camera and the plants.

That involved three connected effects: water reduces the contrast of what lies beneath it, its surface bends the view, and it reflects the environment above. I built those effects around a mostly flat scene, separating their responsibilities so changes to one would not damage the others.

Separating overlap from depth

Each plant is a textured strip whose centerline supplies its movement. The renderer draws these strips and a background into an intermediate image. A later surface pass reads that image and combines it with reflections to produce the visible water scene.

An earlier version tried to represent more detailed plant depth and resolve overlaps through that system. The added complexity brought shape and overlap problems. I simplified the construction to fixed layers: each complete leaf has a place in the drawing order, so the same leaf consistently covers another where they cross.

I placed each leaf on its own flat layer, with a small, fixed gap between layers. Where two leaves overlap, the renderer shows the one closer to the camera and hides the covered part of the other. Leaves bend within their layers, so their front-to-back order stays unchanged as they move.

Reducing contrast with optical distance

The basic attenuation relation is:

T=exp⁡(−σd).T=\exp(-\sigma d).

dd is optical distance, σ\sigma controls how strongly the water attenuates light, and TT is the fraction remaining. The calculation is performed separately for red, green and blue. Greater distance or attenuation reduces the contribution from the leaf.

A simple baseline used this remaining fraction to mix the lit leaf color with a water color. In pseudocode, applied separately to each color channel:

remaining = exp(-attenuation * optical_distance)
color = lit_leaf_color * remaining + water_color * (1 - remaining)

As the leaf's contribution decreases, the water contribution grows. This reduces contrast rather than merely darkening everything toward black. The calculation uses linear RGB, where multiplying a color corresponds to scaling light intensity, before conversion for display.

I made optical distance decrease smoothly from a larger value at the base to a smaller value toward the tip. The transition follows distance along the complete leaf, including any part outside the viewport. Increasing the transition length keeps more of the leaf in deeper-looking water; after that length, the optical distance stays at its shallow value. A shorter leaf may end before reaching that plateau.

Lighting the water between the leaves

Attenuation reduced the leaves' contrast, but the surrounding water could still look like a uniformly colored background. I compared ways to give the water a restrained light contribution of its own.

The simplest candidate used uniform illuminated water. Strengthening that treatment mostly lifted the green background. The useful change was broad spatial variation shared by the leaves and the gaps between them.

The selected treatment combined two very broad bell-shaped regions: one gently brightens the scene, while the other dims it. They were static functions of scene position, not particles or halos attached to individual leaves. Both the leaf pixels and the background evaluated the same field. The background represents the bottom, with its own material color and fixed optical distance.

The calculation first combines attenuated material light with the water's light contribution, then scales both by the shared illumination field at that position. A brighter region therefore continues across a leaf and into the surrounding gaps. Raising a uniform background cannot establish that same relationship.

I compared a restrained and a stronger version of the field, keeping the geometry and motion fixed. The restrained version made the illuminated water readable while preserving dark regions. This light field was authored separately from the reflected clouds; it did not calculate illumination by tracing light from the cloud image.

Shared spatial light field across leaves and gaps
Restrained and stronger water illumination. Both spatial variation and the water-light contribution change; reflections and film effects are disabled here.

Bending the view through the surface

The underwater image now contains the leaves, their attenuation and the illuminated water. The surface pass determines where to look into that image.

Part 2 described the surface normal: a direction indicating how a small water patch is tilted. Here it controls refraction, the change in a viewing ray's direction when it crosses from air into water. The shader uses the refract operation with an air-to-water refractive-index ratio of approximately 1/1.3331/1.333.

The bent ray supplies an offset from the original image coordinate:

bent_ray = refract(viewing_ray, surface_normal, 1 / 1.333)
lookup_offset = projected_image_offset_at_depth(bent_ray)
underwater_color = sample(underwater_image, pixel_position + lookup_offset)

The second line projects the ray to a chosen representative distance and converts its travel along the water plane into a two-dimensional image-coordinate offset. A more sideways ray produces a larger offset.

Reflecting a sky over the plants

The normal also determines a reflected direction. Instead of drawing clouds as a transparent overlay on the finished scene, I used that direction to look into a sky image positioned above the water as a virtual card. Different surface tilts sample different parts of the card, so the reflected clouds distort with the surface.

The balance between the underwater view and reflection depends partly on viewing angle. Looking straight at a patch gives a small reflection contribution; looking across it at a shallow angle increases that contribution. This relationship, called the Fresnel effect, helps determine how much of the sky sample to blend with the refracted underwater sample. The renderer also applies artistic reflection-strength controls, so the result is not a calibrated measurement of light.

The position of the reflected clouds mattered as much as their detail. Allowing them to cross the plants made the image easier to recognize as water: the viewer could read something reflected above a leaf while still seeing the leaf underneath. Reflections confined to empty areas did less to establish that relationship.

The sky began as static generated imagery. I later replaced the Day and Golden skies with a procedural cloud image that changes over time. They share cloud structure and movement, with different colors; Night retains a separate sky calculated directly from mathematical functions. The cloud image updates independently, and the water samples its latest version as the surface moves.

Actual sky texture and its distorted reflection
The Day sky image and its reflection in the water at the same moment.

Photographic character

Once the plants and water had their own movement and optical behavior, the scene still needed a coherent treatment of light, color and texture. I developed daylight, golden-hour and night versions, then added the softness, highlight spill and grain for a film-y texture.

Keeping bright light available for processing

The rendered scene is stored in a linear high-dynamic-range image. “High dynamic range” here means that color values can exceed the range a display ultimately shows. A bright glint therefore retains information that would be lost if it were clipped to display white immediately.

The current processing order is:

render the lit scene and water into a linear HDR image
apply spatial softness, highlight spill and directional glare
apply exposure-dependent grain
apply display exposure and tone mapping
encode for the display, then apply the creative color adjustment
blend with the untreated display image by the overall effect amount

Tone mapping compresses bright scene values into the display range. The implementation uses an ACES-style curve, then sRGB encoding. Display conversion happens once on each image path; applying it twice would change brightness and contrast unintentionally.

The untreated image uses the same scene exposure, tone mapping and display encoding, but bypasses the photographic effects and creative grade.

After display conversion, I adjust saturation, shadow and highlight contrast, and the warmth of the midtones.

Full treatment's effect on scene and highlight detail
The same scene with and without the photographic treatment, including an enlarged detail. Display exposure and tone mapping remain active in both.

Separating softness from highlight spill

I treated three spatial effects separately because they produce different results.

Softness blends nearby image samples to reduce fine contrast. The blur weights are normalized to sum to one, so a uniform patch retains its brightness. The same softness stage includes a weaker, broader diffusion that spreads light over a larger area without giving it a strong color.

Halation adds warm spill around bright regions. The program first extracts highlights using a gradual threshold: values near the threshold enter smoothly rather than switching abruptly on. It blurs that extracted light at two scales, reduces the contribution from the source's core, and adds a warm surrounding glow. This lets a glint keep its original center color while gaining a colored edge.

Warm spill around glints
The same glints with halation disabled and enabled.

Directional glare produces rays extending from bright sources. It uses a different spatial pattern from the rounded halation glow. Treating all three as one generic brightness effect would make it difficult to adjust texture, warm spill and rays independently.

Directional rays distinct from warm rounded spill
An isolated glare demonstration, with other photographic effects disabled. These stronger settings make the rays visible; they are not the default treatment.

A night-scene correction showed why the extraction stage mattered. The moonlit glints looked bright on screen, but their scene-linear values fell below the original halation threshold. Increasing halation strength could not amplify a source that had already been discarded.

I lowered and broadened the extraction threshold. The shader tests each pixel’s linear brightness multiplied by the scene exposure, gradually admitting highlights across a range of 0.12 to 0.45. That multiplication is only for selecting highlights; the extracted energy stays in scene-linear units, and display exposure still applies later to the composed image. The night glints could now enter the effect, allowing the amount control to tune their visible spill. The debugging sequence was to check which light entered the effect before changing how strongly the effect was applied.

Original extraction omitted glints; lower/broader extraction admits them
Before and after correcting highlight extraction: the moonlit glints can now contribute to halation.

Building grain into the image

Grain is the fine, irregular texture of lighter and darker marks visible in a photograph. To create that texture, I generated a random pattern and used it to brighten some parts of the rendered image slightly and darken others. Each adjustment scales red, green and blue together, preserving their proportions instead of adding colored speckles.

The pattern needs a size as well as a strength. I interpolate between random values spread across a grid, so nearby positions form small patches. Changing the grid spacing changes the grain size; changing the brightness adjustment changes how strongly it shows. For patches smaller than a pixel, the grain shader averages the pattern over the pixel's area, reducing detail that the screen cannot resolve.

I also vary the strength with the image beneath it. Dark areas receive larger percentage changes in brightness than bright areas, with a cap to keep the effect restrained. These changes happen before tone mapping, so the final contrast curve acts on the scene and grain together.

Fine brightness texture without independent colored speckles
The same detail without and with grain. All other settings remain fixed.