Wednesday, December 10, 2014

Reflections in Water/Puddles based on Camera Pixel Depth


Water Reflections based on Camera Pixel depth. (Unreal 4)

One thing that has bothered me in some video games is the way the water reflection is treated based off the the player camera. In most instances it is treated correctly, but in some cases the water is too much like a mirror at all distances, close up and far away. 


In reality when we approach a puddle or a body of water the reflectiveness of the water is still there but we are able to see down into what is beneath. (seen in previous images). However, in some games reflections are over the top:


A lot of detail is lost in the street below, though it still is acceptable I wanted to devise a way to assist in the way that reflections are controlled close up in materials.

For this example I am using Unreal Engine 4.


Based on the Pixel Depth of the player Camera:

The pixel depth node is divided by a Constant Parameter I called 'camera depth' which divides the input from pixel depth node to adjust the range of falloff between two values "Min Puddle Roughness" and "Max Puddle Roughness." This value is then added to the overall roughness texture using a mask and plugged directly into the roughness slot in the material editor.

Camera Depth set to 96.0
Camera Depth set to 256.0
As you can see the lower the value the more the player will see the mirror-like reflection in game, but as we push that value further out the player will only see the mirror-like reflection in the distance.

Camera Depth set to 135.0

Gradient: Camera Depth set to 135.0
So in finding a happy-medium, you can still have great results without losing too much in the close-up reflections. You can get into more detail using calculations from light vectors that way depending on the angle at which you are looking at the reflection, values would adjust.


No comments:

Post a Comment