BRDF simulation and mouse movement

This time, I worked on transferring previous work to the project by integrating a shader trying to emulate the BRDF (Bidirectional Reflectance Distribution Function) in real-time. This function represents how much of the incoming light from a specific direction is reflected to an outgoing direction. The idea is: if you calculate it on a specific point of a surface for all incoming directions, for the outgoing direction of your eye, you will get a physically correct simulation of what you would see. While it is currently impossible to achieve in real-time, clever shortcuts and approximations helps get closer to it!

But in short, things look much better now (that is, when models have material set-up, unlike those enemy ships)

BRDF rendering with direct and indirect illumination with single spot light

Computer graphics time-jump... ACTIVATED!

Time spent for this Time spent so far
19 h 120 h

To give more details, the shader is split in two parts:

  • We simulate the direct lights that hits the surfaces (from the single spot light we have in the scene). We use the light’s angle, intensity, distance combined with the surface’s material properties (reflectivity, shininess, fresnel, diffuse, metal, microfacets…) to calculate it.
  • We also simulate the indirect lights by cheating (no ray-tracing here^^). We use an “irradiance map” which is pre-calculated data used to represent how much “global light from the world” is coming on a surface, when viewed from a certain direction (the camera/eye). We then combine the two and that gives us the result visible in the video.

As you can imagine, a lot of additional things can be done to give a better rendering, hopefully I will be adding a couple of them later. Also, to achieve this I had to add a new component for objects that represented the light source (so that the rendering handler could retrieve the necessary values to pass them down to the shaders).

Additionally, from a “game logic” point of view, I added mouse support to control the rotation of an asset. You can see it in action in the video, when I move the light source, and I also used it on cameras to get a better look at my rendering (not visible in this video). This helped me debug by getting a better look at the various surfaces. It took longer than I would have liked to do all this, but it turns out that retrofitting shaders from a monolithic project to an object oriented one requires a fair bit of additional code!


See also