卡通效果—屏幕空间深度等距边缘光

卡通效果—屏幕空间深度等距边缘光

实现逻辑

1.正常计算菲涅尔边缘光

2.对人物模型先正常采样一次深度

3.对人物模型深度进行偏移,就是对采样深度值的UV进行偏移。

4.深度图上距离摄像机近的物体呈现黑色,数值接近0,远的物体呈现白色,接近1,

我们要利用这张图达到一种边缘检测的效果,对场景中的模型所有片元,将每个点的位置向着法线方向位移一段距离,

再采样一个深度,用新采样的深度减去原本的深度,超过某个阈值则视为边缘。 

5.将这个等距边缘与正常的菲涅尔边缘光进行差值得到最终边缘光

代码参考

//

half RTD_RL_S_Sli_Light = lerp(1.70,0.29,_RimLightSoftnessLight);

half RTD_RL_S_Sli_Dark = lerp(1.70,0.29,_RimLightSoftnessDark);

half m_ndl =saturate(dot(inputData.normalWS, mainLight.direction));

half RTD_RL_MAIN = lerp(0.0, 1.0 ,

smoothstep( 1.71,

lerp(RTD_RL_S_Sli_Dark, RTD_RL_S_Sli_Light, m_ndl),

pow(abs( 1.0-max(0,dot(inputData.normalWS, inputData.viewDirectionWS) ) ),

lerp((1.0 - _RimLightUnfillDark), (1.0 - _RimLightUnfillLight), m_ndl)) ));

half RTD_RL_IL_OO = lerp( 0.0, RTD_RL_MAIN, _RimLigInt);

half3 NdLRimColor = lerp(_RimLightColorDark.rgb * _RimLightColorPowerDark, _RimLightColorLight.

rgb * _RimLightColorPowerLight, step(0.15,m_ndl));

//==========================================================================================

//

// UV

float2 RimScreenUV = float2(inputData.positionCS.x / _ScreenParams.x, inputData.positionCS.y /

_ScreenParams.y);

// UVworldNormalNDC

float3 smoothNormal = normalize(UnpackNormalmapRGorAG(half4(0,0,0,0)));

float3x3 tangentTransform = float3x3(half3(0,0,0), half3(0,0,0), normalWS);

float3 worldRimNormal = normalize(mul(smoothNormal, tangentTransform));

float2 RimOffsetUV = float2(mul((float3x3) UNITY_MATRIX_V, worldRimNormal).xy * (_RimOffsets) * 0.

01 / (inputData.positionCS.w+0.0001));

RimOffsetUV += RimScreenUV;

float ScreenDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture,

RimScreenUV);

float Linear01ScreenDepth = LinearEyeDepth(ScreenDepth, _ZBufferParams);

float OffsetDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture,

RimOffsetUV);

float Linear01OffsetDepth = LinearEyeDepth(OffsetDepth, _ZBufferParams);

float diff = Linear01OffsetDepth - Linear01ScreenDepth;

float rimMask = step(1, diff);

half tempRim = lerp(0, RTD_RL_IL_OO, rimMask);

lightingData.mainLightColor = lerp(lightingData.mainLightColor, lightingData.mainLightColor +

NdLRimColor, tempRim);
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容