Friday, October 12, 2012

Depth of field

Hello dear development diary. I haven't touched my hobby and dusty 3D engine for months now so I decided to play a little bit! I rewrote parts of the main rendering loop to take better care to not switch GL states without a good reason, in other words I'm caching the most important state bits. I also rewrote texture and model loader to live in another thread to load the initial scene faster, this is now done with pthread and I have to think about win32 port or try to use a wrapper api there or well, maybe I should just forget about win32 :)


I also implemented a 'depth of field' that seems to work quite well together with light scattering. Closer look at the exploding mesh:


Wednesday, September 21, 2011

Bears with bounding volumes

I recently started to add some primitive collision detection to be able to place objects to scene without them overlapping each other. I calculate bounding volumes during parsing of the object data. Whenever a new vertex comes in I test it for current min and max for x, y and z. Then in the end I calculate midpoint for the mesh as well. I added a debug mode to see the bounding volumes during rendering and this is the result. This is all simple and makes development and debugging much easier. Highly recommended step to do at the very beginning.



I've also rewritten the scenegraph part of the engine so that all CPU work (like the matrix calculation) happens before any GPU work. This meant a lot of refactoring but now I can enjoy much higher FPS rates even with a lot of complex geometry like exploding the buddha mesh and so on.

As next step I will experiment more with the explosion stuff, I want to add more physics. I already did some trials to rotate triangles while they fly but it did not really look that good, I probably will try to add per triangle velocity vertex attribute and apply gravity so that the pieces fall down. One problem also is that when I do the explosion in vertex shader my bounding volumes are not reflected to this change as shown below.


Tuesday, August 09, 2011

Exploding objects

Few months have passed and I've basically rewritten all internals of the engine. Now there is much more generic scenegraph with nodes that reference to objects that then may have one or multiple meshes. While cleaning things up I removed a lot of unnecessary calls bringing some performance up and making it simpler to test more complex scenes. There is a factory class to create terrains and tunnels dynamically and in the future possible other meshes. I also wrote freetype2 support so that it is easy to test and use different fonts.


I started to write 'effect' support which in practice means that scene will pick a particular shader program attached to the node and animate its attributes, offsets and so on. First I started to work on 'explosion' that animates vertices along face normal with an offset. I'm pretty satisfied with the results so far. Plan is to either fade away pieces while making them smaller, or possibly just let them hit the floor after initial 'radial' movement.


Monday, May 23, 2011

Normal tricks

I just spent some time rewriting the model loader. Old one was originally done to a software rasterizer and did not handle per vertex normals correctly. Now that I *finally* rewrote it, I can remove quite a lot of code that just sit there because of dependency reasons with the old SW engine :) Now mesh can have 2 modes, one with face normals that make the object look a bit like a sculpted wooden statue and another mode with per vertex normals that implement Blinn-Phong 'correctly'.

Wood statue :

For wood statue each vertex in a face gets the face normal, so each vertex normal points to the same direction.

Blinn-Phong :



For Blinn-Phong each vertex normal is the normalized sum of normals of all adjacent faces to the vertex.

Saturday, May 14, 2011

Light scattering

I got bored with the engine and decided to just play with effects for now. Here is real time light scattering, like explained in in Fabien Sanglard's blog. I plan to mix this with the earlier bloom shader and see if the thing still runs 60fps. It seems Acer laptop did not like light scattering though, both CPU and GPU temperature peaked very high and my laptop powered off itself, maybe some optimizations needed, eh :)

Tuesday, May 03, 2011

Hairy Balls!


I started to try out a bit more experimental things and implemented sort of a grass effect by abusing the normal data and drawing some GL_LINES per vertex. Looks nice, needs some more touch though ... more on that hopefully later.

Friday, April 29, 2011

Happy Buddha


Lighting is now fixed and speculars are finally moving according to camera and light position. In the end bug was simple but hard to notice, I forgot to normalize camera vector in the shader which made it *very* big compared to light vector in the lighting equation so light movement did not cause any changes and only camera did. Also pick feature got fixed on the way while porting recent changes to win32 build. Now it is time for new features and optimize the mesh loader, it takes ages to load buddha model :)