Sojour

The solo virtual table top

DirectX Separation & PBR

Dorian now supports PBR (Physical Based Rendering)!

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:

Dorian now accepts many texture types to support its material modelling.

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

I’d like a TIE fighter please Sir! But in Chrome!

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

DirectX-11 has now been separated from the Engine!

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):

Whilst the new one held 120 FPS (my TV’s refresh rate) – it took a noticeable dip in performance for 1% and 0.2% lows.
These are frame times. Lower is better and you can see that the newer version’s performance really falls away compared to the pre-DirectX separated version. It also has a ton of random spikes in frame time. (Frame time is a better measure for performance)
This graph really brings home how much worse the newer system was in terms of performance.

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!):

Much better! In fact we are now performing a little better than the original system!
The new version produces lower frame times across the board! The only thing left to investigate are the occasional big spikes.
For smooth frame times the newer Direct-X system is way better than the old one! Quite amazing given how much more complex the new version is!

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!

Dorian in action!

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

Comments

Leave a Reply