浏览代码

Lw/api review v2 (#1892)

*  RenderingData is now readonly.

*  renderer is cleared up before calling setup. This way there's no need to an IRendererSetup call clear.

*  Removed GC.Alloc from LWRP. The only remaining ones are due to the GetComponent bug.
 Change functions from static to member.

*  Added requires depth prepass to RenderingData. Moved CanCopyDepth to LWRP.

*  Made static functions from ScriptableRenderer member functions

*  Removed LightweightForwardPass. Added RenderObjectsWithError to renderer.

*   Moved RenderPostProcess to renderer

*  Added cullResults to RenderingData. Change ScriptableRenderPass and IRenderer interface.

*  Moved rendering methods from Core to Renderer. Made LWRP class sealed.

*  Changed camera sorting to use lambda.

*  Run autoformat tool

*  updated release notes

*  Changed ScriptableRenderer functions that don't use class members to static.

*  LWRP functions have to be static due to the ability to render a...
/main
GitHub 6 年前
当前提交
2d2ce5c3
共有 41 个文件被更改,包括 422 次插入504 次删除
  1. 8
      com.unity.render-pipelines.lightweight/CHANGELOG.md
  2. 56
      com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs
  3. 2
      com.unity.render-pipelines.lightweight/LWRP/IAfterDepthPrePass.cs
  4. 2
      com.unity.render-pipelines.lightweight/LWRP/IAfterOpaquePass.cs
  5. 2
      com.unity.render-pipelines.lightweight/LWRP/IAfterOpaquePostProcess.cs
  6. 2
      com.unity.render-pipelines.lightweight/LWRP/IAfterRender.cs
  7. 2
      com.unity.render-pipelines.lightweight/LWRP/IAfterSkyboxPass.cs
  8. 2
      com.unity.render-pipelines.lightweight/LWRP/IAfterTransparentPass.cs
  9. 4
      com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs
  10. 49
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
  11. 92
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipelineCore.cs
  12. 4
      com.unity.render-pipelines.lightweight/LWRP/LightweightShadowUtils.cs
  13. 2
      com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs
  14. 6
      com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs
  15. 16
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs
  16. 14
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs
  17. 13
      com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs
  18. 10
      com.unity.render-pipelines.lightweight/LWRP/Passes/DepthOnlyPass.cs
  19. 23
      com.unity.render-pipelines.lightweight/LWRP/Passes/DirectionalShadowsPass.cs
  20. 19
      com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs
  21. 6
      com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs
  22. 8
      com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs
  23. 31
      com.unity.render-pipelines.lightweight/LWRP/Passes/LocalShadowsPass.cs
  24. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs
  25. 48
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs
  26. 42
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs
  27. 4
      com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs
  28. 18
      com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs
  29. 6
      com.unity.render-pipelines.lightweight/LWRP/Passes/ScriptableRenderPass.cs
  30. 4
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs
  31. 44
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs
  32. 12
      com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs
  33. 15
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandle.cs
  34. 2
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs
  35. 2
      com.unity.render-pipelines.lightweight/LWRP/SampleCount.cs
  36. 2
      com.unity.render-pipelines.lightweight/LWRP/SceneViewDrawMode.cs
  37. 214
      com.unity.render-pipelines.lightweight/LWRP/ScriptableRenderer.cs
  38. 12
      com.unity.testing.srp.lightweight/Tests/Scenes/045_CustomLWPipe/CustomLWPipe.cs
  39. 23
      com.unity.testing.srp.lightweight/Tests/Scenes/052_LWCallbacks/CameraCallbackTests.cs
  40. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs.meta
  41. 83
      com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs

8
com.unity.render-pipelines.lightweight/CHANGELOG.md


## [3.4.0-preview]
### Added
- When you have enabled Gizmos, they now appear correctly in the Game view.
- Added requiresDepthPrepass field to RenderingData struct to tell if the runtime platform requires a depth prepass to generate a camera depth texture.
- The _RenderingData_ struct now holds a reference to _CullResults_.
### Changed
- The _RenderingData_ struct is now read-only.
- _ScriptableRenderer_ always perform a Clear before calling _IRendererSetup::Setup_.
- _ScriptableRenderPass::Execute_ no longer takes _CullResults_ as input. Instead, use _RenderingData_ as input, since that references _CullResults_.
- _IRendererSetup::Setup_ no longer takes _ScriptableRenderContext_ and _CullResults_ as input.
- Reduced GC pressure by removing several per-frame memory allocations.
## [3.3.0-preview]
### Added

56
com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs


using System;
using System;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline

m_Initialized = true;
}
public void Setup(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults, ref RenderingData renderingData)
public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData)
renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRTDesc(ref renderingData.cameraData);
renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
bool requiresCameraDepth = renderingData.cameraData.requiresDepthTexture;
bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve
|| renderingData.cameraData.isSceneViewCamera
|| (requiresCameraDepth && !ScriptableRenderer.CanCopyDepth(ref renderingData.cameraData));
bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve || renderingData.cameraData.isSceneViewCamera ||
(renderingData.cameraData.requiresDepthTexture && !CanCopyDepth(ref renderingData.cameraData));
// For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo
requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled;

renderer.EnqueuePass(m_ScreenSpaceShadowResolvePass);
}
bool requiresRenderToTexture =
ScriptableRenderer.RequiresIntermediateColorTexture(
ref renderingData.cameraData,
baseDescriptor);
bool requiresRenderToTexture = ScriptableRenderer.RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor);
RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget;
RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget;

depthHandle = DepthAttachment;
}
}
bool dynamicBatching = renderingData.supportsDynamicBatching;
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ScriptableRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching);
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ScriptableRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration);
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessingContext))
m_OpaquePostProcessPass.Setup(renderer.postProcessRenderContext, baseDescriptor, colorHandle);
m_OpaquePostProcessPass.Setup(renderer.postProcessingContext, baseDescriptor, colorHandle);
renderer.EnqueuePass(m_OpaquePostProcessPass);
foreach (var pass in camera.GetComponents<IAfterOpaquePostProcess>())

foreach (var pass in camera.GetComponents<IAfterSkyboxPass>())
renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
if (requiresCameraDepth && !requiresDepthPrepass)
if (renderingData.cameraData.requiresDepthTexture && !requiresDepthPrepass)
{
m_CopyDepthPass.Setup(depthHandle, DepthTexture);
renderer.EnqueuePass(m_CopyDepthPass);

renderer.EnqueuePass(m_CopyColorPass);
}
m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ClearFlag.None, camera.backgroundColor, rendererConfiguration, dynamicBatching);
m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, rendererConfiguration);
renderer.EnqueuePass(m_RenderTransparentForwardPass);
foreach (var pass in camera.GetComponents<IAfterTransparentPass>())

{
m_TransparentPostProcessPass.Setup(renderer.postProcessRenderContext, baseDescriptor, colorHandle, BuiltinRenderTextureType.CameraTarget);
m_TransparentPostProcessPass.Setup(renderer.postProcessingContext, baseDescriptor, colorHandle, BuiltinRenderTextureType.CameraTarget);
renderer.EnqueuePass(m_TransparentPostProcessPass);
}
else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget)

renderer.EnqueuePass(m_SceneViewDepthCopyPass);
}
#endif
}
bool CanCopyDepth(ref CameraData cameraData)
{
bool msaaEnabledForCamera = (int)cameraData.msaaSamples > 1;
bool supportsTextureCopy = SystemInfo.copyTextureSupport != CopyTextureSupport.None;
bool supportsDepthTarget = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth);
bool supportsDepthCopy = !msaaEnabledForCamera && (supportsDepthTarget || supportsTextureCopy);
// TODO: We don't have support to highp Texture2DMS currently and this breaks depth precision.
// currently disabling it until shader changes kick in.
//bool msaaDepthResolve = msaaEnabledForCamera && SystemInfo.supportsMultisampledTextures != 0;
bool msaaDepthResolve = false;
return supportsDepthCopy || msaaDepthResolve;
}
}
}

2
com.unity.render-pipelines.lightweight/LWRP/IAfterDepthPrePass.cs


{
ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle depthAttachmentHandle);
}
}
}

2
com.unity.render-pipelines.lightweight/LWRP/IAfterOpaquePass.cs


RenderTargetHandle colorAttachmentHandle,
RenderTargetHandle depthAttachmentHandle);
}
}
}

2
com.unity.render-pipelines.lightweight/LWRP/IAfterOpaquePostProcess.cs


ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorHandle,
RenderTargetHandle depthHandle);
}
}
}

2
com.unity.render-pipelines.lightweight/LWRP/IAfterRender.cs


{
ScriptableRenderPass GetPassToEnqueue();
}
}
}

2
com.unity.render-pipelines.lightweight/LWRP/IAfterSkyboxPass.cs


{
ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorHandle, RenderTargetHandle depthHandle);
}
}
}

2
com.unity.render-pipelines.lightweight/LWRP/IAfterTransparentPass.cs


{
ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorHandle, RenderTargetHandle depthHandle);
}
}
}

4
com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs


{
public interface IRendererSetup
{
void Setup(ScriptableRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData);
void Setup(ScriptableRenderer renderer, ref RenderingData renderingData);
}
}

49
com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public partial class LightweightPipeline : RenderPipeline
public sealed partial class LightweightPipeline : RenderPipeline
{
static class PerFrameBuffer
{

public LightweightPipelineAsset pipelineAsset { get; private set; }
private static IRendererSetup m_DefaultRendererSetup;
private static IRendererSetup defaultRendererSetup
{

}
}
CameraComparer m_CameraComparer = new CameraComparer();
const string k_RenderCameraTag = "Render Camera";
private PipelineSettings m_PipelineSettings;
PipelineSettings m_PipelineSettings;
public struct PipelineSettings
{

m_Renderer.Dispose();
}
public interface IBeforeCameraRender
{
void ExecuteBeforeCameraRender(ScriptableRenderContext context, Camera camera, PipelineSettings pipelineSettings, ScriptableRenderer renderer);

GraphicsSettings.lightsUseLinearIntensity = true;
SetupPerFrameShaderConstants();
// Sort cameras array by camera depth
Array.Sort(cameras, m_CameraComparer);
SortCameras(cameras);
foreach (Camera camera in cameras)
{
BeginCameraRendering(camera);

public static void RenderSingleCamera(ScriptableRenderContext context, PipelineSettings settings, Camera camera, ref CullResults cullResults, IRendererSetup setup, ScriptableRenderer renderer)
{
string renderCameraTag = camera.name;
CommandBuffer cmd = CommandBufferPool.Get(renderCameraTag);
using (new ProfilingSample(cmd, renderCameraTag))
CommandBuffer cmd = CommandBufferPool.Get(k_RenderCameraTag);
using (new ProfilingSample(cmd, k_RenderCameraTag))
{
CameraData cameraData;
InitializeCameraData(settings, camera, out cameraData);

ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
#endif
CullResults.Cull(ref cullingParameters, context, ref cullResults);
List<VisibleLight> visibleLights = cullResults.visibleLights;
InitializeRenderingData(settings, ref cameraData, visibleLights,
renderer.maxSupportedLocalLightsPerPass, renderer.maxSupportedVertexLights,
out renderingData);
InitializeRenderingData(settings, ref cameraData, ref cullResults,
renderer.maxSupportedLocalLightsPerPass, renderer.maxSupportedVertexLights, out renderingData);
setupToUse.Setup(renderer, ref context, ref cullResults, ref renderingData);
renderer.Execute(ref context, ref cullResults, ref renderingData);
renderer.Clear();
setupToUse.Setup(renderer, ref renderingData);
renderer.Execute(context, ref renderingData);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

Rect cameraRect = camera.rect;
cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f ||
Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f));
Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f));
// If XR is enabled, use XR renderScale.
// If XR is enabled, use XR renderScale.
// Discard variations lesser than kRenderScaleThreshold.
// Scale is only enabled for gameview.
float usedRenderScale = XRGraphicsConfig.enabled ? settings.savedXRGraphicsConfig.renderScale : settings.renderScale;

cameraData.requiresDepthTexture |= cameraData.postProcessEnabled;
}
static void InitializeRenderingData(PipelineSettings settings, ref CameraData cameraData,
List<VisibleLight> visibleLights, int maxSupportedLocalLightsPerPass, int maxSupportedVertexLights,
static void InitializeRenderingData(PipelineSettings settings, ref CameraData cameraData, ref CullResults cullResults,
int maxSupportedLocalLightsPerPass, int maxSupportedVertexLights,
List<VisibleLight> visibleLights = cullResults.visibleLights;
bool hasDirectionalShadowCastingLight = false;
bool hasLocalShadowCastingLight = false;

}
}
renderingData.cullResults = cullResults;
renderingData.cameraData = cameraData;
InitializeLightData(settings, visibleLights, maxSupportedLocalLightsPerPass, maxSupportedVertexLights, localLightIndices, out renderingData.lightData);
InitializeShadowData(settings, hasDirectionalShadowCastingLight, hasLocalShadowCastingLight, out renderingData.shadowData);

shadowData.localShadowAtlasWidth = shadowData.localShadowAtlasHeight = settings.localShadowAtlasResolution;
shadowData.supportsSoftShadows = settings.supportsSoftShadows;
shadowData.bufferBitCount = 16;
shadowData.renderedDirectionalShadowQuality = LightShadows.None;
shadowData.renderedLocalShadowQuality = LightShadows.None;
}
static void InitializeLightData(PipelineSettings settings, List<VisibleLight> visibleLights,

92
com.unity.render-pipelines.lightweight/LWRP/LightweightPipelineCore.cs


using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.XR;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{

public struct RenderingData
{
public CullResults cullResults;
public CameraData cameraData;
public LightData lightData;
public ShadowData shadowData;

public int localShadowAtlasHeight;
public bool supportsSoftShadows;
public int bufferBitCount;
public LightShadows renderedDirectionalShadowQuality;
public LightShadows renderedLocalShadowQuality;
}
public class CameraComparer : IComparer<Camera>
{
public int Compare(Camera lhs, Camera rhs)
{
return (int)(lhs.depth - rhs.depth);
}
}
public static class LightweightKeywordStrings

public static readonly string DepthNoMsaa = "_DEPTH_NO_MSAA";
public static readonly string DepthMsaa2 = "_DEPTH_MSAA_2";
public static readonly string DepthMsaa4 = "_DEPTH_MSAA_4";
public static readonly string SoftParticles = "SOFTPARTICLES_ON";
public partial class LightweightPipeline
public sealed partial class LightweightPipeline
static Mesh s_FullscreenMesh = null;
public static Mesh fullscreenMesh
{
get
{
if (s_FullscreenMesh != null)
return s_FullscreenMesh;
float topV = 1.0f;
float bottomV = 0.0f;
Mesh mesh = new Mesh { name = "Fullscreen Quad" };
mesh.SetVertices(new List<Vector3>
{
new Vector3(-1.0f, -1.0f, 0.0f),
new Vector3(-1.0f, 1.0f, 0.0f),
new Vector3(1.0f, -1.0f, 0.0f),
new Vector3(1.0f, 1.0f, 0.0f)
});
mesh.SetUVs(0, new List<Vector2>
{
new Vector2(0.0f, bottomV),
new Vector2(0.0f, topV),
new Vector2(1.0f, bottomV),
new Vector2(1.0f, topV)
});
mesh.SetIndices(new[] { 0, 1, 2, 2, 1, 3 }, MeshTopology.Triangles, 0, false);
mesh.UploadMeshData(true);
return mesh;
}
}
}
public void SortCameras(Camera[] cameras)
{
Array.Sort(cameras, (lhs, rhs) => (int)(lhs.depth - rhs.depth));
}
static void SetPipelineCapabilities(LightweightPipelineAsset pipelineAsset)

if (pipelineAsset.keepSoftShadowVariants)
s_PipelineCapabilities |= PipelineCapabilities.SoftShadows;
}
}
public static void DrawFullScreen(CommandBuffer commandBuffer, Material material,
MaterialPropertyBlock properties = null, int shaderPassId = 0)
{
commandBuffer.DrawMesh(fullscreenMesh, Matrix4x4.identity, material, 0, shaderPassId, properties);
}
public static void GetLightCookieMatrix(VisibleLight light, out Matrix4x4 cookieMatrix)

// Remaining light types don't support cookies
}
public static void CopyTexture(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material)
{
// TODO: In order to issue a copyTexture we need to also check if source and dest have same size
//if (SystemInfo.copyTextureSupport != CopyTextureSupport.None)
// cmd.CopyTexture(source, dest);
//else
cmd.Blit(source, dest, material);
}
public static bool IsSupportedShadowType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;
}
public static bool IsSupportedCookieType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;

{
bool isSceneViewCamera = camera.cameraType == CameraType.SceneView;
return XRGraphicsConfig.enabled && !isSceneViewCamera && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
}
public static void RenderPostProcess(CommandBuffer cmd, PostProcessRenderContext context, ref CameraData cameraData, RenderTextureFormat colorFormat, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool opaqueOnly)
{
Camera camera = cameraData.camera;
context.Reset();
context.camera = camera;
context.source = source;
context.sourceFormat = colorFormat;
context.destination = dest;
context.command = cmd;
context.flip = !IsStereoEnabled(camera) && camera.targetTexture == null;
if (opaqueOnly)
cameraData.postProcessLayer.RenderOpaqueOnly(context);
else
cameraData.postProcessLayer.Render(context);
}
}
}

4
com.unity.render-pipelines.lightweight/LWRP/LightweightShadowUtils.cs


{
ShadowSplitData splitData;
bool success = cullResults.ComputeDirectionalShadowMatricesAndCullingPrimitives(shadowLightIndex,
cascadeIndex, shadowData.directionalLightCascadeCount, shadowData.directionalLightCascades, shadowResolution, shadowNearPlane, out viewMatrix, out projMatrix,
out splitData);
cascadeIndex, shadowData.directionalLightCascadeCount, shadowData.directionalLightCascades, shadowResolution, shadowNearPlane, out viewMatrix, out projMatrix,
out splitData);
cascadeSplitDistance = splitData.cullingSphere;
shadowSliceData.offsetX = (cascadeIndex % 2) * shadowResolution;

2
com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs


ScrenSpaceShadow,
Count,
}
}
}

6
com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs


{
public class BeginXRRenderingPass : ScriptableRenderPass
{
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
}
}

16
com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs


{
public class CopyColorPass : ScriptableRenderPass
{
const string k_CopyColorTag = "Copy Color";
public CopyColorPass()
{
m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset");

this.destination = destination;
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
CommandBuffer cmd = CommandBufferPool.Get("Copy Color");
CommandBuffer cmd = CommandBufferPool.Get(k_CopyColorTag);
RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRTDesc(ref renderingData.cameraData, opaqueScaler);
RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData, opaqueScaler);
RenderTargetIdentifier colorRT = source.Identifier();
RenderTargetIdentifier opaqueColorRT = destination.Identifier();

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void FrameCleanup(CommandBuffer cmd)
{
if (destination != RenderTargetHandle.CameraTarget)

}
}
}
}

14
com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs


this.destination = destination;
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_DepthCopyTag);
RenderTargetIdentifier depthSurface = source.Identifier();

RenderTextureDescriptor descriptor = ScriptableRenderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor descriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
if (renderingData.cameraData.msaaSamples > 1)
{
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);

cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, depthCopyMaterial);
ScriptableRenderer.CopyTexture(cmd, depthSurface, copyDepthSurface, depthCopyMaterial);
public override void FrameCleanup(CommandBuffer cmd)
{
if (destination != RenderTargetHandle.CameraTarget)

13
com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs


{
public class CreateLightweightRenderTexturesPass : ScriptableRenderPass
{
const string k_CreateRenderTexturesTag = "Create Render Textures";
const int k_DepthStencilBufferBits = 32;
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTargetHandle depthAttachmentHandle { get; set; }

descriptor = baseDescriptor;
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
CommandBuffer cmd = CommandBufferPool.Get("");
CommandBuffer cmd = CommandBufferPool.Get(k_CreateRenderTexturesTag);
colorDescriptor.msaaSamples = (int) samples;
colorDescriptor.msaaSamples = (int)samples;
cmd.GetTemporaryRT(colorAttachmentHandle.id, colorDescriptor, FilterMode.Bilinear);
}

depthDescriptor.colorFormat = RenderTextureFormat.Depth;
depthDescriptor.depthBufferBits = k_DepthStencilBufferBits;
depthDescriptor.msaaSamples = (int) samples;
depthDescriptor.bindMS = (int) samples > 1;
depthDescriptor.msaaSamples = (int)samples;
depthDescriptor.bindMS = (int)samples > 1;
cmd.GetTemporaryRT(depthAttachmentHandle.id, depthDescriptor, FilterMode.Point);
}

10
com.unity.render-pipelines.lightweight/LWRP/Passes/DepthOnlyPass.cs


};
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_DepthPrepassTag);
using (new ProfilingSample(cmd, k_DepthPrepassTag))

{
Camera camera = renderingData.cameraData.camera;
context.StartMultiEye(camera);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
public override void FrameCleanup(CommandBuffer cmd)
{
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)

}
}
}
}

23
com.unity.render-pipelines.lightweight/LWRP/Passes/DirectionalShadowsPass.cs


public static int _ShadowOffset3;
public static int _ShadowmapSize;
}
const int k_MaxCascades = 4;
const int k_ShadowmapBufferBits = 16;
int m_ShadowCasterCascadesCount;

Vector4[] m_CascadeSplitDistances;
const string k_RenderDirectionalShadowmapTag = "Render Directional Shadowmap";
private RenderTargetHandle destination { get; set; }
public DirectionalShadowsPass()

{
this.destination = destination;
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
RenderDirectionalCascadeShadowmap(ref context, ref cullResults, ref renderingData.lightData, ref renderingData.shadowData);
RenderDirectionalCascadeShadowmap(ref context, ref renderingData.cullResults, ref renderingData.lightData, ref renderingData.shadowData);
}
}

void RenderDirectionalCascadeShadowmap(ref ScriptableRenderContext context, ref CullResults cullResults, ref LightData lightData, ref ShadowData shadowData)
{
LightShadows shadowQuality = LightShadows.None;
int shadowLightIndex = lightData.mainLightIndex;
if (shadowLightIndex == -1)
return;

var settings = new DrawShadowsSettings(cullResults, shadowLightIndex);
m_DirectionalShadowmapTexture = RenderTexture.GetTemporary(shadowData.directionalShadowAtlasWidth,
shadowData.directionalShadowAtlasHeight, k_ShadowmapBufferBits, m_ShadowmapFormat);
shadowData.directionalShadowAtlasHeight, k_ShadowmapBufferBits, m_ShadowmapFormat);
m_DirectionalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_DirectionalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;
SetRenderTarget(cmd, m_DirectionalShadowmapTexture, RenderBufferLoadAction.DontCare,

}
if (success)
{
shadowQuality = (shadowData.supportsSoftShadows) ? light.shadows : LightShadows.Hard;
}
// TODO: We should have RenderingData as a readonly but currently we need this to pass shadow rendering to litpass
shadowData.renderedDirectionalShadowQuality = shadowQuality;
}
void SetupDirectionalShadowReceiverConstants(CommandBuffer cmd, ref ShadowData shadowData, VisibleLight shadowLight)

cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowOffset2, new Vector4(-invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f));
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowOffset3, new Vector4(invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f));
cmd.SetGlobalVector(DirectionalShadowConstantBuffer._ShadowmapSize, new Vector4(invShadowAtlasWidth, invShadowAtlasHeight,
shadowData.directionalShadowAtlasWidth, shadowData.directionalShadowAtlasHeight));
shadowData.directionalShadowAtlasWidth, shadowData.directionalShadowAtlasHeight));
}
};
}

19
com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering;
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
if(renderingData.cameraData.isStereoEnabled && XRGraphicsConfig.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
if (renderingData.cameraData.isStereoEnabled && XRGraphicsConfig.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
{
cmd.SetRenderTarget(colorAttachmentHandle.Identifier(), depthAttachmentHandle.Identifier(), 0, CubemapFace.Unknown, -1);
}

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}

6
com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs


{
public class EndXRRenderingPass : ScriptableRenderPass
{
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
context.StopMultiEye(camera);

}
}

8
com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs


private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
public void Setup(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorAttachmentHandle)
{
this.colorAttachmentHandle = colorAttachmentHandle;

public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
{
Material material = renderingData.cameraData.isStereoEnabled ? null : renderer.GetMaterial(MaterialHandles.Blit);
RenderTargetIdentifier sourceRT = colorAttachmentHandle.Identifier();

cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(renderingData.cameraData.camera.pixelRect);
LightweightPipeline.DrawFullScreen(cmd, material);
ScriptableRenderer.RenderFullscreenQuad(cmd, material);
}
else
{

31
com.unity.render-pipelines.lightweight/LWRP/Passes/LocalShadowsPass.cs


public static int _LocalShadowOffset3;
public static int _LocalShadowmapSize;
}
const int k_ShadowmapBufferBits = 16;
RenderTexture m_LocalShadowmapTexture;
RenderTextureFormat m_LocalShadowmapFormat;

float[] m_LocalShadowStrength;
const string k_RenderLocalShadows = "Render Local Shadows";
private RenderTargetHandle destination { get; set; }
public LocalShadowsPass()

? RenderTextureFormat.Shadowmap
: RenderTextureFormat.Depth;
}
if (m_LocalShadowMatrices.Length != maxVisibleLocalLights)
{
m_LocalShadowMatrices = new Matrix4x4[maxVisibleLocalLights];

}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
RenderLocalShadowmapAtlas(ref context, ref cullResults, ref renderingData.lightData, ref renderingData.shadowData);
RenderLocalShadowmapAtlas(ref context, ref renderingData.cullResults, ref renderingData.lightData, ref renderingData.shadowData);
}
}

Matrix4x4 view, proj;
Bounds bounds;
int shadowSampling = 0;
CommandBuffer cmd = CommandBufferPool.Get(k_RenderLocalShadows);
using (new ProfilingSample(cmd, k_RenderLocalShadows))

int sliceResolution = LightweightShadowUtils.GetMaxTileResolutionInAtlas(atlasWidth, atlasHeight, shadowCastingLightsCount);
m_LocalShadowmapTexture = RenderTexture.GetTemporary(shadowData.localShadowAtlasWidth,
shadowData.localShadowAtlasHeight, k_ShadowmapBufferBits, m_LocalShadowmapFormat);
shadowData.localShadowAtlasHeight, k_ShadowmapBufferBits, m_LocalShadowmapFormat);
m_LocalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_LocalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;

Matrix4x4 shadowTransform;
bool success = LightweightShadowUtils.ExtractSpotLightMatrix(ref cullResults, ref shadowData,
shadowLightIndex, out shadowTransform, out view, out proj);
shadowLightIndex, out shadowTransform, out view, out proj);
if (success)
{

m_LocalLightSlices[i].shadowTransform = shadowTransform;
m_LocalShadowStrength[i] = light.shadowStrength;
shadowSampling = Math.Max(shadowSampling, (int)light.shadows);
if (shadowCastingLightsCount > 1)
LightweightShadowUtils.ApplySliceTransform(ref m_LocalLightSlices[i], atlasWidth, atlasHeight);

}
}
SetupLocalLightsShadowReceiverConstants(ref context, cmd, ref shadowData);
SetupLocalLightsShadowReceiverConstants(cmd, ref shadowData);
// TODO: We should have RenderingData as a readonly but currently we need this to pass shadow rendering to litpass
shadowData.renderedLocalShadowQuality = (shadowData.supportsSoftShadows) ? (LightShadows)shadowSampling : LightShadows.Hard;
void SetupLocalLightsShadowReceiverConstants(ref ScriptableRenderContext context, CommandBuffer cmd, ref ShadowData shadowData)
void SetupLocalLightsShadowReceiverConstants(CommandBuffer cmd, ref ShadowData shadowData)
{
for (int i = 0; i < m_LocalLightSlices.Length; ++i)
m_LocalShadowMatrices[i] = m_LocalLightSlices[i].shadowTransform;

cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowOffset2, new Vector4(-invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f));
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowOffset3, new Vector4(invHalfShadowAtlasWidth, invHalfShadowAtlasHeight, 0.0f, 0.0f));
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowmapSize, new Vector4(invShadowAtlasWidth, invShadowAtlasHeight,
shadowData.localShadowAtlasWidth, shadowData.localShadowAtlasHeight));
shadowData.localShadowAtlasWidth, shadowData.localShadowAtlasHeight));
}
}
}

11
com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs


{
public class OpaquePostProcessPass : ScriptableRenderPass
{
const string k_OpaquePostProcessTag = "Render Opaque PostProcess Effects";
private PostProcessRenderContext postContext { get; set; }
public void Setup(
PostProcessRenderContext postProcessRenderContext,

this.colorAttachmentHandle = colorAttachmentHandle;
this.postContext = postProcessRenderContext;
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
CommandBuffer cmd = CommandBufferPool.Get("Render Opaque PostProcess Effects");
CommandBuffer cmd = CommandBufferPool.Get(k_OpaquePostProcessTag);
LightweightPipeline.RenderPostProcess(cmd, postContext, ref renderingData.cameraData, descriptor.colorFormat, source, colorAttachmentHandle.Identifier(), true);
renderer.RenderPostProcess(cmd, ref renderingData.cameraData, descriptor.colorFormat, source, colorAttachmentHandle.Identifier(), true);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

48
com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class RenderOpaqueForwardPass : LightweightForwardPass
public class RenderOpaqueForwardPass : ScriptableRenderPass
public FilterRenderersSettings opaqueFilterSettings { get; private set; }
FilterRenderersSettings m_OpaqueFilterSettings;
RenderTargetHandle colorAttachmentHandle { get; set; }
RenderTargetHandle depthAttachmentHandle { get; set; }
RenderTextureDescriptor descriptor { get; set; }
ClearFlag clearFlag { get; set; }
Color clearColor { get; set; }
RendererConfiguration rendererConfiguration;
opaqueFilterSettings = new FilterRenderersSettings(true)
RegisterShaderPassName("LightweightForward");
RegisterShaderPassName("SRPDefaultUnlit");
m_OpaqueFilterSettings = new FilterRenderersSettings(true)
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle,
RenderTargetHandle depthAttachmentHandle,
ClearFlag clearFlag,
Color clearColor,
RendererConfiguration configuration)
{
this.colorAttachmentHandle = colorAttachmentHandle;
this.depthAttachmentHandle = depthAttachmentHandle;
this.clearColor = CoreUtils.ConvertSRGBToActiveColorSpace(clearColor);
this.clearFlag = clearFlag;
descriptor = baseDescriptor;
this.rendererConfiguration = configuration;
}
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
SetRenderTarget(cmd, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor));
RenderBufferLoadAction loadOp = RenderBufferLoadAction.DontCare;
RenderBufferStoreAction storeOp = RenderBufferStoreAction.Store;
SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp,
depthAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension);
// TODO: We need a proper way to handle multiple camera/ camera stack. Issue is: multiple cameras can share a same RT
// (e.g, split screen games). However devs have to be dilligent with it and know when to clear/preserve color.

cmd.Clear();
Camera camera = renderingData.cameraData.camera;
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, renderingData.supportsDynamicBatching);
context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, m_OpaqueFilterSettings);
RenderObjectsWithError(renderer, ref context, ref cullResults, camera, opaqueFilterSettings, SortFlags.None);
renderer.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_OpaqueFilterSettings, SortFlags.None);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

42
com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class RenderTransparentForwardPass : LightweightForwardPass
public class RenderTransparentForwardPass : ScriptableRenderPass
private FilterRenderersSettings transparentFilterSettings { get; set; }
FilterRenderersSettings m_TransparentFilterSettings;
RenderTargetHandle colorAttachmentHandle { get; set; }
RenderTargetHandle depthAttachmentHandle { get; set; }
RenderTextureDescriptor descriptor { get; set; }
RendererConfiguration rendererConfiguration;
transparentFilterSettings = new FilterRenderersSettings(true)
RegisterShaderPassName("LightweightForward");
RegisterShaderPassName("SRPDefaultUnlit");
m_TransparentFilterSettings = new FilterRenderersSettings(true)
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle,
RenderTargetHandle depthAttachmentHandle,
RendererConfiguration configuration)
{
this.colorAttachmentHandle = colorAttachmentHandle;
this.depthAttachmentHandle = depthAttachmentHandle;
descriptor = baseDescriptor;
rendererConfiguration = configuration;
}
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
SetRenderTarget(cmd, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor));
RenderBufferLoadAction loadOp = RenderBufferLoadAction.Load;
RenderBufferStoreAction storeOp = RenderBufferStoreAction.Store;
SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp,
depthAttachmentHandle.Identifier(), loadOp, storeOp, ClearFlag.None, Color.black, descriptor.dimension);
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, transparentFilterSettings);
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, renderingData.supportsDynamicBatching);
context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, m_TransparentFilterSettings);
RenderObjectsWithError(renderer, ref context, ref cullResults, camera, transparentFilterSettings, SortFlags.None);
renderer.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_TransparentFilterSettings, SortFlags.None);
}
context.ExecuteCommandBuffer(cmd);

4
com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs


this.source = source;
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
{
// Restore Render target for additional editor rendering.
// Note: Scene view camera always perform depth prepass

18
com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
const string k_CollectShadowsTag = "Collect Shadows";
RenderTextureFormat m_ColorFormat;
public ScreenSpaceShadowResolvePass()

descriptor = baseDescriptor;
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
if (renderingData.shadowData.renderedDirectionalShadowQuality == LightShadows.None)
if (renderingData.lightData.mainLightIndex == -1)
CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows");
CommandBuffer cmd = CommandBufferPool.Get(k_CollectShadowsTag);
SetShadowCollectPassKeywords(cmd, ref renderingData.shadowData);
VisibleLight shadowLight = renderingData.lightData.visibleLights[renderingData.lightData.mainLightIndex];
SetShadowCollectPassKeywords(cmd, ref shadowLight, ref renderingData.shadowData);
// Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that
// doesn't like null sources when trying to determine a stereo-ized blit. So for proper

}
}
void SetShadowCollectPassKeywords(CommandBuffer cmd, ref ShadowData shadowData)
void SetShadowCollectPassKeywords(CommandBuffer cmd, ref VisibleLight shadowLight, ref ShadowData shadowData)
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.SoftShadows, shadowData.renderedDirectionalShadowQuality == LightShadows.Soft);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.SoftShadows, shadowData.supportsSoftShadows && shadowLight.light.shadows == LightShadows.Soft);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.CascadeShadows, shadowData.directionalLightCascadeCount > 1);
}
}

6
com.unity.render-pipelines.lightweight/LWRP/Passes/ScriptableRenderPass.cs


public virtual void FrameCleanup(CommandBuffer cmd)
{}
public abstract void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData);
public abstract void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData);
protected void RegisterShaderPassName(string passName)
{

4
com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs


{
public class SetupForwardRenderingPass : ScriptableRenderPass
{
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
{
// SetupCameraProperties does the following:
// Setup Camera RenderTarget and Viewport

44
com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs


public static int _LightIndexBuffer;
}
const string k_SetupLightConstants = "Setup Light Constants";
MixedLightingSetup m_MixedLightingSetup;
Vector4 k_DefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);

Vector4[] m_LightDistanceAttenuations;
Vector4[] m_LightSpotDirections;
Vector4[] m_LightSpotAttenuations;
private int maxVisibleLocalLights { get; set; }
private ComputeBuffer perObjectLightIndices { get; set; }

{
this.maxVisibleLocalLights = maxVisibleLocalLights;
this.perObjectLightIndices = perObjectLightIndices;
if (m_LightColors.Length != maxVisibleLocalLights)
{
m_LightPositions = new Vector4[maxVisibleLocalLights];

// if not using a compute buffer, engine will set indices in 2 vec4 constants
// unity_4LightIndices0 and unity_4LightIndices1
if (perObjectLightIndices != null)
cmd.SetGlobalBuffer("_LightIndexBuffer", perObjectLightIndices);
cmd.SetGlobalBuffer(LightConstantBuffer._LightIndexBuffer, perObjectLightIndices);
}
else
{

// TODO: We have to discuss cookie approach on LWRP.
// CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.MainLightCookieText, mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
LightShadows directionalShadowQuality = shadowData.renderedDirectionalShadowQuality;
LightShadows localShadowQuality = shadowData.renderedLocalShadowQuality;
List<VisibleLight> visibleLights = lightData.visibleLights;
// If shadows were resolved in screen space we don't sample shadowmap in lit shader. In that case we just set softDirectionalShadows to false.
bool softDirectionalShadows = shadowData.renderDirectionalShadows && !shadowData.requiresScreenSpaceShadowResolve &&
shadowData.supportsSoftShadows && lightData.mainLightIndex != -1 &&
visibleLights[lightData.mainLightIndex].light.shadows == LightShadows.Soft;
bool softLocalShadows = false;
if (shadowData.renderLocalShadows && shadowData.supportsSoftShadows)
{
List<int> visibleLocalLightIndices = lightData.visibleLocalLightIndices;
for (int i = 0; i < visibleLocalLightIndices.Count; ++i)
{
if (visibleLights[visibleLocalLightIndices[i]].light.shadows == LightShadows.Soft)
{
softLocalShadows = true;
break;
}
}
}
bool hasSoftShadows = (directionalShadowQuality == LightShadows.Soft || localShadowQuality == LightShadows.Soft) &&
shadowData.supportsSoftShadows;
bool hasSoftShadows = softDirectionalShadows || softLocalShadows;
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.DirectionalShadows, directionalShadowQuality != LightShadows.None);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.LocalShadows, localShadowQuality != LightShadows.None);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.DirectionalShadows, shadowData.renderDirectionalShadows);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.LocalShadows, shadowData.renderLocalShadows);
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", cameraData.requiresSoftParticles);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.SoftParticles, cameraData.requiresSoftParticles);
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants");
CommandBuffer cmd = CommandBufferPool.Get(k_SetupLightConstants);
SetupShaderLightConstants(cmd, ref renderingData.lightData);
SetShaderKeywords(cmd, ref renderingData.cameraData, ref renderingData.lightData, ref renderingData.shadowData);
context.ExecuteCommandBuffer(cmd);

12
com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs


{
public class TransparentPostProcessPass : ScriptableRenderPass
{
const string k_PostProcessingTag = "Render PostProcess Effects";
private PostProcessRenderContext postContext { get; set; }
private RenderTargetIdentifier destination { get; set; }
public void Setup(

RenderTargetIdentifier destination)
{
this.colorAttachmentHandle = colorAttachmentHandle;
this.postContext = postProcessRenderContext;
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
CommandBuffer cmd = CommandBufferPool.Get("Render PostProcess Effects");
LightweightPipeline.RenderPostProcess(cmd, postContext, ref renderingData.cameraData, descriptor.colorFormat, colorAttachmentHandle.Identifier(), destination, false);
CommandBuffer cmd = CommandBufferPool.Get(k_PostProcessingTag);
renderer.RenderPostProcess(cmd, ref renderingData.cameraData, descriptor.colorFormat, colorAttachmentHandle.Identifier(), destination, false);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

15
com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandle.cs


public struct RenderTargetHandle
{
public int id { private set; get; }
public static readonly RenderTargetHandle CameraTarget = new RenderTargetHandle {id = -1};
public void Init(string shaderProperty)

public RenderTargetIdentifier Identifier()
{
if (id == -1)

return new RenderTargetIdentifier(id);
}
public bool Equals(RenderTargetHandle other)
{
return id == other.id;

{
if (ReferenceEquals(null, obj)) return false;
return obj is RenderTargetHandle && Equals((RenderTargetHandle) obj);
return obj is RenderTargetHandle && Equals((RenderTargetHandle)obj);
}
public override int GetHashCode()

public static bool operator ==(RenderTargetHandle c1, RenderTargetHandle c2)
public static bool operator==(RenderTargetHandle c1, RenderTargetHandle c2)
public static bool operator !=(RenderTargetHandle c1, RenderTargetHandle c2)
public static bool operator!=(RenderTargetHandle c1, RenderTargetHandle c2)
}
}

2
com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs


{
}*/
}
}

2
com.unity.render-pipelines.lightweight/LWRP/SampleCount.cs


Two = 2,
Four = 4,
}
}
}

2
com.unity.render-pipelines.lightweight/LWRP/SceneViewDrawMode.cs


cameraMode.drawMode == DrawCameraMode.ValidateMetalSpecular ||
cameraMode.drawMode == DrawCameraMode.ShadowMasks ||
cameraMode.drawMode == DrawCameraMode.LightOverlap
)
)
return false;
return true;

214
com.unity.render-pipelines.lightweight/LWRP/ScriptableRenderer.cs


using System;
using System.Collections.Generic;
using System.Diagnostics;
public class ScriptableRenderer
public sealed class ScriptableRenderer
{
// Lights are culled per-object. In platforms that don't use StructuredBuffer
// the engine will set 4 light indices in the following constant unity_4LightIndices0

{
get
{
// TODO: Graphics Emulation are breaking StructuredBuffers disabling it for now until
// TODO: Graphics Emulation are breaking StructuredBuffers disabling it for now until
// we have a fix for it
return false;
// return SystemInfo.supportsComputeShaders &&

public int maxSupportedVertexLights { get { return k_MaxVertexLights; } }
public PostProcessRenderContext postProcessRenderContext { get; private set; }
public PostProcessRenderContext postProcessingContext { get; private set; }
static Mesh s_FullscreenMesh = null;
static Mesh fullscreenMesh
{
get
{
if (s_FullscreenMesh != null)
return s_FullscreenMesh;
float topV = 1.0f;
float bottomV = 0.0f;
Mesh mesh = new Mesh { name = "Fullscreen Quad" };
mesh.SetVertices(new List<Vector3>
{
new Vector3(-1.0f, -1.0f, 0.0f),
new Vector3(-1.0f, 1.0f, 0.0f),
new Vector3(1.0f, -1.0f, 0.0f),
new Vector3(1.0f, 1.0f, 0.0f)
});
mesh.SetUVs(0, new List<Vector2>
{
new Vector2(0.0f, bottomV),
new Vector2(0.0f, topV),
new Vector2(1.0f, bottomV),
new Vector2(1.0f, topV)
});
mesh.SetIndices(new[] { 0, 1, 2, 2, 1, 3 }, MeshTopology.Triangles, 0, false);
mesh.UploadMeshData(true);
return mesh;
}
}
List<ShaderPassName> m_LegacyShaderPassNames = new List<ShaderPassName>()
{
new ShaderPassName("Always"),
new ShaderPassName("ForwardBase"),
new ShaderPassName("PrepassBase"),
new ShaderPassName("Vertex"),
new ShaderPassName("VertexLMRGBM"),
new ShaderPassName("VertexLM"),
};
const string k_ReleaseResourcesTag = "Release Resources";
public ScriptableRenderer(LightweightPipelineAsset pipelineAsset)
{
m_Materials = new[]

CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader),
};
postProcessRenderContext = new PostProcessRenderContext();
postProcessingContext = new PostProcessRenderContext();
}
public void Dispose()

CoreUtils.Destroy(m_Materials[i]);
}
public static RenderTextureDescriptor CreateRTDesc(ref CameraData cameraData, float scaler = 1.0f)
{
Camera camera = cameraData.camera;
RenderTextureDescriptor desc;
float renderScale = cameraData.renderScale;
if (cameraData.isStereoEnabled)
{
return XRGraphicsConfig.eyeTextureDesc;
}
else
{
desc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
}
desc.colorFormat = cameraData.isHdrEnabled ? RenderTextureFormat.DefaultHDR :
RenderTextureFormat.Default;
desc.enableRandomWrite = false;
desc.sRGB = true;
desc.width = (int)((float)desc.width * renderScale * scaler);
desc.height = (int)((float)desc.height * renderScale * scaler);
return desc;
}
public void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
public void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
m_ActiveRenderPassQueue[i].Execute(this, ref context, ref cullResults, ref renderingData);
m_ActiveRenderPassQueue[i].Execute(this, context, ref renderingData);
DisposePasses(ref context);
}

if (handleID >= m_Materials.Length)
{
Debug.LogError(string.Format("Material {0} is not registered.",
Enum.GetName(typeof(MaterialHandles), handleID)));
Enum.GetName(typeof(MaterialHandles), handleID)));
public void Clear()
{

m_ActiveRenderPassQueue.Add(pass);
}
public static bool RequiresIntermediateColorTexture(ref CameraData cameraData, RenderTextureDescriptor baseDescriptor)
{
if (cameraData.isOffscreenRender)
return false;
bool isScaledRender = !Mathf.Approximately(cameraData.renderScale, 1.0f);
bool isTargetTexture2DArray = baseDescriptor.dimension == TextureDimension.Tex2DArray;
return cameraData.isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
cameraData.postProcessEnabled || cameraData.requiresOpaqueTexture || isTargetTexture2DArray || !cameraData.isDefaultViewport;
}
public static bool CanCopyDepth(ref CameraData cameraData)
{
bool msaaEnabledForCamera = (int)cameraData.msaaSamples > 1;
bool supportsTextureCopy = SystemInfo.copyTextureSupport != CopyTextureSupport.None;
bool supportsDepthTarget = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth);
bool supportsDepthCopy = !msaaEnabledForCamera && (supportsDepthTarget || supportsTextureCopy);
// TODO: We don't have support to highp Texture2DMS currently and this breaks depth precision.
// currently disabling it until shader changes kick in.
//bool msaaDepthResolve = msaaEnabledForCamera && SystemInfo.supportsMultisampledTextures != 0;
bool msaaDepthResolve = false;
return supportsDepthCopy || msaaDepthResolve;
}
void DisposePasses(ref ScriptableRenderContext context)
{
CommandBuffer cmd = CommandBufferPool.Get("Release Resources");
for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
m_ActiveRenderPassQueue[i].FrameCleanup(cmd);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public void SetupPerObjectLightIndices(ref CullResults cullResults, ref LightData lightData)
{
if (lightData.totalAdditionalLightsCount == 0)

}
}
public void RenderPostProcess(CommandBuffer cmd, ref CameraData cameraData, RenderTextureFormat colorFormat, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool opaqueOnly)
{
Camera camera = cameraData.camera;
postProcessingContext.Reset();
postProcessingContext.camera = camera;
postProcessingContext.source = source;
postProcessingContext.sourceFormat = colorFormat;
postProcessingContext.destination = dest;
postProcessingContext.command = cmd;
postProcessingContext.flip = !cameraData.isStereoEnabled && camera.targetTexture == null;
if (opaqueOnly)
cameraData.postProcessLayer.RenderOpaqueOnly(postProcessingContext);
else
cameraData.postProcessLayer.Render(postProcessingContext);
}
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
public void RenderObjectsWithError(ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags)
{
Material errorMaterial = GetMaterial(MaterialHandles.Error);
if (errorMaterial != null)
{
DrawRendererSettings errorSettings = new DrawRendererSettings(camera, m_LegacyShaderPassNames[0]);
for (int i = 1; i < m_LegacyShaderPassNames.Count; ++i)
errorSettings.SetShaderPassName(i, m_LegacyShaderPassNames[i]);
errorSettings.sorting.flags = sortFlags;
errorSettings.rendererConfiguration = RendererConfiguration.None;
errorSettings.SetOverrideMaterial(errorMaterial, 0);
context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings);
}
}
public static RenderTextureDescriptor CreateRenderTextureDescriptor(ref CameraData cameraData, float scaler = 1.0f)
{
Camera camera = cameraData.camera;
RenderTextureDescriptor desc;
float renderScale = cameraData.renderScale;
if (cameraData.isStereoEnabled)
{
return XRGraphicsConfig.eyeTextureDesc;
}
else
{
desc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
}
desc.colorFormat = cameraData.isHdrEnabled ? RenderTextureFormat.DefaultHDR :
RenderTextureFormat.Default;
desc.enableRandomWrite = false;
desc.sRGB = true;
desc.width = (int)((float)desc.width * renderScale * scaler);
desc.height = (int)((float)desc.height * renderScale * scaler);
return desc;
}
public static bool RequiresIntermediateColorTexture(ref CameraData cameraData, RenderTextureDescriptor baseDescriptor)
{
if (cameraData.isOffscreenRender)
return false;
bool isScaledRender = !Mathf.Approximately(cameraData.renderScale, 1.0f);
bool isTargetTexture2DArray = baseDescriptor.dimension == TextureDimension.Tex2DArray;
return cameraData.isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled ||
cameraData.postProcessEnabled || cameraData.requiresOpaqueTexture || isTargetTexture2DArray || !cameraData.isDefaultViewport;
}
public static ClearFlag GetCameraClearFlag(Camera camera)
{
ClearFlag clearFlag = ClearFlag.None;

}
return configuration;
}
public static void RenderFullscreenQuad(CommandBuffer cmd, Material material, MaterialPropertyBlock properties = null, int shaderPassId = 0)
{
cmd.DrawMesh(fullscreenMesh, Matrix4x4.identity, material, 0, shaderPassId, properties);
}
public static void CopyTexture(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier dest, Material material)
{
// TODO: In order to issue a copyTexture we need to also check if source and dest have same size
//if (SystemInfo.copyTextureSupport != CopyTextureSupport.None)
// cmd.CopyTexture(source, dest);
//else
cmd.Blit(source, dest, material);
}
void DisposePasses(ref ScriptableRenderContext context)
{
CommandBuffer cmd = CommandBufferPool.Get(k_ReleaseResourcesTag);
for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
m_ActiveRenderPassQueue[i].FrameCleanup(cmd);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

12
com.unity.testing.srp.lightweight/Tests/Scenes/045_CustomLWPipe/CustomLWPipe.cs


m_Initialized = true;
}
public void Setup(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults, ref RenderingData renderingData)
public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData)
renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRTDesc(ref renderingData.cameraData);
renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;

renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
Camera camera = renderingData.cameraData.camera;
bool dynamicBatching = renderingData.supportsDynamicBatching;
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ScriptableRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching);
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ScriptableRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration);
renderer.EnqueuePass(m_RenderOpaqueForwardPass);
}
}

23
com.unity.testing.srp.lightweight/Tests/Scenes/052_LWCallbacks/CameraCallbackTests.cs


using UnityEngine;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Rendering;

m_Target = target;
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
var cmd = CommandBufferPool.Get("Capture Pass");
cmd.GetTemporaryRT(m_Target.id, opaqueDesc);

{
CapturePass m_CopyResult = new CapturePass();
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
m_CopyResult.Execute(renderer, ref context, ref cullResults, ref renderingData);
m_CopyResult.Execute(renderer, context, ref renderingData);
Material material = renderer.GetMaterial(MaterialHandles.Blit);

cmd.SetViewport(new Rect(0, renderingData.cameraData.camera.pixelRect.height / 2.0f, renderingData.cameraData.camera.pixelRect.width / 3.0f, renderingData.cameraData.camera.pixelRect.height / 2.0f));
cmd.SetGlobalTexture("_BlitTex", afterDepth.Identifier());
LightweightPipeline.DrawFullScreen(cmd, material);
ScriptableRenderer.RenderFullscreenQuad(cmd, material);
LightweightPipeline.DrawFullScreen(cmd, material);
ScriptableRenderer.RenderFullscreenQuad(cmd, material);
LightweightPipeline.DrawFullScreen(cmd, material);
ScriptableRenderer.RenderFullscreenQuad(cmd, material);
LightweightPipeline.DrawFullScreen(cmd, material);
ScriptableRenderer.RenderFullscreenQuad(cmd, material);
LightweightPipeline.DrawFullScreen(cmd, material);
ScriptableRenderer.RenderFullscreenQuad(cmd, material);
//TODO: Upsidown UV trash, ignore this for now

11
com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs.meta


fileFormatVersion: 2
guid: 55fe4224e5c9e3a499307d28ede17d2b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

83
com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs


using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public abstract class LightweightForwardPass : ScriptableRenderPass
{
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTargetHandle depthAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
protected ClearFlag clearFlag { get; set; }
protected Color clearColor { get; set; }
List<ShaderPassName> m_LegacyShaderPassNames;
protected RendererConfiguration rendererConfiguration;
protected bool dynamicBatching;
protected LightweightForwardPass()
{
m_LegacyShaderPassNames = new List<ShaderPassName>();
m_LegacyShaderPassNames.Add(new ShaderPassName("Always"));
m_LegacyShaderPassNames.Add(new ShaderPassName("ForwardBase"));
m_LegacyShaderPassNames.Add(new ShaderPassName("PrepassBase"));
m_LegacyShaderPassNames.Add(new ShaderPassName("Vertex"));
m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLMRGBM"));
m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLM"));
RegisterShaderPassName("LightweightForward");
RegisterShaderPassName("SRPDefaultUnlit");
}
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle,
RenderTargetHandle depthAttachmentHandle,
ClearFlag clearFlag,
Color clearColor,
RendererConfiguration configuration,
bool dynamicbatching)
{
this.colorAttachmentHandle = colorAttachmentHandle;
this.depthAttachmentHandle = depthAttachmentHandle;
this.clearColor = clearColor;
this.clearFlag = clearFlag;
descriptor = baseDescriptor;
this.rendererConfiguration = configuration;
this.dynamicBatching = dynamicbatching;
}
protected void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor)
{
SetRenderTarget(
cmd,
colorAttachmentHandle.Identifier(),
loadOp,
storeOp,
depthAttachmentHandle.Identifier(),
loadOp,
storeOp,
clearFlag,
clearColor,
descriptor.dimension);
}
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
protected void RenderObjectsWithError(ScriptableRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags)
{
Material errorMaterial = renderer.GetMaterial(MaterialHandles.Error);
if (errorMaterial != null)
{
DrawRendererSettings errorSettings = new DrawRendererSettings(camera, m_LegacyShaderPassNames[0]);
for (int i = 1; i < m_LegacyShaderPassNames.Count; ++i)
errorSettings.SetShaderPassName(i, m_LegacyShaderPassNames[i]);
errorSettings.sorting.flags = sortFlags;
errorSettings.rendererConfiguration = RendererConfiguration.None;
errorSettings.SetOverrideMaterial(errorMaterial, 0);
context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings);
}
}
}
}
正在加载...
取消
保存