lunedì 31 agosto 2015

Day 56 & 57: Bugs and faulty drivers

In these two days I noticed a bad bug in the spot lights bounding box.

While I was trying to fix it, I updated the nVidia drivers, and everything stopped working. It was partially fault of the drivers, but this also allowed me to find a bad bug in the spot lights.

Today I also fixed the rotation bug,which was due to a bad usage of pitch and yaw, and now everything should be fine. In the next days I'll continue to refactor the game and the engine both.

sabato 29 agosto 2015

Day 55: Engine and Game

Today I spent a lot of time on a substanctial refactoring.
Now, instead of a single project, I have a RynoEngine library project, and a Game project that uses its functionalities.
I lost a lot of time on a problem with the lights, and it turned out it was just a driver problem.

Then I tested a bit the engine and  I noticed there is a pretty bad bug on the rotation of the lights, but I'm not seeing a way to fix it for now.

mercoledì 26 agosto 2015

Day 54: No more Lights

Today I finally finished the lighting system.

I Found out that the bug I had yesterday was due to the stencil buffer. I wasn't able to solve it, and so, since I read online that very often it actually makes performances worse, I remove it for good.

Then I implemented the bounding boxes for spot lights. They rotate and they grow in width depending on the cutoff value. In the picture there is an example of a bounding box perfectly aligned with its light. This allows to draw way less pixels for each spot light.

With this, I declared finished all my work on lights.


martedì 25 agosto 2015

Day 53: Rotations

Today I started by trying to change the bounding box of the spotlighs to a rotating pyramid.
Sadly I noticed a bug I have somewhere: the bounding boxes are rendered with missing faces, like a culling problem or a depth problem, or a model loading problem.
This happens only to models without uvs (which are the ones I use for boxing purposes).
For sphere boxes this leads to no problem, because the faces are so many that everything is covered by the model anyway, but for a cube or a cone, I get whole areas of light cut off.
I'll try to fix it tomorrow and finally finish this lighting stuff.

This evening I decided that it's very bad to declare light directions via a vector, so I left to the user the possibility to pass pitch and yaw in degrees, and then I convert them internally to a vec3 representing the direction.

In the picture I placed the three different lights supported by the engine. From left to right: point, directional and point light shadows.
Tomorrow I'll try to fix the problem, and implement the rotating bounding box, after that, no more lighting.


lunedì 24 agosto 2015

Day 52: Spot lights

Today I wrote a lot of stuff.

I started by creating everything needed for the spot lights, by duplicating the point light classes (and shaders) already there.

In the meanwhile I also refactored a bit the Point light and Directional light classes.

Then I implemented all the different things that are different in spot lights compared to the other kinds of lights.

The main problem I had (and actually still have) is how to set the field of view of the spot light...apparently it is not the angle,but  the arccos of the angle, for reasons that are still unknown to me...So in the end I used this method, but, with very narrow fileds (close to 0), the arccos tends to infinite, so i manually set a value of the fov for these values, because the resulting shadows were messy...
Oh and I cannot use field higher then 90 degrees, but 90 is quite a lot anywhay for spot lights.
I don't know if there are better solutions, but now everything works fine, and I don't want to lose my sleep over it.

One last thing to do, not even really necessary, is to change the bounding box of the spot lights.
Right now they uses the same spherical box of the point_lights, but with this method a lot of space inside the sphere is rendered for no reason.
I should use a parallelepiped / cone and rotate it in the direction pointed by the light.


domenica 23 agosto 2015

Day 51: Nothing special

I had really little time today, so I just set up a few things to start working on spot ligths.

sabato 22 agosto 2015

Day 50: Geometry shader

Today I decided to do one last thing on my point shadows.
I read  online that, instead of rendering 6 times to the six faces, you can just render the scene one time, and then use a geometry shader to render the 6 images to the 6 correct faces of the cube.

I guess this is quite faster, because you don't need to bind/unbind 6 textures from the depth_attachment, but the main reason why i liked the idea, is because i never used geometry shaders, and it was time to learn.

Everything went pretty smoothly, no problems at all!

Then I refactored the shader class to handles geometry shaders more nicely, and realized I could just remove all the .meta files I had till today, and all the "binding attribute" step, which is another nice polish of the engine.

So, actually nothing new, but a very positive day. In the picture i just toyed around a little with the shadows.


venerdì 21 agosto 2015

Day 49: Cubemap shadows in depth buffer

Today I decided to move the cubemap for the shadows from the color buffer to the depth buffer.

That's because you don't really need 32 bits for storing the depth, and only the depth buffer allows you to have 16 bit values.

To do so I had to tweak a few things, for example I needed to remap the distance between fragment and light to the interval [0;1], because the depth buffer can only accept those buffers.

In the end everything was unexpectedly working in less then an hour, which is a relief after the last week. Now I'll stop working on point light shadows, and probably I will add spotlights (with the relative shadows), and then stop working on graphic stuff for a while, and move to other aspects of the engine.

In the picture I have 9 dynamic lights (10 with the directional light) casting lots of shadows from 121 parallelepipeds. It runs at 50 fps, which is quite good on my card I guess, considering that each light requires 6 renderings.
I doesn't surprise me that even in modern games there are just a few lights on screen in the same moment, and not all of them are shadow casting.


giovedì 20 agosto 2015

Day 48: 3D shadows: It's finally over

After a terribly frustrating week I finally found the bug:

An angle in degrees instead of radiants...

That happens, and of course I immediatly tought of that, one week ago, but the documentation of the function was wrong, and asked for a DEGREE angle...

Well, I'm still angry with that, but now everything is fine, and in the picture you can see five lights and the five shadows casted by the lit surfaces.


mercoledì 19 agosto 2015

Day 47: Problems with shadow maps

I'm stuck again, this time trying to use the values in the cubemap to render the shadows.

I can read the cubemap, and display some oddly shaped shadows, so the problem lies somewhere in the shader, I cannot see where yet.

martedì 18 agosto 2015

Day 46: Writing to cubemap

Finally, after a few painful days, I managed to proceed with the multipass shadows.
The main problem was that i was using a cubemap too large, and so a black screen was rendered. This made me lose two days of work, it was really frustrating.

After that I spent quite some time to render exactly what i wanted, but now everything is fine.

In the picture on the left there is the usual rendering (horribly modified because I was using colors to debug the scene), and on the right there are 6 little images:

the top two are back and front X faces, the middle ones back and front Y and the bottom one back and front Z (referred to a point light I placed on the scene).

The next step will be to sample this cubemap inside my point light shader, which will be similar to what I already do with the directional shader (for the most part).


domenica 16 agosto 2015

Day 44, 45: Cubemap shadow nightmare

I'm having a really hard time with the shadow maps for point lights.
I wrote the code for it, but somehow it does not render anything, I really have no clue how to proceed.
I have in my mind pretty clearly how the process work, i guess there is some OpenGl error that i'm not seeing which is dragging everything down...
Tomorrow I'll probably continue to work on this, i hope things will be better

venerdì 14 agosto 2015

Day 43: Fix and refactoring

Today I finally managed to fix all those things that were annoying me, and while the engine does just a few new things since yesterday, it's been one of the most productive days I recently had.

First I decided to move the shadow rendering on a new FBO, and leave the deferred rendering on the other one. It's not clear if this is more convenient than using one buffer for everything, but anywhay, it's a nice, logical division.

Then I finally fixed the problem with the depth texture, and now the shadow map is saved in the depth buffer, and uses only 16 bits, cutting the bandwidth in half.

Then i noticed that the engine didn't support objects that doesn't cast shadows, and to do so i had to change from scratch the Batch3D.
Actually I divided it in two, one for geometry rendering, the other for shadow rendering, and both inherits from an abstract one. This will  probably be useful when i'll need to write a 2D batch to render a GUI.

In the picture you can se a big shadow-casting pillar, and a circle of non shadow-casting spheres (with point lights inside them).

giovedì 13 agosto 2015

Day 42: Problems

Before implementing the mutipass shadow maps for point lights, i wanted to fix an annoying problem i had with the shadow map.

Right now the shadow map is stored inside a color channel, which is more expensive than the depth buffer, soo i tried everything to use it instead, but it just won't work...

Tomorrow i'll create a new framebuffer from scratch and use it for shadow rendering, maybe with its depth buffer i'll manage to make it work

mercoledì 12 agosto 2015

Day 41: CPU Profiler

It's been two weeks since my last post because I went to holiday and the update to windows 10 destroyed my pc. Now everything is fine, and I set up the visual studio enironemment from scratch, adding a useful plugin to integrate SVN into the ide.

I noticed that the game is pretty slow to start, something around 3 seconds, so i wrote a CPU profiler to identify the bottleneck. (i also tried the GPU profiler i already wrote, but i found out, not surprisingly, that the times are not correct for CPU).

It came out that mesh loading is a very fast operation, while texture loading takes up a whole second. But the real problem is the cubemap, because of it's high resolution, which takes 2 seconds to load.

For now I'm gonna ignore these problems, probably with uncompressed formats the loading time would be faster, but with a large memory use.

However the cpu profiler is pretty nice and will be very useful in the future.

In the next days (or weeks probably) I would like to implement spotlights, perspective shadow maps and volumetric shadows for the point lights, and then take a pause from the graphic stuff, and maybe work on something new, like a simple GUI or maybe some basic physics engine.