一,距离雾
float4 unityObjectToClipPos = TransformWorldToHClip(TransformObjectToWorld(IN.posOS.xyz));
float eyeDepth = LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH( screenPos.xy ),_ZBufferParams);
half3 WorldPosFromDepth = ( _WorldSpaceCameraPos - ( eyeDepth * ( ( _WorldSpaceCameraPos - WorldPosition ) / screenPos.w ) ) );
float temp = saturate( ( ( distance( WorldPosFromDepth , _WorldSpaceCameraPos ) - _FogDistanceStart ) / ( _FogDistanceEnd - _FogDistanceStart ) ) );
float FogDistance = ( 1.0 - pow( ( 1.0 - abs( temp ) ) ,_FogDistanceFalloff ) );
二,高度雾
float3 depthOption = ( WorldPosFromDepth* _FogAxisOption );
float temp = saturate( ( ( distance( WorldPosFromDepth, _WorldSpaceCameraPos ) - _FogDistanceEnd ) / ( ( _FogDistanceEnd + _FarDistanceOffset ) - _FogDistanceEnd ) ) );
half FogDistanceMaskFar = pow(temp,2);
float FogHeightEdge = lerp( _FogHeightEnd , ( _FogHeightEnd + _FarDistanceHeight ) , FogDistanceMaskFar);
half FogHeightMask = pow( abs( saturate( ( (depthOption - FogHeightEdge ) / ( _FogHeightStart - FogHeightEdge ) ) ) ) , _FogHeightFalloff );
三,天空盒雾
float3 normalizeResult = normalize( ( WorldPosFromDepth - _WorldSpaceCameraPos ) ) * _FogAxisOption;
float saferPower = abs( saturate( ( ( abs( ( ( normalizeResult.x + normalizeResult.y + normalizeResult.z ) -_SkyboxFogOffset ) ) - _SkyboxFogHeight ) / ( 0.0 - _SkyboxFogHeight ) ) ); );
half SkyboxFogHeightMask = ( lerp( saturate( ( pow( saferPower , _SkyboxFogFalloff ) + ( _SkyboxFogBottom * step( temp_output_449_0_g1027 , 0.0 ) ) ) ) , 1.0 , _SkyboxFogFill) * _SkyboxFogIntensity );
四,最终效果