浏览代码

Jitter ray origin to add noise instead of banding when raymarching

/main
Frédéric Vauchelles 7 年前
当前提交
6f23a811
共有 6 个文件被更改,包括 43 次插入4 次删除
  1. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  3. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  4. 36
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs


}
// Set up UnityPerView CBuffer.
public void SetupGlobalParams(CommandBuffer cmd, float time, float lastTime)
public void SetupGlobalParams(CommandBuffer cmd, float time, float lastTime, uint frameCount)
{
cmd.SetGlobalMatrix(HDShaderIDs._ViewMatrix, viewMatrix);
cmd.SetGlobalMatrix(HDShaderIDs._InvViewMatrix, viewMatrix.inverse);

cmd.SetGlobalVector(HDShaderIDs.unity_DeltaTime, new Vector4(dt, 1.0f / dt, sdt, 1.0f / sdt));
cmd.SetGlobalVector(HDShaderIDs._SinTime, new Vector4(Mathf.Sin(ct * 0.125f), Mathf.Sin(ct * 0.25f), Mathf.Sin(ct * 0.5f), Mathf.Sin(ct)));
cmd.SetGlobalVector(HDShaderIDs._CosTime, new Vector4(Mathf.Cos(ct * 0.125f), Mathf.Cos(ct * 0.25f), Mathf.Cos(ct * 0.5f), Mathf.Cos(ct)));
cmd.SetGlobalInt(HDShaderIDs._FrameCount, (int)frameCount);
}
public void SetupGlobalStereoParams(CommandBuffer cmd)

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


ssReflection.PushShaderParameters(cmd);
// Set up UnityPerView CBuffer.
hdCamera.SetupGlobalParams(cmd, m_Time, m_LastTime);
hdCamera.SetupGlobalParams(cmd, m_Time, m_LastTime, m_FrameCount);
if (m_FrameSettings.enableStereo) hdCamera.SetupGlobalStereoParams(cmd);
cmd.SetGlobalInt(HDShaderIDs._SSReflectionEnabled, m_FrameSettings.enableSSR ? 1 : 0);

// Overwrite camera properties set during the shadow pass with the original camera properties.
renderContext.SetupCameraProperties(camera, m_FrameSettings.enableStereo);
hdCamera.SetupGlobalParams(cmd, m_Time, m_LastTime);
hdCamera.SetupGlobalParams(cmd, m_Time, m_LastTime, m_FrameCount);
if (m_FrameSettings.enableStereo) hdCamera.SetupGlobalStereoParams(cmd);
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _UseTileLightList = Shader.PropertyToID("_UseTileLightList");
public static readonly int _FrameCount = Shader.PropertyToID("_FrameCount");
public static readonly int _Time = Shader.PropertyToID("_Time");
public static readonly int _LastTime = Shader.PropertyToID("_LastTime");
public static readonly int _SinTime = Shader.PropertyToID("_SinTime");

36
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl


//
// Use library here, like ScreenSpaceProxyRaycastReflection(...)
// #################################################
// Notes
// #################################################
// Some banding issues can occurs when raymarching the depth buffer.
//
// This can be hidden by offsetting the ray origin with a jitter.
// Combined with a temporal filtering, the banding artifact will be smoothed.
// This will trade banding for noise.
//
// This happens when we raymarch with a ray direction that is quite different from the view vector.
// Exemple when raymarching with a direction perpendicular to the view vector:
//
// Depth buffer far
// |
// v
// near
//
// --------
// hit ==>xx
// xx
//
// fail ===>
// xx
// hit ===>xx
//
// xx
// #################################################

}
}
#endif
float SampleBayer4(uint2 positionSS)
{
const float4x4 Bayer4 = float4x4(0, 8, 2, 10,
12, 4, 14, 6,
3, 11, 1, 9,
15, 7, 13, 5) / 16;
return Bayer4[positionSS.x % 4][positionSS.y % 4];
}
// -------------------------------------------------
// Algorithms

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


ScreenSpaceRaymarchInput ssRayInput;
ZERO_INITIALIZE(ScreenSpaceRaymarchInput, ssRayInput);
ssRayInput.rayOriginWS = rayOriginWS;
ssRayInput.rayOriginWS = rayOriginWS + rayDirWS * SampleBayer4(posInput.positionSS + _FrameCount) * 0.1;
ssRayInput.rayDirWS = rayDirWS;
#if DEBUG_DISPLAY
ssRayInput.debug = debug;

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl


float4 _SinTime; // { sin(t/8), sin(t/4), sin(t/2), sin(t) }
float4 _CosTime; // { cos(t/8), cos(t/4), cos(t/2), cos(t) }
float4 unity_DeltaTime; // { dt, 1/dt, smoothdt, 1/smoothdt }
int _FrameCount;
// Volumetric lighting.
float4 _AmbientProbeCoeffs[7]; // 3 bands of SH, packed, rescaled and convolved with the phase function

正在加载...
取消
保存