参数设置1
参数设置2
细致到毛孔的高光
次表面散射的耳朵
人皮渲染是十多年的课题了,人们想尽一切办法想让其变得真实可信,大型3A级次时代游戏近来做的又来越真实了如《罗马之子》,他们的皮肤自称已经超过了NVIDIA的例子
这是在2005年SIGGRAPH的多层皮肤渲染,他们的参数都是经过精密的医学上的测量的,而且渲染花费了5分钟的时间。。。
2. 基于物理的渲染
包括specular和brdf等等,brdf我用了一张贴图调整曲率来代替,specular在之前这篇文章有详细讲解 链接在此3. 法线模糊
等等之类。。。
/*
*this part is compute Physically-Based Rendering
*the method is in the ppt about "ops2"
*/
float _SP = pow(8192, _GL);
float d = (_SP + 2) / (8 * PIE) * pow(dot(n2, H), _SP);
float f = _SC + (1 - _SC)*pow(2, -10 * dot(H, lightDir));
float k = min(1, _GL + 0.545);
float v = 1 / (k* dot(viewDir, H)*dot(viewDir, H) + (1 - k));
float all = d*f*v;
float3 refDir = reflect(-viewDir, n2);
float3 ref = texCUBElod(_Cubemap, float4(refDir, _nMips - _GL*_nMips)).rgb;
float specBase = max(0, dot(n2, H));
float spec = pow(specBase, 10) *(_GL + 0.2);
spec = lerp(0, 1.2, spec);
float3 spec3 = spec * (tex2D(_SpecularTex, i.uv_MainTex) - 0.1);
spec3 *= Luminance(diff);
spec3 = saturate(spec3);
spec3 *= _SpecularPower;
光经过哪,就带一部分那里的颜色,可以发现光从入射到出射,位置和方向都变了
为了节省花销,省去了ppt中的rendering时blur,直接在ps上做了6张高斯模糊的贴图放入material,并线性混合
float3 c = tex2D(_MainTex, i.uv_MainTex) * 128;
c += tex2D(_BlurTex1, i.uv_MainTex) * 64;
c += tex2D(_BlurTex2, i.uv_MainTex) * 32;
c += tex2D(_BlurTex3, i.uv_MainTex) * 16;
c += tex2D(_BlurTex4, i.uv_MainTex) * 8;
c += tex2D(_BlurTex5, i.uv_MainTex) * 4;
c += tex2D(_BlurTex6, i.uv_MainTex) * 2;
c /= 256;
而且使人皮有了次表面散射的质感
/*
*this part is to add the sss
*used front rim,back rim and BRDF
*/
float3 rim = (1 - dot(viewDir, n2))*_RimPower * _RimColor *tex2D(_RimTex, i.uv_MainTex);
float3 frontrim = (dot(viewDir, n2))*_FrontRimPower * _FrontRimColor *tex2D(_FrontRimTex, i.uv_MainTex);
float3 sss = (1 - dot(viewDir, n2)) / 50 * _SSSPower;
sss = lerp(tex2D(_SSSFrontTex, i.uv_MainTex), tex2D(_SSSBackTex, i.uv_MainTex), sss * 20)*sss;
fixed atten = LIGHT_ATTENUATION(i);
float curvature = length(fwidth(mul(_Object2World, float4(normalize(i.normal), 0)))) /
length(fwidth(i.worldpos)) * _CurveScale;
float3 brdf = tex2D(_BRDFTex, float2((dot(normalize(i.normal), lightDir) * 0.5 + 0.5)* atten, curvature)).rgb;
光源在嘴里
float3 n1 = tex2D(texBase, uv).xyz*2 - 1;
float3 n2 = tex2D(texDetail, uv).xyz*2 - 1;
float3 r = normalize(n1 + n2);
return r*0.5 + 0.5;
float3 n1 = tex2D(texBase, uv).xyz;
float3 n2 = tex2D(texDetail, uv).xyz;
float3 r = n1 < 0.5 ? 2*n1*n2 : 1 - 2*(1 - n1)*(1 - n2);
r = normalize(r*2 - 1);
return r*0.5 + 0.5;
就是法线1的法线比较深的地方,就多一些权重,比较浅的地方就被法线2适当覆盖,但是这样效果还是不够真实
float3x3 nBasis = float3x3(
float3(n1.z, n1.y, -n1.x), //绕着y轴+90度旋转
float3(n1.x, n1.z, -n1.y),// 绕着x轴-90度旋转
float3 (n1.x, n1.y, n1.z ));
n = normalize (n2.x*nBasis[0] + n2.y*nBasis[1] + n2.z*nBasis[2]);
得到的结果是这样的,是不是好了许多?
双方的细节程度都有很多提升,
他们用了一个basis来变换第二法线。具体可以看 这篇文章—链接fixed atten = LIGHT_ATTENUATION(i);