【TA】Marmoset头发高光Model复刻进Unity

将八猴的FlowMap和头发高光模型复刻进Unity。

本文为原创内容,转载请注明地址。

起因

之前给项目组做过一版Unity内的编辑器HairFlowMapEditor和头发高光的模型,但是项目组美术同学认为不太好使+效果不是很满意。在尝试过八猴的FlowMap和头发高光模型后美术表示给我整一个这玩意,于是去扒一下八猴shader部分的源码看看怎么复刻。

实现

八猴的实现主要在这几个文件里:anisoParams.frag lightAnisotropic.frag sampleAnisotropic.frag

1
2
3
4
5
6
7
8
9
10
11
12
_pAnisoRoughnessToA( roughness, a, ax, ay,uAnisoAspect );
//unity to Marmoset Space
half3 normalNoise = normal;
normal = lerp(vertexNormal,normal,_SpecularNoiseStrength);
normal = normalize(normal);

//Area light adjustments look a bit odd with anisotropy; could use improvement.

//get tangent surface parameters
float3 anisTangent, anisBitangent;
_pAnisoGetBasis( normal,uAnisoDirectionMapScaleBias,uAnisoRotation,tangent,bitangent ,uv,anisTangent,anisBitangent);

对贴图储存的方向进行一个从(0,1)—->(-1,1)的重映射。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
   uAnisoDirectionMapScaleBias =half2(2,-1);
tex_specular = SAMPLE_TEXTURE2D( _AnisoDirectionMap, sampler_AnisoDirectionMap,vertexTexCoord );
tangent.xy = tex_specular.xy;
tangent.xy = uAnisoDirectionMapScaleBias.x * tangent.xy + uAnisoDirectionMapScaleBias.y;

// //rotate tangent
// // tangent.xy = tangent.x * uAnisoRotation.xy + tangent.y * uAnisoRotation.zw;

// //transform into render space
tangent = tangent.x * vertexTangent +
tangent.y * vertexBitangent;

// //project tangent onto normal plane
tangent = tangent - normal*dot( tangent, normal );
tangent = normalize( tangent );

效果

1(暂时不能展示)

继续优化效果

和KK模型结合,加上一些根据切线法线方向的Noise来丰富头发高光的形状:

1