浏览代码

refactoring frustum corners to util function

/main
John 7 年前
当前提交
f210f98e
共有 2 个文件被更改,包括 29 次插入27 次删除
  1. 37
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 19
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs

37
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


context.DrawRenderers(m_CullResults.visibleRenderers, ref opaqueDrawSettings, opaqueFilterSettings);
}
//TODO: Find place to live.
private Vector4[] GetFarPlaneCorners()
{
Vector4[] corners = new Vector4[4];
float farH = 2.0f * Mathf.Tan(m_CurrCamera.fieldOfView * 0.5f * Mathf.Deg2Rad) * m_CurrCamera.farClipPlane;
float farW = farH * m_CurrCamera.aspect;
Vector3 fc = Vector3.forward * m_CurrCamera.farClipPlane;
Vector3 up = Vector3.up;
Vector3 right = Vector3.right;
corners[0] = fc - (up * farH / 2) - (right * farW / 2);
corners[1] = fc + (up * farH / 2) - (right * farW / 2);
corners[2] = fc + (up * farH / 2) + (right * farW / 2);
corners[3] = fc - (up * farH / 2) + (right * farW / 2);
return corners;
}
CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows");
if (m_Asset.AreShadowsEnabled() && lightData.mainLightIndex != -1)
{
CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows");
SetupShadowReceiverConstants(cmd, lights[lightData.mainLightIndex]); //Reciever constants set up here in case of screen space shadows.
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.R8);
cmd.SetGlobalVectorArray("_FrustumCorners", GetFarPlaneCorners()); //TODO: Move to a constant buffer. Shadow or Camera?
cmd.Blit(null, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
SetupShadowReceiverConstants(cmd, lights[lightData.mainLightIndex]); //Reciever constants set up here in case of screen space shadows.
cmd.GetTemporaryRT(m_ScreenSpaceShadowMapRTID, m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.R8);
cmd.SetGlobalVectorArray("_FrustumCorners", LightweightUtils.GetFarPlaneCorners(m_CurrCamera)); //TODO: Move to a constant buffer. Shadow or Camera?
cmd.Blit(null, m_ScreenSpaceShadowMapRT, m_ScreenSpaceShadowsMaterial);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
private void ForwardPass(List<VisibleLight> visibleLights, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context, ref LightData lightData, bool stereoEnabled)

19
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs


// Remaining light types don't support cookies
}
public static Vector4[] GetFarPlaneCorners(Camera camera)
{
Vector4[] corners = new Vector4[4];
float farH = 2.0f * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad) * camera.farClipPlane;
float farW = farH * camera.aspect;
Vector3 fc = Vector3.forward * camera.farClipPlane;
Vector3 up = Vector3.up;
Vector3 right = Vector3.right;
corners[0] = fc - (up * farH / 2) - (right * farW / 2);
corners[1] = fc + (up * farH / 2) - (right * farW / 2);
corners[2] = fc + (up * farH / 2) + (right * farW / 2);
corners[3] = fc - (up * farH / 2) + (right * farW / 2);
return corners;
}
public static bool IsSupportedShadowType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;

正在加载...
取消
保存