浏览代码

Draft/lw/callbacks (#1646)

* Add explicit pass architecture to lightweight. It is possible to write a custom pass and a custom LW renderer and arrange these passes in a way that makes sense for your project.

* Remove Command buffer from setup API

* Pull surface data into their own passes for more explicit control.

* Splitting out existing LW passes to be more granular

* Add default LWRP renderer that can be used as a reference

* Add test for custom LW pipe.

* Split out RT handles to be part of the renderer configuration now.

* Remove Surface handling from LW Renderer and push to passes.

* Add template images for new test.

* Update changelog
/main
GitHub 7 年前
当前提交
170c9b56
共有 63 个文件被更改,包括 2394 次插入917 次删除
  1. 35
      TestProjects/LWGraphicsTest/Packages/manifest.json
  2. 3
      TestProjects/LWGraphicsTest/ProjectSettings/EditorBuildSettings.asset
  3. 1
      com.unity.render-pipelines.lightweight/CHANGELOG.md
  4. 50
      com.unity.render-pipelines.lightweight/LWRP/LightweightConstantBuffer.cs
  5. 213
      com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs
  6. 31
      com.unity.render-pipelines.lightweight/LWRP/LightweightPipeline.cs
  7. 49
      com.unity.render-pipelines.lightweight/LWRP/Passes/DepthOnlyPass.cs
  8. 28
      com.unity.render-pipelines.lightweight/LWRP/Passes/DirectionalShadowsPass.cs
  9. 579
      com.unity.render-pipelines.lightweight/LWRP/Passes/ForwardLitPass.cs
  10. 23
      com.unity.render-pipelines.lightweight/LWRP/Passes/LocalShadowsPass.cs
  11. 28
      com.unity.render-pipelines.lightweight/LWRP/Passes/ScreenSpaceShadowResolvePass.cs
  12. 82
      com.unity.render-pipelines.lightweight/LWRP/Passes/ScriptableRenderPass.cs
  13. 34
      TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/OSXEditor/Metal/045_CustomLWPipe.png
  14. 88
      TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/OSXEditor/Metal/045_CustomLWPipe.png.meta
  15. 36
      TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/045_CustomLWPipe.png
  16. 88
      TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/045_CustomLWPipe.png.meta
  17. 466
      TestProjects/LWGraphicsTest/Assets/Scenes/045_CustomLWPipe.unity
  18. 8
      TestProjects/LWGraphicsTest/Assets/Scenes/045_CustomLWPipe.unity.meta
  19. 206
      com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs
  20. 11
      com.unity.render-pipelines.lightweight/LWRP/DefaultRendererSetup.cs.meta
  21. 9
      com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs
  22. 11
      com.unity.render-pipelines.lightweight/LWRP/IRendererSetup.cs.meta
  23. 12
      com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs
  24. 11
      com.unity.render-pipelines.lightweight/LWRP/MaterialHandles.cs.meta
  25. 14
      com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs
  26. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/BeginXRRenderingPass.cs.meta
  27. 70
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs
  28. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyColorPass.cs.meta
  29. 72
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs
  30. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/CopyDepthPass.cs.meta
  31. 69
      com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs
  32. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/CreateLightweightRenderTexturesPass.cs.meta
  33. 14
      com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs
  34. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/DrawSkyboxPass.cs.meta
  35. 15
      com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs
  36. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/EndXRRenderingPass.cs.meta
  37. 56
      com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs
  38. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/FinalBlitPass.cs.meta
  39. 99
      com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs
  40. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/LightweightForwardPass.cs.meta
  41. 32
      com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs
  42. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/OpaquePostProcessPass.cs.meta
  43. 42
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs
  44. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderOpaqueForwardPass.cs.meta
  45. 33
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs
  46. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/RenderTransparentForwardPass.cs.meta
  47. 32
      com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs
  48. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/SceneViewDepthCopy.cs.meta
  49. 21
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs
  50. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupForwardRenderingPass.cs.meta
  51. 272
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs
  52. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/SetupLightweightConstanstPass.cs.meta
  53. 30
      com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs
  54. 11
      com.unity.render-pipelines.lightweight/LWRP/Passes/TransparentPostProcessPass.cs.meta
  55. 52
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandle.cs
  56. 11
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandle.cs.meta
  57. 7
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs
  58. 11
      com.unity.render-pipelines.lightweight/LWRP/RenderTargetHandles.cs.meta
  59. 9
      com.unity.render-pipelines.lightweight/LWRP/SampleCount.cs
  60. 11
      com.unity.render-pipelines.lightweight/LWRP/SampleCount.cs.meta
  61. 61
      TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs
  62. 11
      TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs.meta

35
TestProjects/LWGraphicsTest/Packages/manifest.json


{
"dependencies": {
"com.unity.analytics": "2.0.16",
"com.unity.package-manager-ui": "2.0.0-preview.3",
"com.unity.standardevents": "1.0.13",
"com.unity.textmeshpro": "1.2.1",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
"com.unity.textmeshpro": "1.2.4"
},
"testables": [
"com.unity.render-pipelines.lightweight",

3
TestProjects/LWGraphicsTest/ProjectSettings/EditorBuildSettings.asset


- enabled: 1
path: Assets/Scenes/035_Shader_TerrainShaders.unity
guid: 770b86964e87d47e4bdbafa425ccd238
- enabled: 1
path: Assets/Scenes/045_CustomLWPipe.unity
guid: 349df85634812cd4e9157f31eace4abe
m_configObjects: {}

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


### Added
- Added camera additional data component to control shadows, depth and color texture.
- pipeline now uses XRSEttings.eyeTextureResolutionScale as renderScale when in XR.
- New pass architecture. Allows for custom passes to be written and then used on a per camera basis in LWRP
### Changed
- Shadow rendering has been optimized for the Mali Utgard architecture by removing indexing and avoiding divisions for orthographic projections. This reduces the frame time by 25% on the Overdraw benchmark.

50
com.unity.render-pipelines.lightweight/LWRP/LightweightConstantBuffer.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public static class PerFrameBuffer
{
public static int _GlossyEnvironmentColor;
public static int _SubtractiveShadowColor;
}
public static class PerCameraBuffer
{
public static int _MainLightPosition;
public static int _MainLightColor;
public static int _MainLightCookie;
public static int _WorldToLight;
public static int _AdditionalLightCount;
public static int _AdditionalLightPosition;
public static int _AdditionalLightColor;
public static int _AdditionalLightDistanceAttenuation;
public static int _AdditionalLightSpotDir;
public static int _AdditionalLightSpotAttenuation;
public static int _LightIndexBuffer;
public static int _ScaledScreenParams;
}
public static class DirectionalShadowConstantBuffer
{
public static int _WorldToShadow;
public static int _ShadowData;
public static int _DirShadowSplitSpheres0;
public static int _DirShadowSplitSpheres1;
public static int _DirShadowSplitSpheres2;
public static int _DirShadowSplitSpheres3;
public static int _DirShadowSplitSphereRadii;
public static int _ShadowOffset0;
public static int _ShadowOffset1;
public static int _ShadowOffset2;
public static int _ShadowOffset3;
public static int _ShadowmapSize;
}
public static class LocalShadowConstantBuffer
{
public static int _LocalWorldToShadowAtlas;
public static int _LocalShadowStrength;
public static int _LocalShadowOffset0;
public static int _LocalShadowOffset1;
public static int _LocalShadowOffset2;
public static int _LocalShadowOffset3;
public static int _LocalShadowmapSize;
}
}

213
com.unity.render-pipelines.lightweight/LWRP/LightweightForwardRenderer.cs


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public enum RenderPassHandles
{
DepthPrepass,
DirectionalShadows,
LocalShadows,
ScreenSpaceShadowResolve,
ForwardLit,
Count,
}
public enum MaterialHandles
{
Error,
DepthCopy,
Sampling,
Blit,
ScrenSpaceShadow,
Count,
}
public static class RenderTargetHandles
{
public static int Color;
public static int DepthAttachment;
public static int DepthTexture;
public static int OpaqueColor;
public static int DirectionalShadowmap;
public static int LocalShadowmap;
public static int ScreenSpaceShadowmap;
}
public class LightweightForwardRenderer
{
// Lights are culled per-object. In platforms that don't use StructuredBuffer

}
// TODO: Profile performance of using ComputeBuffer on mobiles that support it
public bool useComputeBufferForPerObjectLightIndices
public static bool useComputeBufferForPerObjectLightIndices
{
get
{

public FilterRenderersSettings opaqueFilterSettings { get; private set; }
public FilterRenderersSettings transparentFilterSettings { get; private set; }
Dictionary<int, RenderTargetIdentifier> m_ResourceMap = new Dictionary<int, RenderTargetIdentifier>();
List<ScriptableRenderPass> m_ActiveShadowQueue = new List<ScriptableRenderPass>();
ScriptableRenderPass[] m_RenderPassSet = new ScriptableRenderPass[(int)RenderPassHandles.Count];
// RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
// Samples (MSAA) depend on camera and pipeline
RegisterSurface("_CameraColorTexture", out RenderTargetHandles.Color);
RegisterSurface("_CameraDepthAttachment", out RenderTargetHandles.DepthAttachment);
RegisterSurface("_CameraDepthTexture", out RenderTargetHandles.DepthTexture);
RegisterSurface("_CameraOpaqueTexture", out RenderTargetHandles.OpaqueColor);
RegisterSurface("_DirectionalShadowmapTexture", out RenderTargetHandles.DirectionalShadowmap);
RegisterSurface("_LocalShadowmapTexture", out RenderTargetHandles.LocalShadowmap);
RegisterSurface("_ScreenSpaceShadowMapTexture", out RenderTargetHandles.ScreenSpaceShadowmap);
m_Materials = new Material[(int)MaterialHandles.Count]
{
CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"),

CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader),
};
m_RenderPassSet = new ScriptableRenderPass[(int)RenderPassHandles.Count]
{
new DepthOnlyPass(this),
new DirectionalShadowsPass(this),
new LocalShadowsPass(this),
new ScreenSpaceShadowResolvePass(this),
new ForwardLitPass(this),
};
postProcessRenderContext = new PostProcessRenderContext();
opaqueFilterSettings = new FilterRenderersSettings(true)

return desc;
}
public void Setup(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
Clear();
SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;
bool requiresCameraDepth = renderingData.cameraData.requiresDepthTexture;
bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve ||
renderingData.cameraData.isSceneViewCamera || (requiresCameraDepth && !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;
CommandBuffer cmd = CommandBufferPool.Get("Setup Rendering");
if (requiresDepthPrepass)
EnqueuePass(cmd, RenderPassHandles.DepthPrepass, baseDescriptor, null, RenderTargetHandles.DepthTexture);
if (renderingData.shadowData.renderDirectionalShadows)
{
EnqueuePass(cmd, RenderPassHandles.DirectionalShadows, shadowDescriptor);
if (renderingData.shadowData.requiresScreenSpaceShadowResolve)
EnqueuePass(cmd, RenderPassHandles.ScreenSpaceShadowResolve, baseDescriptor, new[] {RenderTargetHandles.ScreenSpaceShadowmap});
}
if (renderingData.shadowData.renderLocalShadows)
EnqueuePass(cmd, RenderPassHandles.LocalShadows, shadowDescriptor);
bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass;
bool requiresColorAttachment = RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor, requiresDepthAttachment);
int[] colorHandles = (requiresColorAttachment) ? new[] {RenderTargetHandles.Color} : null;
int depthHandle = (requiresDepthAttachment) ? RenderTargetHandles.DepthAttachment : -1;
EnqueuePass(cmd, RenderPassHandles.ForwardLit, baseDescriptor, colorHandles, depthHandle, renderingData.cameraData.msaaSamples);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
// TODO: The reason we have to separate passes into two queues is because shadows require different camera
// context. We need to take a look at approaches to effectively share shadow between cameras, then we
// can move this out
for (int i = 0; i < m_ActiveShadowQueue.Count; ++i)
m_ActiveShadowQueue[i].Execute(ref context, ref cullResults, ref renderingData);
// SetupCameraProperties does the following:
// Setup Camera RenderTarget and Viewport
// VR Camera Setup and SINGLE_PASS_STEREO props
// Setup camera view, proj and their inv matrices.
// Setup properties: _WorldSpaceCameraPos, _ProjectionParams, _ScreenParams, _ZBufferParams, unity_OrthoParams
// Setup camera world clip planes props
// setup HDR keyword
// Setup global time properties (_Time, _SinTime, _CosTime)
context.SetupCameraProperties(renderingData.cameraData.camera, renderingData.cameraData.isStereoEnabled);
#if UNITY_EDITOR
if (renderingData.cameraData.isSceneViewCamera)
{
// Restore Render target for additional editor rendering.
// Note: Scene view camera always perform depth prepass
CommandBuffer cmd = CommandBufferPool.Get("Copy Depth to Camera");
CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget);
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
cmd.Blit(GetSurface(RenderTargetHandles.DepthTexture), BuiltinRenderTextureType.CameraTarget, GetMaterial(MaterialHandles.DepthCopy));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
#endif
public RenderTargetIdentifier GetSurface(int handle)
{
if (handle == -1)
return BuiltinRenderTextureType.CameraTarget;
RenderTargetIdentifier renderTargetID;
if (!m_ResourceMap.TryGetValue(handle, out renderTargetID))
{
Debug.LogError(string.Format("Handle {0} has not any surface registered to it.", handle));
return new RenderTargetIdentifier();
}
return renderTargetID;
}
public Material GetMaterial(MaterialHandles handle)
{
int handleID = (int)handle;

return m_Materials[handleID];
}
ScriptableRenderPass GetPass(RenderPassHandles handle)
{
int handleID = (int)handle;
if (handleID >= m_RenderPassSet.Length)
{
Debug.LogError(string.Format("Render Pass {0} is not registered.",
Enum.GetName(typeof(RenderPassHandles), handleID)));
return null;
}
return m_RenderPassSet[handleID];
}
void Clear()
public void Clear()
m_ActiveShadowQueue.Clear();
void RegisterSurface(string shaderProperty, out int handle)
{
handle = Shader.PropertyToID(shaderProperty);
m_ResourceMap.Add(handle, new RenderTargetIdentifier(handle));
}
void EnqueuePass(CommandBuffer cmd, RenderPassHandles passHandle, RenderTextureDescriptor baseDescriptor,
int[] colorAttachmentHandles = null, int depthAttachmentHandle = -1, int samples = 1)
public void EnqueuePass(ScriptableRenderPass pass)
ScriptableRenderPass pass = GetPass(passHandle);
pass.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
if (passHandle == RenderPassHandles.DirectionalShadows || passHandle == RenderPassHandles.LocalShadows)
m_ActiveShadowQueue.Add(pass);
else
m_ActiveRenderPassQueue.Add(pass);
m_ActiveRenderPassQueue.Add(pass);
bool RequiresIntermediateColorTexture(ref CameraData cameraData, RenderTextureDescriptor baseDescriptor, bool requiresCameraDepth)
public static bool RequiresIntermediateColorTexture(ref CameraData cameraData, RenderTextureDescriptor baseDescriptor, bool requiresCameraDepth)
{
if (cameraData.isOffscreenRender)
return false;

cameraData.postProcessEnabled || cameraData.requiresOpaqueTexture || isTargetTexture2DArray || !cameraData.isDefaultViewport;
}
bool CanCopyDepth(ref CameraData cameraData)
public static bool CanCopyDepth(ref CameraData cameraData)
bool msaaEnabledForCamera = cameraData.msaaSamples > 1;
bool msaaEnabledForCamera = (int)cameraData.msaaSamples > 1;
bool supportsTextureCopy = SystemInfo.copyTextureSupport != CopyTextureSupport.None;
bool supportsDepthTarget = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Depth);
bool supportsDepthCopy = !msaaEnabledForCamera && (supportsDepthTarget || supportsTextureCopy);

void DisposePasses(ref ScriptableRenderContext context)
{
CommandBuffer cmd = CommandBufferPool.Get("Release Resources");
for (int i = 0; i < m_ActiveShadowQueue.Count; ++i)
m_ActiveShadowQueue[i].Dispose(cmd);
for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
m_ActiveRenderPassQueue[i].Dispose(cmd);

}
void SetupPerObjectLightIndices(ref CullResults cullResults, ref LightData lightData)
public void SetupPerObjectLightIndices(ref CullResults cullResults, ref LightData lightData)
{
if (lightData.totalAdditionalLightsCount == 0)
return;

cullResults.FillLightIndices(perObjectLightIndices);
}
}
}
public static ClearFlag GetCameraClearFlag(Camera camera)
{
ClearFlag clearFlag = ClearFlag.None;
CameraClearFlags cameraClearFlags = camera.clearFlags;
if (cameraClearFlags != CameraClearFlags.Nothing)
{
clearFlag |= ClearFlag.Depth;
if (cameraClearFlags == CameraClearFlags.Color || cameraClearFlags == CameraClearFlags.Skybox)
clearFlag |= ClearFlag.Color;
}
return clearFlag;
}
public static RendererConfiguration GetRendererConfiguration(int localLightsCount)
{
RendererConfiguration configuration = RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe;
if (localLightsCount > 0)
{
if (useComputeBufferForPerObjectLightIndices)
configuration |= RendererConfiguration.ProvideLightIndices;
else
configuration |= RendererConfiguration.PerObjectLightIndices8;
}
return configuration;
}
}
}

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


{
public partial class LightweightPipeline : RenderPipeline
{
private static class PerFrameBuffer
{
public static int _GlossyEnvironmentColor;
public static int _SubtractiveShadowColor;
}
private IRendererSetup defaultRendererSetup
{
get
{
if (m_DefaultRendererSetup == null)
m_DefaultRendererSetup = new DefaultRendererSetup();
return m_DefaultRendererSetup;
}
}
CameraComparer m_CameraComparer = new CameraComparer();
LightweightForwardRenderer m_Renderer;

bool m_IsCameraRendering;
private IRendererSetup m_DefaultRendererSetup;
public LightweightPipeline(LightweightPipelineAsset asset)
{

PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");
PerCameraBuffer._ScaledScreenParams = Shader.PropertyToID("_ScaledScreenParams");
SetupLightweightConstanstPass.PerCameraBuffer._ScaledScreenParams = Shader.PropertyToID("_ScaledScreenParams");
m_Renderer = new LightweightForwardRenderer(asset);
// Let engine know we have MSAA on for cases where we support MSAA backbuffer

InitializeRenderingData(ref cameraData, visibleLights,
m_Renderer.maxSupportedLocalLightsPerPass, m_Renderer.maxSupportedVertexLights,
out renderingData);
m_Renderer.Setup(ref context, ref m_CullResults, ref renderingData);
var setup = cameraData.camera.GetComponent<IRendererSetup>();
if (setup == null)
setup = defaultRendererSetup;
setup.Setup(m_Renderer, ref context, ref m_CullResults, ref renderingData);
m_Renderer.Execute(ref context, ref m_CullResults, ref renderingData);
}
#if UNITY_EDITOR

cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView;
cameraData.isOffscreenRender = camera.targetTexture != null && !cameraData.isSceneViewCamera;
cameraData.isStereoEnabled = IsStereoEnabled(camera);
// TODO: There's currently an issue in engine side that breaks MSAA with texture2DArray.
// for now we force msaa disabled when using texture2DArray. This fixes VR multiple and single pass instanced modes.
if (cameraData.isStereoEnabled && XRGraphicsConfig.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)

{
float cameraWidth = (float)cameraData.camera.pixelWidth * cameraData.renderScale;
float cameraHeight = (float)cameraData.camera.pixelHeight * cameraData.renderScale;
Shader.SetGlobalVector(PerCameraBuffer._ScaledScreenParams, new Vector4(cameraWidth, cameraHeight, 1.0f + 1.0f / cameraWidth, 1.0f + 1.0f / cameraHeight));
Shader.SetGlobalVector(SetupLightweightConstanstPass.PerCameraBuffer._ScaledScreenParams, new Vector4(cameraWidth, cameraHeight, 1.0f + 1.0f / cameraWidth, 1.0f + 1.0f / cameraHeight));
}
}
}

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


int kDepthBufferBits = 32;
public DepthOnlyPass(LightweightForwardRenderer renderer) : base(renderer)
{
RegisterShaderPassName("DepthOnly");
}
private RenderTargetHandle depthAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles, int depthAttachmentHandle = -1, int samples = 1)
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle depthAttachmentHandle,
SampleCount samples)
base.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
this.depthAttachmentHandle = depthAttachmentHandle;
if (samples > 1)
if ((int)samples > 1)
baseDescriptor.bindMS = samples > 1;
baseDescriptor.msaaSamples = samples;
baseDescriptor.bindMS = (int)samples > 1;
baseDescriptor.msaaSamples = (int)samples;
cmd.GetTemporaryRT(depthAttachmentHandle, baseDescriptor, FilterMode.Point);
descriptor = baseDescriptor;
}
public DepthOnlyPass(LightweightForwardRenderer renderer) : base(renderer)
{
RegisterShaderPassName("DepthOnly");
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)

{
SetRenderTarget(cmd, GetSurface(depthAttachmentHandle), RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
ClearFlag.Depth, Color.black);
cmd.GetTemporaryRT(depthAttachmentHandle.id, descriptor, FilterMode.Point);
SetRenderTarget(
cmd,
depthAttachmentHandle.Identifier(),
RenderBufferLoadAction.DontCare,
RenderBufferStoreAction.Store,
ClearFlag.Depth,
Color.black,
descriptor.dimension);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
{
cmd.ReleaseTemporaryRT(depthAttachmentHandle.id);
depthAttachmentHandle = RenderTargetHandle.CameraTarget;
}
}
}
}

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


{
public class DirectionalShadowsPass : ScriptableRenderPass
{
private static class DirectionalShadowConstantBuffer
{
public static int _WorldToShadow;
public static int _ShadowData;
public static int _DirShadowSplitSpheres0;
public static int _DirShadowSplitSpheres1;
public static int _DirShadowSplitSpheres2;
public static int _DirShadowSplitSpheres3;
public static int _DirShadowSplitSphereRadii;
public static int _ShadowOffset0;
public static int _ShadowOffset1;
public static int _ShadowOffset2;
public static int _ShadowOffset3;
public static int _ShadowmapSize;
}
const int k_MaxCascades = 4;
const int k_ShadowmapBufferBits = 16;
int m_ShadowCasterCascadesCount;

RenderTextureDescriptor m_DirectionalShadowmapDescriptor;
Matrix4x4[] m_DirectionalShadowMatrices;
ShadowSliceData[] m_CascadeSlices;

private RenderTargetHandle destination { get; set; }
public DirectionalShadowsPass(LightweightForwardRenderer renderer) : base(renderer)
{

: RenderTextureFormat.Depth;
}
public void Setup(RenderTargetHandle destination)
{
this.destination = destination;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
if (renderingData.shadowData.renderDirectionalShadows)

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

float invShadowAtlasHeight = 1.0f / shadowData.directionalShadowAtlasHeight;
float invHalfShadowAtlasWidth = 0.5f * invShadowAtlasWidth;
float invHalfShadowAtlasHeight = 0.5f * invShadowAtlasHeight;
cmd.SetGlobalTexture(RenderTargetHandles.DirectionalShadowmap, m_DirectionalShadowmapTexture);
cmd.SetGlobalTexture(destination.id, m_DirectionalShadowmapTexture);
if (shadowData.directionalLightCascadeCount > 1)
cmd.SetGlobalMatrixArray(DirectionalShadowConstantBuffer._WorldToShadow, m_DirectionalShadowMatrices);
else

579
com.unity.render-pipelines.lightweight/LWRP/Passes/ForwardLitPass.cs


using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine.Experimental.GlobalIllumination;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class ForwardLitPass : ScriptableRenderPass
{
const int k_DepthStencilBufferBits = 32;
Vector4 k_DefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
Vector4 k_DefaultLightColor = Color.black;
Vector4 k_DefaultLightAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
Vector4 k_DefaultLightSpotDirection = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
Vector4 k_DefaultLightSpotAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
Vector4[] m_LightPositions;
Vector4[] m_LightColors;
Vector4[] m_LightDistanceAttenuations;
Vector4[] m_LightSpotDirections;
Vector4[] m_LightSpotAttenuations;
RenderTextureFormat m_ColorFormat;
MixedLightingSetup m_MixedLightingSetup;
Material m_BlitMaterial;
Material m_ErrorMaterial;
// Depth Copy Pass
Material m_DepthCopyMaterial;
// Opaque Copy Pass
Material m_SamplingMaterial;
float[] m_OpaqueScalerValues = {1.0f, 0.5f, 0.25f, 0.25f};
int m_SampleOffsetShaderHandle;
const string k_RenderOpaquesTag = "Render Opaques";
const string k_RenderTransparentsTag = "Render Transparents";
List<ShaderPassName> m_LegacyShaderPassNames;
public ForwardLitPass(LightweightForwardRenderer renderer) : base(renderer)
{
RegisterShaderPassName("LightweightForward");
RegisterShaderPassName("SRPDefaultUnlit");
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"));
PerCameraBuffer._MainLightPosition = Shader.PropertyToID("_MainLightPosition");
PerCameraBuffer._MainLightColor = Shader.PropertyToID("_MainLightColor");
PerCameraBuffer._MainLightCookie = Shader.PropertyToID("_MainLightCookie");
PerCameraBuffer._WorldToLight = Shader.PropertyToID("_WorldToLight");
PerCameraBuffer._AdditionalLightCount = Shader.PropertyToID("_AdditionalLightCount");
PerCameraBuffer._AdditionalLightPosition = Shader.PropertyToID("_AdditionalLightPosition");
PerCameraBuffer._AdditionalLightColor = Shader.PropertyToID("_AdditionalLightColor");
PerCameraBuffer._AdditionalLightDistanceAttenuation = Shader.PropertyToID("_AdditionalLightDistanceAttenuation");
PerCameraBuffer._AdditionalLightSpotDir = Shader.PropertyToID("_AdditionalLightSpotDir");
PerCameraBuffer._AdditionalLightSpotAttenuation = Shader.PropertyToID("_AdditionalLightSpotAttenuation");
PerCameraBuffer._LightIndexBuffer = Shader.PropertyToID("_LightIndexBuffer");
int maxVisibleLocalLights = renderer.maxVisibleLocalLights;
m_LightPositions = new Vector4[maxVisibleLocalLights];
m_LightColors = new Vector4[maxVisibleLocalLights];
m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights];
m_LightSpotDirections = new Vector4[maxVisibleLocalLights];
m_LightSpotAttenuations = new Vector4[maxVisibleLocalLights];
m_ColorFormat = RenderTextureFormat.Default;
m_BlitMaterial = renderer.GetMaterial(MaterialHandles.Blit);
m_ErrorMaterial = renderer.GetMaterial(MaterialHandles.Error);
// Copy Depth Pass
m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy);
// Copy Opaque Color Pass
m_SamplingMaterial = renderer.GetMaterial(MaterialHandles.Sampling);
m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset");
}
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles, int depthAttachmentHandle = -1, int samples = 1)
{
base.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
m_ColorFormat = baseDescriptor.colorFormat;
if (colorAttachmentHandle != -1)
{
var descriptor = baseDescriptor;
descriptor.depthBufferBits = k_DepthStencilBufferBits; // TODO: does the color RT always need depth?
descriptor.sRGB = true;
descriptor.msaaSamples = samples;
cmd.GetTemporaryRT(colorAttachmentHandle, descriptor, FilterMode.Bilinear);
}
if (depthAttachmentHandle != -1)
{
var descriptor = baseDescriptor;
descriptor.colorFormat = RenderTextureFormat.Depth;
descriptor.depthBufferBits = k_DepthStencilBufferBits;
descriptor.msaaSamples = samples;
descriptor.bindMS = samples > 1;
cmd.GetTemporaryRT(depthAttachmentHandle, descriptor, FilterMode.Point);
}
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
bool dynamicBatching = renderingData.supportsDynamicBatching;
SetupShaderConstants(ref context, ref renderingData.cameraData, ref renderingData.lightData, ref renderingData.shadowData);
RendererConfiguration rendererConfiguration = GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
if (renderingData.cameraData.isStereoEnabled)
context.StartMultiEye(camera);
RenderOpaques(ref context, ref cullResults, ref renderingData.cameraData, rendererConfiguration, dynamicBatching);
if (renderingData.cameraData.postProcessEnabled &&
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
OpaquePostProcessSubPass(ref context, ref renderingData.cameraData);
if (depthAttachmentHandle != -1)
CopyDepthSubPass(ref context, ref renderingData.cameraData);
if (renderingData.cameraData.requiresOpaqueTexture)
CopyColorSubpass(ref context, ref renderingData.cameraData);
RenderTransparents(ref context, ref cullResults, ref renderingData.cameraData, rendererConfiguration, dynamicBatching);
if (renderingData.cameraData.postProcessEnabled)
PostProcessPass(ref context, ref renderingData.cameraData);
else if (!renderingData.cameraData.isOffscreenRender && colorAttachmentHandle != -1)
FinalBlitPass(ref context, ref renderingData.cameraData);
if (renderingData.cameraData.isStereoEnabled)
{
context.StopMultiEye(camera);
context.StereoEndRender(camera);
}
}
RendererConfiguration GetRendererConfiguration(int localLightsCount)
{
RendererConfiguration configuration = RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe;
if (localLightsCount > 0)
{
if (renderer.useComputeBufferForPerObjectLightIndices)
configuration |= RendererConfiguration.ProvideLightIndices;
else
configuration |= RendererConfiguration.PerObjectLightIndices8;
}
return configuration;
}
void SetupShaderConstants(ref ScriptableRenderContext context, ref CameraData cameraData, ref LightData lightData, ref ShadowData shadowData)
{
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants");
SetupShaderLightConstants(cmd, ref lightData);
SetShaderKeywords(cmd, ref cameraData, ref lightData, ref shadowData);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
void SetupShaderLightConstants(CommandBuffer cmd, ref LightData lightData)
{
// Clear to default all light constant data
for (int i = 0; i < renderer.maxVisibleLocalLights; ++i)
InitializeLightConstants(lightData.visibleLights, -1, out m_LightPositions[i],
out m_LightColors[i],
out m_LightDistanceAttenuations[i],
out m_LightSpotDirections[i],
out m_LightSpotAttenuations[i]);
m_MixedLightingSetup = MixedLightingSetup.None;
// Main light has an optimized shader path for main light. This will benefit games that only care about a single light.
// Lightweight pipeline also supports only a single shadow light, if available it will be the main light.
SetupMainLightConstants(cmd, ref lightData);
SetupAdditionalLightConstants(cmd, ref lightData);
}
void SetupMainLightConstants(CommandBuffer cmd, ref LightData lightData)
{
Vector4 lightPos, lightColor, lightDistanceAttenuation, lightSpotDir, lightSpotAttenuation;
List<VisibleLight> lights = lightData.visibleLights;
InitializeLightConstants(lightData.visibleLights, lightData.mainLightIndex, out lightPos, out lightColor, out lightDistanceAttenuation, out lightSpotDir, out lightSpotAttenuation);
if (lightData.mainLightIndex >= 0)
{
VisibleLight mainLight = lights[lightData.mainLightIndex];
Light mainLightRef = mainLight.light;
if (LightweightPipeline.IsSupportedCookieType(mainLight.lightType) && mainLightRef.cookie != null)
{
Matrix4x4 lightCookieMatrix;
LightweightPipeline.GetLightCookieMatrix(mainLight, out lightCookieMatrix);
cmd.SetGlobalTexture(PerCameraBuffer._MainLightCookie, mainLightRef.cookie);
cmd.SetGlobalMatrix(PerCameraBuffer._WorldToLight, lightCookieMatrix);
}
}
cmd.SetGlobalVector(PerCameraBuffer._MainLightPosition, new Vector4(lightPos.x, lightPos.y, lightPos.z, lightDistanceAttenuation.w));
cmd.SetGlobalVector(PerCameraBuffer._MainLightColor, lightColor);
}
void SetupAdditionalLightConstants(CommandBuffer cmd, ref LightData lightData)
{
int maxVisibleLocalLights = renderer.maxVisibleLocalLights;
List<VisibleLight> lights = lightData.visibleLights;
if (lightData.totalAdditionalLightsCount > 0)
{
int localLightsCount = 0;
for (int i = 0; i < lights.Count && localLightsCount < maxVisibleLocalLights; ++i)
{
VisibleLight light = lights[i];
if (light.lightType != LightType.Directional)
{
InitializeLightConstants(lights, i, out m_LightPositions[localLightsCount],
out m_LightColors[localLightsCount],
out m_LightDistanceAttenuations[localLightsCount],
out m_LightSpotDirections[localLightsCount],
out m_LightSpotAttenuations[localLightsCount]);
localLightsCount++;
}
}
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, new Vector4(lightData.pixelAdditionalLightsCount,
lightData.totalAdditionalLightsCount, 0.0f, 0.0f));
// if not using a compute buffer, engine will set indices in 2 vec4 constants
// unity_4LightIndices0 and unity_4LightIndices1
if (renderer.perObjectLightIndices != null)
cmd.SetGlobalBuffer("_LightIndexBuffer", renderer.perObjectLightIndices);
}
else
{
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, Vector4.zero);
}
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightPosition, m_LightPositions);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightColor, m_LightColors);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightDistanceAttenuation, m_LightDistanceAttenuations);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotDir, m_LightSpotDirections);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotAttenuation, m_LightSpotAttenuations);
}
ClearFlag GetCameraClearFlag(Camera camera)
{
ClearFlag clearFlag = ClearFlag.None;
CameraClearFlags cameraClearFlags = camera.clearFlags;
if (cameraClearFlags != CameraClearFlags.Nothing)
{
clearFlag |= ClearFlag.Depth;
if (cameraClearFlags == CameraClearFlags.Color || cameraClearFlags == CameraClearFlags.Skybox)
clearFlag |= ClearFlag.Color;
}
return clearFlag;
}
void SetShaderKeywords(CommandBuffer cmd, ref CameraData cameraData, ref LightData lightData, ref ShadowData shadowData)
{
int vertexLightsCount = lightData.totalAdditionalLightsCount - lightData.pixelAdditionalLightsCount;
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.AdditionalLights, lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.MixedLightingSubtractive, m_MixedLightingSetup == MixedLightingSetup.Subtractive);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.VertexLights, vertexLightsCount > 0);
// 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;
// Currently shadow filtering keyword is shared between local and directional shadows.
bool hasSoftShadows = (directionalShadowQuality == LightShadows.Soft || localShadowQuality == LightShadows.Soft) &&
shadowData.supportsSoftShadows;
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.DirectionalShadows, directionalShadowQuality != LightShadows.None);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.LocalShadows, localShadowQuality != LightShadows.None);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.SoftShadows, hasSoftShadows);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.CascadeShadows, shadowData.directionalLightCascadeCount > 1);
// TODO: Remove this. legacy particles support will be removed from Unity in 2018.3. This should be a shader_feature instead with prop exposed in the Standard particles shader.
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", cameraData.requiresSoftParticles);
}
void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor)
{
if (colorAttachmentHandle != -1)
{
if (depthAttachmentHandle != -1)
SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, GetSurface(depthAttachmentHandle), loadOp, storeOp, clearFlag, clearColor);
else
SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, clearFlag, clearColor);
}
else
{
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, loadOp, storeOp, clearFlag, clearColor);
}
}
void RenderOpaques(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, RendererConfiguration rendererConfiguration, bool dynamicBatching)
{
CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag);
using (new ProfilingSample(cmd, k_RenderOpaquesTag))
{
Camera camera = cameraData.camera;
ClearFlag clearFlag = GetCameraClearFlag(camera);
SetRenderTarget(cmd, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(camera.backgroundColor));
// 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.
// For now we make it consistent by resolving viewport with a RT until we can have a proper camera management system
//if (colorAttachmentHandle == -1 && !cameraData.isDefaultViewport)
// cmd.SetViewport(camera.pixelRect);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.opaqueFilterSettings);
// Render objects that did not match any shader pass with error shader
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.opaqueFilterSettings, SortFlags.None);
if (camera.clearFlags == CameraClearFlags.Skybox)
context.DrawSkybox(camera);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
void RenderTransparents(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, RendererConfiguration rendererConfiguration, bool dynamicBatching)
{
CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag);
using (new ProfilingSample(cmd, k_RenderTransparentsTag))
{
Camera camera = cameraData.camera;
SetRenderTarget(cmd, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, ClearFlag.None, Color.black);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.transparentFilterSettings);
// Render objects that did not match any shader pass with error shader
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.transparentFilterSettings, SortFlags.None);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
void FinalBlitPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
Material material = cameraData.isStereoEnabled ? null : m_BlitMaterial;
RenderTargetIdentifier sourceRT = GetSurface(colorAttachmentHandle);
CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass");
cmd.SetGlobalTexture("_BlitTex", sourceRT);
// We need to handle viewport on a RT. We do it by rendering a fullscreen quad + viewport
if (!cameraData.isDefaultViewport)
{
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.None, Color.black);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(cameraData.camera.pixelRect);
LightweightPipeline.DrawFullScreen(cmd, material);
}
else
{
cmd.Blit(GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, material);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
void InitializeLightConstants(List<VisibleLight> lights, int lightIndex, out Vector4 lightPos, out Vector4 lightColor, out Vector4 lightDistanceAttenuation, out Vector4 lightSpotDir,
out Vector4 lightSpotAttenuation)
{
lightPos = k_DefaultLightPosition;
lightColor = k_DefaultLightColor;
lightDistanceAttenuation = k_DefaultLightSpotAttenuation;
lightSpotDir = k_DefaultLightSpotDirection;
lightSpotAttenuation = k_DefaultLightAttenuation;
// When no lights are visible, main light will be set to -1.
// In this case we initialize it to default values and return
if (lightIndex < 0)
return;
VisibleLight lightData = lights[lightIndex];
if (lightData.lightType == LightType.Directional)
{
Vector4 dir = -lightData.localToWorld.GetColumn(2);
lightPos = new Vector4(dir.x, dir.y, dir.z, 0.0f);
}
else
{
Vector4 pos = lightData.localToWorld.GetColumn(3);
lightPos = new Vector4(pos.x, pos.y, pos.z, 1.0f);
}
// VisibleLight.finalColor already returns color in active color space
lightColor = lightData.finalColor;
// Directional Light attenuation is initialize so distance attenuation always be 1.0
if (lightData.lightType != LightType.Directional)
{
// Light attenuation in lightweight matches the unity vanilla one.
// attenuation = 1.0 / 1.0 + distanceToLightSqr * quadraticAttenuation
// then a smooth factor is applied to linearly fade attenuation to light range
// the attenuation smooth factor starts having effect at 80% of light range
// smoothFactor = (lightRangeSqr - distanceToLightSqr) / (lightRangeSqr - fadeStartDistanceSqr)
// We rewrite smoothFactor to be able to pre compute the constant terms below and apply the smooth factor
// with one MAD instruction
// smoothFactor = distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
// distanceSqr * oneOverFadeRangeSqr + lightRangeSqrOverFadeRangeSqr
float lightRangeSqr = lightData.range * lightData.range;
float fadeStartDistanceSqr = 0.8f * 0.8f * lightRangeSqr;
float fadeRangeSqr = (fadeStartDistanceSqr - lightRangeSqr);
float oneOverFadeRangeSqr = 1.0f / fadeRangeSqr;
float lightRangeSqrOverFadeRangeSqr = -lightRangeSqr / fadeRangeSqr;
float quadAtten = 25.0f / lightRangeSqr;
lightDistanceAttenuation = new Vector4(quadAtten, oneOverFadeRangeSqr, lightRangeSqrOverFadeRangeSqr, 1.0f);
}
if (lightData.lightType == LightType.Spot)
{
Vector4 dir = lightData.localToWorld.GetColumn(2);
lightSpotDir = new Vector4(-dir.x, -dir.y, -dir.z, 0.0f);
// Spot Attenuation with a linear falloff can be defined as
// (SdotL - cosOuterAngle) / (cosInnerAngle - cosOuterAngle)
// This can be rewritten as
// invAngleRange = 1.0 / (cosInnerAngle - cosOuterAngle)
// SdotL * invAngleRange + (-cosOuterAngle * invAngleRange)
// If we precompute the terms in a MAD instruction
float cosOuterAngle = Mathf.Cos(Mathf.Deg2Rad * lightData.spotAngle * 0.5f);
// We neeed to do a null check for particle lights
// This should be changed in the future
// Particle lights will use an inline function
float cosInnerAngle;
if (lightData.light != null)
cosInnerAngle = Mathf.Cos(LightmapperUtils.ExtractInnerCone(lightData.light) * 0.5f);
else
cosInnerAngle = Mathf.Cos((2.0f * Mathf.Atan(Mathf.Tan(lightData.spotAngle * 0.5f * Mathf.Deg2Rad) * (64.0f - 18.0f) / 64.0f)) * 0.5f);
float smoothAngleRange = Mathf.Max(0.001f, cosInnerAngle - cosOuterAngle);
float invAngleRange = 1.0f / smoothAngleRange;
float add = -cosOuterAngle * invAngleRange;
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f);
}
Light light = lightData.light;
// TODO: Add support to shadow mask
if (light != null && light.bakingOutput.mixedLightingMode == MixedLightingMode.Subtractive && light.bakingOutput.lightmapBakeType == LightmapBakeType.Mixed)
{
if (m_MixedLightingSetup == MixedLightingSetup.None && lightData.light.shadows != LightShadows.None)
{
m_MixedLightingSetup = MixedLightingSetup.Subtractive;
lightDistanceAttenuation.w = 0.0f;
}
}
}
// TODO: move to postfx pass
void PostProcessPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
CommandBuffer cmd = CommandBufferPool.Get("Render PostProcess Effects");
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, false);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
void RenderObjectsWithError(ref ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags)
{
if (m_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(m_ErrorMaterial, 0);
context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings);
}
}
void OpaquePostProcessSubPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
CommandBuffer cmd = CommandBufferPool.Get("Render Opaque PostProcess Effects");
RenderTargetIdentifier source = GetSurface(colorAttachmentHandle);
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, source, GetSurface(colorAttachmentHandle), true);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
void CopyDepthSubPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
CommandBuffer cmd = CommandBufferPool.Get("Depth Copy");
RenderTargetIdentifier depthSurface = GetSurface(depthAttachmentHandle);
RenderTargetIdentifier copyDepthSurface = GetSurface(RenderTargetHandles.DepthTexture);
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref cameraData);
descriptor.colorFormat = RenderTextureFormat.Depth;
descriptor.depthBufferBits = k_DepthStencilBufferBits;
descriptor.msaaSamples = 1;
descriptor.bindMS = false;
cmd.GetTemporaryRT(RenderTargetHandles.DepthTexture, descriptor, FilterMode.Point);
if (cameraData.msaaSamples > 1)
{
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
if (cameraData.msaaSamples == 4)
{
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
}
else
{
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
}
cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial);
}
else
{
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
void CopyColorSubpass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
CommandBuffer cmd = CommandBufferPool.Get("Copy Opaque Color");
Downsampling downsampling = cameraData.opaqueTextureDownsampling;
float opaqueScaler = m_OpaqueScalerValues[(int)downsampling];
RenderTextureDescriptor opaqueDesc = renderer.CreateRTDesc(ref cameraData, opaqueScaler);
RenderTargetIdentifier colorRT = GetSurface(colorAttachmentHandle);
RenderTargetIdentifier opaqueColorRT = GetSurface(RenderTargetHandles.OpaqueColor);
cmd.GetTemporaryRT(RenderTargetHandles.OpaqueColor, opaqueDesc, cameraData.opaqueTextureDownsampling == Downsampling.None ? FilterMode.Point : FilterMode.Bilinear);
switch (downsampling)
{
case Downsampling.None:
cmd.Blit(colorRT, opaqueColorRT);
break;
case Downsampling._2xBilinear:
cmd.Blit(colorRT, opaqueColorRT);
break;
case Downsampling._4xBox:
m_SamplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2);
cmd.Blit(colorRT, opaqueColorRT, m_SamplingMaterial, 0);
break;
case Downsampling._4xBilinear:
cmd.Blit(colorRT, opaqueColorRT);
break;
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


{
public class LocalShadowsPass : ScriptableRenderPass
{
private static class LocalShadowConstantBuffer
{
public static int _LocalWorldToShadowAtlas;
public static int _LocalShadowStrength;
public static int _LocalShadowOffset0;
public static int _LocalShadowOffset1;
public static int _LocalShadowOffset2;
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(LightweightForwardRenderer renderer) : base(renderer)
{

? RenderTextureFormat.Shadowmap
: RenderTextureFormat.Depth;
}
public void Setup(RenderTargetHandle destination)
{
this.destination = destination;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{

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

float invHalfShadowAtlasWidth = 0.5f * invShadowAtlasWidth;
float invHalfShadowAtlasHeight = 0.5f * invShadowAtlasHeight;
cmd.SetGlobalTexture(RenderTargetHandles.LocalShadowmap, m_LocalShadowmapTexture);
cmd.SetGlobalTexture(destination.id, m_LocalShadowmapTexture);
cmd.SetGlobalMatrixArray(LocalShadowConstantBuffer._LocalWorldToShadowAtlas, m_LocalShadowMatrices);
cmd.SetGlobalFloatArray(LocalShadowConstantBuffer._LocalShadowStrength, m_LocalShadowStrength);
cmd.SetGlobalVector(LocalShadowConstantBuffer._LocalShadowOffset0, new Vector4(-invHalfShadowAtlasWidth, -invHalfShadowAtlasHeight, 0.0f, 0.0f));

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class ScreenSpaceShadowResolvePass : ScriptableRenderPass
{
RenderTextureFormat m_ColorFormat;

m_ScreenSpaceShadowsMaterial = renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow);
}
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles, int depthAttachmentHandle = -1, int samples = 1)
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle)
base.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
this.colorAttachmentHandle = colorAttachmentHandle;
cmd.GetTemporaryRT(colorAttachmentHandle, baseDescriptor, FilterMode.Bilinear);
descriptor = baseDescriptor;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)

CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows");
cmd.GetTemporaryRT(colorAttachmentHandle.id, descriptor, FilterMode.Bilinear);
SetShadowCollectPassKeywords(cmd, ref renderingData.shadowData);
// Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that

// An alternative would be DrawProcedural, but that would require further changes in the shader.
RenderTargetIdentifier screenSpaceOcclusionTexture = GetSurface(colorAttachmentHandle);
RenderTargetIdentifier screenSpaceOcclusionTexture = colorAttachmentHandle.Identifier();
ClearFlag.Color | ClearFlag.Depth, Color.white);
ClearFlag.Color | ClearFlag.Depth, Color.white, descriptor.dimension);
cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, m_ScreenSpaceShadowsMaterial);
if (renderingData.cameraData.isStereoEnabled)

else
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
{
cmd.ReleaseTemporaryRT(colorAttachmentHandle.id);
colorAttachmentHandle = RenderTargetHandle.CameraTarget;
}
}
void SetShadowCollectPassKeywords(CommandBuffer cmd, ref ShadowData shadowData)

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


{
public abstract class ScriptableRenderPass
{
public LightweightForwardRenderer renderer { get; private set; }
public int[] colorAttachmentHandles { get; private set; }
protected LightweightForwardRenderer renderer { get; }
public int colorAttachmentHandle { get; private set; }
private List<ShaderPassName> m_ShaderPassNames = new List<ShaderPassName>();
public int depthAttachmentHandle { get; private set; }
public TextureDimension textureDimension { get; private set; }
public int samples { get; private set; }
protected List<ShaderPassName> m_ShaderPassNames = new List<ShaderPassName>();
public ScriptableRenderPass(LightweightForwardRenderer renderer)
protected ScriptableRenderPass(LightweightForwardRenderer renderer)
public virtual void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles = null, int depthAttachmentHandle = -1, int samples = 1)
{
this.colorAttachmentHandles = colorAttachmentHandles;
this.depthAttachmentHandle = depthAttachmentHandle;
this.samples = samples;
colorAttachmentHandle = (colorAttachmentHandles != null && colorAttachmentHandles.Length > 0)
? colorAttachmentHandles[0]
: -1;
textureDimension = baseDescriptor.dimension;
}
{
if (colorAttachmentHandles != null)
{
for (int i = 0; i < colorAttachmentHandles.Length; ++i)
if (colorAttachmentHandles[i] != -1)
cmd.ReleaseTemporaryRT(colorAttachmentHandles[i]);
}
if (depthAttachmentHandle != -1)
cmd.ReleaseTemporaryRT(depthAttachmentHandle);
}
{}
public RenderTargetIdentifier GetSurface(int handle)
{
if (renderer == null)
{
Debug.LogError("Pass has invalid renderer");
return new RenderTargetIdentifier();
}
return renderer.GetSurface(handle);
}
public void RegisterShaderPassName(string passName)
protected void RegisterShaderPassName(string passName)
public DrawRendererSettings CreateDrawRendererSettings(Camera camera, SortFlags sortFlags, RendererConfiguration rendererConfiguration, bool supportsDynamicBatching)
protected DrawRendererSettings CreateDrawRendererSettings(Camera camera, SortFlags sortFlags, RendererConfiguration rendererConfiguration, bool supportsDynamicBatching)
{
DrawRendererSettings settings = new DrawRendererSettings(camera, m_ShaderPassNames[0]);
for (int i = 1; i < m_ShaderPassNames.Count; ++i)

return settings;
}
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction, ClearFlag clearFlag, Color clearColor)
protected static void SetRenderTarget(
CommandBuffer cmd,
RenderTargetIdentifier colorAttachment,
RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction,
ClearFlag clearFlag,
Color clearColor,
TextureDimension dimension)
if (textureDimension == TextureDimension.Tex2DArray)
if (dimension == TextureDimension.Tex2DArray)
public void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction, RenderTargetIdentifier depthAttachment, RenderBufferLoadAction depthLoadAction,
RenderBufferStoreAction depthStoreAction, ClearFlag clearFlag, Color clearColor)
protected static void SetRenderTarget(
CommandBuffer cmd,
RenderTargetIdentifier colorAttachment,
RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction,
RenderTargetIdentifier depthAttachment,
RenderBufferLoadAction depthLoadAction,
RenderBufferStoreAction depthStoreAction,
ClearFlag clearFlag,
Color clearColor,
TextureDimension dimension)
if (textureDimension == TextureDimension.Tex2DArray)
if (dimension == TextureDimension.Tex2DArray)
CoreUtils.SetRenderTarget(cmd, colorAttachment, depthAttachment,
clearFlag, clearColor, 0, CubemapFace.Unknown, -1);
else

34
TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/OSXEditor/Metal/045_CustomLWPipe.png

之前 之后
宽度: 512  |  高度: 512  |  大小: 8.0 KiB

88
TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/OSXEditor/Metal/045_CustomLWPipe.png.meta


fileFormatVersion: 2
guid: e8cb6d76b1ce24a4e97f88ab70abb6db
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 7
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

36
TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/045_CustomLWPipe.png

之前 之后
宽度: 512  |  高度: 512  |  大小: 8.0 KiB

88
TestProjects/LWGraphicsTest/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/045_CustomLWPipe.png.meta


fileFormatVersion: 2
guid: 3633c62c6bb83e74baa40034bba66123
TextureImporter:
fileIDToRecycleName: {}
externalObjects: {}
serializedVersion: 7
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

466
TestProjects/LWGraphicsTest/Assets/Scenes/045_CustomLWPipe.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.18029502, g: 0.22572649, b: 0.30692935, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 112000002, guid: fd8f2c6386dc54f158818f3b4ce8a20d, type: 2}
m_UseShadowmask: 0
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &234236910
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 234236914}
- component: {fileID: 234236913}
- component: {fileID: 234236912}
- component: {fileID: 234236911}
m_Layer: 0
m_Name: Cube (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &234236911
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 234236910}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 2100000, guid: 14ba8c0a5d5381f4fb7ef200c8c10b26, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &234236912
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 234236910}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &234236913
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 234236910}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &234236914
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 234236910}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.244, y: 0.82283884, z: 27.958}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &380492249
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 380492254}
- component: {fileID: 380492253}
- component: {fileID: 380492251}
- component: {fileID: 380492250}
- component: {fileID: 380492252}
- component: {fileID: 380492255}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &380492250
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 380492249}
m_Enabled: 1
--- !u!124 &380492251
Behaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 380492249}
m_Enabled: 1
--- !u!114 &380492252
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 380492249}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 73231aa468d81ea49bc3d914080de185, type: 3}
m_Name:
m_EditorClassIdentifier:
ImageComparisonSettings:
TargetWidth: 512
TargetHeight: 512
PerPixelCorrectnessThreshold: 0.005
AverageCorrectnessThreshold: 0.005
WaitFrames: 0
--- !u!20 &380492253
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 380492249}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 1}
m_projectionMatrixMode: 1
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &380492254
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 380492249}
m_LocalRotation: {x: 0.24609356, y: 0.36251447, z: -0.099864565, w: 0.89333546}
m_LocalPosition: {x: -3.6031294, y: 2.2863412, z: 26.36942}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &380492255
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 380492249}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7e0da365be9e44c3bae8da691ccd8de6, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &707831285
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 707831287}
- component: {fileID: 707831286}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &707831286
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 707831285}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &707831287
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 707831285}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &1203640971
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1203640975}
- component: {fileID: 1203640974}
- component: {fileID: 1203640973}
- component: {fileID: 1203640972}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &1203640972
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1203640971}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 2100000, guid: 2875962f52041b64ab757b73da605810, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &1203640973
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1203640971}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &1203640974
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1203640971}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1203640975
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1203640971}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.8925657, y: 0.82283884, z: 28.129997}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

8
TestProjects/LWGraphicsTest/Assets/Scenes/045_CustomLWPipe.unity.meta


fileFormatVersion: 2
guid: 349df85634812cd4e9157f31eace4abe
timeCreated: 1493133740
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


using System;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class DefaultRendererSetup : IRendererSetup
{
private DepthOnlyPass m_DepthOnlyPass;
private DirectionalShadowsPass m_DirectionalShadowPass;
private LocalShadowsPass m_LocalShadowPass;
private SetupForwardRenderingPass m_SetupForwardRenderingPass;
private ScreenSpaceShadowResolvePass m_ScreenSpaceShadowResovePass;
private CreateLightweightRenderTexturesPass m_CreateLightweightRenderTexturesPass;
private BeginXRRenderingPass m_BeginXrRenderingPass;
private SetupLightweightConstanstPass m_SetupLightweightConstants;
private RenderOpaqueForwardPass m_RenderOpaqueForwardPass;
private OpaquePostProcessPass m_OpaquePostProcessPass;
private DrawSkyboxPass m_DrawSkyboxPass;
private CopyDepthPass m_CopyDepthPass;
private CopyColorPass m_CopyColorPass;
private RenderTransparentForwardPass m_RenderTransparentForwardPass;
private TransparentPostProcessPass m_TransparentPostProcessPass;
private FinalBlitPass m_FinalBlitPass;
private EndXRRenderingPass m_EndXrRenderingPass;
#if UNITY_EDITOR
private SceneViewDepthCopyPass m_SceneViewDepthCopyPass;
#endif
private RenderTargetHandle Color;
private RenderTargetHandle DepthAttachment;
private RenderTargetHandle DepthTexture;
private RenderTargetHandle OpaqueColor;
private RenderTargetHandle DirectionalShadowmap;
private RenderTargetHandle LocalShadowmap;
private RenderTargetHandle ScreenSpaceShadowmap;
[NonSerialized]
private bool m_Initialized = false;
private void Init(LightweightForwardRenderer renderer)
{
if (m_Initialized)
return;
m_DepthOnlyPass = new DepthOnlyPass(renderer);
m_DirectionalShadowPass = new DirectionalShadowsPass(renderer);
m_LocalShadowPass = new LocalShadowsPass(renderer);
m_SetupForwardRenderingPass = new SetupForwardRenderingPass(renderer);
m_ScreenSpaceShadowResovePass = new ScreenSpaceShadowResolvePass(renderer);
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer);
m_BeginXrRenderingPass = new BeginXRRenderingPass(renderer);
m_SetupLightweightConstants = new SetupLightweightConstanstPass(renderer);
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer);
m_OpaquePostProcessPass = new OpaquePostProcessPass(renderer);
m_DrawSkyboxPass = new DrawSkyboxPass(renderer);
m_CopyDepthPass = new CopyDepthPass(renderer);
m_CopyColorPass = new CopyColorPass(renderer);
m_RenderTransparentForwardPass = new RenderTransparentForwardPass(renderer);
m_TransparentPostProcessPass = new TransparentPostProcessPass(renderer);
m_FinalBlitPass = new FinalBlitPass(renderer);
m_EndXrRenderingPass = new EndXRRenderingPass(renderer);
#if UNITY_EDITOR
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(renderer);
#endif
// RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
// Samples (MSAA) depend on camera and pipeline
Color.Init("_CameraColorTexture");
DepthAttachment.Init("_CameraDepthAttachment");
DepthTexture.Init("_CameraDepthTexture");
OpaqueColor.Init("_CameraOpaqueTexture");
DirectionalShadowmap.Init("_DirectionalShadowmapTexture");
LocalShadowmap.Init("_LocalShadowmapTexture");
ScreenSpaceShadowmap.Init("_ScreenSpaceShadowMapTexture");
m_Initialized = true;
}
public void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults, ref RenderingData renderingData)
{
Init(renderer);
renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;
bool requiresCameraDepth = renderingData.cameraData.requiresDepthTexture;
bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve ||
renderingData.cameraData.isSceneViewCamera ||
(requiresCameraDepth &&
!LightweightForwardRenderer.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;
if (renderingData.shadowData.renderDirectionalShadows)
{
m_DirectionalShadowPass.Setup(DirectionalShadowmap);
renderer.EnqueuePass(m_DirectionalShadowPass);
}
if (renderingData.shadowData.renderLocalShadows)
{
m_LocalShadowPass.Setup(LocalShadowmap);
renderer.EnqueuePass(m_LocalShadowPass);
}
renderer.EnqueuePass(m_SetupForwardRenderingPass);
if (requiresDepthPrepass)
{
m_DepthOnlyPass.Setup(baseDescriptor, DepthTexture, SampleCount.One);
renderer.EnqueuePass(m_DepthOnlyPass);
}
if (renderingData.shadowData.renderDirectionalShadows &&
renderingData.shadowData.requiresScreenSpaceShadowResolve)
{
m_ScreenSpaceShadowResovePass.Setup(baseDescriptor, ScreenSpaceShadowmap);
renderer.EnqueuePass(m_ScreenSpaceShadowResovePass);
}
bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass;
bool requiresColorAttachment =
LightweightForwardRenderer.RequiresIntermediateColorTexture(
ref renderingData.cameraData,
baseDescriptor,
requiresDepthAttachment);
RenderTargetHandle colorHandle = (requiresColorAttachment) ? Color : RenderTargetHandle.CameraTarget;
RenderTargetHandle depthHandle = (requiresDepthAttachment) ? DepthAttachment : RenderTargetHandle.CameraTarget;
var sampleCount = (SampleCount) renderingData.cameraData.msaaSamples;
m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
if (renderingData.cameraData.isStereoEnabled)
renderer.EnqueuePass(m_BeginXrRenderingPass);
Camera camera = renderingData.cameraData.camera;
bool dynamicBatching = renderingData.supportsDynamicBatching;
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
renderer.EnqueuePass(m_SetupLightweightConstants);
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration,dynamicBatching);
renderer.EnqueuePass(m_RenderOpaqueForwardPass);
if (renderingData.cameraData.postProcessEnabled &&
renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
{
m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_OpaquePostProcessPass);
}
if (camera.clearFlags == CameraClearFlags.Skybox)
renderer.EnqueuePass(m_DrawSkyboxPass);
if (depthHandle != RenderTargetHandle.CameraTarget)
{
m_CopyDepthPass.Setup(depthHandle, DepthTexture);
renderer.EnqueuePass(m_CopyDepthPass);
}
if (renderingData.cameraData.requiresOpaqueTexture)
{
m_CopyColorPass.Setup(colorHandle, OpaqueColor);
renderer.EnqueuePass(m_CopyColorPass);
}
m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ClearFlag.None, camera.backgroundColor, rendererConfiguration, dynamicBatching);
renderer.EnqueuePass(m_RenderTransparentForwardPass);
if (renderingData.cameraData.postProcessEnabled)
{
m_TransparentPostProcessPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_TransparentPostProcessPass);
}
else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget)
{
m_FinalBlitPass.Setup(baseDescriptor, colorHandle);
renderer.EnqueuePass(m_FinalBlitPass);
}
if (renderingData.cameraData.isStereoEnabled)
{
renderer.EnqueuePass(m_EndXrRenderingPass);
}
#if UNITY_EDITOR
if (renderingData.cameraData.isSceneViewCamera)
{
m_SceneViewDepthCopyPass.Setup(DepthTexture);
renderer.EnqueuePass(m_SceneViewDepthCopyPass);
}
#endif
}
}
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public interface IRendererSetup
{
void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData);
}
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public enum MaterialHandles
{
Error,
DepthCopy,
Sampling,
Blit,
ScrenSpaceShadow,
Count,
}
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class BeginXRRenderingPass : ScriptableRenderPass
{
public BeginXRRenderingPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
context.StartMultiEye(camera);
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class CopyColorPass : ScriptableRenderPass
{
Material m_SamplingMaterial;
float[] m_OpaqueScalerValues = {1.0f, 0.5f, 0.25f, 0.25f};
int m_SampleOffsetShaderHandle;
private RenderTargetHandle source { get; set; }
private RenderTargetHandle destination { get; set; }
public CopyColorPass(LightweightForwardRenderer renderer) : base(renderer)
{
m_SamplingMaterial = renderer.GetMaterial(MaterialHandles.Sampling);
m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset");
}
public void Setup(RenderTargetHandle source, RenderTargetHandle destination)
{
this.source = source;
this.destination = destination;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("Copy Color");
Downsampling downsampling = renderingData.cameraData.opaqueTextureDownsampling;
float opaqueScaler = m_OpaqueScalerValues[(int)downsampling];
RenderTextureDescriptor opaqueDesc = renderer.CreateRTDesc(ref renderingData.cameraData, opaqueScaler);
RenderTargetIdentifier colorRT = source.Identifier();
RenderTargetIdentifier opaqueColorRT = destination.Identifier();
cmd.GetTemporaryRT(destination.id, opaqueDesc, renderingData.cameraData.opaqueTextureDownsampling == Downsampling.None ? FilterMode.Point : FilterMode.Bilinear);
switch (downsampling)
{
case Downsampling.None:
cmd.Blit(colorRT, opaqueColorRT);
break;
case Downsampling._2xBilinear:
cmd.Blit(colorRT, opaqueColorRT);
break;
case Downsampling._4xBox:
m_SamplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2);
cmd.Blit(colorRT, opaqueColorRT, m_SamplingMaterial, 0);
break;
case Downsampling._4xBilinear:
cmd.Blit(colorRT, opaqueColorRT);
break;
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (destination != RenderTargetHandle.CameraTarget)
{
cmd.ReleaseTemporaryRT(destination.id);
destination = RenderTargetHandle.CameraTarget;
}
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class CopyDepthPass : ScriptableRenderPass
{
Material m_DepthCopyMaterial;
private RenderTargetHandle source { get; set; }
private RenderTargetHandle destination { get; set; }
public CopyDepthPass(LightweightForwardRenderer renderer) : base(renderer)
{
m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy);
}
public void Setup(RenderTargetHandle source, RenderTargetHandle destination)
{
this.source = source;
this.destination = destination;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("Depth Copy");
RenderTargetIdentifier depthSurface = source.Identifier();
RenderTargetIdentifier copyDepthSurface = destination.Identifier();
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
descriptor.colorFormat = RenderTextureFormat.Depth;
descriptor.depthBufferBits = 32; //TODO: fix this ;
descriptor.msaaSamples = 1;
descriptor.bindMS = false;
cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point);
if (renderingData.cameraData.msaaSamples > 1)
{
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
if (renderingData.cameraData.msaaSamples == 4)
{
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
}
else
{
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
}
cmd.Blit(depthSurface, copyDepthSurface, m_DepthCopyMaterial);
}
else
{
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (destination != RenderTargetHandle.CameraTarget)
{
cmd.ReleaseTemporaryRT(destination.id);
destination = RenderTargetHandle.CameraTarget;
}
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class CreateLightweightRenderTexturesPass : ScriptableRenderPass
{
public CreateLightweightRenderTexturesPass(LightweightForwardRenderer renderer) : base(renderer)
{}
const int k_DepthStencilBufferBits = 32;
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTargetHandle depthAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
private SampleCount samples { get; set; }
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle,
RenderTargetHandle depthAttachmentHandle,
SampleCount samples)
{
this.colorAttachmentHandle = colorAttachmentHandle;
this.depthAttachmentHandle = depthAttachmentHandle;
this.samples = samples;
descriptor = baseDescriptor;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("");
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
{
var colorDescriptor = descriptor;
colorDescriptor.depthBufferBits = k_DepthStencilBufferBits; // TODO: does the color RT always need depth?
colorDescriptor.sRGB = true;
colorDescriptor.msaaSamples = (int) samples;
cmd.GetTemporaryRT(colorAttachmentHandle.id, colorDescriptor, FilterMode.Bilinear);
}
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
{
var depthDescriptor = descriptor;
depthDescriptor.colorFormat = RenderTextureFormat.Depth;
depthDescriptor.depthBufferBits = k_DepthStencilBufferBits;
depthDescriptor.msaaSamples = (int) samples;
depthDescriptor.bindMS = (int) samples > 1;
cmd.GetTemporaryRT(depthAttachmentHandle.id, depthDescriptor, FilterMode.Point);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
{
cmd.ReleaseTemporaryRT(colorAttachmentHandle.id);
colorAttachmentHandle = RenderTargetHandle.CameraTarget;
}
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
{
cmd.ReleaseTemporaryRT(depthAttachmentHandle.id);
depthAttachmentHandle = RenderTargetHandle.CameraTarget;
}
}
}
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class DrawSkyboxPass : ScriptableRenderPass
{
public DrawSkyboxPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
{
context.DrawSkybox(renderingData.cameraData.camera);
}
}
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class EndXRRenderingPass : ScriptableRenderPass
{
public EndXRRenderingPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
context.StopMultiEye(camera);
context.StereoEndRender(camera);
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class FinalBlitPass : ScriptableRenderPass
{
Material m_BlitMaterial;
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
public FinalBlitPass(LightweightForwardRenderer renderer) : base(renderer)
{
m_BlitMaterial = renderer.GetMaterial(MaterialHandles.Blit);
}
public void Setup(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorAttachmentHandle)
{
this.colorAttachmentHandle = colorAttachmentHandle;
this.descriptor = baseDescriptor;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
Material material = renderingData.cameraData.isStereoEnabled ? null : m_BlitMaterial;
RenderTargetIdentifier sourceRT = colorAttachmentHandle.Identifier();
CommandBuffer cmd = CommandBufferPool.Get("Final Blit Pass");
cmd.SetGlobalTexture("_BlitTex", sourceRT);
// We need to handle viewport on a RT. We do it by rendering a fullscreen quad + viewport
if (!renderingData.cameraData.isDefaultViewport)
{
SetRenderTarget(
cmd,
BuiltinRenderTextureType.CameraTarget,
RenderBufferLoadAction.DontCare,
RenderBufferStoreAction.Store,
ClearFlag.None,
Color.black,
descriptor.dimension);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(renderingData.cameraData.camera.pixelRect);
LightweightPipeline.DrawFullScreen(cmd, material);
}
else
{
cmd.Blit(colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, material);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


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

99
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; }
const string k_SwitchRTs = "Switch RT";
Material m_ErrorMaterial;
List<ShaderPassName> m_LegacyShaderPassNames;
protected RendererConfiguration rendererConfiguration;
protected bool dynamicBatching;
protected LightweightForwardPass(LightweightForwardRenderer renderer) : base(renderer)
{
m_ErrorMaterial = renderer.GetMaterial(MaterialHandles.Error);
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)
{
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
{
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
SetRenderTarget(
cmd,
colorAttachmentHandle.Identifier(),
loadOp,
storeOp,
depthAttachmentHandle.Identifier(),
loadOp,
storeOp,
clearFlag,
clearColor,
descriptor.dimension);
else
SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension);
}
else
{
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, loadOp, storeOp, clearFlag, clearColor, descriptor.dimension);
}
}
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
protected void RenderObjectsWithError(ref ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags)
{
if (m_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(m_ErrorMaterial, 0);
context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings);
}
}
}
}

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:

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class OpaquePostProcessPass : ScriptableRenderPass
{
public OpaquePostProcessPass(LightweightForwardRenderer renderer) : base(renderer)
{}
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle)
{
this.colorAttachmentHandle = colorAttachmentHandle;
descriptor = baseDescriptor;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("Render Opaque PostProcess Effects");
RenderTargetIdentifier source = colorAttachmentHandle.Identifier();
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref renderingData.cameraData, descriptor.colorFormat, source, colorAttachmentHandle.Identifier(), true);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class RenderOpaqueForwardPass : LightweightForwardPass
{
const string k_RenderOpaquesTag = "Render Opaques";
public RenderOpaqueForwardPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag);
using (new ProfilingSample(cmd, k_RenderOpaquesTag))
{
SetRenderTarget(cmd, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor));
// 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.
// For now we make it consistent by resolving viewport with a RT until we can have a proper camera management system
//if (colorAttachmentHandle == -1 && !cameraData.isDefaultViewport)
// cmd.SetViewport(camera.pixelRect);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
Camera camera = renderingData.cameraData.camera;
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.opaqueFilterSettings);
// Render objects that did not match any shader pass with error shader
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.opaqueFilterSettings, SortFlags.None);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class RenderTransparentForwardPass : LightweightForwardPass
{
const string k_RenderTransparentsTag = "Render Transparents";
public RenderTransparentForwardPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag);
using (new ProfilingSample(cmd, k_RenderTransparentsTag))
{
SetRenderTarget(cmd, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor));
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
Camera camera = renderingData.cameraData.camera;
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, dynamicBatching);
context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, renderer.transparentFilterSettings);
// Render objects that did not match any shader pass with error shader
RenderObjectsWithError(ref context, ref cullResults, camera, renderer.transparentFilterSettings, SortFlags.None);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class SceneViewDepthCopyPass : ScriptableRenderPass
{
private RenderTargetHandle source { get; set; }
public SceneViewDepthCopyPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public void Setup(RenderTargetHandle source)
{
this.source = source;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
// Restore Render target for additional editor rendering.
// Note: Scene view camera always perform depth prepass
CommandBuffer cmd = CommandBufferPool.Get("Copy Depth to Camera");
CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget);
cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
cmd.Blit(source.Identifier(), BuiltinRenderTextureType.CameraTarget, renderer.GetMaterial(MaterialHandles.DepthCopy));
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class SetupForwardRenderingPass : ScriptableRenderPass
{
public SetupForwardRenderingPass(LightweightForwardRenderer renderer) : base(renderer)
{}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
// SetupCameraProperties does the following:
// Setup Camera RenderTarget and Viewport
// VR Camera Setup and SINGLE_PASS_STEREO props
// Setup camera view, proj and their inv matrices.
// Setup properties: _WorldSpaceCameraPos, _ProjectionParams, _ScreenParams, _ZBufferParams, unity_OrthoParams
// Setup camera world clip planes props
// setup HDR keyword
// Setup global time properties (_Time, _SinTime, _CosTime)
context.SetupCameraProperties(renderingData.cameraData.camera, renderingData.cameraData.isStereoEnabled);
}
}
}

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


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

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


using System.Collections.Generic;
using UnityEngine.Experimental.GlobalIllumination;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class SetupLightweightConstanstPass : ScriptableRenderPass
{
public static class PerCameraBuffer
{
public static int _MainLightPosition;
public static int _MainLightColor;
public static int _MainLightCookie;
public static int _WorldToLight;
public static int _AdditionalLightCount;
public static int _AdditionalLightPosition;
public static int _AdditionalLightColor;
public static int _AdditionalLightDistanceAttenuation;
public static int _AdditionalLightSpotDir;
public static int _AdditionalLightSpotAttenuation;
public static int _LightIndexBuffer;
public static int _ScaledScreenParams;
}
MixedLightingSetup m_MixedLightingSetup;
Vector4 k_DefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
Vector4 k_DefaultLightColor = Color.black;
Vector4 k_DefaultLightAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
Vector4 k_DefaultLightSpotDirection = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);
Vector4 k_DefaultLightSpotAttenuation = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
Vector4[] m_LightPositions;
Vector4[] m_LightColors;
Vector4[] m_LightDistanceAttenuations;
Vector4[] m_LightSpotDirections;
Vector4[] m_LightSpotAttenuations;
public SetupLightweightConstanstPass(LightweightForwardRenderer renderer) : base(renderer)
{
PerCameraBuffer._MainLightPosition = Shader.PropertyToID("_MainLightPosition");
PerCameraBuffer._MainLightColor = Shader.PropertyToID("_MainLightColor");
PerCameraBuffer._MainLightCookie = Shader.PropertyToID("_MainLightCookie");
PerCameraBuffer._WorldToLight = Shader.PropertyToID("_WorldToLight");
PerCameraBuffer._AdditionalLightCount = Shader.PropertyToID("_AdditionalLightCount");
PerCameraBuffer._AdditionalLightPosition = Shader.PropertyToID("_AdditionalLightPosition");
PerCameraBuffer._AdditionalLightColor = Shader.PropertyToID("_AdditionalLightColor");
PerCameraBuffer._AdditionalLightDistanceAttenuation = Shader.PropertyToID("_AdditionalLightDistanceAttenuation");
PerCameraBuffer._AdditionalLightSpotDir = Shader.PropertyToID("_AdditionalLightSpotDir");
PerCameraBuffer._AdditionalLightSpotAttenuation = Shader.PropertyToID("_AdditionalLightSpotAttenuation");
PerCameraBuffer._LightIndexBuffer = Shader.PropertyToID("_LightIndexBuffer");
int maxVisibleLocalLights = renderer.maxVisibleLocalLights;
m_LightPositions = new Vector4[maxVisibleLocalLights];
m_LightColors = new Vector4[maxVisibleLocalLights];
m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights];
m_LightSpotDirections = new Vector4[maxVisibleLocalLights];
m_LightSpotAttenuations = new Vector4[maxVisibleLocalLights];
}
void InitializeLightConstants(List<VisibleLight> lights, int lightIndex, out Vector4 lightPos, out Vector4 lightColor, out Vector4 lightDistanceAttenuation, out Vector4 lightSpotDir,
out Vector4 lightSpotAttenuation)
{
lightPos = k_DefaultLightPosition;
lightColor = k_DefaultLightColor;
lightDistanceAttenuation = k_DefaultLightSpotAttenuation;
lightSpotDir = k_DefaultLightSpotDirection;
lightSpotAttenuation = k_DefaultLightAttenuation;
// When no lights are visible, main light will be set to -1.
// In this case we initialize it to default values and return
if (lightIndex < 0)
return;
VisibleLight lightData = lights[lightIndex];
if (lightData.lightType == LightType.Directional)
{
Vector4 dir = -lightData.localToWorld.GetColumn(2);
lightPos = new Vector4(dir.x, dir.y, dir.z, 0.0f);
}
else
{
Vector4 pos = lightData.localToWorld.GetColumn(3);
lightPos = new Vector4(pos.x, pos.y, pos.z, 1.0f);
}
// VisibleLight.finalColor already returns color in active color space
lightColor = lightData.finalColor;
// Directional Light attenuation is initialize so distance attenuation always be 1.0
if (lightData.lightType != LightType.Directional)
{
// Light attenuation in lightweight matches the unity vanilla one.
// attenuation = 1.0 / 1.0 + distanceToLightSqr * quadraticAttenuation
// then a smooth factor is applied to linearly fade attenuation to light range
// the attenuation smooth factor starts having effect at 80% of light range
// smoothFactor = (lightRangeSqr - distanceToLightSqr) / (lightRangeSqr - fadeStartDistanceSqr)
// We rewrite smoothFactor to be able to pre compute the constant terms below and apply the smooth factor
// with one MAD instruction
// smoothFactor = distanceSqr * (1.0 / (fadeDistanceSqr - lightRangeSqr)) + (-lightRangeSqr / (fadeDistanceSqr - lightRangeSqr)
// distanceSqr * oneOverFadeRangeSqr + lightRangeSqrOverFadeRangeSqr
float lightRangeSqr = lightData.range * lightData.range;
float fadeStartDistanceSqr = 0.8f * 0.8f * lightRangeSqr;
float fadeRangeSqr = (fadeStartDistanceSqr - lightRangeSqr);
float oneOverFadeRangeSqr = 1.0f / fadeRangeSqr;
float lightRangeSqrOverFadeRangeSqr = -lightRangeSqr / fadeRangeSqr;
float quadAtten = 25.0f / lightRangeSqr;
lightDistanceAttenuation = new Vector4(quadAtten, oneOverFadeRangeSqr, lightRangeSqrOverFadeRangeSqr, 1.0f);
}
if (lightData.lightType == LightType.Spot)
{
Vector4 dir = lightData.localToWorld.GetColumn(2);
lightSpotDir = new Vector4(-dir.x, -dir.y, -dir.z, 0.0f);
// Spot Attenuation with a linear falloff can be defined as
// (SdotL - cosOuterAngle) / (cosInnerAngle - cosOuterAngle)
// This can be rewritten as
// invAngleRange = 1.0 / (cosInnerAngle - cosOuterAngle)
// SdotL * invAngleRange + (-cosOuterAngle * invAngleRange)
// If we precompute the terms in a MAD instruction
float cosOuterAngle = Mathf.Cos(Mathf.Deg2Rad * lightData.spotAngle * 0.5f);
// We neeed to do a null check for particle lights
// This should be changed in the future
// Particle lights will use an inline function
float cosInnerAngle;
if (lightData.light != null)
cosInnerAngle = Mathf.Cos(LightmapperUtils.ExtractInnerCone(lightData.light) * 0.5f);
else
cosInnerAngle = Mathf.Cos((2.0f * Mathf.Atan(Mathf.Tan(lightData.spotAngle * 0.5f * Mathf.Deg2Rad) * (64.0f - 18.0f) / 64.0f)) * 0.5f);
float smoothAngleRange = Mathf.Max(0.001f, cosInnerAngle - cosOuterAngle);
float invAngleRange = 1.0f / smoothAngleRange;
float add = -cosOuterAngle * invAngleRange;
lightSpotAttenuation = new Vector4(invAngleRange, add, 0.0f);
}
Light light = lightData.light;
// TODO: Add support to shadow mask
if (light != null && light.bakingOutput.mixedLightingMode == MixedLightingMode.Subtractive && light.bakingOutput.lightmapBakeType == LightmapBakeType.Mixed)
{
if (m_MixedLightingSetup == MixedLightingSetup.None && lightData.light.shadows != LightShadows.None)
{
m_MixedLightingSetup = MixedLightingSetup.Subtractive;
lightDistanceAttenuation.w = 0.0f;
}
}
}
void SetupShaderLightConstants(CommandBuffer cmd, ref LightData lightData)
{
// Clear to default all light constant data
for (int i = 0; i < renderer.maxVisibleLocalLights; ++i)
InitializeLightConstants(lightData.visibleLights, -1, out m_LightPositions[i],
out m_LightColors[i],
out m_LightDistanceAttenuations[i],
out m_LightSpotDirections[i],
out m_LightSpotAttenuations[i]);
m_MixedLightingSetup = MixedLightingSetup.None;
// Main light has an optimized shader path for main light. This will benefit games that only care about a single light.
// Lightweight pipeline also supports only a single shadow light, if available it will be the main light.
SetupMainLightConstants(cmd, ref lightData);
SetupAdditionalLightConstants(cmd, ref lightData);
}
void SetupMainLightConstants(CommandBuffer cmd, ref LightData lightData)
{
Vector4 lightPos, lightColor, lightDistanceAttenuation, lightSpotDir, lightSpotAttenuation;
List<VisibleLight> lights = lightData.visibleLights;
InitializeLightConstants(lightData.visibleLights, lightData.mainLightIndex, out lightPos, out lightColor, out lightDistanceAttenuation, out lightSpotDir, out lightSpotAttenuation);
if (lightData.mainLightIndex >= 0)
{
VisibleLight mainLight = lights[lightData.mainLightIndex];
Light mainLightRef = mainLight.light;
if (LightweightPipeline.IsSupportedCookieType(mainLight.lightType) && mainLightRef.cookie != null)
{
Matrix4x4 lightCookieMatrix;
LightweightPipeline.GetLightCookieMatrix(mainLight, out lightCookieMatrix);
cmd.SetGlobalTexture(PerCameraBuffer._MainLightCookie, mainLightRef.cookie);
cmd.SetGlobalMatrix(PerCameraBuffer._WorldToLight, lightCookieMatrix);
}
}
cmd.SetGlobalVector(PerCameraBuffer._MainLightPosition, new Vector4(lightPos.x, lightPos.y, lightPos.z, lightDistanceAttenuation.w));
cmd.SetGlobalVector(PerCameraBuffer._MainLightColor, lightColor);
}
void SetupAdditionalLightConstants(CommandBuffer cmd, ref LightData lightData)
{
int maxVisibleLocalLights = renderer.maxVisibleLocalLights;
List<VisibleLight> lights = lightData.visibleLights;
if (lightData.totalAdditionalLightsCount > 0)
{
int localLightsCount = 0;
for (int i = 0; i < lights.Count && localLightsCount < maxVisibleLocalLights; ++i)
{
VisibleLight light = lights[i];
if (light.lightType != LightType.Directional)
{
InitializeLightConstants(lights, i, out m_LightPositions[localLightsCount],
out m_LightColors[localLightsCount],
out m_LightDistanceAttenuations[localLightsCount],
out m_LightSpotDirections[localLightsCount],
out m_LightSpotAttenuations[localLightsCount]);
localLightsCount++;
}
}
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, new Vector4(lightData.pixelAdditionalLightsCount,
lightData.totalAdditionalLightsCount, 0.0f, 0.0f));
// if not using a compute buffer, engine will set indices in 2 vec4 constants
// unity_4LightIndices0 and unity_4LightIndices1
if (renderer.perObjectLightIndices != null)
cmd.SetGlobalBuffer("_LightIndexBuffer", renderer.perObjectLightIndices);
}
else
{
cmd.SetGlobalVector(PerCameraBuffer._AdditionalLightCount, Vector4.zero);
}
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightPosition, m_LightPositions);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightColor, m_LightColors);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightDistanceAttenuation, m_LightDistanceAttenuations);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotDir, m_LightSpotDirections);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightSpotAttenuation, m_LightSpotAttenuations);
}
void SetShaderKeywords(CommandBuffer cmd, ref CameraData cameraData, ref LightData lightData, ref ShadowData shadowData)
{
int vertexLightsCount = lightData.totalAdditionalLightsCount - lightData.pixelAdditionalLightsCount;
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.AdditionalLights, lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.MixedLightingSubtractive, m_MixedLightingSetup == MixedLightingSetup.Subtractive);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.VertexLights, vertexLightsCount > 0);
// 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;
// Currently shadow filtering keyword is shared between local and directional shadows.
bool hasSoftShadows = (directionalShadowQuality == LightShadows.Soft || localShadowQuality == LightShadows.Soft) &&
shadowData.supportsSoftShadows;
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.DirectionalShadows, directionalShadowQuality != LightShadows.None);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.LocalShadows, localShadowQuality != LightShadows.None);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.SoftShadows, hasSoftShadows);
CoreUtils.SetKeyword(cmd, LightweightKeywordStrings.CascadeShadows, shadowData.directionalLightCascadeCount > 1);
// TODO: Remove this. legacy particles support will be removed from Unity in 2018.3. This should be a shader_feature instead with prop exposed in the Standard particles shader.
CoreUtils.SetKeyword(cmd, "SOFTPARTICLES_ON", cameraData.requiresSoftParticles);
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants");
SetupShaderLightConstants(cmd, ref renderingData.lightData);
SetShaderKeywords(cmd, ref renderingData.cameraData, ref renderingData.lightData, ref renderingData.shadowData);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class TransparentPostProcessPass : ScriptableRenderPass
{
public TransparentPostProcessPass(LightweightForwardRenderer renderer) : base(renderer)
{}
private RenderTargetHandle colorAttachmentHandle { get; set; }
private RenderTextureDescriptor descriptor { get; set; }
public void Setup(
RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle)
{
this.colorAttachmentHandle = colorAttachmentHandle;
descriptor = baseDescriptor;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
CommandBuffer cmd = CommandBufferPool.Get("Render PostProcess Effects");
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref renderingData.cameraData, descriptor.colorFormat, colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, false);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}

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


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

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


using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public struct RenderTargetHandle
{
public int id { private set; get; }
public static readonly RenderTargetHandle CameraTarget = new RenderTargetHandle {id = -1};
public void Init(string shaderProperty)
{
id = Shader.PropertyToID(shaderProperty);
}
public RenderTargetIdentifier Identifier()
{
if (id == -1)
{
return BuiltinRenderTextureType.CameraTarget;
}
return new RenderTargetIdentifier(id);
}
public bool Equals(RenderTargetHandle other)
{
return id == other.id;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is RenderTargetHandle && Equals((RenderTargetHandle) obj);
}
public override int GetHashCode()
{
return id;
}
public static bool operator ==(RenderTargetHandle c1, RenderTargetHandle c2)
{
return c1.Equals(c2);
}
public static bool operator !=(RenderTargetHandle c1, RenderTargetHandle c2)
{
return !c1.Equals(c2);
}
}
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
/*public static class RenderTargetHandles
{
}*/
}

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


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

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public enum SampleCount
{
One = 1,
Two = 2,
Four = 4,
}
}

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


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

61
TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Rendering;
public class CustomLWPipe : MonoBehaviour, IRendererSetup
{
private SetupForwardRenderingPass m_SetupForwardRenderingPass;
private CreateLightweightRenderTexturesPass m_CreateLightweightRenderTexturesPass;
private SetupLightweightConstanstPass m_SetupLightweightConstants;
private RenderOpaqueForwardPass m_RenderOpaqueForwardPass;
[NonSerialized]
private bool m_Initialized = false;
private void Init(LightweightForwardRenderer renderer)
{
if (m_Initialized)
return;
m_SetupForwardRenderingPass = new SetupForwardRenderingPass(renderer);
m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer);
m_SetupLightweightConstants = new SetupLightweightConstanstPass(renderer);
m_RenderOpaqueForwardPass = new RenderOpaqueForwardPass(renderer);
m_Initialized = true;
}
public void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults, ref RenderingData renderingData)
{
Init(renderer);
renderer.Clear();
renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
RenderTextureDescriptor baseDescriptor = renderer.CreateRTDesc(ref renderingData.cameraData);
RenderTextureDescriptor shadowDescriptor = baseDescriptor;
shadowDescriptor.dimension = TextureDimension.Tex2D;
renderer.EnqueuePass(m_SetupForwardRenderingPass);
RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget;
RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget;
var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples;
m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
Camera camera = renderingData.cameraData.camera;
bool dynamicBatching = renderingData.supportsDynamicBatching;
RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);
renderer.EnqueuePass(m_SetupLightweightConstants);
m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching);
renderer.EnqueuePass(m_RenderOpaqueForwardPass);
}
}

11
TestProjects/LWGraphicsTest/Assets/TestScripts/CustomLWPipe.cs.meta


fileFormatVersion: 2
guid: 7e0da365be9e44c3bae8da691ccd8de6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存