Shader interface
Each material has associated pair of vertex and fragment shaders. Those shaders are
GLSL ES 3.0 and should start with #version 300 es
(for Mac OS this string is patched
to #version 410 core
internally as Mac OS doesn't provide OpenGL 4.3 which is needed
for GLSL ES 3.0 on desktop GL).
#
Vertex AttributesThere are two types of materials in effects:
- FRX face mesh materials (
onface=true
in cfg.toml) - materials for skinned geometry from .bsm2 files
FRX face mesh materials receive 3 attributes:
.bsm2 materials receive 6 attributes:
#
Uniform parametersShaders can receive 4 uniform blocks with parameters:
- glfx_GLOBAL
- glfx_INSTANCES
- glfx_BASIS_DATA
- glfx_ACTION_UNITS
glfx_MVPs
and glfx_MVs
arrays meant to be indexed with gl_InstanceID
for .bsm2 shaders
and with glfx_CURRENT_FACE
uint uniform for FRX face mesh shaders.
For compatibility with single-face effects it is possible to declare glfx_GLOBAL block as:
And shader will be patched automatically during loading.
#
Texture samplersShaders can use uniform samplers for textures declared in samplers
table in cfg.toml
Additionaly, following built-in samplers are available:
uniform sampler2D glfx_BONES
for .bsm2 materials this will contain bone transformations as mat3x4. Typical skinning transformation code look like:For physics meshes this texture have height = 1 and transformation matrices already include modelview transformation. For regular animated (non-physics) .bsm2 matrices in glfx_BONES doesn't include modelview transform.
uniform sampler2D glfx_STATICPOS
texture with base face positions for Y-flipped face UVs. Typically should be sampled withvec2(attrib_uv.x,1.-attrib_uv.y)
texcoords if mesh from .bsm2 have texcoords corresponding to face mesh texcoords.uniform sampler2DArray glfx_UVMORPH
textures with position offsets of FRX face meshes from the base face mesh for Y-flipped face UVs. Each layer of sampler2DArray corresponds to each found face. For compatibility with single-face effects it can be declared asuniform sampler2D glfx_UVMORPH
and shader will be patched during loading.uniform sampler2DArray glfx_UVMORPH_FISHEYE
same as glfx_UVMORPH, but meant to be sampled withvec3(smoothstep(0.,1.,attrib_uv),float(gl_InstanceID))
. This texture is smaller than glfx_UVMORPH and results in faster rendering.uniform sampler2DArray glfx_MORPH
textures with position offsets of FRX face meshes from the base face mesh for automatic cylindrical mapping:uniform sampler2D glfx_VIDEO
video frame .mp4, which can be declared in config.jsonuniform sampler2D glfx_BACKGROUND
texture with framebuffer copy, can be updated with '!glfx_UPDATE_BG' command in draw_order in cfg.toml. This texture can be created with mipmaps by settingbg_mips=true
in cfg.tomluniform sampler2D glfx_BLUR_BACKGROUND
blurred version of glfx_BACKGROUND, blur strength can be configured from script withApi.meshfxMsg("blur", 0, strength)
uniform sampler2DShadow glfx_SHADOW
dynamic shadows sampler with geometry with materials markedshadow=true
in cfg.toml. In spherical projection imitating shadows from environment lighting. Meant to be sampled with following texcoords:uniform sampler2D glfx_BG_MASK
background separation mask texture from neural networkuniform sampler2D glfx_HAIR_MASK
hair mask texture from neural networkuniform sampler2D glfx_OCCLUSION
occlusion mask texture from neural networkuniform sampler2D glfx_L_EYE_MASK, glfx_R_EYE_MASK
eyes segmentation mask textures from neural networkuniform sampler2D glfx_LIPS_MASK
lips segmentation mask textures from neural networkuniform sampler2D glfx_SKIN_MASK
skin segmentation mask texture from neural networkuniform sampler3D glfx_WLUT0, glfx_WLUT1, glfx_WLUT2, glfx_WLUT3
weighted lut as 3D texture which can be configured from script withApi.meshfxMsg("wlut",idx,weight,file)
#
Fragment shader outputFragment shaders should write its result to 0 location, for example:
This can be omitted for materials with colorwrite=false
in cfg.toml.
Additionaly, on mobiles with EXT_shader_framebuffer_fetch this variable can be declared
as inout
to allow reading color from framebuffer.