There are two basic different kinds of shaders:
- Vertex shaders
- Pixel shaders
Just about everything you see in HeroEngine is rendered on the display using a shader.
Effect Shaders and Effect Permutation Shaders
There are two types of shaders in HeroEngine: effect shaders, and effect permutation shaders.
Effect shaders are shader programs that are compiled and executed to display a single graphical effect. Wireframe is an example of an effect shader, because regardless of lighting or other client engine settings, wireframe is always rendered exactly the same way.
Effect permutation shaders are shader programs that are compiled multiple times, each time with a different set of conditional compile flags in order to handle different render situations. Skin is an example of an effect permutation shader as the number of lights may vary in a scene, and the shader must be compiled into different permutations to handle each different number and type of lights.
Shader Repository Locations
Shaders are stored in the Repository under the $/HE/Render/... directory.
There are two sets of shader directories that always go together /Effects, and /EffectPermutations.
These directories will be followed by a number indicating the last HeroEngine version where they were updated for release, for example: /Effects40 and /EffectPermutations40
Sometimes you may see multiple pairs of these folders, and you usually want the pair with the highest number after them.
You can edit HeroEngine shaders by updating them just like any other Repository asset.
However, please be aware that when we send out a major update which includes Repository data changes, we may increment the version number of the effect directories, or overwrite a shader if we've also modified it.
Editing Shaders Locally
In order to iterate on the development of shaders, you can edit them locally and then upload your changes to the repository for everyone to use when your changes are complete.
To do this, create a file called client.ini in the HeroEngine installation directory. This is the directory that heroblade.exe is in, and probably looks something like:
Within client.ini file, add the following lines:
This will indicate to the client engine to load the shaders locally instead of from the repository.
Now, copy the $/HE/Render/... directory from the Repository to the local HeroEngine installation directory.
You will at need at least the two current effects directories, so you should have something that looks like this:
C:\Program Files\HeroEngine\HEROBLADEHC001\Render\Effects65\ C:\Program Files\HeroEngine\HEROBLADEHC001\Render\EffectPermutations65\
You can edit the shaders locally, and once you are done, copy them back to the Repository directory.
Specifying Custom Shaders
Custom shaders can be specified by typing them into the Shader field of the Hero Material in Autodesk Max or Autodesk Maya.
For example, entering "mycelshader.fx" into the Hero Material will utilize the mycelshader.fx file when shading the mesh for display in HeroEngine. The ".fx" file extension is required, and if not added by the user, will be automatically appended.
Leaving the Shader field of the Hero Material blank, or empty, will result in the use of the default shader.
Hair utilizes a special shader, and checking the "Hair" checkbox will override the specified shader regardless of what the value is.
Specifying a Custom Static Mesh and Boned / Dynamic Mesh Shader
Static shaders, or non-permutation shaders, are placed in the /Effects directory.
When a custom shader is specified in the HeroMaterial (e.g.: “glow.fx”), HeroEngine will automatically look for a bone supporting version (e.g.: “glow_bones.fx”)
You don’t have to supply both versions, and you can make the basic one static or bone-based at your discretion. But if you do have both of them, all your assets which reference the shader will render properly without worrying about extra naming conventions or issues.
Specifying a Custom Permutation Shader
Permutation shaders are placed in the /EffectPermutations directory.
When the custom shader name includes the word "permutation" (e.g.: "glowpermutation.fx"), HeroEngine will treat it as a permutation shader. Referencing the previous discussion above, permutation shaders are essentially shaders which participate in scene lighting and shadowing. They are compiled multiple times with different parameters in order to generate final shaders which meet the specific set of lights and lighting conditions that are found in the scene.
Typically, the existing "lightpermutations.fx" is a good starting point for creating a custom permutation shader.
Shader Constants and Variables
NOTE: This section discusses functionality for an upcoming release of HeroEngine
The following constants and variables are exposed to shaders by the HeroEngine renderer.
|Variable Name||Type||Additional Notes|
|Samplers||int||Number of samplers in use by the shader|