Unity Shader half-transparent highlighting of the occluded part

renderings

reality principle

Implementation of occlusion relationship processing: through two passes and depth testing

The edge light effect is realized by detecting the angle between the line of sight direction and the normal direction.

The pass for rendering X-ray effects uses ZTest Greater. When rendering, the depth of the occluder before the occluded part, while the unoccluded part will not pass the depth test due to the infinite depth, does not display any content, and the occluded part , the depth is the depth of the occluder. The depth of the character behind the occluder is greater than that of the occluder. If the depth test passes, the occluded part will be rendered as the output of the Pass, and this Pass cannot be written into the depth, because we still need to draw the character without drawing normally. For the occluded part, ZTest LEqual can be tested for normal depth at this time. The occluded part is not rendered, and only the unoccluded part is rendered.

That is, the first pass renders the occluded part, and the second pass renders the unoccluded part normally.

Occlude part of the shader core code

fixed4 frag(v2f i) : COLOR0  
{  
    float3 normal = normalize(i.normal);  
    float3 viewDir = normalize(i.viewDir);  
    //视线方向V与法线方向N垂直时,这个法线对应的面就与视线方向平行,
    //说明当前这个点对于当前视角来说,就处在边缘;
    float rim = 1 - dot(normal, viewDir);  

    //增加了一点噪声效果
    half3 noise = tex2D(_NoiseTex, i.zw );  
   // return lerp(_XRayColor * rim, fixed4(noise.rgb, 0.2), _Density);
    return _XRayColor * rim;  
} 

sample download

Supongo que te gusta

Origin blog.csdn.net/st75033562/article/details/129441652
Recomendado
Clasificación