标签:shader 图形学 unity3d subsurface scatterin 次表面散射
次表面散射是一种非常常用的效果,可以用在很多材质上
这是本文在unity中实现了的次表面散射效果:
<span style="font-size:14px;">float Lri(float3 w_P, float phi_x, float p_L_Dist, float D) { float _Sigma_t = _Sigma_A + _Sigma_S; float L = 1 / (4 * PIE) * phi_x + 3 / (4 * PIE) * dot(w_P, -D*_Nabla * phi_x); float Lri = L * pow(E, -_Sigma_t* p_L_Dist); return Lri; }</span>
for (int i = 0; i < 30; i++) { w_P = normalize(float3(N.x + rand(fixed2(i*0.05, i*0.05)), N.y + rand(fixed2(-i*0.05, i*0.05)), N.z + rand(fixed2(i*0.05, -i*0.05)))); // float3 w_P = normalize(float3(lightDir.x + rand(i.uv_MainTex + fixed2(i*0.01, i*0.01)), lightDir.y + rand(i.uv_MainTex + fixed2(-i*0.01, i*0.01)), lightDir.z + rand(i.uv_MainTex + fixed2(i*0.01, -i*0.01)))); Q += phase(dot(lightDir, w_P))*Lri(w_P, phi_x, p_L_Dist, D); Q *= _Sigma_S; Q1 += Q*w_P; }
30次随机光线散射方向
if (_WorldSpaceLightPos0.w != 0) { p_L_Dist = distance(_WorldSpaceLightPos0, i.worldPos); } float v_C_Dist = distance(_WorldSpaceCameraPos, i.worldPos)*0.3;
<span style="font-size:14px;">float3 ref = -D * (dot(N, _Nabla*phi_x_S)) / (diff*_LumPow_D);</span>
最终效果:
参考:
1. A Practical Model for Subsurface Light Transport2. A Measurement-Based Skin Re?ectance Model for Face Rendering and Editing
----- by wolf96 http://blog.csdn.net/wolf96
Unity3d shader之次表面散射(Subsurface Scattering)
标签:shader 图形学 unity3d subsurface scatterin 次表面散射
原文地址:http://blog.csdn.net/wolf96/article/details/45618327