SRP_07_LOD_and_Reflection


使用

  • 可以使用LODGroup.crossFadeAnimationDuration 控制切换的动画时间,默认0.5秒
  • image-20221215204227666
// -- 需要放在后面,放在 unity_WorldTransformParams 那个地方时会失效
// LOD0 到 LOD1 CrossFade 时 参数从 0..1
// LOD1 到 LOD2 CrossFade 时,参数从 -1..0
float4 unity_LODFade;

// 宏定义
#pragma multi_compile _ LOD_FADE_CROSSFADE

struct Fragment
{
    float2 positionSS; //屏幕空间纹素的位置
    float2 screenUV; //屏幕空间UV
    float depth; //view-space 深度(到相机 XY 平面的距离,线性)
    float bufferDepth; // 从深度图读取的深度,
};

Fragment GetFragment (float4 positionSS)
{
    Fragment fragment = (Fragment)0;
    fragment.positionSS = positionSS.xy;
    fragment.screenUV = fragment.positionSS * _CameraBufferSize;
    fragment.depth = IsOrthographicCamera() ? OrthographicDepthBufferToLinear(positionSS.z) : positionSS.w;
    fragment.bufferDepth = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, sampler_point_clamp, fragment.screenUV, 0);
    fragment.bufferDepth = IsOrthographicCamera() ?
        OrthographicDepthBufferToLinear(fragment.bufferDepth):
        LinearEyeDepth(fragment.bufferDepth, _ZBufferParams);
    return fragment;
}


void ClipLOD(Fragment fragment, float fade)
{
    #if defined(LOD_FADE_CROSSFADE)
        float dither = InterleavedGradientNoise(fragment.positionSS, 0);
        clip(fade + (fade < 0.0 ? dither : -dither));
    #endif
}

// include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Random.hlsl" 中的方法
//From  Next Generation Post Processing in Call of Duty: Advanced Warfare [Jimenez 2014]
// http://advances.realtimerendering.com/s2014/index.html
float InterleavedGradientNoise(float2 pixCoord, int frameCount)
{
    const float3 magic = float3(0.06711056f, 0.00583715f, 52.9829189f);
    float2 frameMagicScale = float2(2.083f, 4.867f);
    pixCoord += frameCount * frameMagicScale;
    return frac(magic.z * frac(dot(pixCoord, magic.xy)));
}

录制_2022_12_15_20_51_54_626


文章作者: 血魂S
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 血魂S !
  目录