![]() |
Thomas, 2008-03-10, "The unseen stuff" - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Frictional Games (https://www.frictionalgames.com/forum/forum-3.html) +--- Forum: Blog (https://www.frictionalgames.com/forum/forum-23.html) +--- Thread: Thomas, 2008-03-10, "The unseen stuff" (/thread-1899.html) |
Thomas, 2008-03-10, "The unseen stuff" - Thomas - 03-10-2008 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: Code: @ifdef UseSpecular 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 ![]() ![]() RE: Thomas, 2008-03-10, "The unseen stuff" - jo291 - 03-10-2008 Thomas Wrote:please don't quote entire posts when there is no point in quoting anything to begin with.thats pretty neat! RE: Thomas, 2008-03-10, "The unseen stuff" - Bou_Frost - 03-10-2008 Wow, that's really ... difficile ... o.O ... but it's cool to see how's a programmers dayly work is ^^ ... great Log !!! RE: Thomas, 2008-03-10, "The unseen stuff" - GrayChild - 03-10-2008 Great work Thomas! Thanks for sharing this info. RE: Thomas, 2008-03-10, "The unseen stuff" - WindexGlow - 03-10-2008 Pff, my team of monkeys could make HPL2 if given an infinite amount of time. RE: Thomas, 2008-03-10, "The unseen stuff" - Thomas - 03-10-2008 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... ![]() |