前言:
网上全是代码的各向异性效果,做一个shaderGraph连连看,里面用一个AniF.hlsl方法,分别将(bitangentWS ,normalWS,转换一下
(是网上另一个各向异性效果,使用shader写成)
原理如下:
各向异性的公式原理就不说,网上大把,直接搜索就有,下面的我的找到一个简单算法
half StrandSpecular(half3 bitangentWS,half3 viewDirWS,half3 lightDirWS,half exponent)
{
half3 H = normalize(lightDirWS + viewDirWS);
half dotTH = dot(bitangentWS,H);
half sinTH = sqrt(1.0 - dotTH * dotTH);
half dirAttenuation = smoothstep(-1.0,0.0,dotTH);
return dirAttenuation * pow(sinTH,exponent);
}
另一个是核心是ShiftTangent是U3D内置的参数
half3 t1 = ShiftTangent(bitangentWS,normalWS,_Shift + shiftTex);
其实网上全是shader版本的,shaderGraph版本方便修改,基本就是高光,这里的核心是shiftTex,就是拉丝噪点图,也可用于头发效果
ShaderGraph连连看图如下
URP
直接上算法:
#ifndef MYANI_INCLUDED
#define MYANI_INCLUDED
void ANI_half(half3 lightDir,half3 shiftTex, half Shift, half powerVal, half3 bitangent, half3 viewDir, half3 normal, out half AniVal)
{
half3 viewDirVal = SafeNormalize(viewDir);
//half3 lightDir = half3(0,1,0);
lightDir = normalize(lightDir);
half3 halfDir = normalize(-viewDirVal + lightDir);
/*
float nh = dot(normal, halfDir);
nh = max(0.0001, nh);
float spec = pow(nh, powerVal);
*/
//float3 shiftTex=float3(0.5,0.5,0.5);
shiftTex.r -= 0.5;
half shiftTex2 = Shift + shiftTex.r;
half3 normalWS = normalize(normal);
half3 bitangentWS = cross(normalWS, bitangent);
half3 tangent = ShiftTangent(bitangentWS, normal, shiftTex2);
float dotTH = dot(tangent, halfDir);
float dirAtten = smoothstep(-1., 0., dotTH);
float sinTH = sqrt(1. - dotTH * dotTH);
sinTH=max(0.0001, sinTH);
AniVal = dirAtten * pow(sinTH, powerVal);
//AniVal = spec;
// half3 hairColor = LightingHair(bitangentWS, light.direction, normalWS, viewWS, IN.texcoord, _SpecularExp, _SpecularColor.rgb);
}
#endif
下载地址