浏览代码

Move stuff from `UnityPerFrame' which was actually updated at the per-view frequency

/main
Evgenii Golubev 7 年前
当前提交
1c4ab14a
共有 3 个文件被更改,包括 51 次插入45 次删除
  1. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
  2. 33
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  3. 46
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl

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


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

cmd.SetGlobalVector(HDShaderIDs._FrustumParams, frustumParams);
cmd.SetGlobalVector(HDShaderIDs._TaaFrameRotation, taaFrameRotation);
cmd.SetGlobalVectorArray(HDShaderIDs._FrustumPlanes, frustumPlaneEquations);
// Time is also a part of the UnityPerView CBuffer.
// Different views can have different values of the "Animated Materials" setting.
bool animateMaterials = CoreUtils.AreAnimatedMaterialsEnabled(camera);
float ct = animateMaterials ? currentTime : 0;
float pt = animateMaterials ? previousTime : 0;
float dt = Time.deltaTime;
float sdt = Time.smoothDeltaTime;
cmd.SetGlobalVector(HDShaderIDs._CurrentTime, new Vector4(ct * 0.05f, ct, ct * 2.0f, ct * 3.0f));
cmd.SetGlobalVector(HDShaderIDs._PreviousTime, new Vector4(pt * 0.05f, pt, pt * 2.0f, pt * 3.0f));
cmd.SetGlobalVector(HDShaderIDs._DeltaTime, new Vector4(dt, 1.0f / dt, sdt, 1.0f / sdt));
cmd.SetGlobalVector(HDShaderIDs._SinCurrentTime, new Vector4(Mathf.Sin(ct * 0.125f), Mathf.Sin(ct * 0.25f), Mathf.Sin(ct * 0.5f), Mathf.Sin(ct)));
cmd.SetGlobalVector(HDShaderIDs._CosCurrentTime, new Vector4(Mathf.Cos(ct * 0.125f), Mathf.Cos(ct * 0.25f), Mathf.Cos(ct * 0.5f), Mathf.Cos(ct)));
}
public void SetupGlobalStereoParams(CommandBuffer cmd)

33
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


// Use to detect frame changes
int m_FrameCount;
float m_TimeSinceStartup;
float m_PreviousTime, m_CurrentTime;
public int GetCurrentShadowCount() { return m_LightLoop.GetCurrentShadowCount(); }
public int GetShadowAtlasCount() { return m_LightLoop.GetShadowAtlasCount(); }

{
using (new ProfilingSample(cmd, "Push Global Parameters", CustomSamplerId.PushGlobalParameters.GetSampler()))
{
bool animateMaterials = CoreUtils.AreAnimatedMaterialsEnabled(hdCamera.camera);
// Do not use 'Time.timeSinceLevelLoad' - it ticks in the Scene View for a fraction of a second
// after you select an object even if the "Animated Materials" option is disabled.
float ct = animateMaterials ? Time.realtimeSinceStartup : 0;
float pt = (m_TimeSinceStartup > 0) ? m_TimeSinceStartup : ct;
float dt = Time.deltaTime;
float sdt = Time.smoothDeltaTime;
cmd.SetGlobalVector(HDShaderIDs._CurrentTime, new Vector4(ct * 0.05f, ct, ct * 2.0f, ct * 3.0f));
cmd.SetGlobalVector(HDShaderIDs._PreviousTime, new Vector4(pt * 0.05f, pt, pt * 2.0f, pt * 3.0f));
cmd.SetGlobalVector(HDShaderIDs._DeltaTime, new Vector4(dt, 1.0f / dt, sdt, 1.0f / sdt));
cmd.SetGlobalVector(HDShaderIDs._SinCurrentTime, new Vector4(Mathf.Sin(ct * 0.125f), Mathf.Sin(ct * 0.25f), Mathf.Sin(ct * 0.5f), Mathf.Sin(ct)));
cmd.SetGlobalVector(HDShaderIDs._CosCurrentTime, new Vector4(Mathf.Cos(ct * 0.125f), Mathf.Cos(ct * 0.25f), Mathf.Cos(ct * 0.5f), Mathf.Cos(ct)));
m_SSSBufferManager.PushGlobalParams(cmd, sssParameters, m_FrameSettings);
m_DbufferManager.PushGlobalParams(cmd, m_FrameSettings);

ssrefraction.PushShaderParameters(cmd);
// Set up UnityPerView CBuffer.
hdCamera.SetupGlobalParams(cmd);
hdCamera.SetupGlobalParams(cmd, m_CurrentTime, m_PreviousTime);
// Update the current time.
m_TimeSinceStartup = ct;
}
}

if (m_FrameCount != Time.frameCount)
{
// New frame.
// Do not use 'Time.timeSinceLevelLoad' - it does not tick all the time as expected.
float t = Time.realtimeSinceStartup;
// Make sure both are never 0.
m_PreviousTime = (m_CurrentTime > 0) ? m_CurrentTime : t;
m_CurrentTime = t;
}
// TODO: Render only visible probes

// Overwrite camera properties set during the shader pass with the original camera properties.
renderContext.SetupCameraProperties(camera, m_FrameSettings.enableStereo);
hdCamera.SetupGlobalParams(cmd);
hdCamera.SetupGlobalParams(cmd, m_CurrentTime, m_PreviousTime);
if (m_FrameSettings.enableStereo) hdCamera.SetupGlobalStereoParams(cmd);
}

46
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl


#endif
float4 unity_ShadowColor;
// t = animateMaterials ? Time.realtimeSinceStartup : 0.
float4 _CurrentTime; // { t/20, t, t*2, t*3 }
float4 _PreviousTime; // { t/20, t, t*2, t*3 }
float4 _DeltaTime; // { dt, 1/dt, smoothdt, 1/smoothdt }
float4 _SinCurrentTime; // { sin(t/8), sin(t/4), sin(t/2), sin(t) }
float4 _CosCurrentTime; // { cos(t/8), cos(t/4), cos(t/2), cos(t) }
// Volumetric lighting.
float4 _AmbientProbeCoeffs[7]; // 3 bands of SH, packed, rescaled and convolved with the phase function
float _GlobalAsymmetry;
float3 _GlobalScattering;
float _GlobalExtinction;
float4 _VBufferResolution; // { w, h, 1/w, 1/h }
float4 _VBufferSliceCount; // { count, 1/count, 0, 0 }
float4 _VBufferDepthEncodingParams; // See the call site for description
float4 _VBufferDepthDecodingParams; // See the call site for description
CBUFFER_END
// ----------------------------------------------------------------------------

float4x4 _ViewProjMatrix;
float4x4 _InvViewProjMatrix;
float4x4 _NonJitteredViewProjMatrix;
float4x4 _PrevViewProjMatrix; // non-jittered
float4x4 _PrevViewProjMatrix; // non-jittered
// TODO: put commonly used vars together (below), and then sort them by the frequency of use (descending).
// Note: a matrix is 4 * 4 * 4 = 64 bytes (1x cache line), so no need to sort those.

float3 _CameraPositionWS;
#endif
float _DetViewMatrix; // determinant(_ViewMatrix)
float4 _ScreenSize; // { w, h, 1 / w, 1 / h }
float4 _ScreenToTargetScale; // { w / RTHandle.maxWidth, h / RTHandle.maxHeight, 0, 0 }
float _DetViewMatrix; // determinant(_ViewMatrix)
float4 _ScreenSize; // { w, h, 1 / w, 1 / h }
float4 _ScreenToTargetScale; // { w / RTHandle.maxWidth, h / RTHandle.maxHeight, 0, 0 }
// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
// x = 1 - f/n

// w = orthographic camera's height (0 if perspective)
float4 _FrustumParams;
float4 _FrustumPlanes[6]; // { (a, b, c) = N, d = -dot(N, P) } [L, R, T, B, N, F]
// t = animateMaterials ? Time.realtimeSinceStartup : 0.
float4 _CurrentTime; // { t/20, t, t*2, t*3 }
float4 _PreviousTime; // { t/20, t, t*2, t*3 }
float4 _DeltaTime; // { dt, 1/dt, smoothdt, 1/smoothdt }
float4 _SinCurrentTime; // { sin(t/8), sin(t/4), sin(t/2), sin(t) }
float4 _CosCurrentTime; // { cos(t/8), cos(t/4), cos(t/2), cos(t) }
float4 _TaaFrameRotation; // { sin(taaFrame * PI/2), cos(taaFrame * PI/2), 0, 0 }
float4 _TaaFrameRotation; // { sin(taaFrame * PI/2), cos(taaFrame * PI/2), 0, 0 }
float4 _FrustumPlanes[6]; // { (a, b, c) = N, d = -dot(N, P) } [L, R, T, B, N, F]
// Volumetric lighting.
float4 _AmbientProbeCoeffs[7]; // 3 bands of SH, packed, rescaled and convolved with the phase function
float _GlobalAsymmetry;
float3 _GlobalScattering;
float _GlobalExtinction;
float4 _VBufferResolution; // { w, h, 1/w, 1/h }
float4 _VBufferSliceCount; // { count, 1/count, 0, 0 }
float4 _VBufferDepthEncodingParams; // See the call site for description
float4 _VBufferDepthDecodingParams; // See the call site for description
CBUFFER_END
// Custom generated by HDRP, not from Unity Engine (passed in via HDCamera)

正在加载...
取消
保存