(Redirected from Effect shaders)
Jump to: navigation, search


A Shader is a small program which runs on the graphics processor.  It is written in a special scripting language called HLSL (High Level Shader Language) for Direct3D.

Shaders interact with multiple systems in HeroEngine, such as Environment Schemes, Meshes, Displacement mapping, Shadows, and Dynamic Sky.

There are two basic different kinds of 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.

Editing Shaders

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:

C:\Program Files\HeroEngine\HEROBLADEHC001

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
DiffuseMap Texture
DetailMap Texture
SecondLayerDiffuseMap Texture
SkinMap1 Texture
SkinMap2 Texture
SkinMap3 Texture
TintMaskMap Texture
SecondLayerTintMaskMap Texture
NormalMap Texture
NormalMap2 Texture
NormalMap3 Texture
NormalWithSpecularMap Texture
SecondLayerNormalMap Texture
MacroMap Texture
MacroUVScale Texture
MacroMapScaleMatrix Matrix
ShadowDepthMap Texture
ShadowLowDetailDepthMap Texture
NormalizingCubeMap Texture
NoiseMap Texture
AttenuationMap3D Texture
SpecularShiftMap Texture
SpecularMaskMap Texture
FFHairDot3Map Texture
FFHairLerpMap Texture
DiffuseLightColor Float4
BackLightColor Float4
DiffuseLightColorWithIntensity Float4
AmbientLightColor Float4
DiffuseLightDirection Float4
SpotLightDirection Float4
DiffuseLightPosition Float4
DirectionalLightIntensity Float
LightRange Float
LightIntensity Float
Att2 Float
Att1 Float
Att0 Float
SpotTheta Float
SpotPhi Float
SpotCosThetaDiv2 Float
SpotCosPhiDiv2 Float
SpotReciprocal Float
CameraPosition Float4
CameraOffset Float4
WorldMatrix Matrix
ViewMatrix Matrix
ProjectionMatrix Matrix
WorldViewProjectionMatrix Matrix
ViewProjectionMatrix Matrix
InverseWorldViewMatrix Matrix
InverseViewMatrix Matrix
InverseProjectionMatrix Matrix
WorldViewMatrix Matrix
InverseWorldMatrix Matrix
BoneMatrixPalette Matrix array
FadeFactor Float4
Clock Float
TexTransform0 Matrix
FogColor DWORD
Samplers int Number of samplers in use by the shader
ShadeColor Float4
TexFilter DWORD
LightViewProjectionMatrix Matrix
LightCompositeMatrix Matrix
ShadowScreen Texture
RainNormalMap Texture
FogAtt0 Float4
FogAtt1 Float4
MipReferenceMap Texture
AnimUV Float4 Array[2]
AspectRatio Float
InvAspectRatio Float
EnvironmentMap Texture
Reflection Float
OverrideColor Float4
DoVertexColor Float

See also

Personal tools