The magic of skybox reflections
Skyboxes and environment maps are for sure one of the more powerful tools for physically based rendering to give a scene a touch of realism. A skybox is essentially a cube map rendered onto a cube which we position in the background of our scene.
A cube map is a map of 6 textures, one for each internal side of a cube. A normal 2D texture is sampled using uv-coordinates, representing the "x" and "y" axes of the image. That is, each vertex is assigned a uv coordinate, from which a point on the texture is sampled in the fragment shader.
For cube maps, as they represent the inside of a cube, for convenience, there is no reason to apply uv-coordinates to sample the texture. Instead, one selects a point using a 3D vector, pointing from the center inside of the cube into any of the textured cube faces. This makes cube maps very handy for light calculations in 3D. Reflections are then mathematically very simple to create using a cube map, as we just have to calculate the reflection vector at each surface point, and then sample the cube map using this vector.
Left: Specular reflections in calm water. Middle: Cube map sampled reflections in calm water. Right: Cube map rendered onto sky box in background, reflections sampled from sky box in calm water.
As can be seen, adding skybox reflections creates a feeling that the water actually is water, even though we are simply just simulating its surface. However, one characteristic of water which is missing, causing the water not to look completely realistic, is refraction.
Refraction is the property causing light to scatter when travelling through mediums of different indices of refractions. So, in fact, when looking at water, we expect some of the light to come from reflections from the environment above water, however we also expect some of the light to come from the environment below the surface, which we can see is not true for any of the images above.
The amount of light coming from below and above the surface is calculated using the fresnel equations.


Fresnel equations for refractive indices. R_s and R_p represent the reflectance for s and p-polarized light. R_eff is their average used as effective reflectivity of the material. n1 and n2 are the refractive indices of the materials and theta i and t are the incident and refracted (transmitted) angles.
In the shader, I thus sample the cube map both in the refracted and reflected vector directions. The colors sampled are then interpolated using the effective reflective index.
The result looks more natural and gives a feeling that there is something below the surface of the water too.
The texture used is not too realistic however, as we would probably not see the bottom of the ocean when that far away into the sea, as it would be too deep. Using a different texture can show the property of refraction in a more realistic setting.


Left: Reflection and refraction making the pebbles on the bottom of the water visible. Right: Perfect reflection making only the environment above sea level visible.
Thanks to www.humus.name for providing free to use high resolution 3D cube maps.
https://www.humus.name/index.php?page=Textures
1. Scratch a pixel, Reflection, Refraction (Transmission) and Fresnel, URL: https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/reflection-refraction-fresnel
Refraction is the property causing light to scatter when travelling through mediums of different indices of refractions. So, in fact, when looking at water, we expect some of the light to come from reflections from the environment above water, however we also expect some of the light to come from the environment below the surface, which we can see is not true for any of the images above.
The amount of light coming from below and above the surface is calculated using the fresnel equations.


Fresnel equations for refractive indices. R_s and R_p represent the reflectance for s and p-polarized light. R_eff is their average used as effective reflectivity of the material. n1 and n2 are the refractive indices of the materials and theta i and t are the incident and refracted (transmitted) angles.
In the shader, I thus sample the cube map both in the refracted and reflected vector directions. The colors sampled are then interpolated using the effective reflective index.
The result looks more natural and gives a feeling that there is something below the surface of the water too.
The texture used is not too realistic however, as we would probably not see the bottom of the ocean when that far away into the sea, as it would be too deep. Using a different texture can show the property of refraction in a more realistic setting.
Left: Reflection and refraction making the pebbles on the bottom of the water visible. Right: Perfect reflection making only the environment above sea level visible.
Thanks to www.humus.name for providing free to use high resolution 3D cube maps.
https://www.humus.name/index.php?page=Textures
1. Scratch a pixel, Reflection, Refraction (Transmission) and Fresnel, URL: https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/reflection-refraction-fresnel
🤩🤩🤩
SvaraRadera