Ocean modifier color and foam I'd like to know how to do two things with materials related to the Ocean Modifier:

1) Change the color depending on the depth of the water, and

2) Create some believable foam.

Both of these features should change as the ocean modifier plays back.

The attached image shows what I mean pretty well, methinks—you can see how the water changes to a darker blue where the water is a bit deeper, a lighter blue where it's shallower, and blends to a white where the foam should be. I also believe that this image was made with Blender's ocean modifier [EDIT apparently it's not, but the point still remains]. I'd like this to be possible regardless of lighting conditions.

Does anybody know how to create these effects with materials that use the ocean modifier?
Final.



I've exaggerated a bit difference between deep and shallow water to present it better.

Node setup and overview.

Water.

Most important thing here is to separate generated texture coordinates on Z axis and assigned to it Color Ramp with our colors of choice representing deep and shallow water. You can add here more colors, not only two of them and/or change interpolation between color stops - I've used default (Linear).

Foam.  

First of all you will need to choose Foam Data Layer Name. I used... 'foam' and use it in Attribute node. I've also added a Math node with Power to fine tune mix between water and foam shader.

Mix.

You can now mix shaders by 'foam' factor and use any other shader for materials. I've used simple Glossy for water and Diffuse for foam.

Nodes and Ocean setup.