Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

Archive for February, 2014

An update

So this is how the current shading looks like now, around 100 lights are rendered. The light attenuation is a bit too weak at the edges I’ve noticed so I’m playing around a bit with the values, it’s nothing I’m too concerned over right now though. Here’s how it looks like currently:


Stencil culling optimization

I optimized the code by using whats known as stencil buffer optimization as well as cleaned up a lot of test code and other features. The result below looks a bit iffy since I exaggarated the parameters for the light attenuation enough that you can’t really tell that the light gets weaker around the sphere. I’m rendering 100 point lights and one directional light currently.

deferred shading done

For the stencil optimization I basically worked from the picture below:


Where the vectors represent vectors from the camera to the screen that cross certain objects, if we base our stencil optimization on this technique we can see a few things happening. If we set the stencil test to always succeed and then increment the stencil value depending on the depth test, you can see that if you focus on the spheres front/back face, in the case of object A the sphere fails both the back and the front test, while for object C it wins both tests. Then if you look at object B you can see that it wins the front test, but fails the back test, knowing this you can set a few parameters for the stencil operation. If the back facing polygons fail the depth test you increment the value in the stencil buffer and if the front face fails the depth test you decrement the value, this ensures that only the relevant fragments will be shaded and not the entire screen like I had previously.


I didn’t run into many problems implementing this as I found some good information on how to do it. The only “problem” I had was that when I loaded my quad for the directional light I forgot to set all the triangles in a counter clockwise ordering which resulted in the culling messing up the screen a bit like in the picture below. It was easily remedied but it’s interesting to look at since it shows the result of the point light pass in the top left and how everything is merged together in the bottom right.



Now I will focus this day on cleaning up the code, making everything look a bit better and begin implementing the tiles.



Crude Deferred Shading implemented!

So today I finished implementing a really basic and unoptimized deferred shader. The basic rundown of what I did today is basically:

– Use the data gathered from the geometry buffers and use them to calculate basic directional light on every fragment by sampling the textures.

– Run a second pass with a shader meant to calculate the point lights, using the following attenuation formula

threshold (1)


And here’s the current results, just using three lights and some textured cubes, as you can notice the z depth test isnt implemented yet and so things that arent actually in the light gets lit up.



Tomorrow I aim to implement some handling so I can spawn as many lights as I want as well as fixing and testing for the depth before I compute the lighting and get it to look reasonably well.



Bug fixed

After some careful debugging using ApiTrace and gDEBugger the bug was finally traced down and eliminated, as it turns out there was just a simple texture management problem that wasn’t as thought out as I thought it would be. This in turns explain why only one framebuffer malfunctioned, the result ¬†shown below still isn’t very pretty but I’m optimistic about being done with this shading technique by tomorrow night.



Milestone 2

The first week I spent researching the subject as well as implementing a math library, a scenegraph, camera and so on. After that I began implementing regular old Deferred Shading and I encountered some interesting problems. So far I’ve written the shaders and the geometry pass which is used in the tiled techniques as well. Below is a picture of the framebuffers currently used:


Now the shaders I’ve written are very basic, they include directional light as well as point lights. But now for the interesting parts, the bugs! So, for some reason one of my texture sampler gets trash values after the first initial frame pictured below. I’ve triple and double checked everything for problems in the code and nothing seems out of order, running ApiTrace seems to confirm that the values and everything are set just fine and GeDebugger can’t seem to help me find a solution either. This has so far been really annoying as it has set me back a good 2-3 days as I wanted to have the basic deferred shading implemented by the milestone meeting, but so far I don’t believe I’ll have to revise my planning as once I find the bug everything should be up and running since I’ve tried my implementating by just giving the cubes a predetermined color instead of using the textures diffuse colors and it works just fine. Below are some pictures to illustrate the problem:

frame problems

ApiTrace however confirms that all texture values are set properly and the way they should be. That’s it for this milestone, hopefully by friday I’ll have everything working properly again.