浏览代码

Merge branch 'master' into LayeredLit

# Conflicts:
#	Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
/main
Julien Ignace 8 年前
当前提交
0f63e44e
共有 179 个文件被更改,包括 2763 次插入974 次删除
  1. 101
      Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
  2. 4
      Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs
  3. 37
      Assets/Editor/Tests/RenderloopTests/RenderloopTestFixture.cs
  4. 19
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  5. 25
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  6. 19
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
  7. 125
      Assets/ScriptableRenderLoop/ShaderLibrary/Fibonacci.hlsl
  8. 11
      Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl
  9. 368
      Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
  10. 71
      Assets/ScriptableRenderLoop/core/RenderPipeline.cs
  11. 80
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  12. 2
      Assets/ShaderGenerator/Editor/ShaderGeneratorMenu.cs
  13. 10
      ProjectSettings/GraphicsSettings.asset
  14. 2
      ProjectSettings/ProjectVersion.txt
  15. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting.meta
  16. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material.meta
  17. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl
  18. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl
  19. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/PostProcess/Resources/FinalPass.shader
  20. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader
  21. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader
  22. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl
  23. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/UpgradeStandardShaderMaterials.cs
  24. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderLoopMenuItems.cs
  25. 46
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderLoopInspector.cs
  26. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky.meta
  27. 56
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs
  28. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
  29. 281
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  30. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl
  31. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
  32. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  33. 120
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute
  34. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass.meta
  35. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader
  36. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Lighting.hlsl
  37. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs
  38. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  39. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl
  40. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
  41. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs
  42. 120
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
  43. 56
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
  44. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
  45. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl
  46. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  47. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader
  48. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
  49. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit.meta
  50. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit.meta
  51. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl
  52. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl
  53. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
  54. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl
  55. 95
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  56. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor.meta
  57. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
  58. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  59. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/PreIntegratedFGD.shader
  60. 6
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/StandardToHDLitMaterialUpgrader.cs
  61. 6
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/StandardSpecularToHDLitMaterialUpgrader.cs
  62. 84
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
  63. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline.meta
  64. 9
      Assets/ScriptableRenderLoop/common/CubeToSpherical.shader.meta
  65. 24
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset
  66. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset.meta
  67. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs.meta
  68. 110
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.hlsl
  69. 1001
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
  70. 152
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  71. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl.meta
  72. 151
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl
  73. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl.meta
  74. 14
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl
  75. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl.meta
  76. 160
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/BuildProbabilityTables.compute
  77. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/BuildProbabilityTables.compute.meta
  78. 33
      Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs
  79. 12
      Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs.meta
  80. 40
      Assets/ScriptableRenderLoop/core/RenderingDataStore.cs
  81. 12
      Assets/ScriptableRenderLoop/core/RenderingDataStore.cs.meta
  82. 9
      Assets/ScriptableRenderLoop/HDRenderLoop.meta
  83. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow
  84. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Debug.meta
  85. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting.meta
  86. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material.meta
  87. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/PostProcess.meta
  88. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs
  89. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl.meta
  90. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.meta
  91. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass.meta
  92. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl
  93. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl.meta
  94. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow.meta

101
Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs


// - This loop also does not setup lightmaps, light probes, reflection probes or light cookies
[ExecuteInEditMode]
public class BasicRenderLoop : RenderPipeline
public class BasicRenderLoop : RenderPipelineAsset
[UnityEditor.MenuItem("Renderloop/Create BasicRenderLoop")]
[UnityEditor.MenuItem("RenderPipeline/Create BasicRenderLoop")]
static void CreateBasicRenderLoop()
{
var instance = ScriptableObject.CreateInstance<BasicRenderLoop>();

[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
protected override IRenderPipeline InternalCreatePipeline()
base.Render(renderLoop, dataStore);
cameraProvider.GetCamerasToRender(m_CamerasToRender);
Render(renderLoop, m_CamerasToRender);
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
return new BasicRenderLoopInstance();
}
public class BasicRenderLoopInstance : RenderPipeline
{
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);
BasicRendering.Render(renderContext, cameras);
}
}
public static class BasicRendering
{
public static void Render(ScriptableRenderContext context, IEnumerable<Camera> cameras)
{
foreach (var camera in cameras)

if (!CullResults.GetCullingParameters (camera, out cullingParams))
if (!CullResults.GetCullingParameters(camera, out cullingParams))
CullResults cull = CullResults.Cull (ref cullingParams, context);
CullResults cull = CullResults.Cull(ref cullingParams, context);
context.SetupCameraProperties (camera);
context.SetupCameraProperties(camera);
// clear depth buffer
var cmd = new CommandBuffer();

// Setup global lighting shader variables
SetupLightShaderVariables (cull.visibleLights, context);
SetupLightShaderVariables(cull.visibleLights, context);
var settings = new DrawRendererSettings (cull, camera, new ShaderPassName("BasicPass"));
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("BasicPass"));
settings.inputFilter.SetQueuesOpaque ();
context.DrawRenderers (ref settings);
settings.inputFilter.SetQueuesOpaque();
context.DrawRenderers(ref settings);
context.DrawSkybox (camera);
context.DrawSkybox(camera);
settings.inputFilter.SetQueuesTransparent ();
context.DrawRenderers (ref settings);
settings.inputFilter.SetQueuesTransparent();
context.DrawRenderers(ref settings);
context.Submit ();
context.Submit();
static void SetupLightShaderVariables (VisibleLight[] lights, ScriptableRenderContext context)
private static void SetupLightShaderVariables(VisibleLight[] lights, ScriptableRenderContext context)
{
// We only support up to 8 visible lights here. More complex approaches would
// be doing some sort of per-object light setups, but here we go for simplest possible

// to the viewer, so that "most important" lights in the scene are picked, and not the 8
// that happened to be first.
int lightCount = Mathf.Min (lights.Length, kMaxLights);
int lightCount = Mathf.Min(lights.Length, kMaxLights);
// Prepare light data
Vector4[] lightColors = new Vector4[kMaxLights];

if (light.lightType == LightType.Directional)
{
// light position for directional lights is: (-direction, 0)
var dir = light.localToWorld.GetColumn (2);
lightPositions[i] = new Vector4 (-dir.x, -dir.y, -dir.z, 0);
var dir = light.localToWorld.GetColumn(2);
lightPositions[i] = new Vector4(-dir.x, -dir.y, -dir.z, 0);
var pos = light.localToWorld.GetColumn (3);
lightPositions[i] = new Vector4 (pos.x, pos.y, pos.z, 1);
var pos = light.localToWorld.GetColumn(3);
lightPositions[i] = new Vector4(pos.x, pos.y, pos.z, 1);
}
// attenuation set in a way where distance attenuation can be computed:
// float lengthSq = dot(toLight, toLight);

// spot direction & attenuation
if (light.lightType == LightType.Spot)
{
var dir = light.localToWorld.GetColumn (2);
lightSpotDirections[i] = new Vector4 (-dir.x, -dir.y, -dir.z, 0);
var dir = light.localToWorld.GetColumn(2);
lightSpotDirections[i] = new Vector4(-dir.x, -dir.y, -dir.z, 0);
float cosTheta = Mathf.Cos (radAngle * 0.25f);
float cosPhi = Mathf.Cos (radAngle * 0.5f);
float cosTheta = Mathf.Cos(radAngle * 0.25f);
float cosPhi = Mathf.Cos(radAngle * 0.5f);
lightAtten[i] = new Vector4 (cosPhi, (cosDiff != 0.0f) ? 1.0f / cosDiff : 1.0f, quadAtten, rangeSq);
lightAtten[i] = new Vector4(cosPhi, (cosDiff != 0.0f) ? 1.0f / cosDiff : 1.0f, quadAtten, rangeSq);
lightSpotDirections[i] = new Vector4 (0, 0, 1, 0);
lightAtten[i] = new Vector4 (-1, 1, quadAtten, rangeSq);
lightSpotDirections[i] = new Vector4(0, 0, 1, 0);
lightAtten[i] = new Vector4(-1, 1, quadAtten, rangeSq);
}
}
GetShaderConstantsFromNormalizedSH (ref ambientSH, shConstants);
GetShaderConstantsFromNormalizedSH(ref ambientSH, shConstants);
cmd.SetGlobalVectorArray ("globalLightColor", lightColors);
cmd.SetGlobalVectorArray ("globalLightPos", lightPositions);
cmd.SetGlobalVectorArray ("globalLightSpotDir", lightSpotDirections);
cmd.SetGlobalVectorArray ("globalLightAtten", lightAtten);
cmd.SetGlobalVector ("globalLightCount", new Vector4 (lightCount, 0, 0, 0));
cmd.SetGlobalVectorArray ("globalSH", shConstants);
context.ExecuteCommandBuffer (cmd);
cmd.Dispose ();
cmd.SetGlobalVectorArray("globalLightColor", lightColors);
cmd.SetGlobalVectorArray("globalLightPos", lightPositions);
cmd.SetGlobalVectorArray("globalLightSpotDir", lightSpotDirections);
cmd.SetGlobalVectorArray("globalLightAtten", lightAtten);
cmd.SetGlobalVector("globalLightCount", new Vector4(lightCount, 0, 0, 0));
cmd.SetGlobalVectorArray("globalSH", shConstants);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
static void GetShaderConstantsFromNormalizedSH (ref SphericalHarmonicsL2 ambientProbe, Vector4[] outCoefficients)
private static void GetShaderConstantsFromNormalizedSH(ref SphericalHarmonicsL2 ambientProbe, Vector4[] outCoefficients)
{
for (int channelIdx = 0; channelIdx < 3; ++channelIdx)
{

outCoefficients[6].z = ambientProbe[2, 8];
outCoefficients[6].w = 1.0f;
}
}

4
Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs


[TestFixture]
public class CullResultsTest
{
void InspectCullResults(Camera camera, CullResults cullResults, ScriptableRenderContext renderLoop)
void InspectCullResults(Camera camera, CullResults cullResults, ScriptableRenderContext renderContext)
{
VisibleReflectionProbe[] probes = cullResults.visibleReflectionProbes;

public void TestReflectionProbes()
{
UnityEditor.SceneManagement.EditorSceneManager.OpenScene("Assets/Editor/Tests/TestScene.unity");
RenderLoopTestFixture.Run(InspectCullResults);
RenderLoopTestFixtureInstance.Run(InspectCullResults);
}
}

37
Assets/Editor/Tests/RenderloopTests/RenderloopTestFixture.cs


using UnityEngine.ScriptableRenderPipeline;
[ExecuteInEditMode]
public class RenderLoopTestFixture : RenderPipeline
public class RenderLoopTestFixture : RenderPipelineAsset
{
protected override IRenderPipeline InternalCreatePipeline()
{
return new BasicRenderLoopInstance();
}
}
public class RenderLoopTestFixtureInstance : RenderPipeline
public delegate void TestDelegate(Camera camera, CullResults cullResults, ScriptableRenderContext renderLoop);
public delegate void TestDelegate(Camera camera, CullResults cullResults, ScriptableRenderContext renderContext);
[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
cameraProvider.GetCamerasToRender(m_CamerasToRender);
base.Render(renderContext, cameras);
foreach (var camera in m_CamerasToRender)
foreach (var camera in cameras)
CullResults cullResults = CullResults.Cull(ref cullingParams, renderLoop);
CullResults cullResults = CullResults.Cull(ref cullingParams, renderContext);
s_Callback(camera, cullResults, renderLoop);
s_Callback(camera, cullResults, renderContext);
renderLoop.Submit();
renderContext.Submit();
}
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
}
public static void Run(TestDelegate renderCallback)
{
if (m_Instance == null)

19
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl


// Texture abstraction
#define TEXTURE2D(textureName) Texture2D textureName;
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName;
#define TEXTURECUBE(textureName) TextureCube textureName;
#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName;
#define TEXTURE3D(textureName) Texture3D textureName;
#define TEXTURE2D(textureName) Texture2D textureName
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName
#define TEXTURECUBE(textureName) TextureCube textureName
#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName
#define TEXTURE3D(textureName) Texture3D textureName
#define SAMPLER2D(samplerName) SamplerState samplerName;
#define SAMPLERCUBE(samplerName) SamplerState samplerName;
#define SAMPLER3D(samplerName) SamplerState samplerName;
#define SAMPLER2D(samplerName) SamplerState samplerName
#define SAMPLERCUBE(samplerName) SamplerState samplerName
#define SAMPLER3D(samplerName) SamplerState samplerName
#define SAMPLER2D_SHADOW(samplerName) SamplerComparisonState samplerName
#define SAMPLERCUBE_SHADOW(samplerName) SamplerComparisonState samplerName

#define SAMPLER2D_FLOAT SAMPLER2D
#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_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 GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2)
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index))

25
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


#define Clamp clamp
#endif // INTRINSIC_CLAMP
#ifndef INTRINSIC_MUL24
int Mul24(int a, int b)
{
return a * b;
}
uint Mul24(uint a, uint b)
{
return a * b;
}
#endif // INTRINSIC_MUL24
#ifndef INTRINSIC_MAD24
int Mad24(int a, int b, int c)
{
return a * b + c;
}
uint Mad24(uint a, uint b, uint c)
{
return a * b + c;
}
#endif // INTRINSIC_MAD24
#ifndef INTRINSIC_MED3
float Med3(float a, float b, float c)
{

#define INV_HALF_PI 0.636619772367
#define FLT_EPSILON 1.192092896e-07 // Smallest positive number, such that 1.0 + FLT_EPSILON != 1.0
#define FLT_MIN 1.175494351e-38 // Minimum representable positive floating-point number
#define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number
#define MERGE_NAME(X, Y) X##Y

19
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


// Get local frame
//-----------------------------------------------------------------------------
// generate an orthonormalBasis from 3d unit vector.
void GetLocalFrame(float3 N, out float3 tangentX, out float3 tangentY)
// Generates an orthonormal basis from two orthogonal unit vectors.
float3x3 GetLocalFrame(float3 localZ, float3 localX)
{
float3 localY = cross(localZ, localX);
return float3x3(localX, localY, localZ);
}
// Generates an orthonormal basis from a unit vector.
float3x3 GetLocalFrame(float3 localZ)
float3 upVector = abs(N.z) < 0.999 ? float3(0.0, 0.0, 1.0) : float3(1.0, 0.0, 0.0);
tangentX = normalize(cross(upVector, N));
tangentY = cross(N, tangentX);
float3 upVector = abs(localZ.z) < 0.999 ? float3(0.0, 0.0, 1.0) : float3(1.0, 0.0, 0.0);
float3 localX = normalize(cross(upVector, localZ));
return GetLocalFrame(localZ, localX);
}
// TODO: test

125
Assets/ScriptableRenderLoop/ShaderLibrary/Fibonacci.hlsl


}
static const int k_FibonacciSeq[] = {
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610
};
static const float2 k_Fibonacci2dSeq21[] = {

float2(0.98181820, 0.38181686)
};
// Loads elements from one of the precomputed tables for sequence lengths of 9, 10, 11.
// Computes the values at runtime otherwise.
// For sampling, the size of the point set is given by { k_FibonacciSeq[sequenceLength - 1] }.
float2 Fibonacci2d(uint i, uint sequenceLength)
static const float2 k_Fibonacci2dSeq89[] = {
float2(0.00000000, 0.00000000),
float2(0.01123596, 0.61797750),
float2(0.02247191, 0.23595500),
float2(0.03370786, 0.85393250),
float2(0.04494382, 0.47191000),
float2(0.05617978, 0.08988762),
float2(0.06741573, 0.70786500),
float2(0.07865169, 0.32584238),
float2(0.08988764, 0.94382000),
float2(0.10112359, 0.56179762),
float2(0.11235955, 0.17977524),
float2(0.12359551, 0.79775238),
float2(0.13483146, 0.41573000),
float2(0.14606741, 0.03370762),
float2(0.15730338, 0.65168476),
float2(0.16853933, 0.26966286),
float2(0.17977528, 0.88764000),
float2(0.19101124, 0.50561714),
float2(0.20224719, 0.12359524),
float2(0.21348314, 0.74157238),
float2(0.22471911, 0.35955048),
float2(0.23595506, 0.97752762),
float2(0.24719101, 0.59550476),
float2(0.25842696, 0.21348286),
float2(0.26966292, 0.83146000),
float2(0.28089887, 0.44943714),
float2(0.29213482, 0.06741524),
float2(0.30337077, 0.68539238),
float2(0.31460676, 0.30336952),
float2(0.32584271, 0.92134666),
float2(0.33707866, 0.53932571),
float2(0.34831461, 0.15730286),
float2(0.35955057, 0.77528000),
float2(0.37078652, 0.39325714),
float2(0.38202247, 0.01123428),
float2(0.39325842, 0.62921333),
float2(0.40449437, 0.24719048),
float2(0.41573033, 0.86516762),
float2(0.42696628, 0.48314476),
float2(0.43820226, 0.10112190),
float2(0.44943821, 0.71910095),
float2(0.46067417, 0.33707809),
float2(0.47191012, 0.95505524),
float2(0.48314607, 0.57303238),
float2(0.49438202, 0.19100952),
float2(0.50561798, 0.80898666),
float2(0.51685393, 0.42696571),
float2(0.52808988, 0.04494286),
float2(0.53932583, 0.66292000),
float2(0.55056179, 0.28089714),
float2(0.56179774, 0.89887428),
float2(0.57303369, 0.51685333),
float2(0.58426964, 0.13483047),
float2(0.59550560, 0.75280762),
float2(0.60674155, 0.37078476),
float2(0.61797750, 0.98876190),
float2(0.62921351, 0.60673904),
float2(0.64044946, 0.22471619),
float2(0.65168542, 0.84269333),
float2(0.66292137, 0.46067429),
float2(0.67415732, 0.07865143),
float2(0.68539327, 0.69662857),
float2(0.69662923, 0.31460571),
float2(0.70786518, 0.93258286),
float2(0.71910113, 0.55056000),
float2(0.73033708, 0.16853714),
float2(0.74157304, 0.78651428),
float2(0.75280899, 0.40449142),
float2(0.76404494, 0.02246857),
float2(0.77528089, 0.64044571),
float2(0.78651685, 0.25842667),
float2(0.79775280, 0.87640381),
float2(0.80898875, 0.49438095),
float2(0.82022470, 0.11235809),
float2(0.83146065, 0.73033524),
float2(0.84269661, 0.34831238),
float2(0.85393256, 0.96628952),
float2(0.86516851, 0.58426666),
float2(0.87640452, 0.20224380),
float2(0.88764048, 0.82022095),
float2(0.89887643, 0.43820190),
float2(0.91011238, 0.05617905),
float2(0.92134833, 0.67415619),
float2(0.93258429, 0.29213333),
float2(0.94382024, 0.91011047),
float2(0.95505619, 0.52808762),
float2(0.96629214, 0.14606476),
float2(0.97752810, 0.76404190),
float2(0.98876405, 0.38201904)
};
// Loads elements from one of the precomputed tables for sample counts of 21, 34, 55.
// Computes sample positions at runtime otherwise.
// Sample count must be a Fibonacci number (see 'k_FibonacciSeq').
float2 Fibonacci2d(uint i, uint sampleCount)
int fibN1 = k_FibonacciSeq[sequenceLength - 1];
int fibN2 = k_FibonacciSeq[sequenceLength - 2];
switch (fibN1)
switch (sampleCount)
default: Fibonacci2dSeq(fibN1, fibN2, i);
case 89: return k_Fibonacci2dSeq89[i];
default:
{
int fibN1 = sampleCount;
int fibN2 = sampleCount;
// These are all constants, so this loop will be optimized away.
for (int j = 1; j < 16; j++)
{
if (k_FibonacciSeq[j] == fibN1)
{
fibN2 = k_FibonacciSeq[j - 1];
}
}
return Fibonacci2dSeq(fibN1, fibN2, i);
}
}
}

11
Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl


float2(0.99609375, 0.99609375)
};
// Loads elements from one of the precomputed tables for sequence lengths of 16, 32, 64, 256.
// Computes the values at runtime otherwise.
// For sampling, the size of the point set is the same as the sequence length.
float2 Hammersley2d(uint i, uint sequenceLength)
// Loads elements from one of the precomputed tables for sample counts of 16, 32, 64, 256.
// Computes sample positions at runtime otherwise.
float2 Hammersley2d(uint i, uint sampleCount)
switch (sequenceLength)
switch (sampleCount)
default: return Hammersley2dSeq(i, sequenceLength);
default: return Hammersley2dSeq(i, sampleCount);
}
}

368
Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl


#include "BSDF.hlsl"
#include "Sampling.hlsl"
// TODO: We need to change this hard limit!
#ifndef UNITY_SPECCUBE_LOD_STEPS
#define UNITY_SPECCUBE_LOD_STEPS 6
#endif
// TODO: We need to change this hard limit!
#define UNITY_SPECCUBE_LOD_STEPS (6)
float perceptualRoughnessToMipmapLevel(float perceptualRoughness)
{

float mipmapLevelToPerceptualRoughness(float mipmapLevel)
{
return mipmapLevel / UNITY_SPECCUBE_LOD_STEPS;
return saturate(mipmapLevel / UNITY_SPECCUBE_LOD_STEPS);
}
//-----------------------------------------------------------------------------
// Coordinate system conversion
//-----------------------------------------------------------------------------
// Transforms the unit vector from the spherical to the Cartesian (right-handed, Z up) coordinate.
float3 SphericalToCartesian(float phi, float sinTheta, float cosTheta)
{
float sinPhi, cosPhi;
sincos(phi, sinPhi, cosPhi);
return float3(sinTheta * cosPhi, sinTheta * sinPhi, cosTheta);
}
// Converts Cartesian coordinates given in the right-handed coordinate system
// with Z pointing upwards (OpenGL style) to the coordinates in the left-handed
// coordinate system with Y pointing up and Z facing forward (DirectX style).
float3 TransformGLtoDX(float x, float y, float z)
{
return float3(x, z, y);
}
float3 TransformGLtoDX(float3 v)
{
return v.xzy;
}
// Performs conversion from equiareal map coordinates to Cartesian (DirectX cubemap) ones.
float3 ConvertEquiarealToCubemap(float u, float v)
{
// The equiareal mapping is defined as follows:
// phi = TWO_PI * (1.0 - u)
// cos(theta) = 1.0 - 2.0 * v
// sin(theta) = sqrt(1.0 - cos^2(theta)) = 2.0 * sqrt(v - v * v)
float phi = TWO_PI - TWO_PI * u;
float cosTheta = 1.0 - 2.0 * v;
float sinTheta = 2.0 * sqrt(v - v * v);
return TransformGLtoDX(SphericalToCartesian(phi, sinTheta, cosTheta));
}
// Ref: See "Moving Frostbite to PBR" Listing 22

// Importance sampling BSDF functions
// ----------------------------------------------------------------------------
void ImportanceSampleCosDir(float2 u,
float3 N,
float3 tangentX,
float3 tangentY,
out float3 L)
void ImportanceSampleCosDir(float2 u,
float3x3 localToWorld,
out float3 L)
float phi = TWO_PI * u.y;
float phi = TWO_PI * u.y;
// Transform from spherical into cartesian
L = float3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);
// Local to world
L = tangentX * L.x + tangentY * L.y + N * L.z;
L = SphericalToCartesian(phi, sinTheta, cosTheta);
L = mul(L, localToWorld);
void ImportanceSampleGGXDir(float2 u,
float3 V,
float3 N,
float3 tangentX,
float3 tangentY,
float roughness,
out float3 H,
out float3 L)
void ImportanceSampleGGXDir(float2 u,
float3 V,
float3x3 localToWorld,
float roughness,
out float3 L,
out float NdotH,
out float VdotH,
bool VeqN = false)
float cosThetaH = sqrt((1.0 - u.x) / (1.0 + (roughness * roughness - 1.0) * u.x));
float sinThetaH = sqrt(saturate(1.0 - cosThetaH * cosThetaH));
float phiH = TWO_PI * u.y;
// Transform from spherical into cartesian
H = float3(sinThetaH * cos(phiH), sinThetaH * sin(phiH), cosThetaH);
// Local to world
H = tangentX * H.x + tangentY * H.y + N * H.z;
// Convert sample from half angle to incident angle
L = 2.0 * dot(V, H) * H - V;
}
float cosTheta = sqrt((1.0 - u.x) / (1.0 + (roughness * roughness - 1.0) * u.x));
float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
float phi = TWO_PI * u.y;
float3 localH = SphericalToCartesian(phi, sinTheta, cosTheta);
// Special case of ImportanceSampleGGXDir() where N == V.
// Approximates GGX with a BRDF which is isotropic for all viewing angles.
void ImportanceSampleGGXViewIndDir(float2 u,
float3 N,
float3 tangentX,
float3 tangentY,
float roughness,
out float3 L,
out float NdotH)
{
// GGX NDF sampling
float cosThetaH = sqrt((1.0 - u.x) / (1.0 + (roughness * roughness - 1.0) * u.x));
float sinThetaH = sqrt(saturate(1.0 - cosThetaH * cosThetaH));
float phiH = TWO_PI * u.y;
NdotH = cosTheta;
// Transform from spherical into Cartesian.
float3 localH = float3(sinThetaH * cos(phiH), sinThetaH * sin(phiH), cosThetaH);
float3 localV;
// localN == localV == float3(0.0, 0.0, 1.0).
NdotH = localH.z;
if (VeqN)
{
// localV == localN
localV = float3(0.0, 0.0, 1.0);
VdotH = NdotH;
}
else
{
localV = mul(V, transpose(localToWorld));
VdotH = saturate(dot(localV, localH));
}
// Compute { L = reflect(-localV, localH) }.
float VdotH = NdotH;
L = float3(0.0, 0.0, -1.0) + 2.0 * VdotH * localH;
// Compute { L = reflect(-localV, localH) }
L = -localV + 2.0 * VdotH * localH;
// Local to world
L = tangentX * L.x + tangentY * L.y + N * L.z;
L = mul(L, localToWorld);
}
// ref: http://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf p26

// H = tangentX * H.x + tangentY * H.y + N * H.z;
// Convert sample from half angle to incident angle
L = 2.0 * dot(V, H) * H - V;
L = 2.0 * saturate(dot(V, H)) * H - V;
void ImportanceSampleLambert(
float2 u,
float3 N,
float3 tangentX,
float3 tangentY,
out float3 L,
out float NdotL,
out float weightOverPdf)
void ImportanceSampleLambert(float2 u,
float3x3 localToWorld,
out float3 L,
out float NdotL,
out float weightOverPdf)
ImportanceSampleCosDir(u, N, tangentX, tangentY, L);
ImportanceSampleCosDir(u, localToWorld, L);
NdotL = saturate(dot(N, L));
NdotL = saturate(dot(localToWorld[2], L));
// Importance sampling weight for each sample
// pdf = N.L / PI

}
// weightOverPdf return the weight (without the Fresnel term) over pdf. Fresnel term must be apply by the caller.
void ImportanceSampleGGX(
float2 u,
float3 V,
float3 N,
float3 tangentX,
float3 tangentY,
float roughness,
float NdotV,
out float3 L,
out float VdotH,
out float NdotL,
out float weightOverPdf)
void ImportanceSampleGGX(float2 u,
float3 V,
float3x3 localToWorld,
float roughness,
float NdotV,
out float3 L,
out float VdotH,
out float NdotL,
out float weightOverPdf)
ImportanceSampleGGXDir(u, V, N, tangentX, tangentY, roughness, H, L);
float NdotH;
ImportanceSampleGGXDir(u, V, localToWorld, roughness, L, NdotH, VdotH);
float NdotH = saturate(dot(N, H));
// Note: since L and V are symmetric around H, LdotH == VdotH
VdotH = saturate(dot(V, H));
NdotL = saturate(dot(N, L));
NdotL = saturate(dot(localToWorld[2], L));
// Importance sampling weight for each sample
// pdf = D(H) * (N.H) / (4 * (L.H))

// Add some jittering on Hammersley2d
float2 randNum = InitRandom(V.xy * 0.5 + 0.5);
float3 tangentX, tangentY;
GetLocalFrame(N, tangentX, tangentY);
float3x3 localToWorld = GetLocalFrame(N);
float2 u = Hammersley2d(i, sampleCount);
u = frac(u + randNum + 0.5);
float2 u = frac(randNum + Hammersley2d(i, sampleCount));
float VdotH;
float NdotL;

ImportanceSampleGGX(u, V, N, tangentX, tangentY, roughness, NdotV,
ImportanceSampleGGX(u, V, localToWorld, roughness, NdotV,
L, VdotH, NdotL, weightOverPdf);
if (NdotL > 0.0)

}
// for Disney we still use a Cosine importance sampling, true Disney importance sampling imply a look up table
ImportanceSampleLambert(u, N, tangentX, tangentY, L, NdotL, weightOverPdf);
ImportanceSampleLambert(u, localToWorld, L, NdotL, weightOverPdf);
if (NdotL > 0.0)
{

float3 V,
float3 N,
float roughness,
float mipmapcount,
float maxMipLevel,
uint sampleCount, // Matches the size of the precomputed Fibonacci point set
bool prefilter = true) // static bool
uint sampleCount, // Must be a Fibonacci number
bool prefilter)
float3 acc = float3(0.0, 0.0, 0.0);
float accWeight = 0;
float2 randNum = InitRandom(V.xy * 0.5 + 0.5);
float3x3 localToWorld = GetLocalFrame(N);
float3 tangentX, tangentY;
GetLocalFrame(N, tangentX, tangentY);
float3 lightInt = float3(0.0, 0.0, 0.0);
float cbsdfInt = 0.0;
float2 u = k_Fibonacci2dSeq55[i];
u = frac(u + randNum);
float2 u = Fibonacci2d(i, sampleCount);
// Bias samples towards the mirror direction to reduce variance.
// This will have a side effect of making the reflection sharper.
// Ref: Stochastic Screen-Space Reflections, p. 67.
const float bias = 0.2;
u.x = lerp(u.x, 0.0, bias);
float NdotH;
ImportanceSampleGGXViewIndDir(u, N, tangentX, tangentY, roughness, L, NdotH);
float NdotH, VdotH;
ImportanceSampleGGXDir(u, V, localToWorld, roughness, L, NdotH, VdotH, true);
float NdotL = saturate(dot(N, L));

{
mipLevel = 0.0;
mipLevel = 0;
}
else // Prefiltered BRDF importance sampling
{

// - OmegaP : Solid angle associated to a pixel of the cubemap
float invPdf = D_GGX_Inverse(NdotH, roughness) * 4.0;
float omegaS = rcp(sampleCount) * invPdf; // Solid angle associated with the sample
// TODO: check the accuracy of the sample's solid angle fit for GGX.
float omegaS = rcp(sampleCount) * invPdf;
// float omegaP = FOUR_PI / (6.0f * cubemapWidth * cubemapWidth); // Solid angle associated with the pixel of the cubemap
mipLevel = 0.5 * log2(omegaS * invOmegaP) + 1.0; // Clamp is not necessary as the hardware will do it
// float omegaP = FOUR_PI / (6.0f * cubemapWidth * cubemapWidth);
mipLevel = 0.5 * log2(omegaS * invOmegaP);
// Bias the MIP map level to compensate for the importance sampling bias.
// This will blur the reflection.
// TODO: find a more accurate MIP bias function.
mipLevel = lerp(mipLevel, maxMipLevel, bias);
if (NdotL > 0.0f)
if (NdotL > 0.0)
// TODO: use a Gaussian-like filter to generate the MIP pyramid.
// See p63 equation (53) of moving Frostbite to PBR v2 for the extra NdotL here (both in weight and value)
acc += val * NdotL;
accWeight += NdotL;
// *********************************************************************************
// Our goal is to use Monte-Carlo integration with importance sampling to evaluate
// X(V) = Integral{Radiance(L) * CBSDF(L, N, V) dL} / Integral{CBSDF(L, N, V) dL}.
// CBSDF = F * D * G * NdotL / (4 * NdotL * NdotV) = F * D * G / (4 * NdotV).
// PDF = D * NdotH / (4 * LdotH).
// Weight = CBSDF / PDF = F * G * LdotH / (NdotV * NdotH).
// Since we perform filtering with the assumption that (V == N),
// (LdotH == NdotH) && (NdotV == 1) && (Weight == F * G).
// We use the approximation of Brian Karis from "Real Shading in Unreal Engine 4":
// Weight ≈ NdotL, which produces nearly identical results in practice.
// *********************************************************************************
lightInt += NdotL * val;
cbsdfInt += NdotL;
return float4(acc * (1.0 / accWeight), 1.0);
return float4(lightInt / cbsdfInt, 1.0);
}
// Searches the row 'j' containing 'n' elements of 'haystack' and
// returns the index of the first element greater or equal to 'needle'.
uint BinarySearchRow(uint j, float needle, TEXTURE2D(haystack), uint n)
{
uint i = n - 1;
float v = LOAD_TEXTURE2D(haystack, uint2(i, j)).r;
if (needle < v)
{
i = 0;
for (uint b = 1 << firstbithigh(n - 1); b != 0; b >>= 1)
{
uint p = i | b;
v = LOAD_TEXTURE2D(haystack, uint2(p, j)).r;
if (v <= needle) { i = p; } // Move to the right.
}
}
return i;
}
float4 IntegrateLD_MIS(TEXTURECUBE_ARGS(envMap, sampler_envMap),
TEXTURE2D(marginalRowDensities),
TEXTURE2D(conditionalDensities),
float3 V,
float3 N,
float roughness,
float invOmegaP,
uint width,
uint height,
uint sampleCount,
bool prefilter)
{
float3x3 localToWorld = GetLocalFrame(N);
float2 randNum = InitRandom(V.xy * 0.5 + 0.5);
float3 lightInt = float3(0.0, 0.0, 0.0);
float cbsdfInt = 0.0;
/*
// Dedicate 50% of samples to light sampling at 1.0 roughness.
// Only perform BSDF sampling when roughness is below 0.5.
const int lightSampleCount = lerp(0, sampleCount / 2, saturate(2.0 * roughness - 1.0));
const int bsdfSampleCount = sampleCount - lightSampleCount;
*/
// The value of the integral of intensity values of the environment map (as a 2D step function).
float envMapInt2dStep = LOAD_TEXTURE2D(marginalRowDensities, uint2(height, 0)).r;
// Since we are using equiareal mapping, we need to divide by the area of the sphere.
float envMapIntSphere = envMapInt2dStep * INV_FOUR_PI;
// Perform light importance sampling.
for (uint i = 0; i < sampleCount; i++)
{
float2 s = frac(randNum + Hammersley2d(i, sampleCount));
// Sample a row from the marginal distribution.
uint y = BinarySearchRow(0, s.x, marginalRowDensities, height - 1);
// Sample a column from the conditional distribution.
uint x = BinarySearchRow(y, s.y, conditionalDensities, width - 1);
// Compute the coordinates of the sample.
// Note: we take the sample in between two texels, and also apply the half-texel offset.
// We could compute fractional coordinates at the cost of 4 extra texel samples.
float u = saturate((float)x / width + 1.0 / width);
float v = saturate((float)y / height + 1.0 / height);
float3 L = ConvertEquiarealToCubemap(u, v);
float NdotL = saturate(dot(N, L));
if (NdotL > 0.0)
{
float3 val = SAMPLE_TEXTURECUBE_LOD(envMap, sampler_envMap, L, 0).rgb;
float pdf = (val.r + val.g + val.b) / envMapIntSphere;
if (pdf > 0.0)
{
// (N == V) && (acos(VdotL) == 2 * acos(NdotH)).
float NdotH = sqrt(NdotL * 0.5 + 0.5);
// *********************************************************************************
// Our goal is to use Monte-Carlo integration with importance sampling to evaluate
// X(V) = Integral{Radiance(L) * CBSDF(L, N, V) dL} / Integral{CBSDF(L, N, V) dL}.
// CBSDF = F * D * G * NdotL / (4 * NdotL * NdotV) = F * D * G / (4 * NdotV).
// Weight = CBSDF / PDF.
// We use two approximations of Brian Karis from "Real Shading in Unreal Engine 4":
// (F * G ≈ NdotL) && (NdotV == 1).
// Weight = D * NdotL / (4 * PDF).
// *********************************************************************************
float weight = D_GGX(NdotH, roughness) * NdotL / (4.0 * pdf);
lightInt += weight * val;
cbsdfInt += weight;
}
}
}
// Prevent NaNs arising from the division of 0 by 0.
cbsdfInt = max(cbsdfInt, FLT_MIN);
return float4(lightInt / cbsdfInt, 1.0);
}
#endif // UNITY_IMAGE_BASED_LIGHTING_INCLUDED

71
Assets/ScriptableRenderLoop/core/RenderPipeline.cs


namespace UnityEngine.ScriptableRenderPipeline
{
public abstract class RenderPipeline : BaseRenderPipeline
{
private readonly HashSet<IScriptableRenderDataStore> m_AssociatedDataStores = new HashSet<IScriptableRenderDataStore>();
private ICameraProvider m_CameraProvider;
public override ICameraProvider cameraProvider
{
get
{
if (m_CameraProvider == null)
m_CameraProvider = ConstructCameraProvider();
return m_CameraProvider;
}
set { m_CameraProvider = value; }
}
public override void Render(ScriptableRenderContext renderContext, IScriptableRenderDataStore dataStore)
{
if (dataStore == null)
throw new ArgumentException(string.Format("Null DataStore has been passed into pipe {0}", this));
if (dataStore.owner == null)
throw new ArgumentException(string.Format("DataStore owner is null. It needs o be owned by loop {0}", this));
if (dataStore.owner != null && !ReferenceEquals(dataStore.owner, this))
throw new ArgumentException(string.Format("DataStore {0} has been passed into pipe {1}, but is owned by {2}", dataStore, this, dataStore.owner));
m_AssociatedDataStores.Add(dataStore);
dataStore.Build();
}
public override void ClearCachedData()
{
foreach (var store in m_AssociatedDataStores)
store.Cleanup();
m_AssociatedDataStores.Clear();
}
public override ICameraProvider ConstructCameraProvider()
{
return new DefaultCameraProvider();
}
public override IScriptableRenderDataStore ConstructDataStore()
{
return new RenderingDataStore(this);
}
public static void CleanCameras(IEnumerable<Camera> cameras)
{
foreach (var camera in cameras)
camera.ClearIntermediateRenderers();
}
}
public abstract class RenderPipeline : IRenderPipeline
{
public virtual void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
if (disposed)
throw new ObjectDisposedException(string.Format("{0} has been disposed. Do not call Render on disposed RenderLoops.", this));
}
public bool disposed { get; private set; }
public virtual void Dispose()
{
disposed = true;
}
}
}

80
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


namespace UnityEngine.Experimental.ScriptableRenderLoop
{
public class FptlLightingInstance : RenderPipeline
{
private readonly FptlLighting m_Owner;
public FptlLightingInstance(FptlLighting owner)
{
m_Owner = owner;
if (m_Owner != null)
m_Owner.Build();
}
public override void Dispose()
{
base.Dispose();
if (m_Owner != null)
m_Owner.Cleanup();
}
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);
m_Owner.Render(renderContext, cameras);
}
}
public class FptlLighting : RenderPipeline
public class FptlLighting : RenderPipelineAsset
[UnityEditor.MenuItem("Renderloop/CreateRenderLoopFPTL")]
[UnityEditor.MenuItem("RenderPipeline/CreateRenderLoopFPTL")]
static void CreateRenderLoopFPTL()
{
var instance = ScriptableObject.CreateInstance<FptlLighting>();

#endif
private class FptlLightingDataStore : RenderingDataStore
protected override IRenderPipeline InternalCreatePipeline()
public FptlLightingDataStore(BaseRenderPipeline owner) : base(owner)
{}
protected override void InternalBuild()
{
base.InternalBuild();
FptlLighting theOwner = owner as FptlLighting;
if (theOwner != null)
theOwner.Build();
}
protected override void InternalCleanup()
{
base.InternalCleanup();
FptlLighting theOwner = owner as FptlLighting;
if (theOwner != null)
theOwner.Cleanup();
}
return new FptlLightingInstance(this);
}
[SerializeField]

m_shadowBufferID = Shader.PropertyToID("g_tShadowBuffer");
}
public override IScriptableRenderDataStore ConstructDataStore()
{
return new FptlLightingDataStore(this);
}
static void SetupGBuffer(int width, int height, CommandBuffer cmd)
{
var format10 = RenderTextureFormat.ARGB32;

return numLightsOut + numProbesOut;
}
[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
public void Render(ScriptableRenderContext renderContext, IEnumerable<Camera> cameras)
base.Render(renderLoop, dataStore);
cameraProvider.GetCamerasToRender(m_CamerasToRender);
foreach (var camera in m_CamerasToRender)
foreach (var camera in cameras)
{
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, out cullingParams))

var cullResults = CullResults.Cull(ref cullingParams, renderLoop);
ExecuteRenderLoop(camera, cullResults, renderLoop);
var cullResults = CullResults.Cull(ref cullingParams, renderContext);
ExecuteRenderLoop(camera, cullResults, renderContext);
renderLoop.Submit();
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
renderContext.Submit();
}
void FinalPass(ScriptableRenderContext loop)

2
Assets/ShaderGenerator/Editor/ShaderGeneratorMenu.cs


{
public class ShaderGeneratorMenu
{
[UnityEditor.MenuItem("Renderloop/Generate Shader Includes")]
[UnityEditor.MenuItem("RenderPipeline/Generate Shader Includes")]
static void GenerateShaderIncludes()
{
CSharpToHLSL.GenerateAll();

10
ProjectSettings/GraphicsSettings.asset


--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 10
serializedVersion: 11
m_Deferred:
m_Mode: 0
m_Shader: {fileID: 0}

m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
m_CustomRenderPipeline: {fileID: 11400000, guid: 2400b74f5ce370c4481e5dc417d03703,
m_CustomRenderPipeline: {fileID: 11400000, guid: e185fecca3c73cd47a09f1092663ef32,
type: 2}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}

m_FogStripping: 0
m_LightmapKeepPlain: 1
m_LightmapKeepDirCombined: 1
m_LightmapKeepDirSeparate: 1
m_LightmapKeepDynamicDirSeparate: 1
m_LightmapKeepShadowMask: 1
m_LightmapKeepSubtractive: 1
m_LightsUseLinearIntensity: 1
m_LightsUseCCT: 1

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 5.6.0b1
m_EditorVersion: 5.6.0b3

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting.meta


fileFormatVersion: 2
guid: 7dc18395c5211d44bbe417b8b8b2e81a
guid: 1c14e71d397fce047b1675fc26d0bb48
folderAsset: yes
timeCreated: 1474297943
licenseType: Pro

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material.meta


fileFormatVersion: 2
guid: 752ba4c5a264906428ff58cb5973e10a
guid: 96af336cb096f854ea18990a1c0a4e19
folderAsset: yes
timeCreated: 1474297943
licenseType: Pro

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl


// TODO: Change code here so probe volume use only one transform instead of all this parameters!
TEXTURE3D(unity_ProbeVolumeSH);
SAMPLER3D(samplerunity_ProbeVolumeSH)
SAMPLER3D(samplerunity_ProbeVolumeSH);
CBUFFER_START(UnityProbeVolume)
// x = Disabled(0)/Enabled(1)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs. Please don't edit by hand.
//
#ifndef SHADERCONFIG_CS_HLSL

4
Assets/ScriptableRenderLoop/HDRenderPipeline/PostProcess/Resources/FinalPass.shader


// Final compositing pass, just does gamma correction for now.
Shader "Hidden/HDRenderLoop/FinalPass"
Shader "Hidden/HDRenderPipeline/FinalPass"
{
Properties
{

#include "Common.hlsl"
#include "Color.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
TEXTURE2D(_MainTex);
SAMPLER2D(sampler_MainTex);

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader


Shader "Hidden/HDRenderLoop/DebugViewTiles"
Shader "Hidden/HDRenderPipeline/DebugViewTiles"
{
SubShader
{

// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Lighting.hlsl" // This include Material.hlsl
//-------------------------------------------------------------------------------------
// variable declaration

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader


Shader "Hidden/HDRenderLoop/DebugViewMaterialGBuffer"
Shader "Hidden/HDRenderPipeline/DebugViewMaterialGBuffer"
{
SubShader
{

// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_LIT
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Material.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl"
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs. Please don't edit by hand.
//
#ifndef DEBUGVIEWMATERIAL_CS_HLSL

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/UpgradeStandardShaderMaterials.cs


using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

return upgraders;
}
[MenuItem("HDRenderLoop/Upgrade Materials - Project")]
[MenuItem("HDRenderPipeline/Upgrade Materials - Project")]
[MenuItem("HDRenderLoop/Upgrade Materials - Selection")]
[MenuItem("HDRenderPipeline/Upgrade Materials - Selection")]
[MenuItem("HDRenderLoop/Modify Light Intensity for Upgrade - Scene Only")]
[MenuItem("HDRenderPipeline/Modify Light Intensity for Upgrade - Scene Only")]
static void UpgradeLights()
{
Light[] lights = Light.GetLights(LightType.Directional, 0);

}
}
}
}
}

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderLoopMenuItems.cs


namespace UnityEditor.Experimental.ScriptableRenderLoop
{
public class HDRenderLoopMenuItems
public class HDRenderPipelineMenuItems
[UnityEditor.MenuItem("HDRenderLoop/Create Scene Settings")]
[UnityEditor.MenuItem("HDRenderPipeline/Create Scene Settings")]
static void CreateSceneSettings()
{
CommonSettings[] settings = Object.FindObjectsOfType(typeof(CommonSettings)) as CommonSettings[];

46
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderLoopInspector.cs


namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[CustomEditor(typeof(HDRenderLoop))]
public class HDRenderLoopInspector : Editor
[CustomEditor(typeof(HDRenderPipeline))]
public class HDRenderPipelineInspector : Editor
{
private class Styles
{

}
}
private void DebugParametersUI(HDRenderLoop renderLoop)
private void DebugParametersUI(HDRenderPipeline renderContext)
var debugParameters = renderLoop.debugParameters;
var debugParameters = renderContext.debugParameters;
EditorGUILayout.LabelField(styles.debugParameters);
EditorGUI.indentLevel++;

if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint
EditorUtility.SetDirty(renderContext); // Repaint
private void ShadowParametersUI(HDRenderLoop renderLoop)
private void ShadowParametersUI(HDRenderPipeline renderContext)
var shadowParameters = renderLoop.shadowSettings;
var shadowParameters = renderContext.shadowSettings;
EditorGUILayout.LabelField(styles.shadowSettings);
EditorGUI.indentLevel++;

if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint
EditorUtility.SetDirty(renderContext); // Repaint
private void TextureParametersUI(HDRenderLoop renderLoop)
private void TextureParametersUI(HDRenderPipeline renderContext)
var textureParameters = renderLoop.textureSettings;
var textureParameters = renderContext.textureSettings;
EditorGUILayout.LabelField(styles.textureSettings);
EditorGUI.indentLevel++;

if (EditorGUI.EndChangeCheck())
{
renderLoop.textureSettings = textureParameters;
EditorUtility.SetDirty(renderLoop); // Repaint
renderContext.textureSettings = textureParameters;
EditorUtility.SetDirty(renderContext); // Repaint
private void TilePassUI(HDRenderLoop renderLoop)
private void TilePassUI(HDRenderPipeline renderContext)
TilePass.LightLoop tilePass = renderLoop.lightLoop as TilePass.LightLoop;
TilePass.LightLoop tilePass = renderContext.lightLoop as TilePass.LightLoop;
if (tilePass != null)
{
EditorGUILayout.LabelField(styles.tileLightLoopSettings);

if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint
EditorUtility.SetDirty(renderContext); // Repaint
renderLoop.ClearCachedData();
renderContext.DestroyCreatedInstances();
}
EditorGUI.BeginChangeCheck();

if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint
EditorUtility.SetDirty(renderContext); // Repaint
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
EditorGUI.indentLevel--;

public override void OnInspectorGUI()
{
var renderLoop = target as HDRenderLoop;
var renderContext = target as HDRenderPipeline;
if (!renderLoop)
if (!renderContext)
DebugParametersUI(renderLoop);
ShadowParametersUI(renderLoop);
TextureParametersUI(renderLoop);
TilePassUI(renderLoop);
DebugParametersUI(renderContext);
ShadowParametersUI(renderContext);
TextureParametersUI(renderContext);
TilePassUI(renderContext);
}
}
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky.meta


fileFormatVersion: 2
guid: d7469c05ebee66f4886264af0ab8bf2a
guid: 066ab4d03bd03384f81c9d82b479f8dd
folderAsset: yes
timeCreated: 1479239906
licenseType: Pro

56
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;

// Render Target Management.
public const ClearFlag kClearAll = ClearFlag.ClearDepth | ClearFlag.ClearColor;
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.ClearNone, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.ClearNone, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
SetRenderTarget(renderLoop, colorBuffer, depthBuffer, ClearFlag.ClearNone, new Color(0.0f, 0.0f, 0.0f, 0.0f), miplevel, cubemapFace);
SetRenderTarget(renderContext, colorBuffer, depthBuffer, ClearFlag.ClearNone, new Color(0.0f, 0.0f, 0.0f, 0.0f), miplevel, cubemapFace);
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
SetRenderTarget(renderLoop, colorBuffer, depthBuffer, clearFlag, new Color(0.0f, 0.0f, 0.0f, 0.0f), miplevel, cubemapFace);
SetRenderTarget(renderContext, colorBuffer, depthBuffer, clearFlag, new Color(0.0f, 0.0f, 0.0f, 0.0f), miplevel, cubemapFace);
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
{
var cmd = new CommandBuffer();
cmd.name = "";

renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer)
SetRenderTarget(renderLoop, colorBuffers, depthBuffer, ClearFlag.ClearNone, Color.black);
SetRenderTarget(renderContext, colorBuffers, depthBuffer, ClearFlag.ClearNone, Color.black);
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag = ClearFlag.ClearNone)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag = ClearFlag.ClearNone)
SetRenderTarget(renderLoop, colorBuffers, depthBuffer, clearFlag, Color.black);
SetRenderTarget(renderContext, colorBuffers, depthBuffer, clearFlag, Color.black);
public static void SetRenderTarget(ScriptableRenderContext renderLoop, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
{
var cmd = new CommandBuffer();
cmd.name = "";

renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

: IDisposable
{
bool disposed = false;
ScriptableRenderContext renderLoop;
ScriptableRenderContext renderContext;
renderLoop = _renderloop;
renderContext = _renderloop;
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

CommandBuffer cmd = new CommandBuffer();
cmd.name = "";
cmd.EndSample(name);
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

return gpuVP;
}
public static HDRenderLoop.HDCamera GetHDCamera(Camera camera)
public static HDRenderPipeline.HDCamera GetHDCamera(Camera camera)
HDRenderLoop.HDCamera hdCamera = new HDRenderLoop.HDCamera();
HDRenderPipeline.HDCamera hdCamera = new HDRenderPipeline.HDCamera();
hdCamera.camera = camera;
hdCamera.screenSize = new Vector4(camera.pixelWidth, camera.pixelHeight, 1.0f / camera.pixelWidth, 1.0f / camera.pixelHeight);

return hdCamera;
}
public static void SetupMaterialHDCamera(HDRenderLoop.HDCamera hdCamera, Material material)
public static void SetupMaterialHDCamera(HDRenderPipeline.HDCamera hdCamera, Material material)
{
material.SetVector("_ScreenSize", hdCamera.screenSize);
material.SetMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);

m.DisableKeyword(keyword);
}
public static HDRenderLoop GetHDRenderLoop()
public static HDRenderPipeline GetHDRenderPipeline()
HDRenderLoop renderLoop = UnityEngine.Rendering.GraphicsSettings.renderPipeline as HDRenderLoop;
if (renderLoop == null)
HDRenderPipeline renderContext = UnityEngine.Rendering.GraphicsSettings.renderPipeline as HDRenderPipeline;
if (renderContext == null)
Debug.LogWarning("SkyParameters component can only be used with HDRenderLoop custom RenderPipeline.");
Debug.LogWarning("SkyParameters component can only be used with HDRenderPipeline custom RenderPipeline.");
return renderLoop;
return renderContext;
}
}
}

26
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs


void OnEnable()
{
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop();
if (renderLoop == null)
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
if (renderLoop.commonSettings == null)
renderLoop.commonSettings = this;
else if (renderLoop.commonSettings != this)
if (renderPipeline.commonSettings == null)
renderPipeline.commonSettings = this;
else if (renderPipeline.commonSettings != this)
Debug.LogWarning("Only one CommonSettings can be setup at a time.");
OnSkyRendererChanged();

{
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop();
if (renderLoop == null)
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
if (renderLoop.commonSettings == this)
renderLoop.commonSettings = null;
if (renderPipeline.commonSettings == this)
renderPipeline.commonSettings = null;
}
void OnValidate()

void OnSkyRendererChanged()
{
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop();
if (renderLoop == null)
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
renderLoop.InstantiateSkyRenderer(skyRendererType);
renderPipeline.InstantiateSkyRenderer(skyRendererType);
Type skyParamType = renderLoop.skyManager.GetSkyParameterType();
Type skyParamType = renderPipeline.skyManager.GetSkyParameterType();
// Disable all incompatible sky parameters and enable the compatible one
bool found = false;

281
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


namespace UnityEngine.Experimental.ScriptableRenderLoop
{
public class HDRenderPipelineInstance : RenderPipeline
{
private readonly HDRenderPipeline m_Owner;
public HDRenderPipelineInstance(HDRenderPipeline owner)
{
m_Owner = owner;
if (m_Owner != null)
m_Owner.Build();
}
public override void Dispose()
{
base.Dispose();
if (m_Owner != null)
m_Owner.Cleanup();
}
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);
m_Owner.Render(renderContext, cameras);
}
}
// This HDRenderLoop assume linear lighting. Don't work with gamma.
public partial class HDRenderLoop : RenderPipeline
// This HDRenderPipeline assume linear lighting. Don't work with gamma.
public class HDRenderPipeline : RenderPipelineAsset
const string k_HDRenderLoopPath = "Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset";
const string k_HDRenderPipelinePath = "Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset";
[UnityEditor.MenuItem("Renderloop/CreateHDRenderLoop")]
static void CreateHDRenderLoop()
[UnityEditor.MenuItem("RenderPipeline/CreateHDRenderPipeline")]
static void CreateHDRenderPipeline()
var instance = ScriptableObject.CreateInstance<HDRenderLoop>();
UnityEditor.AssetDatabase.CreateAsset(instance, k_HDRenderLoopPath);
var instance = ScriptableObject.CreateInstance<HDRenderPipeline>();
UnityEditor.AssetDatabase.CreateAsset(instance, k_HDRenderPipelinePath);
[UnityEditor.MenuItem("HDRenderLoop/Add \"Additional Light Data\" (if not present)")]
[UnityEditor.MenuItem("HDRenderPipeline/Add \"Additional Light Data\" (if not present)")]
static void AddAdditionalLightData()
{
Light[] lights = FindObjectsOfType(typeof(Light)) as Light[];

}
}
#endif
private class HDLoopDataStore : RenderingDataStore
{
public HDLoopDataStore(BaseRenderPipeline owner) : base(owner)
{ }
protected override void InternalBuild()
{
base.InternalBuild();
HDRenderLoop theOwner = owner as HDRenderLoop;
if (theOwner != null)
theOwner.Build();
}
protected override void InternalCleanup()
{
base.InternalCleanup();
HDRenderLoop theOwner = owner as HDRenderLoop;
if (theOwner != null)
theOwner.Cleanup();
}
}
public override IScriptableRenderDataStore ConstructDataStore()
protected override IRenderPipeline InternalCreatePipeline()
return new HDLoopDataStore(this);
return new HDRenderPipelineInstance(this);
SkyManager m_SkyManager = new SkyManager();
public SkyManager skyManager
{

m_SkyManager.Build();
m_FinalPassMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/FinalPass");
m_DebugViewMaterialGBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/DebugViewMaterialGBuffer");
m_FinalPassMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/FinalPass");
m_DebugViewMaterialGBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugViewMaterialGBuffer");
m_ShadowPass = new ShadowRenderPass(m_ShadowSettings);

UnityEngine.Rendering.GraphicsSettings.lightsUseCCT = previousLightsUseCCT;
}
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderLoop)
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderLoop))
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderContext))
using (new Utilities.ProfilingSample("InitGBuffers and clear Depth/Stencil", renderLoop))
using (new Utilities.ProfilingSample("InitGBuffers and clear Depth/Stencil", renderContext))
{
var cmd = new CommandBuffer();
cmd.name = "";

// Also we manage ourself the HDR format, here allocating fp16 directly.
// With scriptable render loop we can allocate temporary RT in a command buffer, they will not be release with ExecuteCommandBuffer
// These temporary surface are release automatically at the end of the scriptable renderloop if not release explicitly
// These temporary surface are release automatically at the end of the scriptable render pipeline if not release explicitly
int w = camera.pixelWidth;
int h = camera.pixelHeight;

{
m_gbufferManager.InitGBuffers(w, h, cmd);
}
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearDepth);
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearDepth);
using (new Utilities.ProfilingSample("Clear HDR target", renderLoop))
using (new Utilities.ProfilingSample("Clear HDR target", renderContext))
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
using (new Utilities.ProfilingSample("Clear GBuffer", renderLoop))
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
}
// END TEMP

void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderLoop, string passName, RendererConfiguration rendererConfiguration = 0)
void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!debugParameters.displayOpaqueObjects)
return;

sorting = { flags = SortFlags.CommonOpaque }
};
settings.inputFilter.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
renderContext.DrawRenderers(ref settings);
void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderLoop, string passName, RendererConfiguration rendererConfiguration = 0)
void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!debugParameters.displayTransparentObjects)
return;

sorting = { flags = SortFlags.CommonTransparent }
};
settings.inputFilter.SetQueuesTransparent();
renderLoop.DrawRenderers(ref settings);
renderContext.DrawRenderers(ref settings);
void RenderDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderLoop)
void RenderDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext)
{
// If we are forward only we will do a depth prepass
// TODO: Depth prepass should be enabled based on light loop settings. LightLoop define if they need a depth prepass + forward only...

using (new Utilities.ProfilingSample("Depth Prepass", renderLoop))
using (new Utilities.ProfilingSample("Depth Prepass", renderContext))
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cull, camera, renderLoop, "DepthOnly");
Utilities.SetRenderTarget(renderContext, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cull, camera, renderContext, "DepthOnly");
void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext renderLoop)
void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext renderContext)
{
if (debugParameters.useForwardRenderingOnly)
{

using (new Utilities.ProfilingSample("GBuffer Pass", renderLoop))
using (new Utilities.ProfilingSample("GBuffer Pass", renderContext))
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT);
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT);
RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer", Utilities.kRendererConfigurationBakedLighting);
RenderOpaqueRenderList(cull, camera, renderContext, "GBuffer", Utilities.kRendererConfigurationBakedLighting);
void RenderForwardOnlyDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderLoop)
void RenderForwardOnlyDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext)
{
// If we are forward only we don't need to render ForwardOpaqueDepth object
// But in case we request a prepass we render it

using (new Utilities.ProfilingSample("Forward opaque depth", renderLoop))
using (new Utilities.ProfilingSample("Forward opaque depth", renderContext))
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cull, camera, renderLoop, "ForwardOnlyDepthOnly");
Utilities.SetRenderTarget(renderContext, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cull, camera, renderContext, "ForwardOnlyDepthOnly");
void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderLoop)
void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("DebugView Material Mode Pass", renderLoop))
using (new Utilities.ProfilingSample("DebugView Material Mode Pass", renderContext))
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, Utilities.kClearAll, Color.black);
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT, Utilities.kClearAll, Color.black);
RenderOpaqueRenderList(cull, hdCamera.camera, renderLoop, "DebugViewMaterial");
RenderOpaqueRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial");
}
// Render GBuffer opaque

// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "GBuffer Debug Pass" };
cmd.Blit(null, m_CameraColorBufferRT, m_DebugViewMaterialGBuffer, 0);
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
RenderTransparentRenderList(cull, hdCamera.camera, renderLoop, "DebugViewMaterial");
RenderTransparentRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial");
}
// Last blit

renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderLoop)
void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext)
{
if (debugParameters.useForwardRenderingOnly)
{

// Bind material data
m_LitRenderLoop.Bind();
m_lightLoop.RenderDeferredLighting(hdCamera, renderLoop, m_CameraColorBuffer);
m_lightLoop.RenderDeferredLighting(hdCamera, renderContext, m_CameraColorBuffer);
void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderLoop)
void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext)
m_SkyManager.UpdateEnvironment(hdCamera, m_lightLoop.GetCurrentSunLight(), renderLoop);
m_SkyManager.UpdateEnvironment(hdCamera, m_lightLoop.GetCurrentSunLight(), renderContext);
void RenderSky(HDCamera hdCamera, ScriptableRenderContext renderLoop)
void RenderSky(HDCamera hdCamera, ScriptableRenderContext renderContext)
m_SkyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderLoop);
m_SkyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderContext);
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop, bool renderOpaque)
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque)
{
// TODO: Currently we can't render opaque object forward when deferred is enabled
// miss option

using (new Utilities.ProfilingSample("Forward Pass", renderLoop))
using (new Utilities.ProfilingSample("Forward Pass", renderContext))
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT);
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT);
m_lightLoop.RenderForward(camera, renderLoop, renderOpaque);
m_lightLoop.RenderForward(camera, renderContext, renderOpaque);
RenderOpaqueRenderList(cullResults, camera, renderLoop, "Forward");
RenderOpaqueRenderList(cullResults, camera, renderContext, "Forward");
RenderTransparentRenderList(cullResults, camera, renderLoop, "Forward", Utilities.kRendererConfigurationBakedLighting);
RenderTransparentRenderList(cullResults, camera, renderContext, "Forward", Utilities.kRendererConfigurationBakedLighting);
}
}
}

void RenderForwardOnly(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
void RenderForwardOnly(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Forward Only Pass", renderLoop))
using (new Utilities.ProfilingSample("Forward Only Pass", renderContext))
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT);
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT);
m_lightLoop.RenderForward(camera, renderLoop, true);
RenderOpaqueRenderList(cullResults, camera, renderLoop, "ForwardOnly");
m_lightLoop.RenderForward(camera, renderContext, true);
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnly");
void RenderForwardUnlit(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
void RenderForwardUnlit(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Forward Unlit Pass", renderLoop))
using (new Utilities.ProfilingSample("Forward Unlit Pass", renderContext))
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
RenderTransparentRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardUnlit");
RenderTransparentRenderList(cullResults, camera, renderContext, "ForwardUnlit");
void RenderVelocity(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
void RenderVelocity(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Velocity Pass", renderLoop))
using (new Utilities.ProfilingSample("Velocity Pass", renderContext))
{
// If opaque velocity have been render during GBuffer no need to render it here
if ((ShaderConfig.s_VelocityInGbuffer == 0) || debugParameters.useForwardRenderingOnly)

var cmd = new CommandBuffer { name = "" };
cmd.GetTemporaryRT(m_VelocityBuffer, w, h, 0, FilterMode.Point, Builtin.RenderLoop.GetVelocityBufferFormat(), Builtin.RenderLoop.GetVelocityBufferReadWrite());
cmd.SetRenderTarget(m_VelocityBufferRT, m_CameraDepthBufferRT);
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
RenderOpaqueRenderList(cullResults, camera, renderLoop, "MotionVectors");
RenderOpaqueRenderList(cullResults, camera, renderContext, "MotionVectors");
void RenderDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderLoop)
void RenderDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Distortion Pass", renderLoop))
using (new Utilities.ProfilingSample("Distortion Pass", renderContext))
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;

cmd.SetRenderTarget(m_DistortionBufferRT, m_CameraDepthBufferRT);
cmd.ClearRenderTarget(false, true, Color.black); // TODO: can we avoid this clear for performance ?
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
RenderTransparentRenderList(cullResults, camera, renderLoop, "DistortionVectors");
RenderTransparentRenderList(cullResults, camera, renderContext, "DistortionVectors");
void FinalPass(ScriptableRenderContext renderLoop)
void FinalPass(ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Final Pass", renderLoop))
using (new Utilities.ProfilingSample("Final Pass", renderContext))
{
// Those could be tweakable for the neutral tonemapper, but in the case of the LookDev we don't need that
const float blackIn = 0.02f;

// Resolve our HDR texture to CameraTarget.
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget, m_FinalPassMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}

}
}
public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderLoop)
public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext)
{
if (m_SkyManager.IsSkyValid())
{

cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);
cmd.SetGlobalMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix);
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
m_lightLoop.PushGlobalParams(hdCamera.camera, renderLoop);
m_lightLoop.PushGlobalParams(hdCamera.camera, renderContext);
}
void UpdateCommonSettings()

m_ShadowSettings.maxShadowDistance = m_CommonSettings.shadowMaxDistance;
}
}
[NonSerialized]
readonly List<Camera> m_CamerasToRender = new List<Camera>();
public override void Render(ScriptableRenderContext renderLoop, IScriptableRenderDataStore dataStore)
public void Render(ScriptableRenderContext renderContext, IEnumerable<Camera> cameras)
base.Render(renderLoop, dataStore);
cameraProvider.GetCamerasToRender(m_CamerasToRender);
m_LitRenderLoop.RenderInit(renderLoop);
m_LitRenderLoop.RenderInit(renderContext);
}
// Do anything we need to do upon a new frame.

// Set Frame constant buffer
// TODO...
foreach (var camera in m_CamerasToRender)
foreach (var camera in cameras)
{
// Set camera constant buffer
// TODO...

m_ShadowPass.UpdateCullingParameters(ref cullingParams);
var cullResults = CullResults.Cull(ref cullingParams, renderLoop);
var cullResults = CullResults.Cull(ref cullingParams, renderContext);
renderLoop.SetupCameraProperties(camera);
renderContext.SetupCameraProperties(camera);
InitAndClearBuffer(camera, renderLoop);
InitAndClearBuffer(camera, renderContext);
RenderDepthPrepass(cullResults, camera, renderLoop);
RenderDepthPrepass(cullResults, camera, renderContext);
RenderForwardOnlyDepthPrepass(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderForwardOnlyDepthPrepass(cullResults, camera, renderContext);
RenderGBuffer(cullResults, camera, renderContext);
RenderDebugViewMaterial(cullResults, hdCamera, renderLoop);
RenderDebugViewMaterial(cullResults, hdCamera, renderContext);
using (new Utilities.ProfilingSample("Shadow Pass", renderLoop))
using (new Utilities.ProfilingSample("Shadow Pass", renderContext))
m_ShadowPass.Render(renderLoop, cullResults, out shadows);
m_ShadowPass.Render(renderContext, cullResults, out shadows);
renderLoop.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
using (new Utilities.ProfilingSample("Build Light list", renderLoop))
using (new Utilities.ProfilingSample("Build Light list", renderContext))
m_lightLoop.BuildGPULightLists(camera, renderLoop, m_CameraDepthBufferRT);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT);
PushGlobalParams(hdCamera, renderLoop);
PushGlobalParams(hdCamera, renderContext);
UpdateSkyEnvironment(hdCamera, renderLoop);
UpdateSkyEnvironment(hdCamera, renderContext);
RenderDeferredLighting(hdCamera, renderLoop);
RenderDeferredLighting(hdCamera, renderContext);
RenderForward(cullResults, camera, renderLoop, true);
RenderForwardOnly(cullResults, camera, renderLoop);
RenderForward(cullResults, camera, renderContext, true);
RenderForwardOnly(cullResults, camera, renderContext);
RenderSky(hdCamera, renderLoop);
RenderSky(hdCamera, renderContext);
RenderForward(cullResults, camera, renderLoop, false);
RenderForward(cullResults, camera, renderContext, false);
RenderForwardUnlit(cullResults, camera, renderLoop);
RenderForwardUnlit(cullResults, camera, renderContext);
RenderVelocity(cullResults, camera, renderLoop); // Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
RenderVelocity(cullResults, camera, renderContext); // Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
RenderDistortion(cullResults, camera, renderLoop);
RenderDistortion(cullResults, camera, renderContext);
FinalPass(renderLoop);
FinalPass(renderContext);
}
// bind depth surface for editor grid/gizmo/selection rendering

cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, m_CameraDepthBufferRT);
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
renderLoop.Submit();
renderContext.Submit();
CleanCameras(m_CamerasToRender);
m_CamerasToRender.Clear();
// Post effects
}
}

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl


//TEXTURE2D(_ShadowAtlas);
//SAMPLER2D_SHADOW(sampler_ShadowAtlas);
//SAMPLER2D(sampler_ManualShadowAtlas); // TODO: settings sampler individually is not supported in shader yet...
TEXTURE2D(g_tShadowBuffer) // TODO: No choice, the name is hardcoded in ShadowrenderPass.cs for now. Need to change this!
TEXTURE2D(g_tShadowBuffer); // TODO: No choice, the name is hardcoded in ShadowrenderPass.cs for now. Need to change this!
SAMPLER2D_SHADOW(samplerg_tShadowBuffer);
// Use texture array for IES

// EnvIndex can also be use to fetch in another array of struct (to atlas information etc...).
float4 SampleEnv(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod)
{
lod = min(lod, UNITY_SPECCUBE_LOD_STEPS);
// This code will be inlined as lightLoopContext is hardcoded in the light loop
if (lightLoopContext.sampleReflection == SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES)
{

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs. Please don't edit by hand.
//
#ifndef TILEPASS_CS_HLSL

22
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs


s_LightList = null;
m_DeferredDirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredDirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredIndirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredIndirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredAllMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredAllMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DebugViewTilesMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/DebugViewTiles");
m_DebugViewTilesMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugViewTiles");
m_SingleDeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_SingleDeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_SingleDeferredMaterial.EnableKeyword("LIGHTLOOP_SINGLE_PASS");
m_DefaultTexture2DArray = new Texture2DArray(1, 1, 1, TextureFormat.ARGB32, false);

}
#endif
public override void RenderDeferredLighting(HDRenderLoop.HDCamera hdCamera, ScriptableRenderContext renderLoop, RenderTargetIdentifier cameraColorBufferRT)
public override void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier cameraColorBufferRT)
{
var bUseClusteredForDeferred = !usingFptl;

}
#endif
using (new Utilities.ProfilingSample(disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass", renderLoop))
using (new Utilities.ProfilingSample(disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass", renderContext))
{
var cmd = new CommandBuffer();

// Pass global parameters to compute shader
// TODO: get rid of this by making global parameters visible to compute shaders
BindGlobalParams(cmd, shadeOpaqueShader, kernel, camera, renderLoop);
BindGlobalParams(cmd, shadeOpaqueShader, kernel, camera, renderContext);
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_CameraDepthTexture", Shader.PropertyToID("_CameraDepthTexture"));
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_GBufferTexture0", Shader.PropertyToID("_GBufferTexture0"));

SetGlobalPropertyRedirect(null, 0, null);
//}
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
public override void RenderForward(Camera camera, ScriptableRenderContext renderLoop, bool renderOpaque)
public override void RenderForward(Camera camera, ScriptableRenderContext renderContext, bool renderOpaque)
{
// Note: if we use render opaque with deferred tiling we need to render a opque depth pass for these opaque objects
bool useFptl = renderOpaque && usingFptl;

cmd.SetGlobalBuffer("g_vLightListGlobal", useFptl ? s_LightList : s_PerVoxelLightLists);
}
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}

120
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute


#pragma kernel ShadeOpaque_Fptl SHADE_OPAQUE_ENTRY=ShadeOpaque_Fptl USE_FPTL_LIGHTLIST=1
#pragma kernel ShadeOpaque_Clustered SHADE_OPAQUE_ENTRY=ShadeOpaque_Clustered USE_CLUSTERED_LIGHTLIST=1
#define LIGHTLOOP_TILE_PASS 1
#define LIGHTLOOP_TILE_DIRECT 1
#define LIGHTLOOP_TILE_INDIRECT 1
#define LIGHTLOOP_TILE_ALL 1
#define USE_FPTL_LIGHTLIST 1
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
#include "Common.hlsl"
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl" // This include Material.hlsl
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
RWTexture2D<float4> uavOutput;
[numthreads(TILE_SIZE, TILE_SIZE, 1)]
void SHADE_OPAQUE_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID)
{
// input.positionCS is SV_Position
uint2 pixelCoord = dispatchThreadId;
PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw);
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, posInput.unPositionSS).x;
UpdatePositionInput(depth, _InvViewProjMatrix, _ViewProjMatrix, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(posInput.positionWS);
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
BSDFData bsdfData;
float3 bakeDiffuseLighting;
DECODE_FROM_GBUFFER(gbuffer, bsdfData, bakeDiffuseLighting);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, bakeDiffuseLighting, diffuseLighting, specularLighting);
uavOutput[pixelCoord] = float4(diffuseLighting + specularLighting, 1.0);
}
#pragma kernel ShadeOpaque_Fptl SHADE_OPAQUE_ENTRY=ShadeOpaque_Fptl USE_FPTL_LIGHTLIST=1
#pragma kernel ShadeOpaque_Clustered SHADE_OPAQUE_ENTRY=ShadeOpaque_Clustered USE_CLUSTERED_LIGHTLIST=1
#define LIGHTLOOP_TILE_PASS 1
#define LIGHTLOOP_TILE_DIRECT 1
#define LIGHTLOOP_TILE_INDIRECT 1
#define LIGHTLOOP_TILE_ALL 1
#define USE_FPTL_LIGHTLIST 1
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
#include "Common.hlsl"
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Lighting.hlsl" // This include Material.hlsl
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
RWTexture2D<float4> uavOutput;
[numthreads(TILE_SIZE, TILE_SIZE, 1)]
void SHADE_OPAQUE_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID)
{
// input.positionCS is SV_Position
uint2 pixelCoord = dispatchThreadId;
PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw);
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, posInput.unPositionSS).x;
UpdatePositionInput(depth, _InvViewProjMatrix, _ViewProjMatrix, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(posInput.positionWS);
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
BSDFData bsdfData;
float3 bakeDiffuseLighting;
DECODE_FROM_GBUFFER(gbuffer, bsdfData, bakeDiffuseLighting);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, bakeDiffuseLighting, diffuseLighting, specularLighting);
uavOutput[pixelCoord] = float4(diffuseLighting + specularLighting, 1.0);
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass.meta


fileFormatVersion: 2
guid: ef8815a81d7dd9147b37093f06d9977c
guid: 8a355c056864a5d4cb26d9c3168ae0bb
folderAsset: yes
timeCreated: 1479218330
licenseType: Pro

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader


Shader "Hidden/HDRenderLoop/Deferred"
Shader "Hidden/HDRenderPipeline/Deferred"
{
Properties
{

// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// the deferred shader will require to use multicompile.
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Lighting.hlsl" // This include Material.hlsl
//-------------------------------------------------------------------------------------
// variable declaration

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Lighting.hlsl


#define HAS_LIGHTLOOP // Allow to not define LightLoop related function in Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightUtilities.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightUtilities.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shadow/Shadow.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Material.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow/Shadow.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePassLoop.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl"
#endif

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs


public virtual void PushGlobalParams(Camera camera, ScriptableRenderContext loop) {}
public virtual void RenderDeferredLighting(HDRenderLoop.HDCamera hdCamera, ScriptableRenderContext renderLoop, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderForward(Camera camera, ScriptableRenderContext renderLoop, bool renderOpaque) {}
public virtual void RenderForward(Camera camera, ScriptableRenderContext renderContext, bool renderOpaque) {}
public Light GetCurrentSunLight() { return m_CurrentSunLight; }
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs. Please don't edit by hand.
//
#ifndef LIGHTDEFINITION_CS_HLSL

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs. Please don't edit by hand.
//
#ifndef SHADERPASS_CS_HLSL

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl


#include "Color.hlsl"
// TODO: This is the max value allowed for emissive (bad name - but keep for now to retrieve it) (It is 8^2.2 (gamma) and 8 is the limit of punctual light slider...), comme from UnityCg.cginc. Fix it!
// Ask Jesper if this can be change for HDRenderLoop
// Ask Jesper if this can be change for HDRenderPipeline
#define EMISSIVE_RGBM_SCALE 97.0
float4 Frag(PackedVaryings packedInput) : SV_Target

18
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs


protected void OnEnable()
{
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop();
if (renderLoop == null)
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
{
return;
}

.GetFields(BindingFlags.Public | BindingFlags.Instance)
.ToArray();
if (renderLoop.skyManager.skyParameters == null || renderLoop.skyManager.skyParameters.GetType() != this.GetType()) // We allow override of parameters only if the type is different. It means that we changed the Sky Renderer and might need a new set of parameters.
renderLoop.skyManager.skyParameters = this;
else if (renderLoop.skyManager.skyParameters != this && renderLoop.skyManager.skyParameters.GetType() == this.GetType())
if (renderPipeline.skyManager.skyParameters == null || renderPipeline.skyManager.skyParameters.GetType() != this.GetType()) // We allow override of parameters only if the type is different. It means that we changed the Sky Renderer and might need a new set of parameters.
renderPipeline.skyManager.skyParameters = this;
else if (renderPipeline.skyManager.skyParameters != this && renderPipeline.skyManager.skyParameters.GetType() == this.GetType())
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop();
if (renderLoop == null)
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
if (renderLoop.skyManager.skyParameters == this)
renderLoop.skyManager.skyParameters = null;
if (renderPipeline.skyManager.skyParameters == this)
renderPipeline.skyManager.skyParameters = null;
}
public int GetHash()

120
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs


using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using System.Collections.Generic;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{

//SkyResolution4096 = 4096
}
[GenerateHLSL(PackingRules.Exact)]
public enum LightSamplingParameters
{
TextureHeight = 256,
TextureWidth = 512
}
public enum EnvironementUpdateMode
{
OnChanged = 0,

public Vector3 cameraPosWS;
public Vector4 screenSize;
public Mesh skyMesh;
public ScriptableRenderContext renderLoop;
public ScriptableRenderContext renderContext;
public Light sunLight;
public RenderTargetIdentifier colorBuffer;
public RenderTargetIdentifier depthBuffer;

{
RenderTexture m_SkyboxCubemapRT = null;
RenderTexture m_SkyboxGGXCubemapRT = null;
RenderTexture m_SkyboxMarginalRowCdfRT = null;
RenderTexture m_SkyboxConditionalCdfRT = null;
ComputeShader m_BuildProbabilityTablesCS = null;
int m_ConditionalDensitiesKernel = -1;
int m_MarginalRowDensitiesKernel = -1;
Vector4 m_CubemapScreenSize;
Matrix4x4[] m_faceCameraViewProjectionMatrix = new Matrix4x4[6];
Matrix4x4[] m_faceCameraInvViewProjectionMatrix = new Matrix4x4[6];

bool m_NeedLowLevelUpdateEnvironment = false;
bool m_UpdateRequired = true;
float m_CurrentUpdateTime = 0.0f;
bool m_useMIS = false;
SkyParameters m_SkyParameters = null;

{
Utilities.Destroy(m_SkyboxCubemapRT);
Utilities.Destroy(m_SkyboxGGXCubemapRT);
Utilities.Destroy(m_SkyboxMarginalRowCdfRT);
Utilities.Destroy(m_SkyboxConditionalCdfRT);
m_UpdateRequired = true; // Special case. Even if update mode is set to OnDemand, we need to regenerate the environment after destroying the texture.
}

m_SkyboxGGXCubemapRT.autoGenerateMips = false;
m_SkyboxGGXCubemapRT.filterMode = FilterMode.Trilinear;
m_SkyboxGGXCubemapRT.Create();
if (m_useMIS)
{
int width = (int)LightSamplingParameters.TextureWidth;
int height = (int)LightSamplingParameters.TextureHeight;
// + 1 because we store the value of the integral of the cubemap at the end of the texture.
m_SkyboxMarginalRowCdfRT = new RenderTexture(height + 1, 1, 1, RenderTextureFormat.RFloat);
m_SkyboxMarginalRowCdfRT.dimension = TextureDimension.Tex2D;
m_SkyboxMarginalRowCdfRT.useMipMap = false;
m_SkyboxMarginalRowCdfRT.autoGenerateMips = false;
m_SkyboxMarginalRowCdfRT.enableRandomWrite = true;
m_SkyboxMarginalRowCdfRT.filterMode = FilterMode.Point;
m_SkyboxMarginalRowCdfRT.Create();
// TODO: switch the format to R16 (once it's available) to save some bandwidth.
m_SkyboxConditionalCdfRT = new RenderTexture(width, height, 1, RenderTextureFormat.RFloat);
m_SkyboxConditionalCdfRT.dimension = TextureDimension.Tex2D;
m_SkyboxConditionalCdfRT.useMipMap = false;
m_SkyboxConditionalCdfRT.autoGenerateMips = false;
m_SkyboxConditionalCdfRT.enableRandomWrite = true;
m_SkyboxConditionalCdfRT.filterMode = FilterMode.Point;
m_SkyboxConditionalCdfRT.Create();
}
}
m_CubemapScreenSize = new Vector4((float)resolution, (float)resolution, 1.0f / (float)resolution, 1.0f / (float)resolution);

m_Renderer.Build();
// TODO: We need to have an API to send our sky information to Enlighten. For now use a workaround through skybox/cubemap material...
m_StandardSkyboxMaterial = Utilities.CreateEngineMaterial("Skybox/Cubemap");
m_GGXConvolveMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/GGXConvolve");
m_StandardSkyboxMaterial = Utilities.CreateEngineMaterial("Skybox/Cubemap");
m_GGXConvolveMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/GGXConvolve");
m_BuildProbabilityTablesCS = Resources.Load<ComputeShader>("BuildProbabilityTables");
m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities");
m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities");
m_CurrentUpdateTime = 0.0f;
}

Utilities.Destroy(m_GGXConvolveMaterial);
Utilities.Destroy(m_SkyboxCubemapRT);
Utilities.Destroy(m_SkyboxGGXCubemapRT);
Utilities.Destroy(m_SkyboxMarginalRowCdfRT);
Utilities.Destroy(m_SkyboxConditionalCdfRT);
if(m_Renderer != null)
m_Renderer.Cleanup();

{
for (int i = 0; i < 6; ++i)
{
Utilities.SetRenderTarget(builtinParams.renderLoop, target, ClearFlag.ClearNone, 0, (CubemapFace)i);
Utilities.SetRenderTarget(builtinParams.renderContext, target, ClearFlag.ClearNone, 0, (CubemapFace)i);
builtinParams.invViewProjMatrix = m_faceCameraInvViewProjectionMatrix[i];
builtinParams.viewProjMatrix = m_faceCameraViewProjectionMatrix[i];

}
}
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderLoop, BuiltinSkyParameters builtinParams, SkyParameters skyParams, Texture input, RenderTexture target)
private void BuildProbabilityTables(ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Sky Pass: GGX Convolution", renderLoop))
// Bind the input cubemap.
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "envMap", m_SkyboxCubemapRT);
// Bind the outputs.
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "marginalRowDensities", m_SkyboxMarginalRowCdfRT);
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "conditionalDensities", m_SkyboxConditionalCdfRT);
m_BuildProbabilityTablesCS.SetTexture(m_MarginalRowDensitiesKernel, "marginalRowDensities", m_SkyboxMarginalRowCdfRT);
var cmd = new CommandBuffer() { name = "" };
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, (int)LightSamplingParameters.TextureHeight, 1, 1);
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_MarginalRowDensitiesKernel, 1, 1, 1);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderContext, BuiltinSkyParameters builtinParams, SkyParameters skyParams, Texture input, RenderTexture target)
{
using (new Utilities.ProfilingSample("Sky Pass: GGX Convolution", renderContext))
{
int mipCount = 1 + (int)Mathf.Log(input.width, 2.0f);
if (mipCount < ((int)EnvConstants.SpecCubeLodStep + 1))

}
if (m_useMIS)
{
BuildProbabilityTables(renderContext);
}
// Copy the first mip.

//for (int f = 0; f < 6; f++)
// Graphics.CopyTexture(input, f, 0, target, f, 0);
if (m_useMIS)
{
m_GGXConvolveMaterial.EnableKeyword("USE_MIS");
m_GGXConvolveMaterial.SetTexture("_MarginalRowDensities", m_SkyboxMarginalRowCdfRT);
m_GGXConvolveMaterial.SetTexture("_ConditionalDensities", m_SkyboxConditionalCdfRT);
}
else
{
m_GGXConvolveMaterial.DisableKeyword("USE_MIS");
}
m_GGXConvolveMaterial.SetFloat("_MipMapCount", mipCount);
m_GGXConvolveMaterial.SetFloat("_MaxLevel", mipCount - 1);
m_GGXConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP);
for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip)

for (int face = 0; face < 6; ++face)
{
Utilities.SetRenderTarget(renderLoop, target, ClearFlag.ClearNone, mip, (CubemapFace)face);
Utilities.SetRenderTarget(renderContext, target, ClearFlag.ClearNone, mip, (CubemapFace)face);
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}

m_UpdateRequired = true;
}
public void UpdateEnvironment(HDRenderLoop.HDCamera camera, Light sunLight, ScriptableRenderContext renderLoop)
public void UpdateEnvironment(HDRenderPipeline.HDCamera camera, Light sunLight, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Sky Environment Pass", renderLoop))
using (new Utilities.ProfilingSample("Sky Environment Pass", renderContext))
m_BuiltinParameters.renderLoop = renderLoop;
m_BuiltinParameters.renderContext = renderContext;
m_BuiltinParameters.sunLight = sunLight;
// We need one frame delay for this update to work since DynamicGI.UpdateEnvironment is executed direclty but the renderloop is not (so we need to wait for the sky texture to be rendered first)

// Render sky into a cubemap - doesn't happen every frame, can be controlled
RenderSkyToCubemap(m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT);
// Convolve downsampled cubemap
RenderCubemapGGXConvolution(renderLoop, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
m_NeedLowLevelUpdateEnvironment = true;
m_UpdateRequired = false;

// DynamicGI.UpdateEnvironment();
// // Clear temp cubemap and redo GGX from black
// Utilities.SetRenderTarget(renderLoop, m_SkyboxCubemapRT, ClearFlag.ClearColor);
// RenderCubemapGGXConvolution(renderLoop, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
// Utilities.SetRenderTarget(renderContext, m_SkyboxCubemapRT, ClearFlag.ClearColor);
// RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
// m_SkyParametersHash = 0;
//}

}
public void RenderSky(HDRenderLoop.HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ScriptableRenderContext renderLoop)
public void RenderSky(HDRenderPipeline.HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ScriptableRenderContext renderContext)
using (new Utilities.ProfilingSample("Sky Pass", renderLoop))
using (new Utilities.ProfilingSample("Sky Pass", renderContext))
m_BuiltinParameters.renderLoop = renderLoop;
m_BuiltinParameters.renderContext = renderContext;
m_BuiltinParameters.sunLight = sunLight;
m_BuiltinParameters.invViewProjMatrix = camera.invViewProjectionMatrix;
m_BuiltinParameters.viewProjMatrix = camera.viewProjectionMatrix;

m_BuiltinParameters.colorBuffer = colorBuffer;
m_BuiltinParameters.depthBuffer = depthBuffer;
Utilities.SetRenderTarget(renderLoop, colorBuffer, depthBuffer);
Utilities.SetRenderTarget(renderContext, colorBuffer, depthBuffer);
m_Renderer.RenderSky(m_BuiltinParameters, skyParameters);
}
}

56
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader


Shader "Hidden/HDRenderLoop/GGXConvolve"
Shader "Hidden/HDRenderPipeline/GGXConvolve"
{
SubShader
{

HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma multi_compile _ USE_MIS
#pragma vertex Vert
#pragma fragment Frag

#include "../SkyManager.cs.hlsl"
struct Attributes
{

TEXTURECUBE(_MainTex);
SAMPLERCUBE(sampler_MainTex);
#ifdef USE_MIS
TEXTURE2D(_MarginalRowDensities);
TEXTURE2D(_ConditionalDensities);
#endif
float _MipMapCount;
float _MaxLevel;
float _InvOmegaP;
half4 Frag(Varyings input) : SV_Target

// Remove view-dependency from GGX, effectively making the BSDF isotropic.
// We approximate the pre-integration with V == N
float4 val = IntegrateLD( TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),
V,
N,
PerceptualRoughnessToRoughness(perceptualRoughness),
_MipMapCount,
_InvOmegaP,
55, // Matches the size of the precomputed Fibonacci point set
true);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
#ifdef USE_MIS
float4 val = IntegrateLD_MIS(TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),
_MarginalRowDensities, _ConditionalDensities,
V, N,
roughness,
_InvOmegaP,
LIGHTSAMPLINGPARAMETERS_TEXTURE_WIDTH,
LIGHTSAMPLINGPARAMETERS_TEXTURE_HEIGHT,
1024,
false);
#else
uint sampleCount = 0;
switch (_Level)
{
case 1: sampleCount = 21; break;
case 2: sampleCount = 34; break;
case 3: sampleCount = 55; break;
case 4: sampleCount = 89; break;
case 5: sampleCount = 89; break;
case 6: sampleCount = 89; break; // UNITY_SPECCUBE_LOD_STEPS
}
float4 val = IntegrateLD(TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),
V, N,
roughness,
_MaxLevel,
_InvOmegaP,
sampleCount, // Must be a Fibonacci number
true);
#endif
return val;
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader


Shader "Hidden/HDRenderLoop/Sky/SkyProcedural"
Shader "Hidden/HDRenderPipeline/Sky/SkyProcedural"
{
SubShader
{

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl


uniform float _MiePhaseAnisotropy;
uniform float _MieExtinctionFactor;
SAMPLER2D(sampler_CameraDepthTexture)
SAMPLER2D(sampler_CameraDepthTexture);
#define SRL_BilinearSampler sampler_CameraDepthTexture // Used for all textures
TEXTURE2D(_CameraDepthTexture);

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs


override public void Build()
{
m_ProceduralSkyMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Sky/SkyProcedural");
m_ProceduralSkyMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Sky/SkyProcedural");
}
override public void Cleanup()

cmd.SetGlobalTexture("_CameraDepthTexture", builtinParams.depthBuffer);
}
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_ProceduralSkyMaterial);
builtinParams.renderLoop.ExecuteCommandBuffer(cmd);
builtinParams.renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader


Shader "Hidden/HDRenderLoop/Sky/SkyHDRI"
Shader "Hidden/HDRenderPipeline/Sky/SkyHDRI"
{
SubShader
{

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs


override public void Build()
{
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Sky/SkyHDRI");
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Sky/SkyHDRI");
}
override public void Cleanup()

var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial);
builtinParams.renderLoop.ExecuteCommandBuffer(cmd);
builtinParams.renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit.meta


fileFormatVersion: 2
guid: d43c06a2afd9f2f4ab88a7a94c43e1a6
guid: e173dfe6cd75d954b95306237244f6de
folderAsset: yes
timeCreated: 1476653183
licenseType: Pro

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit.meta


fileFormatVersion: 2
guid: 24406b9cf8c7f2543b7d20ead11e37d5
guid: d6cadd3aaf3ad6641b86e85a0929b245
folderAsset: yes
timeCreated: 1476653183
licenseType: Pro

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl


// This structure gather all possible varying/interpolator for this shader.
//-------------------------------------------------------------------------------------
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl"
struct FragInputs
{

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs. Please don't edit by hand.
//
#ifndef BUILTINDATA_CS_HLSL

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader


Shader "HDRenderLoop/Unlit"
Shader "HDRenderPipeline/Unlit"
{
Properties
{

//-------------------------------------------------------------------------------------
#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Unlit.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs. Please don't edit by hand.
//
#ifndef UNLIT_CS_HLSL

95
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


Shader "HDRenderLoop/LayeredLit"
Shader "HDRenderPipeline/LayeredLit"
{
Properties
{

// Layer blending options
_LayerMaskMap("LayerMaskMap", 2D) = "white" {}
[ToggleOff] _LayerMaskVertexColor("Use Vertex Color Mask", Float) = 0.0
[ToggleOff] _LayerMaskVertexColor("Use Vertex Color Mask", Float) = 0.0
[ToggleOff] _UseHeightBasedBlend("UseHeightBasedBlend", Float) = 0.0
_HeightOffset1("_HeightOffset1", Range(-0.3, 0.3)) = 0.0

//-------------------------------------------------------------------------------------
#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
#define _MAX_LAYER 4
#if defined(_LAYEREDLIT_4_LAYERS)

# define _LAYER_COUNT 2
#endif
// Set of users variables
#define PROP_DECL(type, name) type name, name##0, name##1, name##2, name##3;
#define PROP_DECL_TEX2D(name)\
TEXTURE2D(name##0); \
SAMPLER2D(sampler##name##0); \
TEXTURE2D(name##1); \
TEXTURE2D(name##2); \
TEXTURE2D(name##3);
// Explicitely said that we are a layered shader as we share code between lit and layered lit
#define LAYERED_LIT_SHADER
// Set of users variables
PROP_DECL(float4, _BaseColor);
PROP_DECL_TEX2D(_BaseColorMap);
float4 _BaseColorMap0_ST;
float4 _BaseColorMap1_ST;
float4 _BaseColorMap2_ST;
float4 _BaseColorMap3_ST;
PROP_DECL(float, _Metallic);
PROP_DECL(float, _Smoothness);
PROP_DECL_TEX2D(_MaskMap);
PROP_DECL_TEX2D(_SpecularOcclusionMap);
PROP_DECL_TEX2D(_NormalMap);
PROP_DECL_TEX2D(_HeightMap);
PROP_DECL_TEX2D(_DetailMask);
PROP_DECL_TEX2D(_DetailMap);
float4 _DetailMap0_ST;
float4 _DetailMap1_ST;
float4 _DetailMap2_ST;
float4 _DetailMap3_ST;
PROP_DECL(float, _UVDetail);
PROP_DECL(float, _DetailAlbedoScale);
PROP_DECL(float, _DetailNormalScale);
PROP_DECL(float, _DetailSmoothnessScale);
PROP_DECL(float, _DetailHeightScale);
PROP_DECL(float, _DetailAOScale);
PROP_DECL(float, _HeightScale);
PROP_DECL(float, _HeightBias);
TEXTURE2D(_DiffuseLightingMap);
SAMPLER2D(sampler_DiffuseLightingMap);
TEXTURE2D(_DistortionVectorMap);
SAMPLER2D(sampler_DistortionVectorMap);
TEXTURE2D(_LayerMaskMap);
SAMPLER2D(sampler_LayerMaskMap);
float _HeightOffset1;
float _HeightOffset2;
float _HeightOffset3;
float _HeightFactor1;
float _HeightFactor2;
float _HeightFactor3;
float _BlendSize1;
float _BlendSize2;
float _BlendSize3;
float _VertexColorHeightFactor;
float3 _EmissiveColor;
TEXTURE2D(_EmissiveColorMap);
SAMPLER2D(sampler_EmissiveColorMap);
float _EmissiveIntensity;
PROP_DECL(float, _TexWorldScale);
PROP_DECL(float, _UVMappingPlanar);
PROP_DECL(float4, _UVMappingMask);
PROP_DECL(float4, _UVDetailsMappingMask);
float _AlphaCutoff;
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl"
ENDHLSL

#pragma fragment Frag
#define SHADERPASS SHADERPASS_GBUFFER
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitMetaPass.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_VELOCITY
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitVelocityPass.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitDepthPass.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitDepthPass.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_DISTORTION
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitDistortionPass.hlsl"

// TEMP until pragma work in include
// #include "../../Lighting/Forward.hlsl"
#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS
#define LAYERED_LIT_SHADER
//#pragma multi_compile SHADOWFILTERING_FIXED_SIZE_PCF
#include "../../Lighting/Lighting.hlsl"

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor.meta


fileFormatVersion: 2
guid: 4e53b0488682a1c4c8fa2b548ae0c25c
guid: 007fa1ca3307f1c4daa3a6efa6bba7e1
folderAsset: yes
timeCreated: 1479127283
licenseType: Pro

7
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs


public void Build()
{
m_InitPreFGD = CreateEngineMaterial("Hidden/HDRenderLoop/PreIntegratedFGD");
m_InitPreFGD = CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");
// TODO: switch to RGBA64 when it becomes available.
m_LtcMultiGGXFresnelDisneyDiffuse = LoadLUT(TextureFormat.RGBAHalf, s_LtcGGXMagnitudeData,
s_LtcGGXFresnelData,
s_LtcDisneyDiffuseMagnitudeData);

isInit = false;
}
public void RenderInit(Rendering.ScriptableRenderContext renderLoop)
public void RenderInit(Rendering.ScriptableRenderContext renderContext)
renderLoop.ExecuteCommandBuffer(cmd);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
isInit = true;

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.cs. Please don't edit by hand.
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs. Please don't edit by hand.
//
#ifndef LIT_CS_HLSL

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/PreIntegratedFGD.shader


Shader "Hidden/HDRenderLoop/PreIntegratedFGD"
Shader "Hidden/HDRenderPipeline/PreIntegratedFGD"
{
SubShader {
Pass {

#include "Common.hlsl"
#include "ImageBasedLighting.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
struct Attributes

6
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/StandardToHDLitMaterialUpgrader.cs


using System;
using System;
using NUnit.Framework;
using UnityEngine;

{
public StandardToHDLitMaterialUpgrader()
{
RenameShader("Standard", "HDRenderLoop/LitLegacySupport");
RenameShader("Standard", "HDRenderPipeline/LitLegacySupport");
RenameTexture("_MainTex", "_BaseColorMap");
RenameColor("_Color", "_BaseColor");

[Test]
public void UpgradeMaterial()
{
var newShader = Shader.Find("HDRenderLoop/LitLegacySupport");
var newShader = Shader.Find("HDRenderPipeline/LitLegacySupport");
var mat = new Material(Shader.Find("Standard"));
var albedo = new Texture2D(1, 1);
var normals = new Texture2D(1, 1);

6
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/StandardSpecularToHDLitMaterialUpgrader.cs


using System;
using System;
using NUnit.Framework;
using UnityEngine;

{
public StandardSpecularToHDLitMaterialUpgrader()
{
RenameShader("Standard (Specular setup)", "HDRenderLoop/LitLegacySupport");
RenameShader("Standard (Specular setup)", "HDRenderPipeline/LitLegacySupport");
RenameTexture("_MainTex", "_BaseColorMap");
RenameColor("_Color", "_BaseColor");

[Test]
public void UpgradeMaterial()
{
var newShader = Shader.Find("HDRenderLoop/LitLegacySupport");
var newShader = Shader.Find("HDRenderPipeline/LitLegacySupport");
var mat = new Material(Shader.Find("Standard (Specular setup)"));
var albedo = new Texture2D(1, 1);
var normals = new Texture2D(1, 1);

84
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader


Shader "HDRenderLoop/Lit"
Shader "HDRenderPipeline/Lit"
{
Properties
{

//-------------------------------------------------------------------------------------
#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
// Set of users variables
float4 _BaseColor;
TEXTURE2D(_BaseColorMap);
SAMPLER2D(sampler_BaseColorMap);
float4 _BaseColorMap_ST;
float _Metallic;
float _Smoothness;
TEXTURE2D(_MaskMap);
SAMPLER2D(sampler_MaskMap);
TEXTURE2D(_SpecularOcclusionMap);
SAMPLER2D(sampler_SpecularOcclusionMap);
TEXTURE2D(_NormalMap);
SAMPLER2D(sampler_NormalMap);
TEXTURE2D(_DetailMask);
SAMPLER2D(sampler_DetailMask);
TEXTURE2D(_DetailMap);
SAMPLER2D(sampler_DetailMap);
float4 _DetailMap_ST;
float _DetailAlbedoScale;
float _DetailNormalScale;
float _DetailSmoothnessScale;
float _DetailHeightScale;
float _DetailAOScale;
TEXTURE2D(_HeightMap);
SAMPLER2D(sampler_HeightMap);
float _HeightScale;
float _HeightBias;
TEXTURE2D(_TangentMap);
SAMPLER2D(sampler_TangentMap);
float _Anisotropy;
TEXTURE2D(_AnisotropyMap);
SAMPLER2D(sampler_AnisotropyMap);
//float _SubSurfaceRadius;
//TEXTURE2D(_SubSurfaceRadiusMap);
//SAMPLER2D(sampler_SubSurfaceRadiusMap);
// float _Thickness;
//TEXTURE2D(_ThicknessMap);
//SAMPLER2D(sampler_ThicknessMap);
// float _CoatCoverage;
//TEXTURE2D(_CoatCoverageMap);
//SAMPLER2D(sampler_CoatCoverageMap);
// float _CoatRoughness;
//TEXTURE2D(_CoatRoughnessMap);
//SAMPLER2D(sampler_CoatRoughnessMap);
TEXTURE2D(_DiffuseLightingMap);
SAMPLER2D(sampler_DiffuseLightingMap);
TEXTURE2D(_DistortionVectorMap);
SAMPLER2D(sampler_DistortionVectorMap);
float3 _EmissiveColor;
TEXTURE2D(_EmissiveColorMap);
SAMPLER2D(sampler_EmissiveColorMap);
float _EmissiveIntensity;
float _AlphaCutoff;
float _TexWorldScale;
float _UVMappingPlanar;
float4 _UVMappingMask;
float4 _UVDetailsMappingMask;
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl"
ENDHLSL

9
Assets/ScriptableRenderLoop/HDRenderPipeline.meta


fileFormatVersion: 2
guid: 4c38eac64d0e8344d85c9f309419d619
folderAsset: yes
timeCreated: 1483548930
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/common/CubeToSpherical.shader.meta


fileFormatVersion: 2
guid: 595434cc3b6405246b6cd3086d0b6f7d
timeCreated: 1482845902
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

24
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d440c0deec24a2f478b3e9021cb66c29, type: 3}
m_Name: HDRenderPipeline
m_EditorClassIdentifier:
m_ShadowSettings:
enabled: 1
shadowAtlasWidth: 4096
shadowAtlasHeight: 4096
maxShadowDistance: 1000
directionalLightCascadeCount: 4
directionalLightCascades: {x: 0.05, y: 0.2, z: 0.3}
m_TextureSettings:
spotCookieSize: 128
pointCookieSize: 512
reflectionCubemapSize: 128

8
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset.meta


fileFormatVersion: 2
guid: e185fecca3c73cd47a09f1092663ef32
timeCreated: 1483606455
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs.meta


fileFormatVersion: 2
guid: d440c0deec24a2f478b3e9021cb66c29
timeCreated: 1483605696
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

110
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.hlsl


#ifndef UNITY_BUILTIN_DATA_INCLUDED
#define UNITY_BUILTIN_DATA_INCLUDED
//-----------------------------------------------------------------------------
// BuiltinData
// This structure include common data that should be present in all material
// and are independent from the BSDF parametrization.
// Note: These parameters can be store in GBuffer if the writer wants
//-----------------------------------------------------------------------------
#include "BuiltinData.cs.hlsl"
//-----------------------------------------------------------------------------
// common Encode/Decode functions
//-----------------------------------------------------------------------------
// Guideline for velocity buffer.
// We support various architecture for HDRenderPipeline
// - Forward only rendering
// - Hybrid forward/deferred opaque
// - Regular deferred
// The velocity buffer is potentially fill in several pass.
// - In gbuffer pass with extra RT
// - In forward opaque pass (Can happen even when deferred) with MRT
// - In dedicated velocity pass
// Also the velocity buffer is only fill in case of dynamic or deformable objects, static case can use camera reprojection to retrieve motion vector (<= TODO: this may be false with TAA due to jitter matrix)
// or just previous and current transform
// So here we decide the following rules:
// - A deferred material can't override the velocity buffer format of builtinData, must use appropriate function
// - If velocity buffer is enable in deferred material it is the last one
// - Velocity buffer can be optionally enabled (either in forward or deferred)
// - Velocity data can't be pack with other properties
// - Same velocity buffer is use for all scenario, so if deferred define a velocity buffer, the same is reuse for forward case.
// For these reasons we chose to avoid to pack velocity buffer with anything else in case of PackgbufferInFP16 (and also in case the format change)
// Encode/Decode velocity/distortion in a buffer (either forward of deferred)
// Design note: We assume that velocity/distortion fit into a single buffer (i.e not spread on several buffer)
void EncodeVelocity(float2 velocity, out float4 outBuffer)
{
// RT - 16:16 float
outBuffer = float4(velocity.xy, 0.0, 0.0);
}
void DecodeVelocity(float4 inBuffer, out float2 velocity)
{
velocity = inBuffer.xy;
}
void EncodeDistortion(float2 distortion, float distortionBlur, out float4 outBuffer)
{
// RT - 16:16:16:16 float
// distortionBlur in alpha for a different blend mode
outBuffer = float4(distortion, 0.0, distortionBlur);
}
void DecodeDistortion(float4 inBuffer, out float2 distortion, out float2 distortionBlur)
{
distortion = inBuffer.xy;
distortionBlur = inBuffer.a;
}
void GetBuiltinDataDebug(uint paramId, BuiltinData builtinData, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_BUILTIN_BUILTINDATA_OPACITY:
result = builtinData.opacity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_BAKE_DIFFUSE_LIGHTING:
// TODO: require a remap
result = builtinData.bakeDiffuseLighting;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_COLOR:
// emissiveColor is premultiply by emissive intensity
result = (builtinData.emissiveColor / builtinData.emissiveIntensity); needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_INTENSITY:
result = builtinData.emissiveIntensity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY:
result = float3(builtinData.velocity, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION:
result = float3(builtinData.distortion, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR:
result = builtinData.distortionBlur.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET:
result = builtinData.depthOffset.xxx * 10.0; // * 10 assuming 1 unity unity is 1m
break;
}
}
void GetLighTransportDataDebug(uint paramId, LighTransportData lightTransportData, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_BUILTIN_LIGHTRANSPORTDATA_DIFFUSE_COLOR:
result = lightTransportData.diffuseColor; needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_LIGHTRANSPORTDATA_EMISSIVE_COLOR:
// TODO: Need a tonemap ?
result = lightTransportData.emissiveColor;
break;
}
}
#endif // UNITY_BUILTIN_DATA_INCLUDED

1001
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
文件差异内容过多而无法显示
查看文件

152
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl


#ifndef LAYERED_LIT_SHADER
// Set of users variables
float4 _BaseColor;
TEXTURE2D(_BaseColorMap);
SAMPLER2D(sampler_BaseColorMap);
float4 _BaseColorMap_ST;
float _Metallic;
float _Smoothness;
TEXTURE2D(_MaskMap);
SAMPLER2D(sampler_MaskMap);
TEXTURE2D(_SpecularOcclusionMap);
SAMPLER2D(sampler_SpecularOcclusionMap);
TEXTURE2D(_NormalMap);
SAMPLER2D(sampler_NormalMap);
TEXTURE2D(_DetailMask);
SAMPLER2D(sampler_DetailMask);
TEXTURE2D(_DetailMap);
SAMPLER2D(sampler_DetailMap);
float4 _DetailMap_ST;
float _DetailAlbedoScale;
float _DetailNormalScale;
float _DetailSmoothnessScale;
float _DetailHeightScale;
float _DetailAOScale;
TEXTURE2D(_HeightMap);
SAMPLER2D(sampler_HeightMap);
float _HeightScale;
float _HeightBias;
TEXTURE2D(_TangentMap);
SAMPLER2D(sampler_TangentMap);
float _Anisotropy;
TEXTURE2D(_AnisotropyMap);
SAMPLER2D(sampler_AnisotropyMap);
//float _SubSurfaceRadius;
//TEXTURE2D(_SubSurfaceRadiusMap);
//SAMPLER2D(sampler_SubSurfaceRadiusMap);
// float _Thickness;
//TEXTURE2D(_ThicknessMap);
//SAMPLER2D(sampler_ThicknessMap);
// float _CoatCoverage;
//TEXTURE2D(_CoatCoverageMap);
//SAMPLER2D(sampler_CoatCoverageMap);
// float _CoatRoughness;
//TEXTURE2D(_CoatRoughnessMap);
//SAMPLER2D(sampler_CoatRoughnessMap);
TEXTURE2D(_DiffuseLightingMap);
SAMPLER2D(sampler_DiffuseLightingMap);
TEXTURE2D(_DistortionVectorMap);
SAMPLER2D(sampler_DistortionVectorMap);
float3 _EmissiveColor;
TEXTURE2D(_EmissiveColorMap);
SAMPLER2D(sampler_EmissiveColorMap);
float _EmissiveIntensity;
float _AlphaCutoff;
float _TexWorldScale;
float _UVMappingPlanar;
float4 _UVMappingMask;
float4 _UVDetailsMappingMask;
#else // LAYERED_LIT_SHADER
// Set of users variables
#define PROP_DECL(type, name) type name, name##0, name##1, name##2, name##3;
#define PROP_DECL_TEX2D(name)\
TEXTURE2D(name##0); \
SAMPLER2D(sampler##name##0); \
TEXTURE2D(name##1); \
TEXTURE2D(name##2); \
TEXTURE2D(name##3);
// Set of users variables
PROP_DECL(float4, _BaseColor);
PROP_DECL_TEX2D(_BaseColorMap);
float4 _BaseColorMap0_ST;
float4 _BaseColorMap1_ST;
float4 _BaseColorMap2_ST;
float4 _BaseColorMap3_ST;
PROP_DECL(float, _Metallic);
PROP_DECL(float, _Smoothness);
PROP_DECL_TEX2D(_MaskMap);
PROP_DECL_TEX2D(_SpecularOcclusionMap);
PROP_DECL_TEX2D(_NormalMap);
PROP_DECL_TEX2D(_HeightMap);
PROP_DECL_TEX2D(_DetailMask);
PROP_DECL_TEX2D(_DetailMap);
float4 _DetailMap0_ST;
float4 _DetailMap1_ST;
float4 _DetailMap2_ST;
float4 _DetailMap3_ST;
PROP_DECL(float, _UVDetail);
PROP_DECL(float, _DetailAlbedoScale);
PROP_DECL(float, _DetailNormalScale);
PROP_DECL(float, _DetailSmoothnessScale);
PROP_DECL(float, _DetailHeightScale);
PROP_DECL(float, _DetailAOScale);
PROP_DECL(float, _HeightScale);
PROP_DECL(float, _HeightBias);
TEXTURE2D(_DiffuseLightingMap);
SAMPLER2D(sampler_DiffuseLightingMap);
TEXTURE2D(_DistortionVectorMap);
SAMPLER2D(sampler_DistortionVectorMap);
TEXTURE2D(_LayerMaskMap);
SAMPLER2D(sampler_LayerMaskMap);
float _HeightOffset1;
float _HeightOffset2;
float _HeightOffset3;
float _HeightFactor1;
float _HeightFactor2;
float _HeightFactor3;
float _BlendSize1;
float _BlendSize2;
float _BlendSize3;
float _VertexColorHeightFactor;
float3 _EmissiveColor;
TEXTURE2D(_EmissiveColorMap);
SAMPLER2D(sampler_EmissiveColorMap);
float _EmissiveIntensity;
PROP_DECL(float, _TexWorldScale);
PROP_DECL(float, _UVMappingPlanar);
PROP_DECL(float4, _UVMappingMask);
PROP_DECL(float4, _UVDetailsMappingMask);
float _AlphaCutoff;
#endif // LAYERED_LIT_SHADER

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl.meta


fileFormatVersion: 2
guid: edd4a01243e14f04687542aee1f03b8a
timeCreated: 1483551695
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

151
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Material.hlsl


#ifndef UNITY_MATERIAL_INCLUDED
#define UNITY_MATERIAL_INCLUDED
#include "Color.hlsl"
#include "Packing.hlsl"
#include "BSDF.hlsl"
#include "Debug.hlsl"
#include "GeometricTools.hlsl"
#include "CommonMaterial.hlsl"
#include "EntityLighting.hlsl"
#include "ImageBasedLighting.hlsl"
//-----------------------------------------------------------------------------
// BuiltinData
//-----------------------------------------------------------------------------
#include "Builtin/BuiltinData.hlsl"
//-----------------------------------------------------------------------------
// Material definition
//-----------------------------------------------------------------------------
// Here we include all the different lighting model supported by the renderloop based on define done in .shader
// Only one deferred layout is allowed for a HDRenderPipeline, this will be detect by the redefinition of GBUFFERMATERIAL_COUNT
// If GBUFFERMATERIAL_COUNT is define two time, the shaders will not compile
#ifdef UNITY_MATERIAL_LIT
#include "Lit/Lit.hlsl"
#elif defined(UNITY_MATERIAL_UNLIT)
#include "Unlit/Unlit.hlsl"
#endif
//-----------------------------------------------------------------------------
// Define for GBuffer management
//-----------------------------------------------------------------------------
#ifdef GBUFFERMATERIAL_COUNT
#if GBUFFERMATERIAL_COUNT == 2
#define OUTPUT_GBUFFER(NAME) \
out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out GBufferType1 MERGE_NAME(NAME, 1) : SV_Target1
#define DECLARE_GBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1));
#define FETCH_GBUFFER(NAME, TEX, unCoord2) \
GBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
GBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target2
#endif
#elif GBUFFERMATERIAL_COUNT == 3
#define OUTPUT_GBUFFER(NAME) \
out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out GBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \
out GBufferType2 MERGE_NAME(NAME, 2) : SV_Target2
#define DECLARE_GBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1)); \
TEXTURE2D(MERGE_NAME(NAME, 2));
#define FETCH_GBUFFER(NAME, TEX, unCoord2) \
GBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
GBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \
GBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target3
#endif
#elif GBUFFERMATERIAL_COUNT == 4
#define OUTPUT_GBUFFER(NAME) \
out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out GBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \
out GBufferType2 MERGE_NAME(NAME, 2) : SV_Target2, \
out GBufferType3 MERGE_NAME(NAME, 3) : SV_Target3
#define DECLARE_GBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1)); \
TEXTURE2D(MERGE_NAME(NAME, 2)); \
TEXTURE2D(MERGE_NAME(NAME, 3));
#define FETCH_GBUFFER(NAME, TEX, unCoord2) \
GBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
GBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \
GBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2); \
GBufferType3 MERGE_NAME(NAME, 3) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 3), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target4
#endif
#elif GBUFFERMATERIAL_COUNT == 5
#define OUTPUT_GBUFFER(NAME) \
out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out GBufferType1 MERGE_NAME(NAME, 1) : SV_Target1, \
out GBufferType2 MERGE_NAME(NAME, 2) : SV_Target2, \
out GBufferType3 MERGE_NAME(NAME, 3) : SV_Target3, \
out GBufferType4 MERGE_NAME(NAME, 4) : SV_Target4
#define DECLARE_GBUFFER_TEXTURE(NAME) \
TEXTURE2D(MERGE_NAME(NAME, 0)); \
TEXTURE2D(MERGE_NAME(NAME, 1)); \
TEXTURE2D(MERGE_NAME(NAME, 2)); \
TEXTURE2D(MERGE_NAME(NAME, 3)); \
TEXTURE2D(MERGE_NAME(NAME, 4));
#define FETCH_GBUFFER(NAME, TEX, unCoord2) \
GBufferType0 MERGE_NAME(NAME, 0) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 0), unCoord2); \
GBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2); \
GBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2); \
GBufferType3 MERGE_NAME(NAME, 3) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 3), unCoord2); \
GBufferType4 MERGE_NAME(NAME, 4) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 4), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target5
#endif
#endif
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define ENCODE_VELOCITY_INTO_GBUFFER(VELOCITY, NAME) EncodeVelocity(VELOCITY, NAME)
#else
#define OUTPUT_GBUFFER_VELOCITY(NAME)
#define ENCODE_VELOCITY_INTO_GBUFFER(VELOCITY, NAME)
#endif
#endif // #ifdef GBUFFERMATERIAL_COUNT
#endif // UNITY_MATERIAL_INCLUDED

9
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl.meta


fileFormatVersion: 2
guid: 2c2d7b256f4650943b60cc4ef1c7aeaa
timeCreated: 1483548875
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

14
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs. Please don't edit by hand.
//
#ifndef SKYMANAGER_CS_HLSL
#define SKYMANAGER_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.LightSamplingParameters: static fields
//
#define LIGHTSAMPLINGPARAMETERS_TEXTURE_HEIGHT (256)
#define LIGHTSAMPLINGPARAMETERS_TEXTURE_WIDTH (512)
#endif

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl.meta


fileFormatVersion: 2
guid: 839dd86bae5fa4d46bf4facd02608862
timeCreated: 1483546512
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

160
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/BuildProbabilityTables.compute


// Given a cube map (passed as a 2D array), builds CDFs of two distributions:
// 1. 1D texture with marginal densities, telling us the likelihood of selecting a particular row,
// 2. 2D texture with conditional densities, which correspond to the PDF of the texel given its row.
// Ref: PBRT v3, 13.6.7 "Piecewise-Constant 2D Distributions".
// Note that we use the equiareal sphere-to-square mapping instead of the latitude-longitude one.
#include "Common.hlsl"
#include "ImageBasedLighting.hlsl"
/* --- Input --- */
#define TEXTURE_HEIGHT 256 // Equiareal texture map: cos(theta) = 1.0 - 2.0 * v
#define TEXTURE_WIDTH 2 * TEXTURE_HEIGHT // Equiareal texture map: phi = TWO_PI * (1.0 - u)
TEXTURECUBE(envMap); // Input cubemap
SAMPLERCUBE(sampler_envMap);
/* --- Output --- */
RWTexture2D<float> marginalRowDensities; // [(TEXTURE_HEIGHT + 1) x 1] (+ 1 for the image integral)
RWTexture2D<float> conditionalDensities; // [TEXTURE_WIDTH x TEXTURE_HEIGHT]
/* --- Implementation --- */
// Creates an access pattern which avoids shared memory bank conflicts.
#define NUM_BANKS 32
#define SHARED_MEM(x) ((x) + (x) / NUM_BANKS)
// Performs a block-level parallel scan.
// Ref: GPU Gems 3, Chapter 39: "Parallel Prefix Sum (Scan) with CUDA".
#define PARALLEL_SCAN(i, n, temp, sum) \
{ \
uint offset; \
\
/* Execute the up-sweep phase. */ \
for (offset = 1; offset <= n / 2; offset *= 2) \
{ \
GroupMemoryBarrierWithGroupSync(); \
\
/*** a1 = (2 * i + 1) * offset - 1 */ \
uint a1 = Mad24(Mad24(2, i, 1), offset, -1); \
uint a2 = a1 + offset; \
\
if (a2 < n) \
{ \
temp[SHARED_MEM(a2)] += temp[SHARED_MEM(a1)]; \
} \
} \
\
GroupMemoryBarrierWithGroupSync(); \
\
/* Prevent NaNs arising from the division of 0 by 0. */ \
sum = max(temp[SHARED_MEM(n - 1)], FLT_MIN); \
\
GroupMemoryBarrierWithGroupSync(); \
\
/* The exclusive scan requires the last element to be 0. */ \
if (i == 0) \
{ \
temp[SHARED_MEM(n - 1)] = 0.0; \
} \
\
/* Execute the down-sweep phase. */ \
for (offset = n / 2; offset > 0; offset /= 2) \
{ \
GroupMemoryBarrierWithGroupSync(); \
\
/*** a1 = (2 * i + 1) * offset - 1 */ \
uint a1 = Mad24(Mad24(2, i, 1), offset, -1); \
uint a2 = a1 + offset; \
\
if (a2 < n) \
{ \
float t1 = temp[SHARED_MEM(a1)]; \
temp[SHARED_MEM(a1)] = temp[SHARED_MEM(a2)]; \
temp[SHARED_MEM(a2)] += t1; \
} \
} \
\
GroupMemoryBarrierWithGroupSync(); \
}
#pragma kernel ComputeConditionalDensities
groupshared float rowVals[SHARED_MEM(TEXTURE_WIDTH)];
[numthreads(TEXTURE_WIDTH / 2, 1, 1)]
void ComputeConditionalDensities(uint3 groupId : SV_GroupID,
uint3 groupThreadId : SV_GroupThreadID)
{
// There are TEXTURE_HEIGHT thread groups processing 2 texels per thread.
const uint n = TEXTURE_WIDTH;
const uint i = groupThreadId.x;
const uint j = groupId.x;
const uint i1 = i;
const uint i2 = i + n / 2;
float w = TEXTURE_WIDTH;
float h = TEXTURE_HEIGHT;
float u1 = i1 / w + 0.5 / w;
float u2 = i2 / w + 0.5 / w;
float v = j / h + 0.5 / h;
float3 L1 = ConvertEquiarealToCubemap(u1, v);
float3 L2 = ConvertEquiarealToCubemap(u2, v);
float3 c1 = SAMPLE_TEXTURECUBE_LOD(envMap, sampler_envMap, L1, 0).rgb;
float3 c2 = SAMPLE_TEXTURECUBE_LOD(envMap, sampler_envMap, L2, 0).rgb;
// Compute the integral of the step function (row values).
// TODO: process 4 texels per thread, and manually unroll.
rowVals[SHARED_MEM(i1)] = c1.r + c1.g + c1.b;
rowVals[SHARED_MEM(i2)] = c2.r + c2.g + c2.b;
float rowValSum;
PARALLEL_SCAN(i, n, rowVals, rowValSum)
// Compute the CDF. Note: the value at (i = n) is implicitly 1.
conditionalDensities[uint2(i1, j)] = rowVals[SHARED_MEM(i1)] / rowValSum;
conditionalDensities[uint2(i2, j)] = rowVals[SHARED_MEM(i2)] / rowValSum;
if (i == 0)
{
float rowIntegralValue = rowValSum / n;
marginalRowDensities[uint2(j, 0)] = rowIntegralValue;
}
}
#pragma kernel ComputeMarginalRowDensities
groupshared float rowInts[SHARED_MEM(TEXTURE_HEIGHT)];
[numthreads(TEXTURE_HEIGHT / 2, 1, 1)]
void ComputeMarginalRowDensities(uint3 groupThreadId : SV_GroupThreadID)
{
// There is only one thread group processing 2 texels per thread.
const uint n = TEXTURE_HEIGHT;
const uint i = groupThreadId.x;
const uint i1 = i;
const uint i2 = i + n / 2;
// Compute the integral of the step function (row integrals).
// TODO: process 4 texels per thread, and manually unroll.
rowInts[SHARED_MEM(i1)] = marginalRowDensities[uint2(i1, 0)];
rowInts[SHARED_MEM(i2)] = marginalRowDensities[uint2(i2, 0)];
float rowIntSum;
PARALLEL_SCAN(i, n, rowInts, rowIntSum)
// Compute the CDF. Note: the value at (i = n) is implicitly 1.
marginalRowDensities[uint2(i1, 0)] = rowInts[SHARED_MEM(i1)] / rowIntSum;
marginalRowDensities[uint2(i2, 0)] = rowInts[SHARED_MEM(i2)] / rowIntSum;
if (i == 0)
{
float imgIntegralValue = rowIntSum / n;
marginalRowDensities[uint2(n, 0)] = imgIntegralValue;
}
}

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/BuildProbabilityTables.compute.meta


fileFormatVersion: 2
guid: b9f26cf340afe9145a699753531b2a4c
timeCreated: 1482419936
licenseType: Pro
ComputeShaderImporter:
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:

33
Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs


using System.Collections.Generic;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.ScriptableRenderPipeline
{
public class DefaultCameraProvider : ICameraProvider
{
public Camera overrideCamera { get; set; }
public static void GetCamerasToRenderDefault(List<Camera> cameras)
{
cameras.Clear();
foreach (var c in Camera.allCameras)
{
if (c.enabled)
cameras.Add(c);
}
}
public void GetCamerasToRender(List<Camera> cameras)
{
if (overrideCamera != null)
{
cameras.Clear();
cameras.Add(overrideCamera);
}
else
{
GetCamerasToRenderDefault(cameras);
}
}
}
}

12
Assets/ScriptableRenderLoop/core/DefaultCameraProvider.cs.meta


fileFormatVersion: 2
guid: 3ac0b0f83d74a194f8578dc2907cacf6
timeCreated: 1483007679
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

40
Assets/ScriptableRenderLoop/core/RenderingDataStore.cs


using UnityEngine.Experimental.Rendering;
namespace UnityEngine.ScriptableRenderPipeline
{
public class RenderingDataStore : IScriptableRenderDataStore
{
private bool m_NeedsBuild = true;
public RenderingDataStore(IRenderPipeline owner)
{
this.owner = owner;
}
public void Build()
{
if (m_NeedsBuild)
{
InternalBuild();
m_NeedsBuild = false;
}
}
protected virtual void InternalBuild()
{}
public void Cleanup()
{
if (!m_NeedsBuild)
{
InternalCleanup();
m_NeedsBuild = true;
}
}
protected virtual void InternalCleanup()
{}
public IRenderPipeline owner { get; private set; }
}
}

12
Assets/ScriptableRenderLoop/core/RenderingDataStore.cs.meta


fileFormatVersion: 2
guid: bd20f7d7bf8c34548b33677973016a96
timeCreated: 1483005411
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop.meta


fileFormatVersion: 2
guid: efe43be6d4923e441a2d4b20b3783b7f
folderAsset: yes
timeCreated: 1474540060
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/Assets/ScriptableRenderLoop/HDRenderLoop/Shadow → /Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow

/Assets/ScriptableRenderLoop/HDRenderLoop/Debug.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Debug.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/Lighting.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/Material.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Material.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/PostProcess.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/PostProcess.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs

/Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl

/Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/Shadow.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow.meta

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存