mercoledì 29 giugno 2016

Day 138: 1024 point lights

Today I built another scene for the presentation of tomorrow.
I decided to create a scene that really shows the power of the deferred rendering, so I just rendered a single plane with 1024 point lights on top.
I made them quite intense, but I set the attenuation to a very high value, in order to reduce the bounding boxes of the lights.
The performance is exactly 21 fps. I say exactly, because it is incredibly constant, probably because the scene is quite simple, and the engine behaves in a very predictable way. I also noticed that I can make the bounding boxes quite a lot bigger without impacting the value, so I guess that the bottleneck is not even the amount of fragments rendered, but the number of draw calls required by the lights.


martedì 28 giugno 2016

Day 137: Percentage-close filtering (soft shadows)

Today I implemented the soft shadows algorithm, because the quality of the shadows was not great.
This algorithm is better than a simple average of the neighbor fragments. It uses a Monte Carlo approach, which states that multiple random extractions approximates the correct result.
To be more specific, PCF consists in sampling randomly around a fragment, with a different random distribution for each fragment. This approach removes the typical "band" effect obtained in normal sampling. The random values are pre-calculated offline, and sent to the shader in a texture.
The result is really good, and while the performance is of course lower, it is possible to reduce the quality of a texture, thanks to the blurred effect.
I implemented it for directional and spot shadows, because unfortunately the point light's cube map doesn't support this technique (even though there are workarounds).

I also added to each light a shadow_strenght and a blur parameter. The latter is the desired intensity of the soft shadows. This allows to use an high quality blur when it is useful, like in the picture, or to make it less demanding where the performance is bad (for example in the scene with 20 spot light).


lunedì 27 giugno 2016

Day 136: New scene and bug fixing

Today I started by fixing a bug affecting the loading of different skyboxes.
Then I implemented a new scene, which loads a prebuilt minecraft model. Because the model is already built, the engine is not able to take full advantage of instancing as if the model were built inside the engine, but the performance is still very good.
I also added a log function to print the camera position and orientation. I used it to position the camera in each scene in an acceptable, because this was not the case until now.


giovedì 23 giugno 2016

Day 135: New / old scene

In a few days I'll be presenting the engine at my university, so I need to add a few scenes just to show a few features of the engine. So I've reimplemented an old scene with lots of cubes, with a few differences due to the new features of the engine.
While I was doing this I fixed a bad bug that was affecting lights when shadows were disabled. I also fixed for good the bug that yesterday I claimed to have solved, but there were other uninitialized variables that were still causing it.


mercoledì 22 giugno 2016

Day 134: Background Color

Today I noticed that the engine was lacking an obvious feature, the ability to have a background color instead of a skybox, so I added this functionality to the camera class, and now it's up to the user to decide which one to use.

Then I fixed a nasty bug that was giving problems to the particle emitters. It took me a very long time to fix, and even now I'm not sure why it was behaving like that. The error was a stupid variable not initialized to zero, and in release mode this created tons of problems.


giovedì 16 giugno 2016

Day 133: Few updates to the scene

Today I didn't really work on the engine, I just modified a bit the scenes to make them more interesting.

The scene with the Sponza model now has 3 point lights, and they could be modified in many ways during the gameplay, to easily show different light effects.

The scene with the rotating point lights now makes the shadows more clearly visible.

domenica 12 giugno 2016

Day 132: Bug fixing

A few days ago I noticed there were problems with the shadows when I was disabling them.
The problem was that the last computed shadow was displayed (instead of nothing).

The problem was a little annoying to track down, and it turned out that I was sending a bool to the shader (instead of casting it to an int), and this generated an undefined behaviour.

Now everything works fine.