浏览代码

Merge remote-tracking branch 'refs/remotes/origin/master' into 2018.1-experimental

/main
sebastienlagarde 7 年前
当前提交
0ddaf44e
共有 62 个文件被更改,包括 904 次插入558 次删除
  1. 32
      LICENSE.md
  2. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/D3D11.hlsl
  3. 11
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/GLCore.hlsl
  4. 1
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/GLES2.hlsl
  5. 1
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/GLES3.hlsl
  6. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/Metal.hlsl
  7. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/PSSL.hlsl
  8. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/Vulkan.hlsl
  9. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/XBoxOne.hlsl
  10. 4
      ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs
  11. 32
      ScriptableRenderPipeline/Core/LICENSE.md
  12. 4
      ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md
  13. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/GlobalLightLoopSettingsUI.cs
  14. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedGlobalLightLoopSettings.cs
  15. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.cs
  16. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs
  17. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  18. 32
      ScriptableRenderPipeline/HDRenderPipeline/LICENSE.md
  19. 32
      ScriptableRenderPipeline/LightweightPipeline/LICENSE.md
  20. 64
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  21. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineEditorResources.cs
  22. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.asset
  23. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs
  24. 102
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
  25. 6
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs
  26. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/LightWeightPBRSubShader.cs
  27. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/LightWeightUnlitSubShader.cs
  28. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRExtraPasses.template
  29. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRForwardPass.template
  30. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitExtraPasses.template
  31. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitPass.template
  32. 176
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  33. 74
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs
  34. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/SceneViewDrawMode.cs
  35. 15
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl
  36. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl
  37. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightBlit.shader
  38. 37
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader
  39. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightSampling.shader
  40. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader
  41. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader
  42. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader
  43. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesSimpleLighting.shader
  44. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader
  45. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader
  46. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader
  47. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrain.shader
  48. 5
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainAddPass.shader
  49. 6
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainBase.shader
  50. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrass.shader
  51. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrassBillboard.shader
  52. 13
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset
  53. 9
      CONTRIBUTIONS.md
  54. 7
      CONTRIBUTIONS.md.meta
  55. 160
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs
  56. 11
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs.meta
  57. 205
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  58. 11
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs.meta
  59. 81
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl
  60. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl.meta
  61. 13
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs.meta
  62. 147
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs

32
LICENSE.md


**Unity Companion Package License v1.0 ("_License_")**
Copyright © 2017 Unity Technologies ApS ("**_Unity_**")
Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License ("**_Software_**"), subject to the following terms and conditions:
1. *Unity Companion Use Only*. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity development engine software license ("**_Engine License_**"). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted.
1. *No Modification of Engine License*. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.
1. *Ownership & Grant Back to You*.
3.1. You own your content. In this License, "derivative works" means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content.
3.2. Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity.
3.3. You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License.
1. *Trademarks*. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates ("**_Trademarks_**"). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Branding Usage Guidelines at [https://unity3d.com/public-relations/brand](https://unity3d.com/public-relations/brand).
1. *Notices & Third-Party Rights*. This License, including the copyright notice above, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity "third-party notices" or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms.
1. *DISCLAIMER, LIMITATION OF LIABILITY*. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1. *USE IS ACCEPTANCE and License Versions*. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License.
1. *Use in Compliance with Law and Termination*. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License.
Copyright © 2018 Unity Technologies ApS
1. *Severability*. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect.
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
1. *Governing Law and Venue*. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License ("**_Dispute_**"). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute.
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.

15
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/D3D11.hlsl


#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
#define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int4(unCoord2, index, 0), sampleIndex)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define PLATFORM_SUPPORT_GATHER
#define GATHER_TEXTURE2D(textureName, samplerName, coord2, offset) textureName.Gather(samplerName, coord2, offset)

11
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/GLCore.hlsl


#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
#define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int4(unCoord2, index, 0), sampleIndex)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#if OPENGL4_1_SM5
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2)

1
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/GLES2.hlsl


#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0)
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0)
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) half4(0, 0, 0, 0)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0)
// Gather not supported. Fallback to regular texture sampling.

1
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/GLES3.hlsl


#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int4(unCoord2, index, 0), sampleIndex)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#if GLES3_1_AEP

15
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/Metal.hlsl


#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
#define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int4(unCoord2, index, 0), sampleIndex)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2)
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index))

15
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/PSSL.hlsl


#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
#define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int4(unCoord2, index, 0), sampleIndex)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define PLATFORM_SUPPORT_GATHER
#define GATHER_TEXTURE2D(textureName, samplerName, coord2, offset) textureName.Gather(samplerName, coord2, offset)

15
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/Vulkan.hlsl


#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
#define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int4(unCoord2, index, 0), sampleIndex)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define PLATFORM_SUPPORT_GATHER
#define GATHER_TEXTURE2D(textureName, samplerName, coord2, offset) textureName.Gather(samplerName, coord2, offset)

15
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/API/XBoxOne.hlsl


#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
#define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
#define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int4(unCoord2, index, 0), sampleIndex)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
#define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
#define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
#define PLATFORM_SUPPORT_GATHER
#define GATHER_TEXTURE2D(textureName, samplerName, coord2, offset) textureName.Gather(samplerName, coord2, offset)

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


};
return mat;
}
public static bool HasFlag<T>(T mask, T flag) where T : IConvertible
{
return (mask.ToUInt32(null) & flag.ToUInt32(null)) != 0;
}
public static void SetKeyword(CommandBuffer cmd, string keyword, bool state)
{

32
ScriptableRenderPipeline/Core/LICENSE.md


**Unity Companion Package License v1.0 ("_License_")**
Copyright © 2017 Unity Technologies ApS ("**_Unity_**")
Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License ("**_Software_**"), subject to the following terms and conditions:
1. *Unity Companion Use Only*. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity development engine software license ("**_Engine License_**"). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted.
1. *No Modification of Engine License*. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.
1. *Ownership & Grant Back to You*.
3.1. You own your content. In this License, "derivative works" means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content.
3.2. Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity.
3.3. You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License.
1. *Trademarks*. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates ("**_Trademarks_**"). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Branding Usage Guidelines at [https://unity3d.com/public-relations/brand](https://unity3d.com/public-relations/brand).
1. *Notices & Third-Party Rights*. This License, including the copyright notice above, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity "third-party notices" or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms.
1. *DISCLAIMER, LIMITATION OF LIABILITY*. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1. *USE IS ACCEPTANCE and License Versions*. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License.
1. *Use in Compliance with Law and Termination*. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License.
Render Pipeline Core copyright © 2018 Unity Technologies ApS
1. *Severability*. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect.
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
1. *Governing Law and Venue*. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License ("**_Dispute_**"). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute.
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.

4
ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md


- Disable per-object culling that was executed in C++ in HD whereas it was not used (Optimization)
- Enable texture streaming debugging (was not working before 2018.2)
### Changed, Removals and deprecations
- Removed GlobalLightLoopSettings.maxPlanarReflectionProbes and instead use value of GlobalLightLoopSettings.planarReflectionProbeCacheSize
- Introduce the VolumetricLightingController component, which can (and should) be placed on the camera, and allows one to control the near and the far plane of the V-Buffer (volumetric "froxel" buffer) along with the depth distribution (from logarithmic to linear)
### Changed, Removals and deprecations
- Remove Resource folder of PreIntegratedFGD and add the resource to RenderPipeline Asset

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/GlobalLightLoopSettingsUI.cs


EditorGUILayout.PropertyField(d.planarReflectionCacheCompressed, _.GetContent("Compress Planar Reflection Probe Cache"));
EditorGUILayout.PropertyField(d.planarReflectionCubemapSize, _.GetContent("Planar Reflection Texture Size"));
EditorGUILayout.PropertyField(d.planarReflectionProbeCacheSize, _.GetContent("Planar Probe Cache Size"));
EditorGUILayout.PropertyField(d.maxPlanarReflectionProbes, _.GetContent("Max Planar Probe Per Frame"));
d.maxPlanarReflectionProbes.intValue = Mathf.Max(1, d.maxPlanarReflectionProbes.intValue);
--EditorGUI.indentLevel;
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedGlobalLightLoopSettings.cs


public SerializedProperty planarReflectionProbeCacheSize;
public SerializedProperty planarReflectionCubemapSize;
public SerializedProperty planarReflectionCacheCompressed;
public SerializedProperty maxPlanarReflectionProbes;
public SerializedProperty skyReflectionSize;
public SerializedProperty skyLightingOverrideLayerMask;

planarReflectionProbeCacheSize = root.Find((GlobalLightLoopSettings s) => s.planarReflectionProbeCacheSize);
planarReflectionCubemapSize = root.Find((GlobalLightLoopSettings s) => s.planarReflectionTextureSize);
planarReflectionCacheCompressed = root.Find((GlobalLightLoopSettings s) => s.planarReflectionCacheCompressed);
maxPlanarReflectionProbes = root.Find((GlobalLightLoopSettings s) => s.maxPlanarReflectionProbes);
skyReflectionSize = root.Find((GlobalLightLoopSettings s) => s.skyReflectionSize);
skyLightingOverrideLayerMask = root.Find((GlobalLightLoopSettings s) => s.skyLightingOverrideLayerMask);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.cs


{
return new ReflectionSystemParameters
{
maxPlanarReflectionProbes = renderPipelineSettings.lightLoopSettings.maxPlanarReflectionProbes,
maxPlanarReflectionProbes = renderPipelineSettings.lightLoopSettings.planarReflectionProbeCacheSize,
planarReflectionProbeSize = renderPipelineSettings.lightLoopSettings.planarReflectionTextureSize
};
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs


public int planarReflectionTextureSize = 128;
public bool reflectionCacheCompressed = false;
public bool planarReflectionCacheCompressed = false;
public int maxPlanarReflectionProbes = 128;
public SkyResolution skyReflectionSize = SkyResolution.SkyResolution256;
public LayerMask skyLightingOverrideLayerMask = 0;
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


m_lightList = new LightList();
m_lightList.Allocate();
m_Env2DCaptureVP.Clear();
for (int i = 0, c = Mathf.Max(1, hdAsset.renderPipelineSettings.lightLoopSettings.maxPlanarReflectionProbes); i < c; ++i)
for (int i = 0, c = Mathf.Max(1, hdAsset.renderPipelineSettings.lightLoopSettings.planarReflectionProbeCacheSize); i < c; ++i)
m_Env2DCaptureVP.Add(Matrix4x4.identity);
m_DirectionalLightDatas = new ComputeBuffer(k_MaxDirectionalLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLightData)));

32
ScriptableRenderPipeline/HDRenderPipeline/LICENSE.md


**Unity Companion Package License v1.0 ("_License_")**
Copyright © 2017 Unity Technologies ApS ("**_Unity_**")
Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License ("**_Software_**"), subject to the following terms and conditions:
1. *Unity Companion Use Only*. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity development engine software license ("**_Engine License_**"). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted.
1. *No Modification of Engine License*. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.
1. *Ownership & Grant Back to You*.
3.1. You own your content. In this License, "derivative works" means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content.
3.2. Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity.
3.3. You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License.
1. *Trademarks*. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates ("**_Trademarks_**"). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Branding Usage Guidelines at [https://unity3d.com/public-relations/brand](https://unity3d.com/public-relations/brand).
1. *Notices & Third-Party Rights*. This License, including the copyright notice above, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity "third-party notices" or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms.
1. *DISCLAIMER, LIMITATION OF LIABILITY*. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1. *USE IS ACCEPTANCE and License Versions*. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License.
1. *Use in Compliance with Law and Termination*. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License.
High Definition Render Pipeline copyright © 2018 Unity Technologies ApS
1. *Severability*. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect.
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
1. *Governing Law and Venue*. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License ("**_Dispute_**"). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute.
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.

32
ScriptableRenderPipeline/LightweightPipeline/LICENSE.md


**Unity Companion Package License v1.0 ("_License_")**
Copyright © 2017 Unity Technologies ApS ("**_Unity_**")
Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License ("**_Software_**"), subject to the following terms and conditions:
1. *Unity Companion Use Only*. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity development engine software license ("**_Engine License_**"). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted.
1. *No Modification of Engine License*. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.
1. *Ownership & Grant Back to You*.
3.1. You own your content. In this License, "derivative works" means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content.
3.2. Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity.
3.3. You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License.
1. *Trademarks*. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates ("**_Trademarks_**"). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Branding Usage Guidelines at [https://unity3d.com/public-relations/brand](https://unity3d.com/public-relations/brand).
1. *Notices & Third-Party Rights*. This License, including the copyright notice above, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity "third-party notices" or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms.
1. *DISCLAIMER, LIMITATION OF LIABILITY*. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1. *USE IS ACCEPTANCE and License Versions*. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License.
1. *Use in Compliance with Law and Termination*. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License.
Lightweight Render Pipeline copyright © 2018 Unity Technologies ApS
1. *Severability*. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect.
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
1. *Governing Law and Venue*. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License ("**_Dispute_**"). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute.
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.

64
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs


public enum ShadowResolution
{
_256 = 256,
_512 = 512,
_1024 = 1024,
_2048 = 2048,

UnityBuiltinDefault
}
public class LightweightPipelineAsset : RenderPipelineAsset
public class LightweightPipelineAsset : RenderPipelineAsset, ISerializationCallbackReceiver
private const int PACKAGE_MANAGER_PATH_INDEX = 1;
[SerializeField] private int kAssetVersion = 2;
[SerializeField] private int kAssetVersion = 3;
[SerializeField] private int m_MaxPixelLights = 4;
[SerializeField] private bool m_SupportsVertexLight = false;
[SerializeField] private bool m_RequireDepthTexture = false;

[SerializeField] private bool m_SupportsHDR = false;
[SerializeField] private MSAAQuality m_MSAA = MSAAQuality._4x;
[SerializeField] private float m_RenderScale = 1.0f;
[SerializeField] private ShadowType m_ShadowType = ShadowType.HARD_SHADOWS;
[SerializeField] private bool m_DirectionalShadowsSupported = true;
[SerializeField] private bool m_LocalShadowsSupported = true;
[SerializeField] private ShadowResolution m_LocalShadowsAtlasResolution = ShadowResolution._512;
[SerializeField] private bool m_SoftShadowsSupported = false;
// Deprecated
[SerializeField] private ShadowType m_ShadowType = ShadowType.HARD_SHADOWS;
#if UNITY_EDITOR
[NonSerialized]

#endif
}
public bool AreShadowsEnabled()
{
return ShadowSetting != ShadowType.NO_SHADOW;
}
public float GetAssetVersion()
public int GetAssetVersion()
{
return kAssetVersion;
}

public bool RequireDepthTexture
{
get { return m_RequireDepthTexture; }
set { m_RequireDepthTexture = value; }
}
public bool RequireSoftParticles

public bool RequireOpaqueTexture
{
get { return m_RequireOpaqueTexture; }
set { m_RequireOpaqueTexture = value; }
set { m_OpaqueDownsampling = value; }
}
public bool SupportsHDR

set { m_RenderScale = value; }
}
public ShadowType ShadowSetting
public bool SupportsDirectionalShadows
get { return m_ShadowType; }
private set { m_ShadowType = value; }
get { return m_DirectionalShadowsSupported; }
public int ShadowAtlasResolution
public int DirectionalShadowAtlasResolution
private set { m_ShadowAtlasResolution = (ShadowResolution)value; }
private set { m_ShadowDistance = value; }
set { m_ShadowDistance = value; }
}
public int CascadeCount

public float Cascade2Split
{
get { return m_Cascade2Split; }
private set { m_Cascade2Split = value; }
private set { m_Cascade4Split = value; }
}
public bool SupportsLocalShadows
{
get { return m_LocalShadowsSupported; }
}
public int LocalShadowAtlasResolution
{
get { return (int)m_LocalShadowsAtlasResolution; }
}
public bool SupportsSoftShadows
{
get { return m_SoftShadowsSupported; }
}
public override Material GetDefaultMaterial()

{
get { return resources != null ? resources.CopyDepthShader : null; }
}
public Shader ScreenSpaceShadowShader
{
get { return resources != null ? resources.ScreenSpaceShadowShader : null; }

{
get { return resources != null ? resources.SamplingShader : null; }
}
public void OnBeforeSerialize()
{
}
public void OnAfterDeserialize()
{
if (kAssetVersion < 3)
{
kAssetVersion = 3;
m_SoftShadowsSupported = (m_ShadowType == ShadowType.SOFT_SHADOWS);
}
}
}
}

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineEditorResources.cs


public Material DefaultMaterial;
public Material DefaultParticleMaterial;
public Material DefaultTerrainMaterial;
}
}

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.asset


--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs


public Shader CopyDepthShader;
public Shader ScreenSpaceShadowShader;
public Shader SamplingShader;
}
}

102
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs


public static GUIContent requireOpaqueTexture = new GUIContent("Opaque Texture", "If enabled the pipeline will copy the screen to texture after opaque objects are drawn. For transparent objects this can be bound in shaders as _CameraOpaqueTexture.");
public static GUIContent opaqueDownsampling = new GUIContent("Opaque Downsampling", "The downsampling method that is used for the opaque texture");
public static GUIContent hdrContent = new GUIContent("HDR", "Controls the global HDR settings.");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing settings.");
public static GUIContent shadowType = new GUIContent("Type",
"Global shadow settings. Options are NO_SHADOW, HARD_SHADOWS and SOFT_SHADOWS.");
public static GUIContent supportsSoftShadows = new GUIContent("Soft Shadows", "If enabled pipeline will perform shadow filtering. Otherwise all lights that cast shadows will fallback to perform a single shadow sample.");
public static GUIContent supportsDirectionalShadows = new GUIContent("Directional Shadows", "If enabled shadows will be supported for directional lights.");
public static GUIContent shadowDistante = new GUIContent("Distance", "Max shadow rendering distance.");
public static GUIContent shadowDistance = new GUIContent("Distance", "Max shadow rendering distance.");
public static GUIContent shadowAtlasResolution = new GUIContent("Shadowmap Resolution",
"Resolution of shadow map texture. If cascades are enabled, cascades will be packed into an atlas and this setting controls the max shadows atlas resolution.");
public static GUIContent directionalShadowAtlasResolution = new GUIContent("Atlas Resolution",
"Resolution of the directional shadow map texture. If cascades are enabled, cascades will be packed into an atlas and this setting controls the max shadows atlas resolution.");
public static GUIContent shadowCascades = new GUIContent("Cascades",
"Number of cascades used in directional lights shadows");

public static GUIContent hdrContent = new GUIContent("HDR", "Controls the global HDR settings.");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing settings.");
public static GUIContent supportsLocalShadows = new GUIContent("Local Shadows", "If enabled shadows will be supported for spot lights.");
public static GUIContent localShadowsAtlasResolution = new GUIContent("Atlas Resolution",
"All local lights are packed into a single atlas. This setting controls the atlas size.");
public static string[] shadowTypeOptions = {"No Shadows", "Hard Shadows", "Hard and Soft Shadows"};
public static string[] shadowCascadeOptions = {"No Cascades", "Two Cascades", "Four Cascades"};
public static string[] opaqueDownsamplingOptions = {"None", "2x (Bilinear)", "4x (Box)", "4x (Bilinear)"};
}

private SerializedProperty m_RequireSoftParticlesProp;
private SerializedProperty m_RequireOpaqueTextureProp;
private SerializedProperty m_OpaqueDownsamplingProp;
private SerializedProperty m_ShadowTypeProp;
private SerializedProperty m_HDR;
private SerializedProperty m_MSAA;
private SerializedProperty m_SoftShadowsSupportedProp;
private SerializedProperty m_DirectionalShadowsSupportedProp;
private SerializedProperty m_ShadowAtlasResolutionProp;
private SerializedProperty m_DirectionalShadowAtlasResolutionProp;
private SerializedProperty m_HDR;
private SerializedProperty m_MSAA;
private SerializedProperty m_LocalShadowSupportedProp;
private SerializedProperty m_LocalShadowsAtlasResolutionProp;
void OnEnable()
{

m_RequireSoftParticlesProp = serializedObject.FindProperty("m_RequireSoftParticles");
m_RequireOpaqueTextureProp = serializedObject.FindProperty("m_RequireOpaqueTexture");
m_OpaqueDownsamplingProp = serializedObject.FindProperty("m_OpaqueDownsampling");
m_ShadowTypeProp = serializedObject.FindProperty("m_ShadowType");
m_HDR = serializedObject.FindProperty("m_SupportsHDR");
m_MSAA = serializedObject.FindProperty("m_MSAA");
m_DirectionalShadowsSupportedProp = serializedObject.FindProperty("m_DirectionalShadowsSupported");
m_ShadowAtlasResolutionProp = serializedObject.FindProperty("m_ShadowAtlasResolution");
m_DirectionalShadowAtlasResolutionProp = serializedObject.FindProperty("m_ShadowAtlasResolution");
m_HDR = serializedObject.FindProperty("m_SupportsHDR");
m_MSAA = serializedObject.FindProperty("m_MSAA");
m_LocalShadowSupportedProp = serializedObject.FindProperty("m_LocalShadowsSupported");
m_LocalShadowsAtlasResolutionProp = serializedObject.FindProperty("m_LocalShadowsAtlasResolution");
m_SoftShadowsSupportedProp = serializedObject.FindProperty("m_SoftShadowsSupported");
m_ShowSoftParticles.valueChanged.AddListener(Repaint);
m_ShowSoftParticles.value = m_RequireSoftParticlesProp.boolValue;

CoreEditorUtils.DrawPopup(content, prop, options);
}
public override void OnInspectorGUI()
void DrawRenderingSettings()
serializedObject.Update();
UpdateAnimationValues();
EditorGUILayout.Space();
EditorGUILayout.LabelField(Styles.renderingLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;

EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
}
void DrawShadowSettings()
{
CoreEditorUtils.DrawPopup(Styles.shadowType, m_ShadowTypeProp, Styles.shadowTypeOptions);
EditorGUILayout.PropertyField(m_ShadowAtlasResolutionProp, Styles.shadowAtlasResolution);
m_ShadowDistanceProp.floatValue = Mathf.Max(0.0f, EditorGUILayout.FloatField(Styles.shadowDistante, m_ShadowDistanceProp.floatValue));
CoreEditorUtils.DrawPopup(Styles.shadowCascades, m_ShadowCascadesProp, Styles.shadowCascadeOptions);
EditorGUILayout.PropertyField(m_DirectionalShadowsSupportedProp, Styles.supportsDirectionalShadows);
bool directionalShadows = m_DirectionalShadowsSupportedProp.boolValue;
if (directionalShadows)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DirectionalShadowAtlasResolutionProp, Styles.directionalShadowAtlasResolution);
m_ShadowDistanceProp.floatValue = Mathf.Max(0.0f,
EditorGUILayout.FloatField(Styles.shadowDistance, m_ShadowDistanceProp.floatValue));
CoreEditorUtils.DrawPopup(Styles.shadowCascades, m_ShadowCascadesProp, Styles.shadowCascadeOptions);
ShadowCascades cascades = (ShadowCascades)m_ShadowCascadesProp.intValue;
if (cascades == ShadowCascades.FOUR_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<Vector3>(ref m_ShadowCascade4SplitProp);
else if (cascades == ShadowCascades.TWO_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<float>(ref m_ShadowCascade2SplitProp);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
EditorGUILayout.PropertyField(m_LocalShadowSupportedProp, Styles.supportsLocalShadows);
bool localShadows = m_LocalShadowSupportedProp.boolValue;
if (localShadows)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LocalShadowsAtlasResolutionProp, Styles.localShadowsAtlasResolution);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
ShadowCascades cascades = (ShadowCascades)m_ShadowCascadesProp.intValue;
if (cascades == ShadowCascades.FOUR_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<Vector3>(ref m_ShadowCascade4SplitProp);
else if (cascades == ShadowCascades.TWO_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<float>(ref m_ShadowCascade2SplitProp);
if (directionalShadows || localShadows)
EditorGUILayout.PropertyField(m_SoftShadowsSupportedProp, Styles.supportsSoftShadows);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
UpdateAnimationValues();
DrawRenderingSettings();
DrawShadowSettings();
serializedObject.ApplyModifiedProperties();
}

6
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs


private bool RequiresAlpha()
{
SurfaceType surfaceType = (SurfaceType) surfaceTypeProp.floatValue;
SurfaceType surfaceType = (SurfaceType)surfaceTypeProp.floatValue;
return alphaClipProp.floatValue > 0.0f || surfaceType == SurfaceType.Transparent;
}

if (RequiresAlpha())
{
GUI.enabled = false;
glossinessSourceProp.floatValue = (float)EditorGUILayout.Popup(Styles.glossinessSourceLabel, (int) GlossinessSource.SpecularAlpha, Styles.glossinessSourceNames);
glossinessSourceProp.floatValue = (float)EditorGUILayout.Popup(Styles.glossinessSourceLabel, (int)GlossinessSource.SpecularAlpha, Styles.glossinessSourceNames);
GUI.enabled = true;
}
else

EditorGUI.BeginChangeCheck();
float shininess = EditorGUILayout.Slider(Styles.shininessLabel, shininessProp.floatValue,
kMinShininessValue, 1.0f);
kMinShininessValue, 1.0f);
if (EditorGUI.EndChangeCheck())
shininessProp.floatValue = shininess;
EditorGUI.indentLevel -= 2;

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/LightWeightPBRSubShader.cs


if (masterNode.IsSlotConnected(PBRMasterNode.AlphaThresholdSlotId))
defines.AddShaderChunk("#define _AlphaClip 1", true);
if(masterNode.surfaceType == SurfaceType.Transparent && masterNode.alphaMode == AlphaMode.Premultiply)
if (masterNode.surfaceType == SurfaceType.Transparent && masterNode.alphaMode == AlphaMode.Premultiply)
defines.AddShaderChunk("#define _ALPHAPREMULTIPLY_ON 1", true);
var templateLocation = GetTemplatePath(template);

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/LightWeightUnlitSubShader.cs


if (masterNode.IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId))
defines.AddShaderChunk("#define _AlphaClip 1", true);
if(masterNode.surfaceType == SurfaceType.Transparent && masterNode.alphaMode == AlphaMode.Premultiply)
if (masterNode.surfaceType == SurfaceType.Transparent && masterNode.alphaMode == AlphaMode.Premultiply)
defines.AddShaderChunk("#define _ALPHAPREMULTIPLY_ON 1", true);
var templateLocation = GetTemplatePath(template);

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRExtraPasses.template


Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On

Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On

// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags{"LightMode" = "Meta"}
Cull Off

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRForwardPass.template


Pass
{
Name "StandardLit"
Tags{"LightMode" = "LightweightForward"}
${Tags}
${Blending}

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitExtraPasses.template


Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitPass.template


Pass
{
Name "StandardUnlit"
Tags{"LightMode" = "LightweightForward"}
${Tags}
${Blending}

176
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


public static int opaque;
}
public class LightweightPipeline : RenderPipeline
public partial class LightweightPipeline : RenderPipeline
{
private readonly LightweightPipelineAsset m_Asset;

private static readonly float kRenderScaleThreshold = 0.05f;
private static readonly string kMSAADepthKeyword = "_MSAA_DEPTH";
private bool m_IsOffscreenCamera;
private Vector4 kDefaultLightPosition = new Vector4(0.0f, 0.0f, 1.0f, 0.0f);

private float[] m_OpaqueScalerValues = {1.0f, 0.5f, 0.25f, 0.25f};
private float m_RenderScale;
private int m_MSAASamples;
private bool m_IntermediateTextureArray;
private bool m_RequireDepthTexture;

private Material m_ErrorMaterial;
private Material m_SamplingMaterial;
private int m_SampleOffset;
private int m_SampleCount;
private int m_BlitTexID = Shader.PropertyToID("_BlitTex");
private CopyTextureSupport m_CopyTextureSupport;

m_Asset = asset;
SetRenderingFeatures();
SetPipelineCapabilities(asset);
PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

CameraRenderTargetID.opaque = Shader.PropertyToID("_CameraOpaqueTexture");
m_SampleOffset = Shader.PropertyToID("_SampleOffset");
m_SampleCount = Shader.PropertyToID("_SampleCount");
m_ColorRT = new RenderTargetIdentifier(CameraRenderTargetID.color);
m_CopyColorRT = new RenderTargetIdentifier(CameraRenderTargetID.copyColor);

m_MaxLocalLightsShadedPerPass = m_UseComputeBuffer ? kMaxVisibleLocalLights : kMaxNonIndexedLocalLights;
m_LocalLightIndices = new List<int>(m_MaxLocalLightsShadedPerPass);
m_ShadowPass = new LightweightShadowPass(m_Asset, m_MaxLocalLightsShadedPerPass);
m_ShadowPass = new LightweightShadowPass(m_Asset, kMaxVisibleLocalLights);
// Let engine know we have MSAA on for cases where we support MSAA backbuffer
if (QualitySettings.antiAliasing != m_Asset.MSAASampleCount)

if (!CullResults.GetCullingParameters(m_CurrCamera, stereoEnabled, out cullingParameters))
continue;
var cmd = CommandBufferPool.Get("");
cullingParameters.shadowDistance = Mathf.Min(m_ShadowPass.RenderingDistance, m_CurrCamera.farClipPlane);
#if UNITY_EDITOR

// Setup global time properties (_Time, _SinTime, _CosTime)
context.SetupCameraProperties(m_CurrCamera, stereoEnabled);
if (LightweightUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DepthPrePass))
if (CoreUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DepthPrePass))
DepthPass(ref context, frameRenderingConfiguration);
if (screenspaceShadows)

cmd.name = "After Camera Render";
CommandBuffer cmd;
{
cmd = CommandBufferPool.Get("Copy Depth to Camera");
cmd.DisableShaderKeyword(kMSAADepthKeyword);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
context.Submit();
cmd = CommandBufferPool.Get("Dispose of Temporaries");
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depthCopy);
cmd.ReleaseTemporaryRT(CameraRenderTargetID.depth);
cmd.ReleaseTemporaryRT(CameraRenderTargetID.color);

m_ShadowPass.Dispose(cmd);
m_ShadowPass.Dispose(cmd);
context.Submit();
}

renderQueueRange = RenderQueueRange.opaque
};
LightweightUtils.StartStereoRendering(m_CurrCamera, ref context, frameRenderingConfiguration);
StartStereoRendering(m_CurrCamera, ref context, frameRenderingConfiguration);
LightweightUtils.StopStereoRendering(m_CurrCamera, ref context, frameRenderingConfiguration);
StopStereoRendering(m_CurrCamera, ref context, frameRenderingConfiguration);
}
private void OpaqueTexturePass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration)

switch(m_Asset.OpaqueDownsampling)
switch (m_Asset.OpaqueDownsampling)
{
case Downsampling.None:
cmd.Blit(m_CurrCameraColorRT, CameraRenderTargetID.opaque);

// TODO: There's currently an issue in the PostFX stack that has a one frame delay when an effect is enabled/disabled
// when an effect is disabled, HasOpaqueOnlyEffects returns true in the first frame, however inside render the effect
// state is update, causing RenderPostProcess here to not blit to FinalColorRT. Until the next frame the RT will have garbage.
if (LightweightUtils.HasFlag(config, FrameRenderingConfiguration.BeforeTransparentPostProcess))
if (CoreUtils.HasFlag(config, FrameRenderingConfiguration.BeforeTransparentPostProcess))
{
// When only have one effect in the stack we blit to a work RT then blit it back to active color RT.
// This seems like an extra blit but it saves us a depth copy/blit which has some corner cases like msaa depth resolve.

SetRenderTarget(cmd, m_CurrCameraColorRT, m_DepthRT);
}
if (LightweightUtils.HasFlag(config, FrameRenderingConfiguration.DepthCopy))
if (CoreUtils.HasFlag(config, FrameRenderingConfiguration.DepthCopy))
CopyTexture(cmd, m_DepthRT, m_CopyDepth, m_CopyDepthMaterial);
bool forceBlit = false;
if (m_MSAASamples > 1)
{
cmd.SetGlobalFloat(m_SampleCount, (float)m_MSAASamples);
cmd.EnableShaderKeyword(kMSAADepthKeyword);
forceBlit = true;
}
else
cmd.DisableShaderKeyword(kMSAADepthKeyword);
CopyTexture(cmd, m_DepthRT, m_CopyDepth, m_CopyDepthMaterial, forceBlit);
cmd.SetGlobalTexture(CameraRenderTargetID.depth, m_CopyDepth);
}
if (setRenderTarget)

}
if(m_Asset.RequireOpaqueTexture)
if (m_Asset.RequireOpaqueTexture)
{
OpaqueTexturePass(ref context, config);
}

private void AfterTransparent(ref ScriptableRenderContext context, FrameRenderingConfiguration config)
{
if (!LightweightUtils.HasFlag(config, FrameRenderingConfiguration.PostProcess))
if (!CoreUtils.HasFlag(config, FrameRenderingConfiguration.PostProcess))
return;
CommandBuffer cmd = CommandBufferPool.Get("After Transparent");

// TODO: PostProcessing and SoftParticles are currently not support for VR
bool postProcessEnabled = m_CameraPostProcessLayer != null && m_CameraPostProcessLayer.enabled && !stereoEnabled;
m_RequireDepthTexture = m_Asset.RequireDepthTexture && !stereoEnabled;
bool canSkipDepthCopy = !m_RequireDepthTexture;
if (postProcessEnabled)
{
m_RequireDepthTexture = true;

}
if (sceneViewCamera)
{
canSkipDepthCopy = false;
}
canSkipDepthCopy = canSkipDepthCopy && !screenspaceShadows;
intermediateTexture = intermediateTexture || !LightweightUtils.PlatformSupportsMSAABackBuffer();
intermediateTexture = intermediateTexture || !PlatformSupportsMSAABackBuffer();
canSkipDepthCopy = false;
// If msaa is enabled we don't use a depth renderbuffer as we might not have support to Texture2DMS to resolve depth.
// Instead we use a depth prepass and whenever depth is needed we use the 1 sample depth from prepass.
// Screen space shadows require depth before opaque shading.
if (!msaaEnabled && !screenspaceShadows)
{
bool supportsDepthCopy = m_CopyTextureSupport != CopyTextureSupport.None && m_Asset.CopyDepthShader.isSupported;
m_DepthRenderBuffer = true;
intermediateTexture = true;
bool hasTex2DMS = SystemInfo.supportsMultisampledTextures != 0;
bool copyShaderSupported = m_Asset.CopyDepthShader.isSupported && (msaaEnabled == hasTex2DMS);
bool supportsDepthCopy = m_CopyTextureSupport != CopyTextureSupport.None || copyShaderSupported;
bool requiresDepthPrepassToResolveMSAA = msaaEnabled && !hasTex2DMS;
bool requiresDepthPrepass = !supportsDepthCopy || screenspaceShadows || requiresDepthPrepassToResolveMSAA;
// If requiring a camera depth texture we need separate depth as it reads/write to depth at same time
// Post process doesn't need the copy
if (!m_Asset.RequireDepthTexture && postProcessEnabled)
configuration |= (supportsDepthCopy) ? FrameRenderingConfiguration.DepthCopy : FrameRenderingConfiguration.DepthPrePass;
}
else
{
m_DepthRenderBuffer = !requiresDepthPrepass;
intermediateTexture = intermediateTexture || m_DepthRenderBuffer;
if (requiresDepthPrepass)
}
else if (supportsDepthCopy && !canSkipDepthCopy)
configuration |= FrameRenderingConfiguration.DepthCopy;
}
Rect cameraRect = m_CurrCamera.rect;

private RenderTextureDescriptor CreateRTDesc(FrameRenderingConfiguration renderingConfig, float scaler = 1.0f)
{
RenderTextureDescriptor desc;
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo))
if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo))
desc = XRSettings.eyeTextureDesc;
else
desc = new RenderTextureDescriptor(m_CurrCamera.pixelWidth, m_CurrCamera.pixelHeight);

CommandBuffer cmd = CommandBufferPool.Get("Setup Intermediate Resources");
int msaaSamples = (m_IsOffscreenCamera) ? Math.Min(m_CurrCamera.targetTexture.antiAliasing, m_Asset.MSAASampleCount) : m_Asset.MSAASampleCount;
msaaSamples = (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Msaa)) ? msaaSamples : 1;
msaaSamples = (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Msaa)) ? msaaSamples : 1;
m_MSAASamples = msaaSamples;
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture) || m_RequireDepthTexture)
if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture) || m_RequireDepthTexture)
SetupIntermediateRenderTextures(cmd, renderingConfig, shadows, msaaSamples);
context.ExecuteCommandBuffer(cmd);

depthRTDesc.colorFormat = RenderTextureFormat.Depth;
depthRTDesc.depthBufferBits = kDepthStencilBufferBits;
cmd.GetTemporaryRT(CameraRenderTargetID.depth, depthRTDesc, FilterMode.Bilinear);
// This also means we don't do a depth copy
bool doesDepthPrepass = CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DepthPrePass);
if (!doesDepthPrepass)
{
depthRTDesc.bindMS = msaaSamples > 1;
depthRTDesc.msaaSamples = msaaSamples;
}
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DepthCopy))
cmd.GetTemporaryRT(CameraRenderTargetID.depthCopy, depthRTDesc, FilterMode.Bilinear);
cmd.GetTemporaryRT(CameraRenderTargetID.depth, depthRTDesc, FilterMode.Point);
if (!doesDepthPrepass)
{
depthRTDesc.bindMS = false;
depthRTDesc.msaaSamples = 1;
cmd.GetTemporaryRT(CameraRenderTargetID.depthCopy, depthRTDesc, FilterMode.Point);
}
m_ShadowPass.InitializeResources(cmd, baseDesc);
}

{
if (visibleLights[i].lightType != LightType.Directional)
m_LocalLightIndices.Add(i);
if (m_LocalLightIndices.Count >= m_MaxLocalLightsShadedPerPass)
break;
}
// Clear to default all light constant data

{
VisibleLight light = visibleLights[i];
if (light.lightType == LightType.Directional)
{
++directionalLightCount;
}
else
perObjectLightIndexMap[i] -= directionalLightCount;
}

// 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);
SetupAdditionalListConstants(cmd, ref lightData);
SetupAdditionalLightConstants(cmd, ref lightData);
}
private void SetupMainLightConstants(CommandBuffer cmd, ref LightData lightData)

VisibleLight mainLight = lights[lightData.mainLightIndex];
Light mainLightRef = mainLight.light;
if (LightweightUtils.IsSupportedCookieType(mainLight.lightType) && mainLightRef.cookie != null)
if (IsSupportedCookieType(mainLight.lightType) && mainLightRef.cookie != null)
LightweightUtils.GetLightCookieMatrix(mainLight, out lightCookieMatrix);
GetLightCookieMatrix(mainLight, out lightCookieMatrix);
cmd.SetGlobalTexture(PerCameraBuffer._MainLightCookie, mainLightRef.cookie);
cmd.SetGlobalMatrix(PerCameraBuffer._WorldToLight, lightCookieMatrix);
}

cmd.SetGlobalVector(PerCameraBuffer._MainLightColor, lightColor);
}
private void SetupAdditionalListConstants(CommandBuffer cmd, ref LightData lightData)
private void SetupAdditionalLightConstants(CommandBuffer cmd, ref LightData lightData)
{
List<VisibleLight> lights = lightData.visibleLights;
if (lightData.totalAdditionalLightsCount > 0)

private void SetShaderKeywords(CommandBuffer cmd, ref LightData lightData)
{
List<VisibleLight> visibleLights = lightData.visibleLights;
int mainLightIndex = lightData.mainLightIndex;
bool shadowsEnabled = m_ShadowPass.HasDirectionalShadowmap || m_ShadowPass.HasLocalLightsShadowmap;
CoreUtils.SetKeyword(cmd, "_SHADOWS_ENABLED", shadowsEnabled);
CoreUtils.SetKeyword(cmd, LightweightKeywords.AdditionalLightsText, lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, LightweightKeywords.MixedLightingSubtractiveText, m_MixedLightingSetup == MixedLightingSetup.Subtractive);
CoreUtils.SetKeyword(cmd, LightweightKeywords.VertexLightsText, vertexLightsCount > 0);
// TODO: Currently we are shading same keyword for directional and local lights
// When we have ability to strip keywords we can use the one below instead
//CoreUtils.SetKeyword(cmd, "_SHADOWS_ENABLED", m_ShadowPass.HasDirectionalShadowmap);
//CoreUtils.SetKeyword(cmd, "_LOCAL_SHADOWS_ENABLED", m_ShadowPass.HasLocalLightsShadowmap);
// TODO: We have to discuss cookie approach on LWRP.
// CoreUtils.SetKeyword(cmd, LightweightKeywords.MainLightCookieText, mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
//TIM: Not used in shader for V1 to reduce keywords
CoreUtils.SetKeyword(cmd, "_MAIN_LIGHT_COOKIE", mainLightIndex != -1 && LightweightUtils.IsSupportedCookieType(visibleLights[mainLightIndex].lightType) && visibleLights[mainLightIndex].light.cookie != null);
bool anyShadowsEnabled = m_ShadowPass.IsDirectionalShadowsEnabled || m_ShadowPass.IsLocalShadowsEnabled;
CoreUtils.SetKeyword(cmd, LightweightKeywords.DirectionalShadowsText, m_ShadowPass.DirectionalShadowsRendered);
CoreUtils.SetKeyword(cmd, LightweightKeywords.LocalShadowsText, m_ShadowPass.LocalShadowsRendered);
CoreUtils.SetKeyword(cmd, LightweightKeywords.SoftShadowsText, m_ShadowPass.IsSoftShadowsEnabled && anyShadowsEnabled);
CoreUtils.SetKeyword(cmd, "_ADDITIONAL_LIGHTS", lightData.totalAdditionalLightsCount > 0);
CoreUtils.SetKeyword(cmd, "_MIXED_LIGHTING_SUBTRACTIVE", m_MixedLightingSetup == MixedLightingSetup.Subtractive);
CoreUtils.SetKeyword(cmd, "_VERTEX_LIGHTS", vertexLightsCount > 0);
// 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", m_RequireDepthTexture && m_Asset.RequireSoftParticles);
}

RenderTargetIdentifier depthRT = BuiltinRenderTextureType.None;
LightweightUtils.StartStereoRendering(m_CurrCamera, ref context, renderingConfig);
StartStereoRendering(m_CurrCamera, ref context, renderingConfig);
bool intermediateTexture = LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture);
bool intermediateTexture = CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture);
if (m_RequireDepthTexture)
if (m_DepthRenderBuffer)
depthRT = m_DepthRT;
}

// If rendering to an intermediate RT we resolve viewport on blit due to offset not being supported
// while rendering to a RT.
if (!intermediateTexture && !LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport))
if (!intermediateTexture && !CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport))
cmd.SetViewport(m_CurrCamera.pixelRect);
context.ExecuteCommandBuffer(cmd);

{
cmd.Blit(m_CurrCameraColorRT, BuiltinRenderTextureType.CameraTarget);
}
else if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture))
else if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture))
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo))
if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo))
if (!LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.PostProcess))
if (!CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.PostProcess))
Blit(cmd, renderingConfig, m_CurrCameraColorRT, BuiltinRenderTextureType.CameraTarget, blitMaterial);
}

CommandBufferPool.Release(cmd);
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo))
if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.Stereo))
{
context.StopMultiEye(m_CurrCamera);
context.StereoEndRender(m_CurrCamera);

private void Blit(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material material = null)
{
cmd.SetGlobalTexture(m_BlitTexID, sourceRT);
if (LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport))
if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DefaultViewport))
{
cmd.Blit(sourceRT, destRT, material);
}

SetRenderTarget(cmd, destRT);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(m_CurrCamera.pixelRect);
LightweightUtils.DrawFullScreen(cmd, m_BlitMaterial);
DrawFullScreen(cmd, m_BlitMaterial);
}
}

74
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs


[Serializable]
public class ShadowSettings
{
public LightShadows directionalShadowQuality;
public bool supportsDirectionalShadows;
public LightShadows localLightsShadowQuality;
public float maxShadowDistance;
public int directionalLightCascadeCount;
public Vector3 directionalLightCascades;
public bool supportsLocalShadows;
public bool supportsSoftShadows;
public float maxShadowDistance;
public int directionalLightCascadeCount;
public Vector3 directionalLightCascades;
public RenderTextureFormat shadowmapTextureFormat;
public RenderTextureFormat screenspaceShadowmapTextureFormat;

if (defaultShadowSettings == null)
{
defaultShadowSettings = new ShadowSettings();
defaultShadowSettings.directionalShadowQuality = LightShadows.None;
defaultShadowSettings.supportsDirectionalShadows = true;
defaultShadowSettings.localLightsShadowQuality = LightShadows.None;
defaultShadowSettings.directionalLightCascadeCount = 1;
defaultShadowSettings.directionalLightCascades = new Vector3(0.067f, 0.2f, 0.467f);
defaultShadowSettings.supportsLocalShadows = true;
defaultShadowSettings.directionalLightCascadeCount = 1;
defaultShadowSettings.directionalLightCascades = new Vector3(0.05F, 0.2F, 0.3F);
defaultShadowSettings.supportsSoftShadows = false;
}
return defaultShadowSettings;
}

public class LightweightShadowPass
{
public bool IsDirectionalShadowsEnabled { get { return m_ShadowSettings.directionalShadowQuality != LightShadows.None; } }
public bool IsLocalShadowsEnabled { get { return m_ShadowSettings.localLightsShadowQuality != LightShadows.None; }}
public bool IsDirectionalShadowsEnabled { get { return m_ShadowSettings.supportsDirectionalShadows; } }
public bool IsLocalShadowsEnabled { get { return m_ShadowSettings.supportsLocalShadows; } }
public bool HasDirectionalShadowmap { get { return m_DirectionalShadowmapQuality != LightShadows.None; } }
public bool HasLocalLightsShadowmap { get { return m_LocalShadowmapQuality != LightShadows.None; } }
public bool DirectionalShadowsRendered { get { return m_DirectionalShadowmapQuality != LightShadows.None; } }
public bool LocalShadowsRendered { get { return m_LocalShadowmapQuality != LightShadows.None; } }
public bool IsSoftShadowsEnabled { get { return m_ShadowSettings.supportsSoftShadows; } }
public float RenderingDistance { get { return m_ShadowSettings.maxShadowDistance; } }

cmd.ClearRenderTarget(true, true, Color.white);
cmd.Blit(m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowsMaterial);
LightweightUtils.StartStereoRendering(camera, ref context, frameRenderingConfiguration);
LightweightPipeline.StartStereoRendering(camera, ref context, frameRenderingConfiguration);
LightweightUtils.StopStereoRendering(camera, ref context, frameRenderingConfiguration);
LightweightPipeline.StopStereoRendering(camera, ref context, frameRenderingConfiguration);
CommandBufferPool.Release(cmd);
}

// Until we can have keyword stripping forcing single cascade hard shadows on gles2
bool supportsScreenSpaceShadows = SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2;
bool supportsLocalShadows = Application.isMobilePlatform || Application.platform == RuntimePlatform.WebGLPlayer;
m_ShadowSettings.directionalShadowQuality = (LightShadows)pipelineAsset.ShadowSetting;
m_ShadowSettings.screenSpace = supportsScreenSpaceShadows;
m_ShadowSettings.supportsDirectionalShadows = pipelineAsset.SupportsDirectionalShadows;
m_ShadowSettings.screenSpace = m_ShadowSettings.supportsDirectionalShadows && supportsScreenSpaceShadows;
m_ShadowSettings.directionalShadowAtlasWidth = pipelineAsset.ShadowAtlasResolution;
m_ShadowSettings.directionalShadowAtlasHeight = pipelineAsset.ShadowAtlasResolution;
m_ShadowSettings.directionalShadowAtlasWidth = pipelineAsset.DirectionalShadowAtlasResolution;
m_ShadowSettings.directionalShadowAtlasHeight = pipelineAsset.DirectionalShadowAtlasResolution;
m_ShadowSettings.shadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap)
? RenderTextureFormat.Shadowmap
: RenderTextureFormat.Depth;
m_ShadowSettings.screenspaceShadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8)
? RenderTextureFormat.R8
: RenderTextureFormat.ARGB32;
switch (m_ShadowSettings.directionalLightCascadeCount)
{

break;
}
// Until we can have keyword stripping we disable local light shadows on mobile
m_ShadowSettings.localLightsShadowQuality = (supportsLocalShadows) ? LightShadows.Hard : LightShadows.None;
m_ShadowSettings.supportsLocalShadows = pipelineAsset.SupportsLocalShadows;
m_ShadowSettings.localShadowAtlasWidth = m_ShadowSettings.localShadowAtlasHeight = pipelineAsset.LocalShadowAtlasResolution;
m_ShadowSettings.supportsSoftShadows = pipelineAsset.SupportsSoftShadows;
m_ShadowSettings.bufferBitCount = 16;
m_ShadowSettings.shadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap)
? RenderTextureFormat.Shadowmap
: RenderTextureFormat.Depth;
m_ShadowSettings.screenspaceShadowmapTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8)
? RenderTextureFormat.R8
: RenderTextureFormat.ARGB32;
}
private void Clear()

private void SetShadowCollectPassKeywords(CommandBuffer cmd)
{
CoreUtils.SetKeyword(cmd, "_SHADOWS_SOFT", m_DirectionalShadowmapQuality == LightShadows.Soft);
CoreUtils.SetKeyword(cmd, "_SHADOWS_CASCADE", m_ShadowSettings.directionalLightCascadeCount > 1);
CoreUtils.SetKeyword(cmd, LightweightKeywords.SoftShadowsText, m_DirectionalShadowmapQuality == LightShadows.Soft);
CoreUtils.SetKeyword(cmd, LightweightKeywords.CascadeShadowsText, m_ShadowSettings.directionalLightCascadeCount > 1);
}
private bool RenderDirectionalCascadeShadowmap(ref CullResults cullResults, ref LightData lightData, ref ScriptableRenderContext context)

if (success)
{
m_DirectionalShadowmapQuality = (m_ShadowSettings.directionalShadowQuality != LightShadows.Soft) ? LightShadows.Hard : light.shadows;
m_DirectionalShadowmapQuality = (IsSoftShadowsEnabled) ? light.shadows : LightShadows.Hard;
// In order to avoid shader variants explosion we only do hard shadows when sampling shadowmap in the lit pass.
// GLES2 platform is forced to hard single cascade shadows.

SetupLocalLightsShadowReceiverConstants(cmd, ref context);
m_LocalShadowmapQuality = (LightShadows)Math.Min(shadowSampling, (int)m_ShadowSettings.directionalShadowQuality);
m_LocalShadowmapQuality = (IsSoftShadowsEnabled) ? (LightShadows)shadowSampling : LightShadows.Hard;
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/SceneViewDrawMode.cs


#if UNITY_EDITOR
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

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

15
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl


CBUFFER_END
CBUFFER_START(_LocalShadowBuffer)
float4x4 _LocalWorldToShadowAtlas[4];
half _LocalShadowStrength[4];
float4x4 _LocalWorldToShadowAtlas[MAX_VISIBLE_LIGHTS];
half _LocalShadowStrength[MAX_VISIBLE_LIGHTS];
half4 _LocalShadowOffset0;
half4 _LocalShadowOffset1;
half4 _LocalShadowOffset2;

#else
float fetchesWeights[9];
float2 fetchesUV[9];
SampleShadow_ComputeSamples_Tent_5x5(_ShadowmapSize, shadowCoord.xy, fetchesWeights, fetchesUV);
SampleShadow_ComputeSamples_Tent_5x5(samplingData.shadowmapSize, shadowCoord.xy, fetchesWeights, fetchesUV);
attenuation = fetchesWeights[0] * SAMPLE_TEXTURE2D_SHADOW(ShadowMap, sampler_ShadowMap, float3(fetchesUV[0].xy, shadowCoord.z));
attenuation += fetchesWeights[1] * SAMPLE_TEXTURE2D_SHADOW(ShadowMap, sampler_ShadowMap, float3(fetchesUV[1].xy, shadowCoord.z));

half MainLightRealtimeShadowAttenuation(float4 shadowCoord)
{
#if defined(NO_SHADOWS) || !defined(_SHADOWS_ENABLED)
#if !defined(_SHADOWS_ENABLED)
return 1.0h;
#elif SHADOWS_SCREEN
return SampleScreenSpaceShadowMap(shadowCoord);

half LocalLightRealtimeShadowAttenuation(int lightIndex, float3 positionWS)
{
// TODO: We can't add more keywords to standard shaders. For now we use
// same _SHADOWS_ENABLED keywords for local lights. In the future we can use
// _LOCAL_SHADOWS_ENABLED keyword
// For now disabling local shadows on mobile until we can get the keyword stripping
//#if defined(NO_SHADOWS) || !defined(_LOCAL_SHADOWS_ENABLED)
#if defined(NO_SHADOWS) || !defined(_SHADOWS_ENABLED) || defined(SHADER_API_MOBILE)
#if !defined(_LOCAL_SHADOWS_ENABLED)
return 1.0h;
#else
float4 shadowCoord = mul(_LocalWorldToShadowAtlas[lightIndex], float4(positionWS, 1.0));

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl


}
#endif // LIGHTWEIGHT_PASS_LIT_TERRAIN_INCLUDED

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightBlit.shader


Pass
{
Name "Default"
Tags { "LightMode" = "LightweightForward"}
ZTest Always ZWrite Off

37
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader


Shader "Hidden/LightweightPipeline/CopyDepth"
{
Properties
{
[HideInInspector] _SampleCount("MSAA sample count", Float) = 1.0
}
Tags { "RenderType" = "Opaque" "RenderPipeline" = "LightiweightPipeline"}
Tags { "RenderType" = "Opaque" "RenderPipeline" = "LightweightPipeline"}
Name "Default"
ZTest Always ZWrite On ColorMask 0
HLSLPROGRAM

#pragma vertex vert
#pragma fragment frag
#include "LWRP/ShaderLibrary/Core.hlsl"
#pragma multi_compile __ _MSAA_DEPTH
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
struct VertexInput
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
#include "LWRP/ShaderLibrary/DepthCopy.hlsl"
struct VertexOutput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
VertexOutput vert(VertexInput i)
{
VertexOutput o;
o.uv = i.uv;
o.position = TransformObjectToHClip(i.vertex.xyz);
return o;
}
float frag(VertexOutput i) : SV_Depth
{
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.uv);
}
ENDHLSL
}
}

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightSampling.shader


// 0 - Downsample - Box filtering
Pass
{
Name "Default"
Tags { "LightMode" = "LightweightForward"}
ZTest Always

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader


Pass
{
Name "Default"
ZTest Always
ZWrite Off
Cull Off

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader


{
// Lightmode matches the ShaderPassName set in LightweightPipeline.cs. SRPDefaultUnlit and passes with
// no LightMode tag are also rendered by Lightweight Pipeline
Name "StandardLit"
Tags{"LightMode" = "LightweightForward"}
Blend[_SrcBlend][_DstBlend]

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
// TODO: Enabled this when we have C# keyword stripping
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On

Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On

// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags{"LightMode" = "Meta"}
Cull Off

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader


Pass
{
Name "ParticlesLit"
Tags {"LightMode" = "LightweightForward"}
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library

#pragma shader_feature _EMISSION
#pragma shader_feature _FADING_ON
#pragma shader_feature _REQUIRE_UV2
#define NO_SHADOWS 1
#include "LWRP/ShaderLibrary/ParticlesPBR.hlsl"
#include "LWRP/ShaderLibrary/Lighting.hlsl"

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesSimpleLighting.shader


Pass
{
Name "ParticlesLit"
Tags {"LightMode" = "LightweightForward"}
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library

#pragma shader_feature _REQUIRE_UV2
#define BUMP_SCALE_NOT_SUPPORTED 1
#define NO_SHADOWS 1
#include "LWRP/ShaderLibrary/Particles.hlsl"
#include "LWRP/ShaderLibrary/Lighting.hlsl"

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader


Pass
{
Name "ParticlesUnlit"
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles

half3 diffuse = AlphaModulate(albedo.rgb, albedo.a);
half alpha = AlphaBlendAndTest(albedo.a, _Cutoff);
half3 emission = SampleEmission(IN, _EmissionColor.rgb, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap));
half3 result = diffuse + emission;
half fogFactor = IN.posWS.w;
ApplyFogColor(result, half3(0, 0, 0), fogFactor);

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader


Pass
{
Name "StandardLit"
Tags { "LightMode" = "LightweightForward" }
// Use same blending / depth states as Standard shader

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
// TODO: Enabled this when we have C# keyword stripping
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On

Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On

// This pass it not used during regular rendering, only for lightmap baking.
Pass
{
Name "Meta"
Tags{ "LightMode" = "Meta" }
Cull Off

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader


Pass
{
Name "StandardUnlit"
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrain.shader


Pass
{
Name "TerrainLit"
Tags { "LightMode" = "LightweightForward" }
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

#pragma multi_compile __ _TERRAIN_NORMAL_MAP
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrain.hlsl"
#include "LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl"

Pass
{
Name "ShadowCaster"
Tags{"LightMode" = "ShadowCaster"}
ZWrite On

Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}
ZWrite On

5
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainAddPass.shader


Pass
{
Name "TerrainAddLit"
Tags { "LightMode" = "LightweightForward" }
Blend One One
HLSLPROGRAM

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

#pragma multi_compile __ _TERRAIN_NORMAL_MAP
#define TERRAIN_SPLAT_ADDPASS 1
#include "LWRP/ShaderLibrary/Terrain/InputSurfaceTerrain.hlsl"
#include "LWRP/ShaderLibrary/Terrain/LightweightPassLitTerrain.hlsl"

6
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainBase.shader


// Forward pass. Shades all light in a single pass. GI + emission + Fog
Pass
{
Name "TerrainBaseLit"
// Lightmode matches the ShaderPassName set in LightweightPipeline.cs. SRPDefaultUnlit and passes with
// no LightMode tag are also rendered by Lightweight Pipeline
Tags{"LightMode" = "LightweightForward"}

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
// TODO: Enabled this when we have C# keyword stripping
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrass.shader


// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Hidden/TerrainEngine/Details/WavingDoublePass" // Has to override the internal shaders so named like this
{
Properties
Properties
{
_WavingTint ("Fade Color", Color) = (.7,.6,.5, 0)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}

SubShader
SubShader
{
Tags {"Queue" = "Geometry+200" "RenderType" = "Grass" "IgnoreProjectors" = "True" "RenderPipeline" = "LightweightPipeline" }//"DisableBatching"="True"
Cull Off

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
// TODO: Enabled this when we have C# keyword stripping
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrassBillboard.shader


// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Hidden/TerrainEngine/Details/BillboardWavingDoublePass" // Has to override the internal shaders so named like this
{
Properties
Properties
{
_WavingTint ("Fade Color", Color) = (.7,.6,.5, 0)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}

SubShader
SubShader
{
Tags {"Queue" = "Geometry+200" "RenderType" = "GrassBillBoard" "IgnoreProjectors" = "True" "RenderPipeline" = "LightweightPipeline" }//"DisableBatching"="True"
Cull Off

#pragma multi_compile _ _VERTEX_LIGHTS
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
#pragma multi_compile _ _SHADOWS_ENABLED
// TODO: Enabled this when we have C# keyword stripping
//#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _LOCAL_SHADOWS_ENABLED
#pragma multi_compile _ _SHADOWS_SOFT
// -------------------------------------
// Unity defined keywords

13
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset


--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1

m_EditorClassIdentifier:
kAssetVersion: 2
kAssetVersion: 3
m_RequireOpaqueTexture: 0
m_OpaqueDownsampling: 1
m_ShadowType: 1
m_DirectionalShadowsSupported: 1
m_ShadowNearPlaneOffset: 2
m_LocalShadowsSupported: 1
m_LocalShadowsAtlasResolution: 256
m_SoftShadowsSupported: 1
m_ShadowType: 0

9
CONTRIBUTIONS.md


# Contributions
## If you are interested in contributing, here are some ground rules:
* Talk to us before doing the work -- we love contributions, but we might already be working on the same thing, or we might have different opinions on how it should be implemented.
## All contributions are subject to the [Unity Contribution Agreement(UCA)](https://unity3d.com/legal/licenses/Unity_Contribution_Agreement)
By making a pull request, you are confirming agreement to the terms and conditions of the UCA, including that your Contributions are your original creation and that you have complete right and authority to make your Contributions.
## Once you have a change ready following these ground rules. Simply make a pull request in Github

7
CONTRIBUTIONS.md.meta


fileFormatVersion: 2
guid: d18fefd6a4409be4a92111b29cb078c1
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

160
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs


//#define LOG_VARIANTS
//#define LOG_ONLY_LWRP_VARIANTS
using System.Collections.Generic;
using UnityEditor.Build;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Rendering;
using LightweightRP = UnityEngine.Experimental.Rendering.LightweightPipeline.LightweightPipeline;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
#if UNITY_2018_2_OR_NEWER
public class ShaderPreprocessor : IPreprocessShaders
{
#if LOG_VARIANTS
int m_TotalVariantsInputCount;
int m_TotalVariantsOutputCount;
#endif
// Multiple callback may be implemented.
// The first one executed is the one where callbackOrder is returning the smallest number.
public int callbackOrder { get { return 0; } }
bool StripUnusedShader(PipelineCapabilities capabilities, Shader shader)
{
if (shader.name.Contains("Debug"))
return true;
if (shader.name.Contains("HDRenderPipeline"))
return true;
if (!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows) &&
shader.name.Contains("ScreenSpaceShadows"))
return true;
return false;
}
bool StripUnusedPass(PipelineCapabilities capabilities, ShaderSnippetData snippetData)
{
if (snippetData.passType == PassType.Meta)
return true;
if (snippetData.passType == PassType.ShadowCaster)
if (!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows) && !CoreUtils.HasFlag(capabilities, PipelineCapabilities.LocalShadows))
return true;
return false;
}
bool StripUnusedVariant(PipelineCapabilities capabilities, ShaderCompilerData compilerData)
{
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.AdditionalLights) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.AdditionalLights))
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.VertexLights) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.VertexLights))
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.DirectionalShadows) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows))
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.LocalShadows) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.LocalShadows))
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.SoftShadows) &&
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.SoftShadows))
return true;
return false;
}
bool StripInvalidVariants(ShaderCompilerData compilerData)
{
bool isShadowVariant = compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.DirectionalShadows) ||
compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.LocalShadows);
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.SoftShadows) && !isShadowVariant)
return true;
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.VertexLights) &&
!compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.AdditionalLights))
return true;
// Note: LWRP doesn't support Dynamic Lightmap.
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.DirectionalLightmap) &&
!compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.Lightmap))
return true;
return false;
}
bool StripUnused(PipelineCapabilities capabilities, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData)
{
if (StripUnusedShader(capabilities, shader))
return true;
if (StripUnusedPass(capabilities, snippetData))
return true;
if (StripUnusedVariant(capabilities, compilerData))
return true;
if (StripInvalidVariants(compilerData))
return true;
return false;
}
#if LOG_VARIANTS
void LogVariants(Shader shader, ShaderSnippetData snippetData, int prevVariantsCount, int currVariantsCount)
{
#if LOG_ONLY_LWRP_VARIANTS
if (shader.name.Contains("LightweightPipeline"))
#endif
{
float percentageCurrent = (float)currVariantsCount / (float)prevVariantsCount * 100f;
float percentageTotal = (float)m_TotalVariantsOutputCount / (float)m_TotalVariantsInputCount * 100f;
string result = string.Format("STRIPPING: {0} ({1} pass) ({2}) -" +
" Remaining shader variants = {3}/{4} = {5}% - Total = {6}/{7} = {8}%",
shader.name, snippetData.passName, snippetData.shaderType.ToString(), currVariantsCount,
prevVariantsCount, percentageCurrent, m_TotalVariantsOutputCount, m_TotalVariantsInputCount,
percentageTotal);
Debug.Log(result);
}
}
#endif
public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList<ShaderCompilerData> compilerDataList)
{
PipelineCapabilities capabilities = LightweightRP.GetPipelineCapabilities();
int prevVariantCount = compilerDataList.Count;
for (int i = 0; i < compilerDataList.Count; ++i)
{
if (StripUnused(capabilities, shader, snippetData, compilerDataList[i]))
{
compilerDataList.RemoveAt(i);
--i;
}
}
#if LOG_VARIANTS
m_TotalVariantsInputCount += prevVariantCount;
m_TotalVariantsOutputCount += compilerDataList.Count;
LogVariants(shader, snippetData, prevVariantCount, compilerDataList.Count);
#endif
}
}
#endif // UNITY_2018_2_OR_NEWER
}

11
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs.meta


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

205
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[Flags]
public enum FrameRenderingConfiguration
{
None = (0 << 0),
Stereo = (1 << 0),
Msaa = (1 << 1),
BeforeTransparentPostProcess = (1 << 2),
PostProcess = (1 << 3),
DepthPrePass = (1 << 4),
DepthCopy = (1 << 5),
DefaultViewport = (1 << 6),
IntermediateTexture = (1 << 7)
}
[Flags]
public enum PipelineCapabilities
{
AdditionalLights = (1 << 0),
VertexLights = (1 << 1),
DirectionalShadows = (1 << 2),
LocalShadows = (1 << 3),
SoftShadows = (1 << 4),
}
public class CameraComparer : IComparer<Camera>
{
public int Compare(Camera lhs, Camera rhs)
{
return (int)(lhs.depth - rhs.depth);
}
}
public class LightweightKeywords
{
public static readonly string AdditionalLightsText = "_ADDITIONAL_LIGHTS";
public static readonly string VertexLightsText = "_VERTEX_LIGHTS";
public static readonly string MixedLightingSubtractiveText = "_MIXED_LIGHTING_SUBTRACTIVE";
public static readonly string MainLightCookieText = "_MAIN_LIGHT_COOKIE";
public static readonly string DirectionalShadowsText = "_SHADOWS_ENABLED";
public static readonly string LocalShadowsText = "_LOCAL_SHADOWS_ENABLED";
public static readonly string SoftShadowsText = "_SHADOWS_SOFT";
public static readonly string CascadeShadowsText = "_SHADOWS_CASCADE";
#if UNITY_2018_2_OR_NEWER
public static readonly ShaderKeyword AdditionalLights = new ShaderKeyword(AdditionalLightsText);
public static readonly ShaderKeyword VertexLights = new ShaderKeyword(VertexLightsText);
public static readonly ShaderKeyword MixedLightingSubtractive = new ShaderKeyword(MixedLightingSubtractiveText);
public static readonly ShaderKeyword MainLightCookie = new ShaderKeyword(MainLightCookieText);
public static readonly ShaderKeyword DirectionalShadows = new ShaderKeyword(DirectionalShadowsText);
public static readonly ShaderKeyword LocalShadows = new ShaderKeyword(LocalShadowsText);
public static readonly ShaderKeyword SoftShadows = new ShaderKeyword(SoftShadowsText);
public static readonly ShaderKeyword Lightmap = new ShaderKeyword("LIGHTMAP_ON");
public static readonly ShaderKeyword DirectionalLightmap = new ShaderKeyword("DIRLIGHTMAP_COMBINED");
#endif
}
public partial class LightweightPipeline
{
static Mesh s_FullscreenMesh = null;
public static Mesh fullscreenMesh
{
get
{
if (s_FullscreenMesh != null)
return s_FullscreenMesh;
float topV = 1.0f;
float bottomV = 0.0f;
Mesh mesh = new Mesh { name = "Fullscreen Quad" };
mesh.SetVertices(new List<Vector3>
{
new Vector3(-1.0f, -1.0f, 0.0f),
new Vector3(-1.0f, 1.0f, 0.0f),
new Vector3(1.0f, -1.0f, 0.0f),
new Vector3(1.0f, 1.0f, 0.0f)
});
mesh.SetUVs(0, new List<Vector2>
{
new Vector2(0.0f, bottomV),
new Vector2(0.0f, topV),
new Vector2(1.0f, bottomV),
new Vector2(1.0f, topV)
});
mesh.SetIndices(new[] { 0, 1, 2, 2, 1, 3 }, MeshTopology.Triangles, 0, false);
mesh.UploadMeshData(true);
return mesh;
}
}
static PipelineCapabilities s_PipelineCapabilities;
public static PipelineCapabilities GetPipelineCapabilities()
{
return s_PipelineCapabilities;
}
static void SetPipelineCapabilities(LightweightPipelineAsset pipelineAsset)
{
s_PipelineCapabilities = 0U;
if (pipelineAsset.MaxPixelLights > 1 || pipelineAsset.SupportsVertexLight)
s_PipelineCapabilities |= PipelineCapabilities.AdditionalLights;
if (pipelineAsset.SupportsVertexLight)
s_PipelineCapabilities |= PipelineCapabilities.VertexLights;
if (pipelineAsset.SupportsDirectionalShadows)
s_PipelineCapabilities |= PipelineCapabilities.DirectionalShadows;
if (pipelineAsset.SupportsLocalShadows)
s_PipelineCapabilities |= PipelineCapabilities.LocalShadows;
bool anyShadows = pipelineAsset.SupportsDirectionalShadows || pipelineAsset.SupportsLocalShadows;
if (pipelineAsset.SupportsSoftShadows && anyShadows)
s_PipelineCapabilities |= PipelineCapabilities.SoftShadows;
}
public static void DrawFullScreen(CommandBuffer commandBuffer, Material material,
MaterialPropertyBlock properties = null, int shaderPassId = 0)
{
commandBuffer.DrawMesh(fullscreenMesh, Matrix4x4.identity, material, 0, shaderPassId, properties);
}
public static void StartStereoRendering(Camera camera, ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration)
{
if (CoreUtils.HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo))
context.StartMultiEye(camera);
}
public static void StopStereoRendering(Camera camera, ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration)
{
if (CoreUtils.HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo))
context.StopMultiEye(camera);
}
public static void GetLightCookieMatrix(VisibleLight light, out Matrix4x4 cookieMatrix)
{
cookieMatrix = Matrix4x4.Inverse(light.localToWorld);
if (light.lightType == LightType.Directional)
{
float scale = 1.0f / light.light.cookieSize;
// apply cookie scale and offset by 0.5 to convert from [-0.5, 0.5] to texture space [0, 1]
Vector4 row0 = cookieMatrix.GetRow(0);
Vector4 row1 = cookieMatrix.GetRow(1);
cookieMatrix.SetRow(0, new Vector4(row0.x * scale, row0.y * scale, row0.z * scale, row0.w * scale + 0.5f));
cookieMatrix.SetRow(1, new Vector4(row1.x * scale, row1.y * scale, row1.z * scale, row1.w * scale + 0.5f));
}
else if (light.lightType == LightType.Spot)
{
// we want out.w = 2.0 * in.z / m_CotanHalfSpotAngle
// c = cotHalfSpotAngle
// 1 0 0 0
// 0 1 0 0
// 0 0 1 0
// 0 0 2/c 0
// the "2" will be used to scale .xy for the cookie as in .xy/2 + 0.5
float scale = 1.0f / light.range;
float halfSpotAngleRad = Mathf.Deg2Rad * light.spotAngle * 0.5f;
float cs = Mathf.Cos(halfSpotAngleRad);
float ss = Mathf.Sin(halfSpotAngleRad);
float cotHalfSpotAngle = cs / ss;
Matrix4x4 scaleMatrix = Matrix4x4.identity;
scaleMatrix.m00 = scaleMatrix.m11 = scaleMatrix.m22 = scale;
scaleMatrix.m33 = 0.0f;
scaleMatrix.m32 = scale * (2.0f / cotHalfSpotAngle);
cookieMatrix = scaleMatrix * cookieMatrix;
}
// Remaining light types don't support cookies
}
public static bool IsSupportedShadowType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;
}
public static bool IsSupportedCookieType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;
}
public static bool PlatformSupportsMSAABackBuffer()
{
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SAMSUNGTV
return true;
#else
return false;
#endif
}
}
}

11
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs.meta


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

81
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl


#ifndef LIGHTWEIGHT_DEPTH_COPY_INCLUDED
#define LIGHTWEIGHT_DEPTH_COPY_INCLUDED
#include "LWRP/ShaderLibrary/Core.hlsl"
struct VertexInput
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct VertexOutput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
VertexOutput vert(VertexInput i)
{
VertexOutput o;
UNITY_SETUP_INSTANCE_ID(i);
UNITY_TRANSFER_INSTANCE_ID(i, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv = i.uv;
o.position = TransformObjectToHClip(i.vertex.xyz);
return o;
}
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
#define DEPTH_TEXTURE_MS Texture2DMSArray
#define DEPTH_TEXTURE(name) TEXTURE2D_ARRAY(name)
#define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthTexture, uv, unity_StereoEyeIndex, sampleIndex)
#define SAMPLE(uv) SAMPLE_TEXTURE2D_ARRAY(_CameraDepthTexture, sampler_CameraDepthTexture, uv, unity_StereoEyeIndex).r
#else
#define DEPTH_TEXTURE_MS Texture2DMS
#define DEPTH_TEXTURE(name) TEXTURE2D(name)
#define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthTexture, uv, sampleIndex)
#define SAMPLE(uv) SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, uv)
#endif
#ifdef _MSAA_DEPTH
DEPTH_TEXTURE_MS<float> _CameraDepthTexture;
float _SampleCount;
float4 _CameraDepthTexture_TexelSize;
#else
DEPTH_TEXTURE(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
#endif
float SampleDepth(float2 uv)
{
#ifdef _MSAA_DEPTH
int2 coord = int2(uv * _CameraDepthTexture_TexelSize.zw);
int samples = (int)_SampleCount;
#if UNITY_REVERSED_Z
float outDepth = 1.0;
#define DEPTH_OP min
#else
float outDepth = 0.0;
#define DEPTH_OP max
#endif
for (int i = 0; i < samples; ++i)
outDepth = DEPTH_OP(LOAD(uv, i), outDepth);
return outDepth;
#else
return SAMPLE(uv);
#endif
}
float frag(VertexOutput i) : SV_Depth
{
UNITY_SETUP_INSTANCE_ID(i);
return SampleDepth(i.uv);
}
#endif // LIGHTWEIGHT_DEPTH_COPY_INCLUDED

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl.meta


fileFormatVersion: 2
guid: 971e7c84ed6bc40fc95bdbb2e008013f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs.meta


fileFormatVersion: 2
guid: 1556a6d19597541c8bed4b90c704fb06
timeCreated: 1505115136
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

147
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineUtils.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public class CameraComparer : IComparer<Camera>
{
public int Compare(Camera lhs, Camera rhs)
{
return (int)(lhs.depth - rhs.depth);
}
}
[Flags]
public enum FrameRenderingConfiguration
{
None = 0,
Stereo = (1 << 0),
Msaa = (1 << 1),
BeforeTransparentPostProcess = (1 << 2),
PostProcess = (1 << 3),
DepthPrePass = (1 << 4),
DepthCopy = (1 << 5),
DefaultViewport = (1 << 6),
IntermediateTexture = (1 << 7)
}
public static class LightweightUtils
{
static Mesh s_FullscreenMesh = null;
public static Mesh fullscreenMesh
{
get
{
if (s_FullscreenMesh != null)
return s_FullscreenMesh;
float topV = 1.0f;
float bottomV = 0.0f;
Mesh mesh = new Mesh {name = "Fullscreen Quad"};
mesh.SetVertices(new List<Vector3>
{
new Vector3(-1.0f, -1.0f, 0.0f),
new Vector3(-1.0f, 1.0f, 0.0f),
new Vector3( 1.0f, -1.0f, 0.0f),
new Vector3( 1.0f, 1.0f, 0.0f)
});
mesh.SetUVs(0, new List<Vector2>
{
new Vector2(0.0f, bottomV),
new Vector2(0.0f, topV),
new Vector2(1.0f, bottomV),
new Vector2(1.0f, topV)
});
mesh.SetIndices(new[] { 0, 1, 2, 2, 1, 3 }, MeshTopology.Triangles, 0, false);
mesh.UploadMeshData(true);
return mesh;
}
}
public static void DrawFullScreen(CommandBuffer commandBuffer, Material material,
MaterialPropertyBlock properties = null, int shaderPassId = 0)
{
commandBuffer.DrawMesh(fullscreenMesh, Matrix4x4.identity, material, 0, shaderPassId, properties);
}
public static void StartStereoRendering(Camera camera, ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration)
{
if (HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo))
context.StartMultiEye(camera);
}
public static void StopStereoRendering(Camera camera, ref ScriptableRenderContext context, FrameRenderingConfiguration renderingConfiguration)
{
if (HasFlag(renderingConfiguration, FrameRenderingConfiguration.Stereo))
context.StopMultiEye(camera);
}
public static void GetLightCookieMatrix(VisibleLight light, out Matrix4x4 cookieMatrix)
{
cookieMatrix = Matrix4x4.Inverse(light.localToWorld);
if (light.lightType == LightType.Directional)
{
float scale = 1.0f / light.light.cookieSize;
// apply cookie scale and offset by 0.5 to convert from [-0.5, 0.5] to texture space [0, 1]
Vector4 row0 = cookieMatrix.GetRow(0);
Vector4 row1 = cookieMatrix.GetRow(1);
cookieMatrix.SetRow(0, new Vector4(row0.x * scale, row0.y * scale, row0.z * scale, row0.w * scale + 0.5f));
cookieMatrix.SetRow(1, new Vector4(row1.x * scale, row1.y * scale, row1.z * scale, row1.w * scale + 0.5f));
}
else if (light.lightType == LightType.Spot)
{
// we want out.w = 2.0 * in.z / m_CotanHalfSpotAngle
// c = cotHalfSpotAngle
// 1 0 0 0
// 0 1 0 0
// 0 0 1 0
// 0 0 2/c 0
// the "2" will be used to scale .xy for the cookie as in .xy/2 + 0.5
float scale = 1.0f / light.range;
float halfSpotAngleRad = Mathf.Deg2Rad * light.spotAngle * 0.5f;
float cs = Mathf.Cos(halfSpotAngleRad);
float ss = Mathf.Sin(halfSpotAngleRad);
float cotHalfSpotAngle = cs / ss;
Matrix4x4 scaleMatrix = Matrix4x4.identity;
scaleMatrix.m00 = scaleMatrix.m11 = scaleMatrix.m22 = scale;
scaleMatrix.m33 = 0.0f;
scaleMatrix.m32 = scale * (2.0f / cotHalfSpotAngle);
cookieMatrix = scaleMatrix * cookieMatrix;
}
// Remaining light types don't support cookies
}
public static bool IsSupportedShadowType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;
}
public static bool IsSupportedCookieType(LightType lightType)
{
return lightType == LightType.Directional || lightType == LightType.Spot;
}
public static bool PlatformSupportsMSAABackBuffer()
{
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SAMSUNGTV
return true;
#else
return false;
#endif
}
public static bool HasFlag(FrameRenderingConfiguration mask, FrameRenderingConfiguration flag)
{
return (mask & flag) != 0;
}
}
}
正在加载...
取消
保存