Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thomas, 2008-03-10, "The unseen stuff"
Thomas Offline
Frictional Games

Posts: 2,634
Threads: 184
Joined: Apr 2006
Reputation: 68
#1
Thomas, 2008-03-10, "The unseen stuff"

Normally you only hear about various graphical effect problems and issues regarding 3D engines. In this log I want to highlight a few other problem many 3D engine builder face, but you do not hear about as much.

Managing multiple shaders files
In HPL1 there I used a bunch of shader files, one for each specific effect I wanted to do. No specular - new shader, new light type - new shader and so on. Even though HPL1 does not have that many shader combinations I ended up with 10 or so shaders that did about the same thing with various smaller changes. This was not so hard at the start, but when I wanted to optimize it was very frustrating to have to update 10 files all the time and some optimization became a bit hackish or simply left out. There where also times when I wanted to add even more shaders to optimize for specific hardware but I just didn't have the energy to mange even more shaders, so I skipped it.

In HPL2 I am using a a custom preprocessing system that can parses the shader file before it is sent of to compilation and in that preprocessing step it is determine what different features the current shader should have. For example:
@ifdef UseSpecular
outColor = color + pow(specularComp, shinyness);
@endif
By using this I can have very few shaders and still have plenty of variation. This helps keeping the code optimized and a lot more maintainable! The reson for having a custom system is that I wanted it to be usable on different types of shaders (GLSL, CG and HLSL (if a dx version is made).

Managing combinations of shaders
Now that I have a simple way to loading various shader types I must have some good way of maintaining them. I started out by simply loading the shader "by hand", writing a line for each shader combo needed, however this turned out to be a bad idea since the number of combinations grows very quickly.

I am now working on a system where I use bit-flags to determine what variables are needed to be set before loading a shader and then loading it correctly. However this becomes even more complicated since I need both a vertex and fragment shader in each shader combination, and the vertex shader is often not changed as much as the fragment one, so I need a system that only creates a new shader when needed. This is problem is actually still work in progress but hopefully solved fully the coming couple of days.

Managing different types of shaders
In HPL1 I used only CG for shaders, but since it is developed by Nvidia it does not function good on ATI cards on some occasions. This made me switch to GLSL, OpenGL's own language, instead. I still wanted to have Cg though, since I never know if it will come in handy.

The problem with this is that Cg and GLSL function quite differently in many aspects. In CG you set vertex and fragment shaders independantly however in GLSL you need to link vertex and fragment together before you can use that combination - resulting in a program. In GLSL variables for a shader is set in this program, but in Cg they are directly in the shaders. And so on...

All these differences required me to think about the design and since I hade never coded in GLSL before starting the design I looked very carefully in specs and tutorials. However, I was not careful enough. Once all of the code was in and I was happy with how it worked, it turns out I need to explicitly set how textures are connected to a shaders in GLSL, something I had not taken into account when designing and this broke all design. Luckily I came up with the idea of setting up textures inside the actual shader using the preprocessor and this turned out to work great.

There you have a little taste on the types of problems I face on a daily basis Smile I am afraid there is no demo for this, but hopefully I have the renderer in a working condition soon and will then provide a work log with demo. For now I just leave you with a little teaser screen, giving hints on the method of rendering I have chosen Wink
03-10-2008, 08:23 AM
Find
jo291 Offline
Senior Member

Posts: 289
Threads: 43
Joined: Dec 2006
Reputation: 0
#2
RE: Thomas, 2008-03-10, "The unseen stuff"

Thomas Wrote:please don't quote entire posts when there is no point in quoting anything to begin with.
thats pretty neat!
(This post was last modified: 03-10-2008, 01:11 PM by jens.)
03-10-2008, 12:59 PM
Find
Bou_Frost Offline
Junior Member

Posts: 10
Threads: 1
Joined: Apr 2007
Reputation: 0
#3
RE: Thomas, 2008-03-10, "The unseen stuff"

Wow, that's really ... difficile ... o.O ... but it's cool to see how's a programmers dayly work is ^^ ... great Log !!!
03-10-2008, 01:06 PM
Find
GrayChild Offline
Junior Member

Posts: 19
Threads: 2
Joined: Feb 2008
Reputation: 0
#4
RE: Thomas, 2008-03-10, "The unseen stuff"

Great work Thomas! Thanks for sharing this info.
03-10-2008, 08:29 PM
Find
WindexGlow Offline
Posting Freak

Posts: 1,108
Threads: 70
Joined: Mar 2007
Reputation: -5
#5
RE: Thomas, 2008-03-10, "The unseen stuff"

Pff, my team of monkeys could make HPL2 if given an infinite amount of time.

Please -REP me.
Honestly, please do. I want to see how low I can go!!
Ignore that error message too. Just ignore it and keep going to give me -rep.
03-10-2008, 09:38 PM
Find
Thomas Offline
Frictional Games

Posts: 2,634
Threads: 184
Joined: Apr 2006
Reputation: 68
#6
RE: Thomas, 2008-03-10, "The unseen stuff"

WindexGlow Wrote:Pff, my team of monkeys could make HPL2 if given an infinite amount of time.
Well my monkeys just solved the problem I just had. Too bad they poop so much... Tongue
03-10-2008, 10:03 PM
Find




Users browsing this thread: 4 Guest(s)