浏览代码

Merge branch 'LWRP' into lw/api-refactor-v1

# Conflicts:
#	ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
#	ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs
/main
Felipe Lira 7 年前
当前提交
1e580cd4
共有 9 个文件被更改,包括 89 次插入42 次删除
  1. 27
      ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs
  2. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  3. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  4. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs
  5. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DirectionalShadowsPass.cs
  6. 36
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs
  7. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LocalShadowsPass.cs
  8. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs
  9. 28
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs

27
ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs


ClearRenderTarget(cmd, clearFlag, clearColor);
}
// Explicit load and store actions
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag, Color clearColor)
{
cmd.SetRenderTarget(buffer, loadAction, storeAction);
ClearRenderTarget(cmd, clearFlag, clearColor);
}
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag)
{
SetRenderTarget(cmd, buffer, loadAction, storeAction, clearFlag, clearColorAllBlack);
}
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction,
RenderTargetIdentifier depthBuffer, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction,
ClearFlag clearFlag, Color clearColor)
{
cmd.SetRenderTarget(colorBuffer, colorLoadAction, colorStoreAction, depthBuffer, depthLoadAction, depthStoreAction);
ClearRenderTarget(cmd, clearFlag, clearColor);
}
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction,
RenderTargetIdentifier depthBuffer, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction,
ClearFlag clearFlag)
{
SetRenderTarget(cmd, colorBuffer, colorLoadAction, colorStoreAction, depthBuffer, depthLoadAction, depthStoreAction, clearFlag, clearColorAllBlack);
}
public static string GetRenderTargetAutoName(int width, int height, RenderTextureFormat format, string name = "", bool mips = false, bool enableMSAA = false, MSAASamples msaaSamples = MSAASamples.None)
{
string temp;

18
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


else
cameraData.postProcessLayer.Render(context);
}
public static void Blit(CommandBuffer cmd, ref CameraData cameraData, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material material = null)
{
cmd.SetGlobalTexture("_BlitTex", sourceRT);
if (cameraData.isDefaultViewport)
{
cmd.Blit(sourceRT, destRT, material);
}
else
{
// Viewport doesn't work when rendering to an RT
// We have to manually blit by rendering a fullscreen quad
CoreUtils.SetRenderTarget(cmd, destRT);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(cameraData.camera.pixelRect);
DrawFullScreen(cmd, material);
}
}
}
}

8
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


commandBuffer.DrawMesh(fullscreenMesh, Matrix4x4.identity, material, 0, shaderPassId, properties);
}
public static int GetRenderTargetDepthSlice(bool stereoRendering)
{
if (stereoRendering && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
return -1;
return 0;
}
public static void GetLightCookieMatrix(VisibleLight light, out Matrix4x4 cookieMatrix)
{
cookieMatrix = Matrix4x4.Inverse(light.localToWorld);

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs


CommandBuffer cmd = CommandBufferPool.Get(kCommandBufferTag);
using (new ProfilingSample(cmd, kProfilerTag))
{
int depthSlice = LightweightPipeline.GetRenderTargetDepthSlice(cameraData.isStereoEnabled);
CoreUtils.SetRenderTarget(cmd, GetSurface(depthAttachmentHandle), ClearFlag.Depth, 0, CubemapFace.Unknown, depthSlice);
SetRenderTarget(cmd, GetSurface(depthAttachmentHandle), RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
ClearFlag.Depth, Color.black);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DirectionalShadowsPass.cs


m_DirectionalShadowmapTexture = RenderTexture.GetTemporary(m_DirectionalShadowmapDescriptor);
m_DirectionalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_DirectionalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;
CoreUtils.SetRenderTarget(cmd, m_DirectionalShadowmapTexture, ClearFlag.Depth);
SetRenderTarget(cmd, m_DirectionalShadowmapTexture, RenderBufferLoadAction.DontCare,
RenderBufferStoreAction.Store, ClearFlag.Depth, Color.black);
bool success = false;
for (int cascadeIndex = 0; cascadeIndex < m_ShadowCasterCascadesCount; ++cascadeIndex)

36
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs


CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", cameraData.requiresSoftParticles);
}
void SetRenderTarget(CommandBuffer cmd, ClearFlag clearFlag)
void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor)
CoreUtils.SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), GetSurface(depthAttachmentHandle), clearFlag);
SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, GetSurface(depthAttachmentHandle), loadOp, storeOp, clearFlag, clearColor);
CoreUtils.SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), clearFlag);
SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, clearFlag, clearColor);
CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, clearFlag);
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, loadOp, storeOp, clearFlag, clearColor);
}
}

Camera camera = cameraData.camera;
ClearFlag clearFlag = GetCameraClearFlag(camera);
SetRenderTarget(cmd, clearFlag);
// TODO: This was merged from previous LOAD/STORE PR. It seems this should not be DontCare
// and instead we should check clearFlags to wheter set to Clear or DontCare
// Same in screenspace shadow resolve pass. Also we should check for the msaa resolve actions.
SetRenderTarget(cmd, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(camera.backgroundColor));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

{
CommandBuffer cmd = CommandBufferPool.Get("Render Opaques");
Camera camera = cameraData.camera;
SetRenderTarget(cmd, ClearFlag.None);
SetRenderTarget(cmd, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, ClearFlag.None, Color.black);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

void FinalBlitPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
var cmd = CommandBufferPool.Get("Final Blit Pass");
if (cameraData.isStereoEnabled && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
cmd.Blit(GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget);
Material material = cameraData.isStereoEnabled ? null : m_BlitMaterial;
RenderTargetIdentifier sourceRT = GetSurface(colorAttachmentHandle);
CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass");
cmd.SetGlobalTexture("_BlitTex", sourceRT);
if (cameraData.isStereoEnabled || cameraData.isDefaultViewport)
{
cmd.Blit(GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, material);
}
LightweightPipeline.Blit(cmd, ref cameraData, GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, cameraData.isStereoEnabled ? null : m_BlitMaterial);
{
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.All, Color.black);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(cameraData.camera.pixelRect);
LightweightPipeline.DrawFullScreen(cmd, material);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LocalShadowsPass.cs


m_LocalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_LocalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;
CoreUtils.SetRenderTarget(cmd, m_LocalShadowmapTexture, ClearFlag.Depth);
SetRenderTarget(cmd, m_LocalShadowmapTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
ClearFlag.Depth, Color.black);
for (int i = 0; i < localLightsCount; ++i)
{

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowResolvePass.cs


// a better solution).
// An alternative would be DrawProcedural, but that would require further changes in the shader.
RenderTargetIdentifier screenSpaceOcclusionTexture = GetSurface(colorAttachmentHandle);
cmd.SetRenderTarget(screenSpaceOcclusionTexture);
cmd.ClearRenderTarget(true, true, Color.white);
SetRenderTarget(cmd, screenSpaceOcclusionTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
ClearFlag.Color | ClearFlag.Depth, Color.white);
cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, m_ScreenSpaceShadowsMaterial);
if (cameraData.isStereoEnabled)

28
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs


public int depthAttachmentHandle { get; private set; }
public TextureDimension textureDimension { get; private set; }
int samples;
public ScriptableRenderPass(LightweightForwardRenderer renderer)
{

{
this.colorAttachmentHandles = colorAttachmentHandles;
this.depthAttachmentHandle = depthAttachmentHandle;
this.samples = samples;
textureDimension = baseDescriptor.dimension;
}
public virtual void Dispose(CommandBuffer cmd)

settings.sorting.flags = sortFlags;
settings.rendererConfiguration = rendererConfiguration;
return settings;
}
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction, ClearFlag clearFlag, Color clearColor)
{
if (textureDimension == TextureDimension.Tex2DArray)
CoreUtils.SetRenderTarget(cmd, colorAttachmentHandle, clearFlag, clearColor, 0, CubemapFace.Unknown, -1);
else
CoreUtils.SetRenderTarget(cmd, colorAttachmentHandle, colorLoadAction, colorStoreAction, clearFlag, clearColor);
}
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction, RenderTargetIdentifier depthAttachment, RenderBufferLoadAction depthLoadAction,
RenderBufferStoreAction depthStoreAction, ClearFlag clearFlag, Color clearColor)
{
if (textureDimension == TextureDimension.Tex2DArray)
CoreUtils.SetRenderTarget(cmd, colorAttachmentHandle, depthAttachmentHandle,
clearFlag, clearColor, 0, CubemapFace.Unknown, -1);
else
CoreUtils.SetRenderTarget(cmd, colorAttachmentHandle, colorLoadAction, colorStoreAction,
depthAttachmentHandle, depthLoadAction, depthStoreAction, clearFlag, clearColor);
}
}
}
正在加载...
取消
保存