Shading time… After a few ‘false starts’ it is time to go through the shading side of the wave system.
Before I get into the shader itself, I thought I’d be a good idea to quickly recap how the UV’s of the wave are integrated into the UV space of the ocean surface. Luckily, I have already posted those details on this here: Another refactoring.
In this post: Shading time!, I went gone into quite some detail in how the wave shader works with the wave zones in a previous version of the system. A few things have changed since then.
Most notably that I completely reworked how the wave zones are defined. In the first version of the zones there was only a single zone attribute that contained all zone information (values from 0 to 4). In the new zone definition there are 5 zone attributes that contain values from 0 to 1. This means that more data is passed along the network, but also that processing the zones is much easier. In addition to this the way the zones are defined in terms of the wave profiles is different. In the previous version the zones were based on the angle of the profile curve measured from the y-axis. In the new definition the zones are explicitly defined as a value on each point of each profile as explained here: Getting the look ‘in the zone’.
So, without any more diversions let’s go through the shader settings in the wave tool.
The ‘Look’ section of the tool contains all settings that define how the water surface and white water are shaded and displaced. The water surface includes both the ocean surface and the wave surface (as they have by now become a single surface with a single UV space). The wave tool has build in shaders, but it’s also possible to not use these and instead use your own. In the latter case its still possible to use the same shaders that are part of the wave tool. These shaders are available as separate materials in the DEFBreakingWave.otl file. It is of course possible to use these ‘stand alone’ shaders as a starting point for building new wave shaders as they contain all the logic to work with the specific data (e.g. zones) in the wave system. The parameter UI of the shaders is the same as the UI presented inside the wave tool.
The Look section also contains a sub section that deals with some lighting rigs that help to quickly setup lighting to quickly get nice looking waves.
The Advanced subsection of the Look section contains the wave zone definitions as explained in: Getting the look ‘in the zone’.
For now I’ll focus on the ‘Shaders’ sub section.
This section contains the surface and displacement shader settings and render parameters for the water surface (both ocean and wave).
In the ‘Foam’ sub section two kinds of foam can be set up.
The Surface foam is an overall foam texture that is placed on the ocean surface in the diffuse channel. The wave tool embeds a default foam texture (size is 4000×4000, but uses mip mapping to reduce memory footprint if possible). By default this texture has a scale of 0.25, which means that it will be 25% of the total ocean surface UV space. The texture is set to repeat itself to fill the entire surface. The rest of the settings for this texture are the basic settings available to textures in VEX shaders. It is of course possible to replace the default texture with any other texture.
The ‘Lip foam’ is foam that is found in the ‘rough area’ of the lip of the wave surface. This is a procedural foam that is generated on where the ‘rough area’ of the lip is defined (as explained here: ). It is based on the overall displacement of the ocean surface, but inside the ‘rough area’ the ‘roughness’ and ‘amplitude’ of the higher octaves of the displacement are increased (more detail can be found in the discussion on displacement below). The result is used as a diffuse channel of which the intensity and color can be specified. The third parameter is a ramp that maps the displacement values into a sensible intensity range.
Look/Shaders/WaterSurface/Surface/Diffuse and Specular
These sections contain the parameters of the overall diffuse and specular contributions of the surface shader. The diffuse channel is a separate diffuse channel from the two foam types and represents the diffuse part of the actual water.
The parameters are fairly standard settings for diffuse and specular contributions, but there are five for each ‘standard’ parameter: one for each zone (most parameters at least).
This section deals with reflection and refraction.
The first sub section contains the ‘index of refraction’ parameters. The outside index only has a single parameter which is shared by all the zones (as this represents the air). The inside index (the water) has a parameter per zone.
The reflection sub section allows you to specify a fairly standard set of parameters to drive reflection like intensity and tint. The Jitter Amount, Area Samples and Cone Angle allow to create soft reflections. The ray bias parameter is used to solve any issues with self reflection.
The refraction sub section is similar to the reflection section but contains parameters to drive refraction.
It has two additional sets of parameters that deal with attenuation of the refracted color. This attenuation is based on a density factor the attenuation color and the depth in which refracted rays travel before hitting another surfaces. This helps create the effect of impurities in the water that reduce the depth in which you can see through the water. This can be used to great affect in combination with the Area samples, jitter and cone angle parameters. The use of area samples can however, greatly impact render time.
Refraction without multiple samples:
Zone specific sample settings:
Refraction with above sample settings:
It is possible however to get a similar result by using the zone render passes as a mask to selectively blur the refraction pass, which gives a much smoother diffusion of the refraction while being very efficient (it is important to maintain edge sharpness while doing the blur).
Full render with multiple samples rendered:
Blurred refraction pass controlled by wave zone pass (a edge detect was used to protect the edges).
As you can see there is quite a difference between the two versions as the multi-sample refraction pass introduced a lot of light specks. There is however also a major performance difference where the multi-sample solution in this case easily took four times as long to render and this was with relatively low amount of samples and a resulting fairly noisy refraction pass. To get results as smooth as the faked version the amount of samples would have to be increased quite a lot. In addition to this a lot of the lip will be covered with lip spray, so the differences between the two options will be further hidden.
The Environment sub section contains a few parameters that deal with reflected/refracted rays that don’t hit any surface. To prevent these from resulting in black pixels its possible to select an environment map or to select a color that is to be used in such cases.
This section deals with shadows and ‘fake’ caustics.
The shadow color can be specified here.
The Caustics sub section supplies a form of fake caustics. This is a remainder of the ‘Glass’ shader on which the wave shader was based. I’m not sure if these are useful enough to keep around as the results aren’t quite great. For caustics its much better to use a point cloud based solution, but that hasn’t been added to the shader as of yet.
This concludes this post on the surface shader part of the tool. In the next post I’ll go into the displacement section of the WaterSurface shader.
Here’s the final render result from which the render passes shown above come: