I’ve been busy

Happy 2019!! First post of the year!! (I checked ;))

During the past month I’ve focused most of my efforts on the new renderer architecture, one of the major changes for Crimild 5. There are many, many things I already changed and a lot more that I want to change and upgrade in order to bring Crimild a little closer to most modern game engines.

At the core of the new rendering pipeline are both Render and Shader Graphs. Both of these tools were already introduced in latest Crimild versions, but as experimental features. It’s time to make them production-ready.

Without further ado, here’s what I’ve been doing so far:

New forward render pass

I’m writing the entire forward pipeline from scratch using shader graphs and fixing exiting errors in lighting calculations.

Point lights with different attenuation values
Spotlights and ambient light, working correctly this time
Directional lighting and specular mapping

Cube and Environmental Mapping

I tried implementing cube mapping years ago, but it was too hard-coded into the engine for it to actually become something useful. Now, with a new Skybox node and cube textures support, working with environmental mapping has become straightforward:

Skybox and Reflections (left bunny)
Refraction

Shadows

Crimild shadow mapping support was bad. Really bad. But that is about to change.

I’m implementing a new shadow pass that creates a single shadow atlas supporting multiple casters with different types and resolutions. Only directional lights can cast shadows at the moment, but except more news in the coming weeks.

Two directional lights casting shadows at the same time!!

Emscripten

Last, but not least, Emscripten support has been greatly improved, with support for WebGL2.

I’m revisiting most of the demos to make them work on the browser.

That’s it for the moment.

2019 has definitely started in a high note for Crimild 🙂

Crimild v4.10.0 is out

This is it.

Crimild v4.10.0 is out and this will be the last of the 4.x versions. From now on I’ll be focused on the next major release for Crimild which will bring a lot of changes. 

But first let’s talk about what’s included in v4.10.0:

Render Graphs

I talked about them in the last couple of posts. Render graphs are great for creating highly modular render pipelines by combining different nodes representing render passes and attachments.

There are many nodes included in this release and many more will come in future versions.

Shader Graphs

Although shader graphs were actually introduced in v4.9, I ended up refactoring them to work in a similar way as render graphs do, simplifying both the internal implementation as well as the API.

Now, each node in the graph represents either a variable or an expression, and there’s also a way to discard nodes that are not relevant to the end result. 

The translation to GLSL mechanism has also being simplified, but I guess it could received a little more love in the future.

Most importantly, this newer API allowed me to create… 

Crimild Shading Language

Well, it’s not an actual programming language, but more of a set of functions providing us a way to write shaders in plain C++, disregarding the actual graphics API using for rendering. 

Of all the new features includes in v4.10.0, this is the one that got me more excited and I’m really looking forward to start creating shaders this way.

UI Canvas & Layout

Last but not least, I started working on several tools for creating UI elements, either in screen or world space. As it is right now, only basic UI elements can be created but there’s support for a very expressive set of layout constraints to arrange them in a canvas, with a size defined independently of the actual screen resolution and aspect ratio.

Minor fixes and updates

As usual, new releases come with a bunch of fixes and minor updates to existing features and v4.10.0 is not the exception.

There are a couple of new containers: Digraph and Set.

In addition, many changes have been made to how render resources are internally handled.

And I finally fixed some math bugs that have been causing issues for quite some time.

Please refer to the complete release notes on Github.

What’s next?

Crimild v4.10.0 includes a lot of (experimental) features that are going to became critical players in v5, Crimild’s next major release. 

The biggest goal for next year will be to refactor the entire rendering system, which has become quite limited and it’s time for it to level up. I’ll be focusing first on improving the existing OpenGL renderer before moving to Vulkan. Not sure what will happen with Metal support, though. 

Indeed, next year is going to be very exciting…

Optimizing Render Graphs

Last week we talk about what render graphs are and how they help us build customizable pipelines for our projects due to their modularity.

But render graphs are not only useful because of their modularity. There are also other benefits when we want to optimize our pipeline.

REUSING ATTACHMENTS

Since each render pass may generate one or more FBOs (each including several render targets), it would be great if we can find a way to reuse them and/or their attachments. Otherwise, we’ll quickly run out of memory on our GPU.

How do we achieve reusability? Simple. Let’s go back to the simple deferred lighting graph we saw on our previous post.

The Depth attachment is a full-screen 32-bit floating point texture and it’s pretty much unique since no other attachments share that texture format. We will assume that the rest of the attachments (normal, opaque, lighting, etc.) are also full screen, but they have an RGBA8 color format. 

By looking at the graph, it’s clear that the Normal attachment is no longer needed once we’ve accumulated all lighting information (since no other render pass makes use of it). Therefore, if we manage to schedule the passes correctly, we can reuse that attachment for storing the result of the translucent pass, for example.

An that’s it. Thanks to our graph design, we can easily identify which inputs and outputs each render pass has at the time of it’s execution. We also know how many passes are linked with any given attachment.

There’s a catch, though.

Let’s assume we want to generate a debug view like this one:

Top row: depth, normal, opaque and translucent. Left column: opaque+translucent, sepia tint and UI

In order to achieve that image, we need to modify our render graph to make it look like this:

The final frame (Debug Frame) is created by the Debug render pass, which reads from several of the previously created attachments in order to compose the debug frame that is displayed. This prevents us from reusing attachments completely because all of them are now needed at all times. That might be an acceptable loss in this scenario because it’s only for debug, but you definitely need to plan each dependency correctly if you want to maximize reusability.

For my implementation, I’ve decided to reuse only attachments, while FBOs are created and discarded on demand. This helps minimize memory bandwidth as well as providing maximum flexibility for creating offscreen buffers.

DISCARDING NODES

Another advantage of using render graphs is that we’re able to identify which nodes are actually relevant to achieve the final frame during the graph compilation time. That is, of all the nodes in the graph, we’re only interested in keeping and executing only those are actually connected to the final node, which is the resulting frame for the graph.

For this reason, each render graph define which attachments serves as the resulting frame for the entire process. Depending on which attachment is set as the final frame, some render passes will become irrelevant and should be discarded.

Once again, look at the debug render graph above, paying special attention to the debug nodes at the right.

We have two possible final frames. The one that only contains the scene (bottom center) and the debug one (bottom right).

If we set the scene frame as the resulting frame, then the Debug Pass will be discarded since its result is no longer relevant and the final render graph will look like the one at the very top of this post. Then, after compiling the render graph, the passes will be executed as following:

That’s great, but why? Why adding extra nodes that are going to be discarded anyway? Well, you shouldn’t do that… except that by doing so it will allow you to create something like an ubber-pipeline, including debug nodes and different branches too. Then, by defining which one is the actual final frame (maybe using configuration flags), you can end up producing different pipelines. I know, it might seem counterintuitive at first, but in practice it’s really useful.

Closing comments

I’m going to leave it here for now, since this article has already become much longer than expected. 

Render graphs are kind of an experimental feature at the time of this writing, but I’m hoping they will become one of the key players in the next major version of Crimild. Together with shader graphs, they should help me create entire modular pipelines in plain C++ and forget about OpenGL/Metal/Vulkan (almost) completely. 

Now it’s time to prepare one more release before the year ends 🙂