#author("2024-07-29T22:25:00+00:00","default:J4Y","J4Y") #author("2024-07-29T22:25:12+00:00","default:J4Y","J4Y") * Shader customization [#xfcc3915] The mesh shader is customizable with four global variables (window object). | ''Variables'' | ''Description'' | Type | | ''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. * Table vertex vars [#aff0abca] | ''Variables'' | ''Scope'' | ''Type'' | ''Description'' | ''BEGIN'' | ''END'' | | ------------- | ------- | -------------- | --------------------------------------------- | ------------- | -------------- | | position | Var | vec3 | Vertex position |BGCOLOR(green):|BGCOLOR(green):| | texUV | Var | vec2 | Vertex uv |BGCOLOR(green):|BGCOLOR(green):| | color | Var | vec3 | Vertex color |BGCOLOR(green):|BGCOLOR(green):| | normal | Var | vec3 | Vertex normal |BGCOLOR(green):|BGCOLOR(green):| | tangent | Var | vec3 | Vertex tangent |BGCOLOR(green):|BGCOLOR(green):| | binormal | Var | vec3 | Vertex binormal |BGCOLOR(green):|BGCOLOR(green):| | posFromLight | Var | vec4 | Vertex position from light source shadow-map |BGCOLOR(red):|BGCOLOR(green):| | output | Var | VertexOutput | The vertex shader output |BGCOLOR(red):|BGCOLOR(red):| | ------------- | ------- | -------------- | --------------------------------------------- | ------------- | -------------- | | LVP_MATRIX | Uniform | mat4x4 | Light view projection (shadow-map) |BGCOLOR(green):|BGCOLOR(green):| | SCENE_INFOS | Uniform | SceneInfos | Various scene informations |BGCOLOR(green):|BGCOLOR(green):| | MESH_INFOS | Uniform | MeshInfos | Contains matrices and mesh identifier |BGCOLOR(green):|BGCOLOR(green):| | MAT_PARAMS | Uniform | MaterialParams | List of float material parameters |BGCOLOR(green):|BGCOLOR(green):| * Table fragment vars [#j60e0591] | ''Variables'' | ''Scope'' | ''Type'' | ''Description'' | ''BEGIN'' | ''END'' | | ------------------------ | ------- | -------------- | --------------------------------------------- | ------------- | -------------- | | fragPos | Var | vec3 | Pixel world position |BGCOLOR(green):|BGCOLOR(green):| | fragUV | Var | vec2 | Texture uv |BGCOLOR(green):|BGCOLOR(green):| | fragColor | Var | vec3 | color |BGCOLOR(green):|BGCOLOR(green):| | fragNormal | Var | vec3 | normal |BGCOLOR(green):|BGCOLOR(green):| | fragTangent | Var | vec3 | tangent |BGCOLOR(green):|BGCOLOR(green):| | fragBinormal | Var | vec3 | binormal |BGCOLOR(green):|BGCOLOR(green):| | fragShadowPos | Var | vec3 | shadow direction |BGCOLOR(green):|BGCOLOR(green):| | normalUV | Var | vec3 | normal uv |BGCOLOR(green):|BGCOLOR(green):| | outputColor | Var | vec4 | Output color (default: 0, 0, 0, 1) |BGCOLOR(green):|BGCOLOR(green):| | texel | Var | vec4 | Texel color (default: 1, 1, 1, 1) |BGCOLOR(green):|BGCOLOR(green):| | textureUV | Var | vec2 | Texture uv after scrolling |BGCOLOR(red):|BGCOLOR(green):| | shadow | Var | float | Shadow-map factor |BGCOLOR(red):|BGCOLOR(green):| | matS0 | Var | vec4 | Texel from free material texture 0 |BGCOLOR(red):|BGCOLOR(green):| | matS1 | Var | vec4 | Texel from free material texutre 1 |BGCOLOR(red):|BGCOLOR(green):| | s0 | Var | vec4 | Texel from free texture 0 |BGCOLOR(red):|BGCOLOR(green):| | s1 | Var | vec4 | Texel from free texture 1 |BGCOLOR(red):|BGCOLOR(green):| | output | Var | FragOutput | The fragment shader output |BGCOLOR(red):|BGCOLOR(red):| | ------------------------ | ------- | -------------- | --------------------------------------------- | ------------- | -------------- | | MESH_INFOS | Uniform | MeshInfos | Contains matrices and mesh identifier |BGCOLOR(green):|BGCOLOR(green):| | SCENE_INFOS | Uniform | SceneInfos | Various scene informations |BGCOLOR(green):|BGCOLOR(green):| | DIR_LIGHT | Uniform | DirLight | Directionnal light informations |BGCOLOR(green):|BGCOLOR(green):| | POINT_LIGHTS | Uniform | PointLight[] | Point light list |BGCOLOR(green):|BGCOLOR(green):| | SPOT_LIGHTS | Uniform | SpotLight[] | Spot light list |BGCOLOR(green):|BGCOLOR(green):| | DECALS | Uniform | Decal[] | Decal list |BGCOLOR(green):|BGCOLOR(green):| | FOG | Uniform | Fog | Fog informations |BGCOLOR(green):|BGCOLOR(green):| | MAT_COLORS | Uniform | MaterialColors | Material colors (ambiant, diffuse, etc...) |BGCOLOR(green):|BGCOLOR(green):| | MAT_PARAMS | Uniform | MaterialParams | Material parameters for some settings |BGCOLOR(green):|BGCOLOR(green):| | MAT_UVS | Uniform | MaterialUvs | Material uv scrolling |BGCOLOR(green):|BGCOLOR(green):| | MAT_TOON_LIGHT_DIR | Uniform | vec3 | Material toon light direction |BGCOLOR(green):|BGCOLOR(green):| | MAT_TEXTURE | Uniform | Texture | Color texture |BGCOLOR(green):|BGCOLOR(green):| | MAT_DISPLACEMENT_TEXTURE | Uniform | Texture | Displace the color texture |BGCOLOR(green):|BGCOLOR(green):| | MAT_DIFFUSE_TEXTURE | Uniform | Texture | Diffuse color texture |BGCOLOR(green):|BGCOLOR(green):| | MAT_SPECULAR_TEXTURE | Uniform | Texture | Specular texture (color and specularity) |BGCOLOR(green):|BGCOLOR(green):| | MAT_EMISSIVE_TEXTURE | Uniform | Texture | Emissive color texture |BGCOLOR(green):|BGCOLOR(green):| | MAT_NORM_TEXTURE | Uniform | Texture | Normal map texture |BGCOLOR(green):|BGCOLOR(green):| | MAT_ENV_MAP_TEXTURE | Uniform | Texture | Env map texture |BGCOLOR(green):|BGCOLOR(green):| | MAT_TOON_TEXTURE | Uniform | Texture | Toon details texture |BGCOLOR(green):|BGCOLOR(green):| | MAT_S0_TEXTURE | Uniform | Texture | Free material texture 0 |BGCOLOR(green):|BGCOLOR(green):| | MAT_S1_TEXTURE | Uniform | Texture | Free material texture 1 |BGCOLOR(green):|BGCOLOR(green):| | DECAL_ATLAS_TEXTURE | Uniform | Texture | Decals texture |BGCOLOR(green):|BGCOLOR(green):| | DECAL_ATLAS_TEXTURE | Uniform | Texture | Decals texture |BGCOLOR(green):|BGCOLOR(green):| | SHADOW_MAP_TEXTURE | Uniform | Texture | Shadow map texture |BGCOLOR(green):|BGCOLOR(green):| | S0_TEXTURE | Uniform | Texture | Free texture 0 |BGCOLOR(green):|BGCOLOR(green):| | S1_TEXTURE | Uniform | Texture | Free texture 1 |BGCOLOR(green):|BGCOLOR(green):| * What about new uniforms ? [#xfcc3915] For numeric there is: - 16 built-in floats available in ''MAT_PARAMS'' from ''S00'' to ''S15'' you can set by '''Gfx3Material.setCustomParam'''. - 16 built-in floats available in ''SCENE_INFOS'' from ''S00'' to ''S15'' you can set by '''Gfx3MeshRenderer.setCustomParam'''. About texture there is: - 2 built-in texture available in ''MAT_S0_TEXTURE'' and ''MAT_S1_TEXTURE'' you can set by '''Gfx3Material.setCustomTextures'''. - 2 built-in texture available in ''S0_TEXTURE'' and ''S1_TEXTURE'' you can set by '''Gfx3MeshRenderer.setCustomTextures'''.