How to calculate intersection and normal at for a plane with ripples / waves

48 Views Asked by At

I'm fiddling with a ray tracer in C# and have various primitives working. However, I'd like to create water with ripples and I'm not sure how to create such a surface type.

Surfaces implement an abstract class which adds an intersection to a list and calculate the normal at the intersection.

Ideally I'd want a surface that's infinite in two axis (like the plane) but also takes a wave octave array to create waves or ripples.

Here's the current plane implementation:

    public class Plane : Surface
    {
        public override void AddIntersections(Ray ray, ref List<Intersection> intersections)
        {
            if (ray.Direction.Y.Near(0.0f))
                return;

            double distance = -ray.Position.Y / ray.Direction.Y;

            intersections.Add(new Intersection(this, distance));
        }
        public override Vector3 SurfaceNormaAt(Vector3 point, Intersection intersection)
        {
            return Directions.Up;
        }
    }

I've worked with creating waves and combining them, but the mathematical implementation for ray tracing eludes me.

EDIT: The Surface type includes a transformation matrix

0

There are 0 best solutions below