浏览代码

Added binding to Depth RT for post processing. Added hook for custom BeforeTransparent fx.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
f8d61440
共有 1 个文件被更改,包括 85 次插入45 次删除
  1. 130
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs

130
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


private int m_ShadowCasterCascadesCount = kMaxCascades;
private int m_ShadowMapProperty;
private int m_CameraRTProperty;
private int m_CameraDepthProperty;
private RenderTargetIdentifier m_CameraDepthRTID;
private bool m_RequireDepthTexture = false;
private bool m_IntermediateTextureArray = false;
private const int kShadowDepthBufferBits = 16;

BuildShadowSettings();
m_ShadowMapProperty = Shader.PropertyToID("_ShadowMap");
m_CameraRTProperty = Shader.PropertyToID("_CameraRT");
m_CameraDepthProperty = Shader.PropertyToID("_CameraDepthTexture");
m_CameraDepthRTID = new RenderTargetIdentifier(m_CameraDepthProperty);
m_PostProcessRenderContext = new PostProcessRenderContext();
// Let engine know we have MSAA on for cases where we support MSAA backbuffer

if (lightData.shadowLightIndex > -1)
lightData.shadowsRendered = RenderShadows(ref m_CullResults, ref visibleLights[lightData.shadowLightIndex], lightData.shadowLightIndex, ref context);
// Setup camera matrices and RT
// Setup camera matrices
context.SetupCameraProperties(m_CurrCamera, stereoEnabled);
// Setup light and shadow shader constants

bool postProcessEnabled = postProcessLayer != null && postProcessLayer.enabled;
m_RenderToIntermediateTarget = postProcessEnabled || GetRenderToIntermediateTarget();
BeginForwardRendering(ref context, stereoEnabled);
// Some post process effects require depth texture (Depth of Field, etc)
m_RequireDepthTexture = postProcessEnabled;
BeginForwardRendering(ref context, stereoEnabled, postProcessEnabled);
var litDrawSettings = new DrawRendererSettings(m_CurrCamera, m_LitPassName);
litDrawSettings.sorting.flags = SortFlags.CommonOpaque;

// TODO: Check skybox shader
context.DrawSkybox(m_CurrCamera);
if (postProcessEnabled)
RenderPostProcess(ref context, postProcessLayer, true);
// Render Alpha blended
var transparentFilterSettings = new FilterRenderersSettings(true) {renderQueueRange = RenderQueueRange.transparent};

if (postProcessEnabled)
RenderPostProcess(ref context, postProcessLayer);
RenderPostProcess(ref context, postProcessLayer, false);
EndForwardRendering(ref context, stereoEnabled, postProcessEnabled);

return (type == LightType.Directional || type == LightType.Spot);
}
private void BeginForwardRendering(ref ScriptableRenderContext context, bool stereoEnabled)
private void BeginForwardRendering(ref ScriptableRenderContext context, bool stereoEnabled, bool postProcess)
if (stereoEnabled)
context.StartMultiEye(m_CurrCamera);
RenderTargetIdentifier colorRenderTarget = BuiltinRenderTextureType.CurrentActive;
RenderTargetIdentifier depthRenderTargetIdentifier = BuiltinRenderTextureType.None;
int rtWidth = m_CurrCamera.pixelWidth;
int rtHeight = m_CurrCamera.pixelHeight;
int msaaSamples = (m_CurrCamera.allowMSAA) ? m_Asset.MSAASampleCount : 1;
m_IntermediateTextureArray = false;
var cmd = CommandBufferPool.Get("SetCameraRenderTarget");
if (m_RenderToIntermediateTarget)

m_IntermediateTextureArray = false;
RenderTextureDescriptor rtDesc = new RenderTextureDescriptor();
RenderTextureDescriptor xrDesc = XRSettings.eyeTextureDesc;
xrDesc.depthBufferBits = kCameraDepthBufferBits;
xrDesc.colorFormat = m_ColorFormat;
xrDesc.msaaSamples = m_Asset.MSAASampleCount;
m_IntermediateTextureArray = (xrDesc.dimension == TextureDimension.Tex2DArray);
context.StartMultiEye(m_CurrCamera);
rtDesc = XRSettings.eyeTextureDesc;
rtDesc.colorFormat = m_ColorFormat;
rtDesc.msaaSamples = msaaSamples;
cmd.GetTemporaryRT(m_CameraRTProperty, xrDesc, FilterMode.Bilinear);
}
else
{
cmd.GetTemporaryRT(m_CameraRTProperty, Screen.width, Screen.height, kCameraDepthBufferBits,
FilterMode.Bilinear, m_ColorFormat, RenderTextureReadWrite.Default, m_Asset.MSAASampleCount);
m_IntermediateTextureArray = (rtDesc.dimension == TextureDimension.Tex2DArray);
cmd.GetTemporaryRT(m_CameraRTProperty, rtDesc, FilterMode.Bilinear);
if (m_IntermediateTextureArray)
cmd.SetRenderTarget(m_CameraRTID, 0, CubemapFace.Unknown, -1);
else
cmd.SetRenderTarget(m_CameraRTID);
// TODO: rtDesc is initilized with flip flag, we have to pass params explicitly
//rtDesc.width = rtWidth;
//rtDesc.height = rtHeight;
//rtDesc.colorFormat = m_ColorFormat;
//rtDesc.msaaSamples = (m_CurrCamera.allowMSAA) ? m_Asset.MSAASampleCount : 1;
//rtDesc.dimension = TextureDimension.Tex2D;
cmd.GetTemporaryRT(m_CameraRTProperty, rtWidth, rtHeight, kCameraDepthBufferBits, FilterMode.Bilinear, m_ColorFormat, RenderTextureReadWrite.Default, msaaSamples);
colorRenderTarget = m_CameraRTID;
cmd.SetRenderTarget(new RenderTargetIdentifier(m_CurrCamera.activeTexture));
colorRenderTarget = new RenderTargetIdentifier(m_CurrCamera.activeTexture);
}
else
{
cmd.SetRenderTarget(BuiltinRenderTextureType.CurrentActive);
}
if (!stereoEnabled)
{
Rect viewport = m_CurrCamera.rect;
if (m_CurrCamera.targetTexture == null)
if (postProcess)
viewport.x *= Screen.width;
viewport.y *= Screen.height;
viewport.width *= Screen.width;
viewport.height *= Screen.height;
cmd.GetTemporaryRT(m_CameraDepthProperty, rtWidth, rtHeight, kCameraDepthBufferBits, FilterMode.Bilinear);
depthRenderTargetIdentifier = m_CameraDepthRTID;
else
{
viewport = new Rect(0.0f, 0.0f, m_CurrCamera.targetTexture.width, m_CurrCamera.targetTexture.height);
}
}
cmd.SetViewport(viewport);
}
SetupCameraRenderTargetAndViewport(cmd, colorRenderTarget, depthRenderTargetIdentifier, stereoEnabled);
// Clear RenderTarget to avoid tile initialization on mobile GPUs
// https://community.arm.com/graphics/b/blog/posts/mali-performance-2-how-to-correctly-handle-framebuffers

}
}
private void RenderPostProcess(ref ScriptableRenderContext renderContext, PostProcessLayer postProcessLayer)
private void SetupCameraRenderTargetAndViewport(CommandBuffer cmd, RenderTargetIdentifier colorRT, RenderTargetIdentifier depthRT, bool stereoEnabled)
{
if (m_IntermediateTextureArray)
{
if (depthRT != BuiltinRenderTextureType.None)
cmd.SetRenderTarget(colorRT, 0, CubemapFace.Unknown, -1);
else
cmd.SetRenderTarget(colorRT, depthRT, 0, CubemapFace.Unknown, -1);
}
else
{
if (depthRT != BuiltinRenderTextureType.None)
cmd.SetRenderTarget(colorRT, depthRT);
else
cmd.SetRenderTarget(colorRT);
}
if (!stereoEnabled)
{
Rect viewport = m_CurrCamera.rect;
if (m_CurrCamera.targetTexture == null)
{
viewport.x *= Screen.width;
viewport.y *= Screen.height;
viewport.width *= Screen.width;
viewport.height *= Screen.height;
}
else
{
viewport = new Rect(0.0f, 0.0f, m_CurrCamera.targetTexture.width, m_CurrCamera.targetTexture.height);
}
cmd.SetViewport(viewport);
}
}
private void RenderPostProcess(ref ScriptableRenderContext renderContext, PostProcessLayer postProcessLayer, bool opaqueOnly)
postProcessCommand.SetGlobalTexture(m_CameraDepthProperty, m_CameraDepthRTID);
m_PostProcessRenderContext.Reset();
m_PostProcessRenderContext.camera = m_CurrCamera;
m_PostProcessRenderContext.source = BuiltinRenderTextureType.CurrentActive;

m_PostProcessRenderContext.flip = true;
postProcessLayer.Render(m_PostProcessRenderContext);
if (opaqueOnly)
postProcessLayer.Render(m_PostProcessRenderContext);
else
postProcessLayer.RenderOpaqueOnly(m_PostProcessRenderContext);
renderContext.ExecuteCommandBuffer(postProcessCommand);
CommandBufferPool.Release(postProcessCommand);
}

正在加载...
取消
保存