
The graphics engine for Sojour 2 has had two quite large enhancements made to it.
Firstly the lighting and materials rendering system now uses Physical Based Modelling (PBR). This is a rendering technique that uses approximations of actual lighting physics to produce more natural lighting.
The other advantage of PBR is that it can simulate practically any material that you can think of with the correct textures and setup.
For example, the sphere shown above is actually a smooth sphere, but looks rocky thanks to the textures below combined in magical mathematical PBR ways:

Even where a model has no textures, like the TIE Fighter for example, you can easily change its look on the fly:

The next huge undertaking was removing DirectX from the engine and keeping it completely separate:

It was a huge job, but it is necessary to allow the engine to support other backend renderers such as DirectX-12 or Vulkan.
This was a huge undertaking as all aspects of the system got altered to support a more abstracted means of rendering.
What makes writing a graphics engine difficult – apart from the complexity – is ensuring performance is not compromised by code changes such as the refactor above.
The amount of code changed to separate DirectX-11 was staggering and the initial performance results were not too good (all graphs measure the scene you see above):



Detailed performance measurements when creating a graphics engine are critical. It’s almost impossible to see the above differences by eye – so you must take the measurements before and after each change.
In this case I traced the problem to the fact that material caching had been broken by the refactor. After around a day of coding everything is now back where it should be (and in fact a little better than it was!):



This is one of the reasons why engine development takes so long. You aren’t just writing code that works, you are also writing code that’s highly performant!
I’ll leave you with a You-Tube video showing everything in motion. As usual, the smooth framerates never seem to translate well on You-Tube. If you look carefully, you’ll see me toggling the TIE Fighter to chrome and back!
Still a long way to go, but we are getting there.
I know writing Dorian seems like a diversion, but Ionian which is the engine used in Sojour cannot be used in conjunction with the latest technologies hence the re-write. (To be fair, Ionian lasted over twenty years, so it has had a great run for its money!)
Have Fun!
RobP

Leave a Reply