The mesh shader is customizable with four global variables (window object).
Variables | Description | Type |
--------------------------------- | ------------------------------------------- | ------------- |
__MESH_SCENE_SLOT_NAMES__ | The scene custom slot names | Array<string> |
__MESH_MATERIAL_SLOT_NAMES__ | The material custom slot names | Array<string> |
__MESH_VERT_BEGIN__ | Insert code at begin of vertex shader. | string |
__MESH_VERT_END__ | Insert code at end of vertex shader | string |
__MESH_VERT_OUT_POSITION__ | Replace vertex output position | string |
__MESH_VERT_OUT_FRAG_POS__ | Replace vertex output world position | string |
__MESH_VERT_OUT_FRAG_UV__ | Replace vertex output uv | string |
__MESH_VERT_OUT_FRAG_COLOR__ | Replace vertex output color | string |
__MESH_VERT_OUT_FRAG_NORMAL__ | Replace vertex output normal | string |
__MESH_VERT_OUT_FRAG_TANGENT__ | Replace vertex output tangent | string |
__MESH_VERT_OUT_FRAG_BINORMAL__ | Replace vertex output binormal | string |
__MESH_VERT_OUT_FRAG_SHADOW_POS__ | Replace vertex output shadow map position | string |
--------------------------------- | ------------------------------------------- | ------------- |
__MESH_FRAG_BEGIN__ | Insert code at begin of fragment shader | string |
__MESH_FRAG_END__ | Insert code at end of fragment shader | string |
__MESH_FRAG_PRE_TEXTURE__ | Insert code before custom texture access | string |
__MESH_FRAG_POST_TEXTURE__ | Insert code after custom texture access | string |
__MESH_FRAG_OUT_BASE__ | Replace fragment output color (color buf) | string |
__MESH_FRAG_OUT_NORMAL__ | Replace fragment output normal (normal buf) | string |
__MESH_FRAG_OUT_ID__ | Replace fragment output id (id buf) | string |
Create a shader.ts file at the same level of your main.ts.
Set variables of your choices and import the script in index.html on top of main.ts.
By this way all these variables are set before the engine start and by extension before the shader program compilation start.
Variables | Scope | Type | Description | BEGIN | END |
------------- | ------- | -------------- | --------------------------------------------- | ------------- | -------------- |
position | Var | vec3 | Vertex position | ||
texUV | Var | vec2 | Vertex uv | ||
color | Var | vec3 | Vertex color | ||
normal | Var | vec3 | Vertex normal | ||
tangent | Var | vec3 | Vertex tangent | ||
binormal | Var | vec3 | Vertex binormal | ||
posFromLight | Var | vec4 | Vertex position from light source shadow-map | ||
output | Var | VertexOutput | The vertex shader output | ||
------------- | ------- | -------------- | --------------------------------------------- | ------------- | -------------- |
LVP_MATRIX | Uniform | mat4x4 | Light view projection (shadow-map) | ||
SCENE_INFOS | Uniform | SceneInfos | Various scene informations | ||
MESH_INFOS | Uniform | MeshInfos | Contains matrices and mesh identifier | ||
MAT_PARAMS | Uniform | MaterialParams | List of float material parameters |
Variables | Scope | Type | Description | BEGIN | END |
------------------------ | ------- | -------------- | --------------------------------------------- | ------------- | -------------- |
fragPos | Var | vec3 | Pixel world position | ||
fragUV | Var | vec2 | Texture uv | ||
fragColor | Var | vec3 | color | ||
fragNormal | Var | vec3 | normal | ||
fragTangent | Var | vec3 | tangent | ||
fragBinormal | Var | vec3 | binormal | ||
fragShadowPos | Var | vec3 | shadow direction | ||
normalUV | Var | vec3 | normal uv | ||
outputColor | Var | vec4 | Output color (default: 0, 0, 0, 1) | ||
texel | Var | vec4 | Texel color (default: 1, 1, 1, 1) | ||
textureUV | Var | vec2 | Texture uv after scrolling | ||
shadow | Var | float | Shadow-map factor | ||
matS0 | Var | vec4 | Texel from free material texture 0 | ||
matS1 | Var | vec4 | Texel from free material texutre 1 | ||
s0 | Var | vec4 | Texel from free texture 0 | ||
s1 | Var | vec4 | Texel from free texture 1 | ||
output | Var | FragOutput | The fragment shader output | ||
------------------------ | ------- | -------------- | --------------------------------------------- | ------------- | -------------- |
MESH_INFOS | Uniform | MeshInfos | Contains matrices and mesh identifier | ||
SCENE_INFOS | Uniform | SceneInfos | Various scene informations | ||
DIR_LIGHT | Uniform | DirLight | Directionnal light informations | ||
POINT_LIGHTS | Uniform | PointLight[] | Point light list | ||
SPOT_LIGHTS | Uniform | SpotLight[] | Spot light list | ||
DECALS | Uniform | Decal[] | Decal list | ||
FOG | Uniform | Fog | Fog informations | ||
MAT_COLORS | Uniform | MaterialColors | Material colors (ambiant, diffuse, etc...) | ||
MAT_PARAMS | Uniform | MaterialParams | Material parameters for some settings | ||
MAT_UVS | Uniform | MaterialUvs | Material uv scrolling | ||
MAT_TOON_LIGHT_DIR | Uniform | vec3 | Material toon light direction | ||
MAT_TEXTURE | Uniform | Texture | Color texture | ||
MAT_DISPLACEMENT_TEXTURE | Uniform | Texture | Displace the color texture | ||
MAT_DIFFUSE_TEXTURE | Uniform | Texture | Diffuse color texture | ||
MAT_SPECULAR_TEXTURE | Uniform | Texture | Specular texture (color and specularity) | ||
MAT_EMISSIVE_TEXTURE | Uniform | Texture | Emissive color texture | ||
MAT_NORM_TEXTURE | Uniform | Texture | Normal map texture | ||
MAT_ENV_MAP_TEXTURE | Uniform | Texture | Env map texture | ||
MAT_TOON_TEXTURE | Uniform | Texture | Toon details texture | ||
MAT_S0_TEXTURE | Uniform | Texture | Free material texture 0 | ||
MAT_S1_TEXTURE | Uniform | Texture | Free material texture 1 | ||
DECAL_ATLAS_TEXTURE | Uniform | Texture | Decals texture | ||
DECAL_ATLAS_TEXTURE | Uniform | Texture | Decals texture | ||
SHADOW_MAP_TEXTURE | Uniform | Texture | Shadow map texture | ||
S0_TEXTURE | Uniform | Texture | Free texture 0 | ||
S1_TEXTURE | Uniform | Texture | Free texture 1 |
For numeric there is:
About texture there is: