martedì 30 giugno 2015

Day 18: Completed Deferred Rendering

Finally i made it to the end, now my system can render various point lights and a directional light, all in deferred rendering.

I expected more fps to be honest, the scene in the picture runs at ~30 fps which is not very nice (even though all the lights are in the view field, so there is a lot of calculations. If they were more sparse the fps count would be better. Oh and my GPU sucks.).

Tomorrow i will refactor the code and hopefully i'll see something to speed it up.

There's also a graphical bug with low-attanuance lights, which i really don't know why it happens.



lunedì 29 giugno 2015

Day 17: Cube Bounding Box

Today i finally optimized point lights. Without this optimization deferred rendering wouldn't be much worth it probably.

Basically instead of rendering all the screen for each light, i just render those fragments that are hit by the light. To do so i calculate the area of influence of the light, and draw a cube in that position.

In the picture you can see a red cube which contains entirely the area of influence of the point light (barely visible). Of course i can make the red cube invisible.

I can also render a rough-edged sphere (an icosahedron maybe), which result in more vertices to draw, but in less fragment to render. I'll need to find a good tradeoff point.

The fragments outside the cube are not rendered in the lighning pass.

To achieve this i also had to create a simpel class to render models...i wrote the big instancing-batched renderer, but i lacked of a simple renderer for single models.

Now i will need to refactor all this light stuff in a more coherent system, and also i need to write a better obj loader.




domenica 28 giugno 2015

Day 16: Point Lights

Today I managed to light my scene with point lights.

It was harder then i expected because i had a bad bug in my geometry shader, and this bug was not a problem for the directional lights i implemented yesterday, so i didn't notice till now.

However, now they works, but i have to add to those lights color, attenuation and so on, and then i was thinking to make a LightManager to automatically render the scene with each light.

Oh, and now point lights are inefficient, because they are rendered even on pixels they are not influencing


sabato 27 giugno 2015

Day 15: Deferred Rendering, second part

Today was a nightmare.

The goal was to finally render on screen using the deferred shading.
I wrote all the necessary code pretty fast, but then i passed the whole day struggling to make it work.
I don't even know what fixed it in the end, horrible, horrible day.

Tomorrow i'll refactor everything because now the code is terrible.
Right now i just have one light, a directional light, tomorrow i'll try to extend the system to point lights.


venerdì 26 giugno 2015

Day 14: Geometry Pass

Today i continued to study on a tutorial about deferred rendering, and i adapt it to my engine.

The first step is called Geometry Step, and it consists of rendering the color, normals, position and depth informations inside a Frame Buffer, instead of the screen.

I implemented it, and then, to see if everything was ok, i moved the content of those buffers on the screen, one per corner (image).

This last step will be removed once i finish everything, but was useful for debugging purposes.

I'm not exactly sure that everything is exactly like it should be, because i did a few things differently from the tutorial, but i guess i'll se that later.

Here's the link of the tutorial, it deserves to be shared because it's the most clear and complete i managed to find online:
http://ogldev.atspace.co.uk/www/tutorial35/tutorial35.html

giovedì 25 giugno 2015

Day 13: Deferred Lighting (Theory)

Now that i can use light in my game, i have to decide if i want to use forward rendering or deferred rendering.

The forward rendering is the obvious one, and it consists of rendering each object for every light in the scene. I used it till now.

Deferred rendering on the other hand is divided in two main step: first make a rendering step for each object, and save normals, diffuse color, specular color and position of the rendered pixels in 4 buffers.
Then render again using these 4 buffers as inputs and apply light calculations.

This second method become better and better the more lights and objects are on the screen, but also has a few bad drawbacks, like the inability to use anti-aliasing or transparent objects.

I will go with deferred rendering, because it's harder to implement (which is a plus) and very interesting conceptually, but it will require sometime.

Today i didn't write a line of code, because i studied these stuff, tomorrow i'll have to continue studying but maybe i'll start writing something.

mercoledì 24 giugno 2015

Day 12: Directional Light

Today i manage to make a big step, which is the introduction of lights in the engine.

Right now it only supports a single directional light, and i'm trying to figure out the best approach to manage multiple lights (of different type too, for example point,directional or spot lights).

The color of a fragment is 20% ambient light and 80% diffuse light, just to show a little of the model even if it is not hit by the light.

In the picture there is the curve i made a couple of days ago, and it is now hit by the light, and in the sky i rendered a big spherical moon which shows pretty well the diffuse light effect.


martedì 23 giugno 2015

Day 11: Audio

Today I added music and sound effects to the editor.

I used a simple library, SDL_Mixer, which is an SDL extension obviously.

I created an Audio Manager class, which makes very easy to load and play audio files, and hides effectively the SDL_Mixer calls.


lunedì 22 giugno 2015

Day 10: Refactoring

Today i added quaternions rotations to the game objects to make rotations faster.

Then i noticed that my MainGame class was full of code, so i created a MainGameAbstract class to handle all this code, and i placed only the important game-related code in a child class.

Then i played around again with the engine to create another wavey effect, just for fun


domenica 21 giugno 2015

Day 9: Quaternions

Today was horribly frustrating...to optimize the rotations of the engine, which are quite expensive, i decided to pass to quaternions.

I already used them in the past, but somehow today i passed my day trying to make things work.

I finally fixed everything after i don't know how many hours, and now my camera works perfectly, tomorrow i'll try the same thing with the other game objects, and i hope it to be quicker than today...

I also played around a little with the engine, and made a few other cool looking effect with lots of cubes


sabato 20 giugno 2015

Day 8: Cool stuff!

Today i started by modifing my camera to work with the mouse, now it's really really handy, and makes moving around very easy.

Then i modified my instancing batch class to use another attribute, the color.
Before i was passing a new color for each vertex, which is quite useless, now each model has a shared color for all it's vertices.

Then i had a little fun, and to test the performances of the engine i instanced 10.000 cubes on a plane, and i made them move on the y axis with a sin wave.

This is not directly useful for the developement of the engine, but it was nice, you can see the result in the picture below


venerdì 19 giugno 2015

Day 7: FPS, Input and Camera

Today i started by refactoring a lot of really bad code.
Then i wrote a class to count the fps, and i immediatly made a few tests to see how many mesh i could render without impacting the performance.

The result is around 25.000 cubes, which is nice considering my horrible gpu.

After that i readapted an old classes i wrote, which allows me to handle all the inputs from the user.
Using this class i was able to finally make my camera works, and now i can move around the map with the wasd-qe keys.

This allowed me to notice a bad bug on the Z axis, which stretch itself while i zoom away. Tomorrow i'll try to fix it.


giovedì 18 giugno 2015

Day 6: Complete Instancing

Today i completed the batching/instancing system.
Now each batch contains all those models with the same texture and the same mesh.

In the picture below I rendered 50 cubes and 50 spheres, using two different textures, and the total draw calls count is 4.
If I had used the metal texture only for the cubes, and the wood texture only for the spheres, the count would be 2.

I also wrote a MeshManager class.
Instead of giving a mesh to each model, i just give them an id, and they can retrieve the mesh from the MeshManager class with this id.
This was necessary in order to implement the batching system.


mercoledì 17 giugno 2015

Day 5: Batch and Instancing

Today i built up the batching system of the 3D models, to avoid bad performances later on.

I built a system that groups together the models with the same texture, and then uses instancing to draw all the models with the same texture together.

This is quite optimized, but if two models have the same texture, but are not the same model, the system does not work. I'll try to handle this problem tomorrow.

I also built the GameObject class, which, for now, contains just a Model and a few other things, and i also built the Camera class, which soon will handle the camera movement.

The whole code now is quite a mess,  so tomorrow i’ll probably make a big refactoring.


martedì 16 giugno 2015

Day 4: 3D Perspective

Today i managed to build a WVP (World -> View -> Perspective) matrix.

By passing it to the vertex shader, i was able to transform the model from it’s own coordinate system to the world one, then to the camera one, and then to the “deformed” perspective coordinate system that is actually responsible for the “3D effect”.

With a few OpenGL instructions I enabled MSAA, Multisampled Antialiasing, which uses gpu buffers to smooth the edges of 3D models.
The code i wrote today needs some serious refactoring though, I’ll get at it tomorrow.

lunedì 15 giugno 2015

Day 3: 3D Model

Lots of code today!

I started by making a “.obj” loader class to load models made with blender.

Then i created a Model class to contain all the vertices info about a model, so that OpenGL can easily draw it.

So i managed to display a simple cube, but the texture of course was missing, so i created a TextureLoader class that can loads pngs thanks to PicoPNG, a third-party open-source library.

Then i modified the shaders to accept the texture as a parameter, and to use it during the rendering.
The result is a textured cube, but there are a few things missing:

1)The cube is stretched like the screen, because i haven’t ported it to camera coordinates yet

2)The cube is flat, because i didn’t put it in perspecive yet

These will be the next two things i’m gonna do.


domenica 14 giugno 2015

Day 2: Shaders

Today i had to write a lot of code, mostly because a lot of stuff needed refactoring.

I started by creating a MainGame class to refactor the game cycle, so that now i have all the game logic in one class, with easy-to-read functions like initialize_system(), draw() or handle_input().

Then i started working on displaying a simple shape on screen.

This required 3 steps:

1) Writing OpenGL code to pass the shape data to the gpu
2) Writing the shaders in GLSL language
3) Make a GLSL program working

The first two steps were pretty easy and straightforward, but the third step required me to create a class to handle everything related to the GLSL program.

So i wrote this class that can load, compile and link the shaders to the GLSL program, and also activate or deactivate the GLSL program when needed.


sabato 13 giugno 2015

Day 1: Setup

Today I set up all the necessary stuff to get started:

Visual  Studio 2013 (IDE)
SDL (window manager)
OpenGL  and glew (graphic library)
glm (math library)

Everything is working fine, and i managed to spawn a window and print a color in it with OpenGL.
I also added a class to handle errors and warnings, and i defined my own custom data types.