Uploaded by khyar on Apr 1, 2010
Here is an output from my newly written code to model small amplitude waves in a tank. In fact the focus here ended up being more on the optical realism. The waves are modelled using the linear wave equation (inertialess, small amplitude disturbances that simply propagate and diffuse), and a damping term is added as well:
d^2z / dt^2 = c^2 * (d^2z / dx^2 + d^2z / dy^2) - mu * dz/dt
This was solved on each pixel using an explicit 2nd order space and time finite difference scheme. The time step was set at the largest value that still guarantees stability (using the equations in Lengyel 2002 - Mathematics for 3D Game Programming and Computer Graphics). This takes a few lines of code and is the easy part..... next the optics!
Refraction:
Snell's law. Fire a ray from the camera (which has direction vector looking straight down, perspective has NOT been modelled here) and compute the transmission vector (using Snell's law in vector form, having specified the refractive indices). This requires the surface normal vectors which are computed using the standard result n = Grad(F) / Mag(F), where F is the implicit function representing the surface (z - f(x,y) = 0). In practice this was done using central differencing. Find the point on the bottom plane where the transmission vector intersects it, then carry out bilinear interpolation on the nearby pixel colour values to get the representative colour at that point (the ray never lands EXACTLY on a pixel, and nearest-neighbour interpolation looks crap). This colour vector is then assigned to the particular pixel directly beneath the camera. This is carried out for all pixels (scanline approach).
Gloss map - specular reflection:
For each pixel, calculate the reflection vector that comes off the light source hitting the surface. Here I modelled a directional light (like the sun), so it is represented by just one 3D unit vector. Now, when this reflection vector happens to go in the direction of the camera, the surface should appear 'shiny'. The degree of shininess is controlled by a falloff exponent (all relevant details are in Lengyel's book).
Caustics:
I found this to be the really beautiful effect, definitely the most important in terms of realism. Caustics are the bright and dark bands that snake around on the bottom of the tank and are caused by the surface curvature focussing / spreading out the light onto certain points on the tank floor. To get this looking good for small perturbations, a single pixel step is sufficient, although the graininess can be reduced by supersampling. Here I did 1 sample per pixel to keep the computation fast enough to be realtime (on a small image anyway!). So for each pixel, compute the transmission vector from the light source intersecting the surface at that point. Where this transmission vector intersects the floor, add a certain irradiance value to the nearest four pixels (this time by carrying out an inverse bilinear interpolation). The correct irradiance value is obtained using the Fresnel factors. These factors come from consideration of the boundary conditions of the Maxwell EM equations when an oscillating electric field (optical field) intersects a dielectric (non-conducting, i.e. transparent) surface. They show how the field amplitude is modulated as a function of the angle of incidence. From these, the irradiance coefficients easily follow (again this can be derived by looking at the Poynting vector for a dielectric medium). Here I used un-polarised (or natural) light. The same irradiance equations were also used earlier on when computing the specular highlights and are also used to modulate the brightness of the refracted pixel colour values.
So, step by step:
1. compute the surface amplitude from the wave equation, and compute the surface normal vector for each pixel
2. compute the caustics for each pixel
3. compute the gloss map and refracted pixel colour values
4. put all these colour maps together using an ambient + specular lighting model, with the caustics being included as part of the refracted background image (so even the caustics are distorted by the surface!)
5. a bit of artistic license to get the contrast and colour balance looking realistic....
The disturbances can be any shape, but best results are obtained by using a Gaussian perturbation that smoothly drops back to zero (rather than a simple step that results in nasty ringing)
The background is a Julia set fractal produced from my own fractal generator code.
All coded from scratch using Visual Basic.NET, using no external libraries or code snippets.
Category:
Tags:
License:
Standard YouTube License
-
7 likes, 0 dislikes
18 videos

Simulations & Non-linear Systems
7:04
Cellular Automata 1by khyar434 views
0:30
Ray Tracing Demoby ASpaceOdyssey2001988 views
3:54
A Multiscale Approach to Mesh-based Surface Tension Flowsby nthuerey13,222 views
2:20
Mass Spring Damper Cloth Simulation 1by khyar2,174 views
2:37
Intel Xeon 7500 ("Nehalem EX") Processor Ray Tracing Performance with Luxion Keyshotby channelintel98,200 views
1:01
Animation/Simulation of Waterby nupul2,506 views
0:30
Realtime raytracing - First stepsby Bearishsun865 views
4:04
Waves travelling against water flow.by JohnTheTechy650 views
3:15
WSM = Wave Structure of Matterby artynz48,819 views
1:39
Illegal hypnosis (this is REALLY creepy watch it)by mirandy73872,235 views
0:43
Pixel Bender: Raytracerby macduyhai2,081 views
0:27
Interference of waves on the surface of water HDby physicsanimations57,753 views
0:55
X10 Distributed Realtime Raytracer (GPU water simulation)by sparkprimeprime353 views
0:57
Waves on the surface of water HDby physicsanimations27,038 views
1:01
3D Water Motion Simulatorby ForgeFX23,501 views
1:44
PS3 Real-time Ray-tracingby barryminor2752,805 views
0:40
Cloth simulation 7 - tearing with freeze-framesby khyar133 views
3:16
CUDA NVidia - Low Viscosity Flow Simulationsby tomass150033,324 views
0:58
Ray-traced fractal animation (WM competition)by seanbell634 views
3:07
Algebra 2 - How to put a linear equation into standard form with fraction coefficients - Cool Mathby MrBrianMcLogan1,553 views
- Loading more suggestions...
wow very nice good ray tracing and cryengine 2
capatais777 1 year ago
@capatais777 thanks! No Cryengine 2 here though, all coded from scratch ;-) Check the description.
khyar 1 year ago
....and thanks for watching ;-)) Hope you liked it ;-O
khyar 1 year ago
I ran out of room in the description(!) for this last bit of info:
Finally, in this video, the waves were created by moving a Gaussian perturbation along the surface in a way that simulates bug movement. A random number between 0 and 1 is generated. If the number is between 0 and 0.333333 then turn left 45deg, if between 0.333333 and 0.666666 keep last direction, and if between 0.666666 and 1.0 then turn right 45deg. Step forward a certain amount after each decision.
khyar 1 year ago