Monday, October 23, 2006

Long time, no see.. erhm.. update.

I haven't worked on the engine for quite some time now. I've had lots of other stuff to do.
This semester I've taken a course in mobile computer graphics. A really great course that have given me a lot of useful knowledge about graphics hardware.

In course we had to do a mobile game project using the M3G (JSR-184) Java API, and once again I teamed up with Jesper Ek. We decided to do something different and we ended up doing a OpenGL accelerated J2SE implementation of M3G. There was a competition to award the greatest game. We obviously didn't win, since we didn't make a game:) We received a Technical Achievement Award, however. The jury consisted of people from the industry, including folks from Sony Ericsson, TAT and LUGG.

You can check out the project here, and the other game entries here (some are really cool!).

What about my engine then?

It's discontinued. Yep. Discontinued.

I have decided to not develop it any further and instead start on a completely new engine using Microsoft XNA!

My old engine was 100% graphics API independent and that's of course a good thing. However, being a single developer with very little spare time, that resulted in slowing down the project considerably. By selecting only one API, I will be able to speed up the development and focus on the cool stuff.

XNA is of course the obvious choice.
It still lacks some important functionality, but I'm very confident that that will be addressed when it's finally released. Micsosoft seems very serious about XNA and I think it has a bright future.

And yeah, I've "upgraded" to the new Blogger beta, so I changed to a new blog template. Sweet.

Saturday, June 17, 2006

Today I added refraction to the water. Pretty standard stuff where the reflection and refraction textures are blended together based on the fresnel term.

I've also improved the texturing a bit. If you look at the second image in my last post, you can see that the terrain at "medium" distance from the camera is blurry. I now use yet another detail texture in this region and the result is that the terrain appears to have detail at all distances.

Tuesday, June 13, 2006





Well, It has been a while since I had time to work on the engine, but today I had some time left.
A few days ago a found a tool called L3DT. It's a very cool and capable terrain generator and it inspired me to improve the texturing of the terrain.

Near the camera I use the same splatting technique as before but the textures are tiled at a much higher density so the ground look really highly detailed even if you look straight down. This ofcourse causes ugly repetition patterns further away. To hide this I blend in a large (1024x1024) color texture on terrain far from the camera.

I've also changed from vertex lighting to a normal map. This makes the lighting independent of the LOD and reduces popping artifacts. It also makes the distant terrain look more detailed.

I use L3DT to generate all texture data I need, since it does that a lot better than my own hack;)

Friday, May 26, 2006

Well, Jesper and I have finished the final assignment in the ASR course. This time it was about shadows.

We implemented both shadow mapping and z-fail shadow volumes. All done on the GPU. The geometry needs to be preprocessed for shadow volume extraction to work entirely on the GPU.

The shot shows "soft" shadow mapping with 3x3 PCF.

Nothing special, but I have to fill my blog with something when I don't have time to work on the engine:)

Btw, my lecturers got their paper "High Dynamic Range Texure Compression For Graphics Hardware" accepted to SIGGRAPH 2006. Really sweet stuff!

Tuesday, May 16, 2006

Well, I'm back from India. It was a great vacation and it feels a bit strange to be home, but I guess it's time to get back to normal life.

The image is a shot from an ocean water simulation I did for an assignment in the ASR course. It features two superpositioned Gerstner waves calculated in a vertex shader.

In the pixel shader I use three scrolling normal maps to add fine detail to the water. There's also cubemap reflection and refraction with fresnel terms. Finally there's a simple HDR hack to add some shininess to the highlights.

When I have time to work on the engine, I'll probably update the water with a similar approach.

Saturday, April 22, 2006

As some might have noticed, I haven't updated the blog for some time now. The reason is that I'm on vacation in India with my girlfriend. I'll be staying here for three weeks so there will be no coding for a while:)

I just wanted to thank everybody who have left comments and sent me email. It's very encouraging and makes me want to keep on going!

In a few hours we're leaving for Kerala. It's supposed to be a real paradise and I think we'll have a great time!

Monday, April 10, 2006

Yesterday I did a quick test of grass rendering.
The grass waves slowly in the wind and is rendered as thousands of camera facing billboards. The nice thing is that everything is done on the GPU. The billboards are stored in one single static vertex buffer and the transformation to face the camera and the animation is done in a vertex shader.
I'm also using a neat trick to "fade" the grass out over distance without the need of alpha sorting.

It's not that good looking right now, but it's just a quick test. Putting it on real terrain with more variation of foliage and good texturing and lighting will hopefully make it look better.

Friday, April 07, 2006

I got stuck when trying to redesign my engine to better support materials that depend on multiple render passes. So I started working on a cloud system instead:)

The system if fully dynamic and the clouds move and deform. The lighting is a (rather) simple trick but looks quite nice. I got the basic idea from an article by Michael Gehling in last months GDMag. I just modified it to suit my needs. The main problem I have is that it's very hard to tweak the system to look good in all situations. Settings that look good at dawn look crap at noon and vice versa. But I think I can solve that by interpolating settings over the day-night cycle.

Another problem is that things are getting rather costly as you can see on the fps counter:) So far I've done no optimizations what so ever so I think I can squeeze quite a few more fps out of this baby.

Here's a few new screenshots:




Tuesday, April 04, 2006





I've added water to the engine. So far there's only reflections but refractions are coming up.

Now I need to render the scene multiple times per frame. The geometry that is going to show up in reflections is first rendered to a texture. This texure is then used in a second pass where the scene is rendered as normal but the reflection texture is projected onto the water plane. The same has to be done for refractions. The reflection pass is done with a lower LOD setting to increase speed, and the distortion of the water makes it very hard to notice the decreased LOD anyway.

I'm not totally happy with the way these multiple render passes are handled by the engine, so I think I have to redesign a bit. That's why I left out refractions for now.

Monday, April 03, 2006





For the second assignment in the ASR course we took a dive into the beautiful world of Global Illumination.

We had to write a Monte Carlo path tracer. The math is a bit involved but it all boils down to a very simple algorithm. Take a loot at this slide for more information.

What you gain in simplicity you loose in speed. Since we approximate the rendering equation with random sampling (Monte Carlo integration) we need to sample a lot to reduce noise. The first image was redered at a resolution of 1024 x 1024 with 625 samples per pixel. It took 72 minutes to complete. The second one uses 2304 samples per pixels and took about 6 hours to render:)

I really like the second image. Note the caustics formed by light passing through the glass objects. Quite pretty! Kudos to Jesper for setting up that scene!

Thursday, March 30, 2006

I've completed the atmospheric scattering implementation, and now the terrain is also affected by the scattering. Here's a few screenshots:




Wednesday, March 29, 2006

I'm working on a fully dynamic sky system. It's far from finished but I couldn't resist uploading a teaser screenshot:)

The system simulates atmospheric scattering, i.e. the effect of sun light scattering in different directions as it hits particles in the atmosphere.
This is what makes the sky blue at noon and red at dawn.
The method is described in this paper.

The sun in the picture is not a skybox or a billboard. It's a direct result of the scattering simulation!

I'll get back with more info as soon as I get this working perfeclty.

Tuesday, March 28, 2006






Good procedural terrain texturing is not easy to achieve. That I learned yesterday.

In the old screenshots I used only one big blurry color texture and one detail texture. This wasn't very realistic since all types of surfaces used the same detail, resulting in for example that grass did not look like grass if I used a rock texture.

Now I use one argb detail texture per surface type and blend them together using a blend controller texture in a pixel shader.

The hard thing is to generate the blend texture. I've made a small tool that generates the this texture based on parameters in the heightmap like elevation and slope. However the result is not as good as I would like. But post-processing the texture in photoshop yields acceptable results;)

Monday, March 27, 2006






Jesper and I have finished the first assignment in the "Advanced shading and rendering" course. We were given an unfinished raytracer and had to implement shading, shadows, reflections, refractions and super-sampling.

We had to implement at least one super-sampling scheme but we decided to make a comparision between a few schemes and ended up implementing uniform grid, stratified grid and adaptive. The latter is especially intresting since it tries to distribute the rays over the pixel area in a optimal way, resulting in good image quality and fast rendering.

The top screenshot shows the test scene rendered with 5x5 uniform grid super-sampling and the bottom shot is a close-up comparison between different sampling schemes.

Saturday, March 25, 2006

Today I extended the engine with support for vertex and pixel shaders.

Right now I have support for shaders written in HLSL but to the engine shaders is an abstract concept so there is nothing stopping me from adding support for other shading languages like Cg and GLSL transparently in the future.
Shaders are integrated into the effect/material system and I have a clean and simple interface for setting shader parameters from the engine. I intend to add support for automatic passing of common parameters like transform matrices to the shaders. Using shaders will be almost as easy as using the fixed function pipeline.

The terrain in the screenshot is rendered with per-pixel diffuse lighting and fog, using a pixel shader. In this kind of scene there is not much visual difference between per-vertex and per-pixel lighting, but when the sun is moving it's more apparent. Also the per-pixel fog is a lot smoother.
I use a slightly reddish sun color to give the impression of late afternoon lighting.

Now, with shader support in place, I can start doing some cool stuff :)

Thursday, March 23, 2006

I've done some minor improvments to the engine.
I added collision detection with the terrian so that the camera alywas stays on the ground.

I have also begun coding on a light management system. Until now I have hardcoded the sun into the renderer but now I have a more flexible system that handles unlimited (sort of) number of dynamic lights. Still need to add smarter culling of the lights though.

Wednesday, March 22, 2006

Since I have a lot less to do in school now, I've started working on the engine again.

Today I finished the terrain LOD system. I'm using the popular GeoMipMapping technique and it works very well. To the left you can see two screenshots taken from the same viewport. The top picture shows brute-force rendering of the terrain and ~2 million triangles are drawn. In the bottom picture the LOD is activated and only ~45k triangles are drawn. That's only ~2% of the original triangles!

It's pretty hard to see any difference in the pictures, but if you look at the distant mountains you are able to see that the bottom picture misses some of the detail.

When the camera is moving it's sometimes possible to notice some popping when the terrain patches changes LOD but still I think the result is quite good for such a simple technique.

Sunday, March 19, 2006

The last few days I've been writing a simple I/O library in x86 assembly for a course at uni.
We had to use the GNU assembler and debugger. It's not my idea of fun to use command line tools like that ;) It was a pain in the butt in the beginning but I got used to it quite quickly.

The GNU assembler is a bit different from other assemblers like MASM. It uses different directives and instruction syntax. The instruction parameters is reversed and you have to use the %-prefix for registers.

movl eax, ebx

becomes:

movl %ebx, %eax

A bit anoying at first, but the parameter order actually feels more natural to me since I used to do a lot of MC68000 coding.
It's been a long time since I did this much assembly coding and while it's fun to optimize small routines, it's mostly annoying to write longer programs ;)
It's a good thing that high level languages gives us enough speed nowadays.

Wednesday, March 15, 2006

The exams are finally over!
I haven't got the results of all of them yet, but I think I passed them all.

Today, I had the first lecture in Advanced shading and rendering. The lecturer is Tomas Akenine-Möller, one of the authors of the legendary Real-Time Rendering. That's pretty cool. I have high expertations of this course, and I don't think I'll be disappointed.

In this course we're using C++, so no more Python for a while! That's a good thing:)

Tuesday, February 28, 2006

We have released our Bomberman clone! One minute before deadline:) It's not fast, it's not perfect, and it's certanly not bug free. But considering that it was put together in more or less one weekend we're very happy with the result.

You can check it out and download it here.

You can take a look at the work of the other project groups here.