Sign in to follow this  
skyfire360

OpenGL Engine design concerning Effect files

Recommended Posts

Recently I've begun coding my second entire engine from scratch using DirectX this time instead of OpenGL, including the window framework, effect shader files, and mesh/texture/effect control units. While doing some research on the web for tips on engine design and messing around in the new nVidia FX Composer, I stumbled upon the Unreal 3 engine's tech demo (a mind-blowingly beautiful engine, I must say). However, there was one quote by the narrator that threw me for a loop: "Complex materials are the key to next generation graphics in games. Unreal Engine 3 gives *artists* complete control over powerful pixel shader 2.0 and 3.0 effects. All materials in this level were created by a level designer and *required no programming whatsoever*." The first time I heard this phrase I thought to myself, "Neat, that was all done in Pixel Shaders!" and moved on without thinking much about it. However, when I showed my roommate the dech demo video, I heard it again and it baffled me. Required no programming whatsoever? Does that mean engine programming will become a lost art and game programmers will be left only to do AI and networking code? After calming down and telling myself not to panic, I thought about the above phrase and was left with quite a few questions... My current engine was set up like so: Model files (my own format) -Each model file contains a number of meshes -Each mesh has exactly one attached effect file attached -Each effect file contains one technique that will be applied to the mesh, contianing all the texturing, animating It is my understanding that you cannot apply more than one Effect File/Technique to any mesh drawn between the effectFile.begin() and .end() calls. If you had a technique that used vertex shaders to "wiggle" verticies and another technique that was used to "balloon" verticies, in order to combine them one would need to write another shader with both of them combined. Another example would be a pixel shader that textures a cube and another pixel shader that applies a dull, metallic look on top of a cube. Designing my engine this way made me realize that I was going to run into some problems fairly quickly. If I were to use this method for everything in my scene, it would become cumbersome in short order. Take a skyboxe for example - it could be loaded as a cube mesh with the position of the center linked to the camera's position and another giant quad or two for cloud layers, another quad or two for sun and/or . while it would be very easy to get an animated cloud layer in there, I would most likely have to code it into a specific skybox class if I wanted to change the type/look of the clouds on the fly. And forget about blending between time "states" in shaders (bright->dusk->night), that would just prove to be a heniously comlicated shader file. Most of that would have to be done in its own skybox class on the cpu, kind of defeating the use of effect files for every model. This would also mean a rediculously large number of .fx files, and I don't believe that Pixel/Vertex Shaders were designed for this purpose The nVidia's FXComposer, from the little that I have played with it, seems to have quite a number of things going for it: - Multiple texture loading done quick and easy - Model loading done in-file - Effects with many techniques (see "wiggle"/"balloon" above) - Allows easy interface with 3D Studio Max - Allows model designers to make models and apply effect files to see the precise result ingame Thus far I've resisted the temptation to cave in and use FXComposer for a few reasons... - I'm extremely wary of being locked into one type of file format (directx model file and .dds) - Call me power hungry, but I feel kind of cheated giving all visual control to the artists - I suffer from severe "Programmer Art" - the imagination is there but the 3DMax skill is not - Less (no?) control over vertex/normal/texcoord/index buffers - Tricky naming conventions for all parameters (every model used in an engine using FXComposer would have to have a parameter named "matrix modelViewInverse", for example) Does anyone have any tips on how to go about managing all the effect files and models and meshes and textures I'm going to need in my engine? Should find a few good artists that know how to use FXComposer? Should I cave in and learn FXComposer myself?

Share this post


Link to post
Share on other sites
FX Composer should be the programmer's IDE for developing shaders. It can be used by artists, I guess, but the bulk of the work done in FX Composer is writing the vertex and pixel shaders. This should be the programmer's job - not the artists.

I believe there is a DX9 Material plugin for 3ds Max that lets the artist import an FX file. From there, they can tweak all of the parameters and save them to file. This is the ideal environment for the artists to be working in - they don't have to deal with the code - just configuring the variables to what is good.

I'm not exactly sure what was meant by "All materials in this level were created by a level designer and *required no programming whatsoever*". However, I think that they are probably using fragment linking, where they have many little fragments of shader code, and then piece them together. This would allow the artist to say "oh yea, I want this, this, and this done in this shader". It's really useful - check out ID3DXFragmentLinker.

Share this post


Link to post
Share on other sites
I work with an artist that actually writes shader code. He uses Max7's built in DX9 Shader support and writes full effect framework (*.fx) files that have HLSL shaders and techniques and so forth.

I then take his shaders and make game engine versions (mainly because Max's interface to the shader is a little different then our engine's). Usually, I just have to adjust the vertex shader to do the correct transform based on the object type and adjust the Vertex Input format. Plus the Max shaders have all the passes in one technique, where the game engine splits them into seperate techniques because of our rendering pipeline. It's really not a lot, I can get one in game in 15 minutes or so depending on complexity.

The place where I do a lot of shader work is in writing the fallback versions for 1.4 and 1.1 pixel shaders and 1.1 vertex shaders. He writes them using SM 2.0.

Anyway, it works fairly well, and he's savvy enough to not go nuts on the shaders so that our game will run well. Some of the time the fallbacks are simply just compiling with vs_1_1 instead of vs_2_0, and so forth.

Of course, most of the artists look at the shader code and go cross-eyed. I guess it's rare to have one that can do it well.

I think some form of this method (perhaps a compromise that is easier for the less savvy artist types) is what we will move to in the future as hardware gets even more powerful and art tools improve.

Getting the look they want is an art, making it work in the game and be fast is my (a coder) job.

Share this post


Link to post
Share on other sites
They (epic) showed this off at GDC last year. They have an editor that allows the artist to choose several textures and several techinques, and drag them together into a final shader. It was a very cool tool that allowed for drag and drop simplicity to make incredible effects. No coding involved.

Share this post


Link to post
Share on other sites
Quote:
Original post by bit64
They (epic) showed this off at GDC last year. They have an editor that allows the artist to choose several textures and several techinques, and drag them together into a final shader. It was a very cool tool that allowed for drag and drop simplicity to make incredible effects. No coding involved.


This sounds really cool. Although I haven't seen the demo, I envision a kind of WYSIWYG editor for materials. You can just add different fragments onto the effect, which are dynamically linked at the end. Would you happen to have the video of this?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this