[유니티 셰이더/양식화된 수면 렌더링/기본 사항] urp 코드 버전 06-간단한 습윤 은행 시뮬레이션

머리말


처음 5개의 챕터는 해안 거품, 수면 채색, 파도, 커스틱스 등의 기능을 완성했습니다. 이 장에서는 단순한 젖은 둑 효과, 즉 썰물 때 둑의 젖은 현상을 시뮬레이션하기 위해 새 패스를 만듭니다.
여기에 이미지 설명 삽입

  • 관련된 지식 포인트
    - 깊이 페이드

새로운 패스


이 패스도 GerstnerWave정점을 변환하는 함수를 사용하지만 파장을 변환해야 합니다.
그런 다음 화면 캡처 _CameraOpaqueTexture텍스처를 가져와 색상을 지정하면 효과는 다음과 같습니다.
여기에 이미지 설명 삽입
그러면 연결이 매우 뻣뻣해질 것입니다. 이 장에서는 주로 이를 개선합니다.
첫 번째 장에서 얻은 결과를 사용하여 RawDepth처리할 수 있습니다. 이 장 ** Depth Fade**를 사용하여 다음 그림 마스크를 생성합니다. ** DepthFade일반적으로 깊이 쓰기가 꺼진 투명 모드에서 작동합니다. 개체를 계산할 수 없습니다. **물 표면이 반투명 메쉬이므로 이 방법을 사용할 수 있습니다.
여기에 이미지 설명 삽입

관찰 공간의 깊이 차이를 구합니다.

원본을 샘플링 한 후 _CameraDepthTexture** LinearEyeDepth** 기능을 사용하여 실제로 깊이 반전을 통해 뷰 공간에서 z를 추론합니다.

                float4 screenPos = i.scrPos / i.scrPos.w;
                float sceneRawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture,screenPos.xy);
                sceneRawDepth =  LinearEyeDepth(sceneRawDepth, _ZBufferParams);

가려진 정점 z를 현재 메쉬의 z에서 빼서 다음과 같은 처리를 합니다.

                float distanceDepth = abs((sceneRawDepth - LinearEyeDepth(screenPos.z , _ZBufferParams)) / ((_FadeDistance * 0.01 )));
                distanceDepth = max((1.0 - distanceDepth), 0.0001);
                float DepthInteraction =  smoothstep(0, _InterSoftness, saturate(pow(distanceDepth, (_FadeSoftness * 0.1))));
                DepthInteraction = 1- saturate( DepthInteraction);

적용된 깊이 차이

그런 다음 알파에 DepthInteraction을 적용하면 다음과 같은 효과를 얻습니다.

            real4 frag(v2f i) : SV_TARGET
            {
    
    
                float4 screenPos = i.scrPos / i.scrPos.w;
                float sceneRawDepth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture,screenPos.xy);
                sceneRawDepth =  LinearEyeDepth(sceneRawDepth, _ZBufferParams);

                float distanceDepth = abs((sceneRawDepth - LinearEyeDepth(screenPos.z , _ZBufferParams)) / ((_FadeDistance * 0.01)));
                distanceDepth = max((1.0 - distanceDepth), 0.0001);
                float DepthInteraction =  smoothstep(0, _InterSoftness, saturate( pow(distanceDepth , (_FadeSoftness * 0.1 ))));
                DepthInteraction = 1- saturate( DepthInteraction);
                real4 grab_col = SAMPLE_TEXTURE2D(_CameraOpaqueTexture, sampler_CameraOpaqueTexture, screenPos.xy) * _Wetness;
                float alpha = lerp(0, 1, DepthInteraction);
                return real4( grab_col.xyz, alpha);
            }

여기에 이미지 설명 삽입

추천

출처blog.csdn.net/qq_43544518/article/details/128760443