Jump to content
  • entries
    943
  • comments
    5,899
  • views
    924,456

Small Victories


Josh

2,924 views

 Share

Two issues in the art pipeline were giving me some doubt. I stopped working on them a couple weeks ago, and I'm glad I did because the solutions became clear to me.

 

Shader Files

First, there is the matter of shaders. A shader can actually consist of half a dozen files:

bumpmapped.opengl3.vert

bumpmapped.opengl3.frag

bumpmapped.opengl4.vert

bumpmapped.opengl4.vert

bumpmapped.opengles.vert

bumpmapped.opengles.vert

 

I originally thought the .shd extension would be good for shaders, in keeping with our extension naming scheme, but there's actually no information an .shd file even needs to contain! I also considered creating a simple format that would pack all the shader strings into a single file, and display the different ones for whatever graphics driver was in use at the time, but that approach reeked of future confusion. I'd like to still be able to open .vert and .frag files in Notepad++ or another text editor.

 

I came up with the idea to use a .shd file that contains all these shader files, but instead of packing them into a file format, the .shd file will just be a renamed .pak. That way you can easily extract the original text files, but shaders can be distributed and loaded as a single file.

 

Material Textures

I've been working with a system that uses texture names defined in the shader file. It works and it's really cool, but I think I have something even cooler. Instead of requiring a shader to define texture unit names, it would be less confusing to just decide on a fixed naming scheme and stick with it, something like this:

texture0 - Diffuse

texture1 - Normal

texture2 - Specular

texture3 - Reflection

texture4 - Emission

texture5 - Height

 

And in C++ you would have constants like this:

#define TEXTURE_DIFFUSE 0
#define TEXTURE_NORMAL 1
...

If you want to create a bumpmapped material, you can simply assign textures 0 and 1, and the material will choose a shader with the assumption those are supposed to be the diffuse and normal map. If the current surface being rendered contains bone weights, an animated version of the shader will be used. If a shader is explicitly defined, that of course will override the material's automatic selection. This way, all you have to do is drag a few textures onto a material, and 95% of the time no shader will even have to be explicitly defined. This is similar to the materials system in 3ds max.

 

The programmer in me screams that this makes no sense, since texture units are completely arbitrary, but from a usage standpoint it makes sense, since the exceptions to this paradigm probably make up less than 5% of the materials in any scene.

 

Now for custom shaders, you might end up with a situation where you are dragging a texture into the "reflection" slot, when it's really going to be used to indicate team colors or something, but it's still far simpler to say "set the reflection texture with...". Everyone knows what you mean, textures can be set in code without having to look up the slot number in the shader, and there's no ambiguity.

 

Anyways, that's just two small design problems overcome that I thought I would share with you. I think the texture issue really demonstrates the difference between engineering and product design.

 

http://www.youtube.com/watch?v=5U6Hzjz5220

 Share

7 Comments


Recommended Comments

Sometimes it's good to take a break to let things sink in a little .. also good song selection the past two blogs!!

Link to comment

Macros in C++ can easily be avoided like this

 

Instead of

#define TEXTURE_DIFFUSE 0
#define TEXTURE_NORMAL 1

 

do this

const int TEXTURE_DIFFUSE = 0;
const int TEXTURE_NORMAL = 1;

Link to comment

Even better:

 

enum TextureMode
{
   TextureMode_Diffuse, /* = 0 if you want to, but I don't really see the need to...*/
   TextureMode_normal
};

 

The main problems with defines are really simple: 'They are not subject to any C++ rule what so ever.' The precompiler just replaces them in place, so you can define them again at a later point in builds, even undefine them, ... with all undefined behavior and strange errors.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...