The skin replacement function is implemented with PS:
One provides two textures. The difference is that the transparency of one skin is 0.
PS processing: Two textures are sampled separately and then mixed. The blending coefficient is based on the texture with Alpha.
// Skin change
Void Charactertemplate_skin_vs (
Float4 pos: position,
Float4 TEX: texcoord0,
Float3 normal: normal,
Out Float4 opos: position,
Out Float2 UV: texcoord0,
Out Float4 emissivecolour: texcoord1,
Out Float4 ocolour: color,
Uniform float4x4 worldmatrix,
Uniform float4x4 viewmatrix,
Uniform float4x4 projectionmatrix,
Uniform float4 diffuse_color,
Uniform float4 emissive_colour
)
{
Float4 pos_ws = Mul (worldmatrix, POS );
Float4 pos_vs = Mul (viewmatrix, pos_ws );
Opos = Mul (projectionmatrix, pos_vs );
UV = Tex;
Emissivecolour = Emissive_colour;
Ocolour = Diffuse_color;
}
// Skin change
Void Charactertemplate_skin_ps (
Float4 itexcoorda: texcoord0,
Float4 emissivecolour: texcoord1,
Float4 color: color,
Out Float4 ocolour: color,
Uniform sampler2d Tex,
Uniform sampler2d texskin
)
{
// Step 1: render a layer with color
Float4 texcolor = Tex2d (Tex, itexcoorda );
Float4 tempcolor;
Tempcolor = Texcolor * Color * Emissivecolour;
// Step 2: render skin
Float4 skincolor = Tex2d (texskin, itexcoorda );
// Step 3: Two-layer hybrid (x * (1-s) + y * s)
Ocolour = Lerp (tempcolor, skincolor, skincolor. );
}