浏览代码

Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop into reduce-gc

# Conflicts:
#	Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
/RenderPassXR_Sandbox
Tim Cooper 7 年前
当前提交
0da91305
共有 25 个文件被更改,包括 742 次插入461 次删除
  1. 15
      Assets/LegacyLayered/UnityLayeredPhotogrammetryCore.cginc
  2. 4
      Assets/LegacyLayered/UnityLayeredPhotogrammetryInput.cginc
  3. 20
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  4. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/UpgradeStandardShaderMaterials.cs
  5. 186
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  6. 17
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs
  7. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader
  8. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  9. 149
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  10. 175
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  11. 14
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs
  12. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/MaterialUtilities.hlsl
  13. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset
  14. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset.meta
  15. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
  16. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs
  17. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
  18. 11
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
  19. 42
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs
  20. 2
      Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl
  21. 36
      Assets/ScriptableRenderPipeline/ShaderLibrary/CommonLighting.hlsl
  22. 427
      Assets/ScriptableRenderPipeline/ShaderLibrary/Fibonacci.hlsl
  23. 2
      ProjectSettings/ProjectVersion.txt
  24. 54
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/CameraMotionVectors.shader
  25. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/CameraMotionVectors.shader.meta

15
Assets/LegacyLayered/UnityLayeredPhotogrammetryCore.cginc


#include "AutoLight.cginc"
float4x4 GetObjectToWorldMatrix()
{
return unity_ObjectToWorld;
}
//-------------------------------------------------------------------------------------
// counterpart for NormalizePerPixelNormal
// skips normalization per-vertex and expects normalization to happen per-pixel

// BEGIN LAYERED_PHOTOGRAMMETRY
#define FRAGMENT_SETUP(x) FragmentCommonData x = \
FragmentSetupLayeredPhotogrammetry(i.pos, i.tex, float4(i.ambientOrLightmapUV.xy, i.texUV3), i.color, i.eyeVec, i.tangentToWorldAndPackedData, IN_WORLDPOS(i));
FragmentSetupLayeredPhotogrammetry(i.pos, i.tex, float4(i.ambientOrLightmapUV.zw, i.texUV3), i.color, i.eyeVec, i.tangentToWorldAndPackedData, IN_WORLDPOS(i));
// JIG CHECK
#define FRAGMENT_SETUP_FWDADD(x) FragmentCommonData x = \

ambientOrLightmapUV.rgb = ShadeSHPerVertex (normalWorld, ambientOrLightmapUV.rgb);
#endif
#ifdef DYNAMICLIGHTMAP_ON
//#ifdef DYNAMICLIGHTMAP_ON
#endif
//#endif
return ambientOrLightmapUV;
}

#elif UNITY_SHOULD_SAMPLE_SH
o.ambientOrLightmapUV.rgb = ShadeSHPerVertex (normalWorld, o.ambientOrLightmapUV.rgb);
#endif
#ifdef DYNAMICLIGHTMAP_ON
//#ifdef DYNAMICLIGHTMAP_ON
#endif
//#endif
#ifdef _PARALLAXMAP
TANGENT_SPACE_ROTATION;

4
Assets/LegacyLayered/UnityLayeredPhotogrammetryInput.cginc


half3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META)
//#if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META)
#endif
//#endif
// BEGIN LAYERED_PHOTOGRAMMETRY
half4 color : COLOR;

20
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


using UnityEngine.SceneManagement;
using UnityEngine.Experimental.Rendering.HDPipeline;
using System.IO;
using UnityEngine.Experimental.Rendering;
[UnityEditor.MenuItem("HDRenderPipeline/Add \"Additional Light Data\" (if not present)")]
static void AddAdditionalLightData()
{
Light[] lights = GameObject.FindObjectsOfType(typeof(Light)) as Light[];
foreach (Light light in lights)
{
// Do not add a component if there already is one.
if (light.GetComponent<AdditionalLightData>() == null)
{
light.gameObject.AddComponent<AdditionalLightData>();
}
}
}
// This script is a helper for the artists to re-synchronise all layered materials
[MenuItem("HDRenderPipeline/Synchronize all Layered materials")]
static void SynchronizeAllLayeredMaterial()

// In case the shader code have change and the inspector have been update with new kind of keywords we need to regenerate the set of keywords use by the material.
// This script will remove all keyword of a material and trigger the inspector that will re-setup all the used keywords.
// It require that the inspector of the material have a static function call that update all keyword based on material properties.
[MenuItem("HDRenderPipeline/Reset all materials keywords")]
[MenuItem("HDRenderPipeline/Test/Reset all materials keywords")]
static void ResetAllMaterialKeywords()
{
try

}
// Funtion used only to check performance of data with and without tessellation
[MenuItem("HDRenderPipeline/Debug/Remove tessellation materials (not reversible)")]
[MenuItem("HDRenderPipeline/Test/Remove tessellation materials (not reversible)")]
static void RemoveTessellationMaterials()
{
Object[] materials = Resources.FindObjectsOfTypeAll<Material>();

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/UpgradeStandardShaderMaterials.cs


return upgraders;
}
[MenuItem("HDRenderPipeline/Upgrade Materials - Project")]
[MenuItem("RenderPipeline/HDRenderPipeline/Material Upgraders/Upgrade Standard Materials to Lit Materials - Project Folder", false, 1)]
[MenuItem("HDRenderPipeline/Upgrade Materials - Selection")]
[MenuItem("RenderPipeline/HDRenderPipeline/Material Upgraders/Upgrade Standard Materials to Lit Materials - Selection", false, 2)]
[MenuItem("HDRenderPipeline/Modify Light Intensity for Upgrade - Scene Only")]
[MenuItem("RenderPipeline/HDRenderPipeline/Material Upgraders/Modify Light Intensity for Upgrade - Scene Only", false, 3)]
static void UpgradeLights()
{
Light[] lights = Light.GetLights(LightType.Directional, 0);

186
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


}
}
public struct HDCamera
// This holds all the matrix data we need for rendering, including data from the previous frame
// (which is the main reason why we need to keep them around for a minimum of one frame).
// HDCameras are automatically created & updated from a source camera and will be destroyed if
// not used during a frame.
public class HDCamera
public Camera camera;
public Vector4 screenSize;
public Matrix4x4 viewProjectionMatrix;
public Matrix4x4 invViewProjectionMatrix;
public Matrix4x4 invProjectionMatrix;
public Vector4 invProjectionParam;
public readonly Camera camera;
public Vector4 screenSize { get; private set; }
public Matrix4x4 viewProjectionMatrix { get; private set; }
public Matrix4x4 prevViewProjectionMatrix { get; private set; }
public Matrix4x4 invViewProjectionMatrix { get; private set; }
public Matrix4x4 invProjectionMatrix { get; private set; }
public Vector4 invProjectionParam { get; private set; }
// The only way to reliably keep track of a frame change right now is to compare the frame
// count Unity gives us. We need this as a single camera could be rendered several times per
// frame and some matrices only have to be computed once. Realistically this shouldn't
// happen, but you never know...
int m_LastFrameActive;
// Always true for cameras that just got added to the pool - needed for previous matrices to
// avoid one-frame jumps/hiccups with temporal effects (motion blur, TAA...)
bool m_FirstFrame;
public HDCamera(Camera camera)
{
this.camera = camera;
Reset();
}
public void Update()
{
screenSize = new Vector4(camera.pixelWidth, camera.pixelHeight, 1.0f / camera.pixelWidth, 1.0f / camera.pixelHeight);
// The actual projection matrix used in shaders is actually massaged a bit to work across all platforms
// (different Z value ranges etc.)
var gpuProj = GL.GetGPUProjectionMatrix(camera.projectionMatrix, false);
var gpuVP = gpuProj * camera.worldToCameraMatrix;
// A camera could be rendered multiple time per frame, only updates the previous viewproj if needed
if (m_LastFrameActive != Time.frameCount)
{
prevViewProjectionMatrix = !m_FirstFrame
? viewProjectionMatrix
: gpuVP;
m_FirstFrame = false;
}
// Ref: An Efficient Depth Linearization Method for Oblique View Frustums, Eq. 6.
var invProjParam = new Vector4(
gpuProj.m20 / (gpuProj.m00 * gpuProj.m23),
gpuProj.m21 / (gpuProj.m11 * gpuProj.m23),
-1.0f / gpuProj.m23,
(-gpuProj.m22
+ gpuProj.m20 * gpuProj.m02 / gpuProj.m00
+ gpuProj.m21 * gpuProj.m12 / gpuProj.m11) / gpuProj.m23
);
viewProjectionMatrix = gpuVP;
invViewProjectionMatrix = gpuVP.inverse;
invProjectionMatrix = gpuProj.inverse;
invProjectionParam = invProjParam;
m_LastFrameActive = Time.frameCount;
}
public void SetupMaterial(Material material)
{
material.SetVector("_ScreenSize", screenSize);
material.SetMatrix("_ViewProjMatrix", viewProjectionMatrix);
material.SetMatrix("_PrevViewProjMatrix", prevViewProjectionMatrix);
material.SetMatrix("_InvViewProjMatrix", invViewProjectionMatrix);
material.SetMatrix("_InvProjMatrix", invProjectionMatrix);
material.SetVector("_InvProjParam", invProjectionParam);
}
public void Reset()
{
m_LastFrameActive = -1;
m_FirstFrame = true;
}
static Dictionary<Camera, HDCamera> m_Cameras = new Dictionary<Camera, HDCamera>();
static List<Camera> m_Cleanup = new List<Camera>(); // Recycled to reduce GC pressure
// Grab the HDCamera tied to a given Camera and update it.
public static HDCamera Get(Camera camera)
{
HDCamera hdcam;
if (!m_Cameras.TryGetValue(camera, out hdcam))
{
hdcam = new HDCamera(camera);
m_Cameras.Add(camera, hdcam);
}
hdcam.Update();
return hdcam;
}
// Look for any camera that hasn't been used in the last frame and remove them for the pool.
public static void CleanUnused()
{
int frameCheck = Time.frameCount - 1;
foreach (var kvp in m_Cameras)
{
if (kvp.Value.m_LastFrameActive != frameCheck)
m_Cleanup.Add(kvp.Key);
}
foreach (var cam in m_Cleanup)
m_Cameras.Remove(cam);
m_Cleanup.Clear();
}
}
public class GBufferManager

Material m_FilterSubsurfaceScattering;
// <<< Old SSS Model
Material m_CameraMotionVectorsMaterial;
Material m_DebugViewMaterialGBuffer;
Material m_DebugDisplayLatlong;
Material m_DebugFullScreen;

// Detect when windows size is changing
int m_CurrentWidth;
int m_CurrentHeight;
// Use to detect frame changes
int m_FrameCount;
public int GetCurrentShadowCount() { return m_LightLoop.GetCurrentShadowCount(); }
public int GetShadowAtlasCount() { return m_LightLoop.GetShadowAtlasCount(); }

CreateSssMaterials(sssSettings.useDisneySSS);
// <<< Old SSS Model
m_CameraMotionVectorsMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CameraMotionVectors");
InitializeDebugMaterials();
// Init Gbuffer description

{
var cmd = CommandBufferPool.Get("Push Global Parameters");
cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize);
cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);
cmd.SetGlobalMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix);
cmd.SetGlobalMatrix("_InvProjMatrix", hdCamera.invProjectionMatrix);
cmd.SetGlobalVector("_InvProjParam", hdCamera.invProjectionParam);
cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize);
cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);
cmd.SetGlobalMatrix("_PrevViewProjMatrix", hdCamera.prevViewProjectionMatrix);
cmd.SetGlobalMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix);
cmd.SetGlobalMatrix("_InvProjMatrix", hdCamera.invProjectionMatrix);
cmd.SetGlobalVector("_InvProjParam", hdCamera.invProjectionParam);
// TODO: cmd.SetGlobalInt() does not exist, so we are forced to use Shader.SetGlobalInt() instead.

Shader.SetGlobalInt( "_TexturingModeFlags", (int)sssParameters.texturingModeFlags);
Shader.SetGlobalInt( "_TransmissionFlags", (int)sssParameters.transmissionFlags);
cmd.SetGlobalFloatArray( "_ThicknessRemaps", sssParameters.thicknessRemaps);
cmd.SetGlobalVectorArray("_ShapeParams", sssParameters.shapeParams);
// We are currently supporting two different SSS mode: Jimenez (with 2-Gaussian profile) and Disney
// We have added the ability to switch between each other for subsurface scattering, but for transmittance this is more tricky as we need to add
// shader variant for forward, gbuffer and deferred shader. We want to avoid this.
// So for transmittance we use Disney profile formulation (that we know is more correct) in both case, and in the case of Jimenez we hack the parameters with 2-Gaussian parameters (Ideally we should fit but haven't find good fit) so it approximately match.
// Note: Jimenez SSS is in cm unit whereas Disney is in mm unit making an inconsistency here to compare model side by side
cmd.SetGlobalVectorArray("_ShapeParams", sssParameters.useDisneySSS ? sssParameters.shapeParams : sssParameters.halfRcpWeightedVariances);
cmd.SetGlobalVectorArray("_TransmissionTints", sssParameters.transmissionTints);
renderContext.ExecuteCommandBuffer(cmd);

SupportedRenderingFeatures.active = s_NeededFeatures;
#endif
if (m_FrameCount != Time.frameCount)
{
HDCamera.CleanUnused();
m_FrameCount = Time.frameCount;
}
GraphicsSettings.lightsUseLinearIntensity = true;
GraphicsSettings.lightsUseColorTemperature = true;

renderContext.SetupCameraProperties(camera);
HDCamera hdCamera = Utilities.GetHDCamera(camera);
var hdCamera = HDCamera.Get(camera);
// TODO: Find a correct place to bind these material textures
// We have to bind the material specific global parameters in this mode

}
else
{
RenderVelocity(m_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 ?
RenderVelocity(m_CullResults, hdCamera, 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 ?
// TODO: Check with VFX team.
// Rendering distortion here have off course lot of artifact.

// Render GBuffer opaque
if (!m_Asset.renderingSettings.ShouldUseForwardRenderingOnly())
{
Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewMaterialGBuffer);
hdCamera.SetupMaterial(m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures
var cmd = CommandBufferPool.Get("DebugViewMaterialGBuffer" );

if (sssSettings.useDisneySSS)
{
cmd.SetGlobalTexture("_IrradianceSource", m_CameraSubsurfaceBufferRT); // Cannot set a RT on a material
// Temp >>>
Matrix4x4 viewMatrix = hdCamera.camera.worldToCameraMatrix;
viewMatrix.SetRow(2, -viewMatrix.GetRow(2)); // Make Z axis point forwards in the view space (left-handed CS)
Matrix4x4 projMatrix = GL.GetGPUProjectionMatrix(hdCamera.camera.projectionMatrix, false);
projMatrix.SetColumn(2, -projMatrix.GetColumn(2)); // Undo the view-space transformation
m_FilterAndCombineSubsurfaceScattering.SetMatrix("_ViewMatrix", viewMatrix);
m_FilterAndCombineSubsurfaceScattering.SetMatrix("_ProjMatrix", projMatrix);
// <<< Temp
m_FilterAndCombineSubsurfaceScattering.SetFloatArray("_WorldScales", sssParameters.worldScales);
m_FilterAndCombineSubsurfaceScattering.SetFloatArray("_FilterKernelsNearField", sssParameters.filterKernelsNearField);
m_FilterAndCombineSubsurfaceScattering.SetFloatArray("_FilterKernelsFarField", sssParameters.filterKernelsFarField);

}
}
void RenderVelocity(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
void RenderVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext)
{
using (new Utilities.ProfilingSample("Velocity", renderContext))
{

int w = camera.pixelWidth;
int h = camera.pixelHeight;
// These flags are still required in SRP or the engine won't compute previous model matrices...
// If the flag hasn't been set yet on this camera, motion vectors will skip a frame.
hdcam.camera.depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;
int w = (int)hdcam.screenSize.x;
int h = (int)hdcam.screenSize.y;
cmd.Blit(BuiltinRenderTextureType.None, m_VelocityBufferRT, m_CameraMotionVectorsMaterial, 0);
RenderOpaqueRenderList(cullResults, camera, renderContext, "MotionVectors");
RenderOpaqueRenderList(cullResults, hdcam.camera, renderContext, "MotionVectors", RendererConfiguration.PerObjectMotionVectors);
}
}

if (postProcessLayer != null && postProcessLayer.enabled)
{
cmd.SetGlobalTexture("_CameraDepthTexture", GetDepthTexture());
cmd.SetGlobalTexture("_CameraMotionVectorsTexture", m_VelocityBufferRT);
var context = m_PostProcessContext;
context.Reset();

context.camera = camera;
context.sourceFormat = RenderTextureFormat.ARGBHalf; // ?
context.sourceFormat = RenderTextureFormat.ARGBHalf;
context.flip = true;
postProcessLayer.Render(context);

17
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs


#if UNITY_EDITOR
const string k_HDRenderPipelinePath = "Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset";
[MenuItem("RenderPipeline/HDRenderPipeline/Create Pipeline Asset")]
[MenuItem("RenderPipeline/HDRenderPipeline/Create Pipeline Asset", false, 16)]
static void CreateHDRenderPipeline()
{
var instance = CreateInstance<HDRenderPipelineAsset>();

instance.renderPipelineResources = AssetDatabase.LoadAssetAtPath<RenderPipelineResources>(RenderPipelineResources.renderPipelineResourcesPath);
}
[UnityEditor.MenuItem("HDRenderPipeline/Add \"Additional Light Data\" (if not present)")]
static void AddAdditionalLightData()
{
Light[] lights = FindObjectsOfType(typeof(Light)) as Light[];
foreach (Light light in lights)
{
// Do not add a component if there already is one.
if (light.GetComponent<AdditionalLightData>() == null)
{
light.gameObject.AddComponent<AdditionalLightData>();
}
}
}
#endif

7
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader


outputs.specularLighting = float4(specularLighting, 1.0);
outputs.diffuseLighting = diffuseLighting;
#if defined(LIGHTLOOP_TILE_INDIRECT) || defined(LIGHTLOOP_TILE_ALL)
// Force non-0 indirect lighting to avoid SSS artifacts.
outputs.diffuseLighting.r = max(outputs.diffuseLighting.r, 0.000001);
// We SSSSS is enabled with use split lighting.
// SSSSS algorithm need to know which pixels contribute to SSS and which doesn't. We could use the stencil for that but it mean that it will increase the cost of SSSSS
// A simpler solution is to add a slight contribution here that isn't visible (here we chose fp16 min (which is also fp11 and fp10 min).
// The SSSSS algorithm will check if diffuse lighting is black and discard the pixel if it is the case
outputs.diffuseLighting.r = max(outputs.diffuseLighting.r, HFLT_MIN);
#endif
#else
outputs.combinedLighting = float4(diffuseLighting + specularLighting, 1.0);

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


if (GetFeatureVariantsEnabled())
{
// featureVariants
Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewTilesMaterial);
hdCamera.SetupMaterial(m_DebugViewTilesMaterial);
m_DebugViewTilesMaterial.SetInt("_NumTiles", numTiles);
m_DebugViewTilesMaterial.SetInt("_ViewTilesFlags", (int)m_TileSettings.tileDebugByCategory);
m_DebugViewTilesMaterial.SetVector("_MousePixelCoord", mousePixelCoord);

else if (m_TileSettings.tileDebugByCategory != TileSettings.TileDebug.None)
{
// lightCategories
Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewTilesMaterial);
hdCamera.SetupMaterial(m_DebugViewTilesMaterial);
m_DebugViewTilesMaterial.SetInt("_ViewTilesFlags", (int)m_TileSettings.tileDebugByCategory);
m_DebugViewTilesMaterial.SetVector("_MousePixelCoord", mousePixelCoord);
m_DebugViewTilesMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");

149
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl


// ===========================================================================
// WARNING:
// On PS4, texture/sampler declarations need to be outside of CBuffers
// Otherwise those parameters are not bound correctly at runtime.
// ===========================================================================
#ifndef LAYERED_LIT_SHADER
TEXTURE2D(_DiffuseLightingMap);
SAMPLER2D(sampler_DiffuseLightingMap);
TEXTURE2D(_DistortionVectorMap);
SAMPLER2D(sampler_DistortionVectorMap);
TEXTURE2D(_EmissiveColorMap);
SAMPLER2D(sampler_EmissiveColorMap);
TEXTURE2D(_BaseColorMap);
SAMPLER2D(sampler_BaseColorMap);
TEXTURE2D(_MaskMap);
SAMPLER2D(sampler_MaskMap);
TEXTURE2D(_SpecularOcclusionMap);
SAMPLER2D(sampler_SpecularOcclusionMap);
TEXTURE2D(_NormalMap);
SAMPLER2D(sampler_NormalMap);
TEXTURE2D(_NormalMapOS);
SAMPLER2D(sampler_NormalMapOS);
TEXTURE2D(_DetailMask);
SAMPLER2D(sampler_DetailMask);
TEXTURE2D(_DetailMap);
SAMPLER2D(sampler_DetailMap);
TEXTURE2D(_HeightMap);
SAMPLER2D(sampler_HeightMap);
TEXTURE2D(_TangentMap);
SAMPLER2D(sampler_TangentMap);
TEXTURE2D(_TangentMapOS);
SAMPLER2D(sampler_TangentMapOS);
TEXTURE2D(_AnisotropyMap);
SAMPLER2D(sampler_AnisotropyMap);
TEXTURE2D(_SubsurfaceRadiusMap);
SAMPLER2D(sampler_SubsurfaceRadiusMap);
TEXTURE2D(_ThicknessMap);
SAMPLER2D(sampler_ThicknessMap);
TEXTURE2D(_SpecularColorMap);
SAMPLER2D(sampler_SpecularColorMap);
#else
// Set of users variables
#define PROP_DECL(type, name) type name##0, name##1, name##2, name##3
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one
// mean we must declare all sampler
#define PROP_DECL_TEX2D(name)\
TEXTURE2D(MERGE_NAME(name, 0)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 0)); \
TEXTURE2D(MERGE_NAME(name, 1)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 1)); \
TEXTURE2D(MERGE_NAME(name, 2)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 2)); \
TEXTURE2D(MERGE_NAME(name, 3)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 3))
PROP_DECL_TEX2D(_BaseColorMap);
PROP_DECL_TEX2D(_MaskMap);
PROP_DECL_TEX2D(_SpecularOcclusionMap);
PROP_DECL_TEX2D(_NormalMap);
PROP_DECL_TEX2D(_NormalMapOS);
PROP_DECL_TEX2D(_HeightMap);
PROP_DECL_TEX2D(_DetailMask);
PROP_DECL_TEX2D(_DetailMap);
TEXTURE2D(_LayerMaskMap);
SAMPLER2D(sampler_LayerMaskMap);
#endif
CBUFFER_START(_PerMaterial)
// shared constant between lit and layered lit

float _PPDMinSamples;
float _PPDLodThreshold;
TEXTURE2D(_DiffuseLightingMap);
SAMPLER2D(sampler_DiffuseLightingMap);
TEXTURE2D(_DistortionVectorMap);
SAMPLER2D(sampler_DistortionVectorMap);
TEXTURE2D(_EmissiveColorMap);
SAMPLER2D(sampler_EmissiveColorMap);
float _EmissiveIntensity;
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"

// Set of users variables
float4 _BaseColor;
TEXTURE2D(_BaseColorMap);
SAMPLER2D(sampler_BaseColorMap);
TEXTURE2D(_MaskMap);
SAMPLER2D(sampler_MaskMap);
TEXTURE2D(_SpecularOcclusionMap);
SAMPLER2D(sampler_SpecularOcclusionMap);
TEXTURE2D(_NormalMap);
SAMPLER2D(sampler_NormalMap);
TEXTURE2D(_NormalMapOS);
SAMPLER2D(sampler_NormalMapOS);
TEXTURE2D(_DetailMask);
SAMPLER2D(sampler_DetailMask);
TEXTURE2D(_DetailMap);
SAMPLER2D(sampler_DetailMap);
TEXTURE2D(_HeightMap);
SAMPLER2D(sampler_HeightMap);
TEXTURE2D(_TangentMap);
SAMPLER2D(sampler_TangentMap);
TEXTURE2D(_TangentMapOS);
SAMPLER2D(sampler_TangentMapOS);
TEXTURE2D(_AnisotropyMap);
SAMPLER2D(sampler_AnisotropyMap);
TEXTURE2D(_SubsurfaceRadiusMap);
SAMPLER2D(sampler_SubsurfaceRadiusMap);
TEXTURE2D(_ThicknessMap);
SAMPLER2D(sampler_ThicknessMap);
TEXTURE2D(_SpecularColorMap);
SAMPLER2D(sampler_SpecularColorMap);
float _TexWorldScale;
float4 _UVMappingMask;

// Set of users variables
#define PROP_DECL(type, name) type name##0, name##1, name##2, name##3
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one
// mean we must declare all sampler
#define PROP_DECL_TEX2D(name)\
TEXTURE2D(MERGE_NAME(name, 0)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 0)); \
TEXTURE2D(MERGE_NAME(name, 1)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 1)); \
TEXTURE2D(MERGE_NAME(name, 2)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 2)); \
TEXTURE2D(MERGE_NAME(name, 3)); \
SAMPLER2D(MERGE_NAME(MERGE_NAME(sampler, name), 3))
// Set of users variables
PROP_DECL_TEX2D(_BaseColorMap);
float4 _BaseColorMap0_ST;
float4 _BaseColorMap1_ST;
float4 _BaseColorMap2_ST;

PROP_DECL(float, _Smoothness);
PROP_DECL_TEX2D(_MaskMap);
PROP_DECL_TEX2D(_SpecularOcclusionMap);
PROP_DECL_TEX2D(_NormalMap);
PROP_DECL_TEX2D(_NormalMapOS);
PROP_DECL_TEX2D(_HeightMap);
PROP_DECL_TEX2D(_DetailMask);
PROP_DECL_TEX2D(_DetailMap);
float4 _DetailMap0_ST;
float4 _DetailMap1_ST;
float4 _DetailMap2_ST;

PROP_DECL(float, _HeightAmplitude);
PROP_DECL(float, _HeightCenter);
TEXTURE2D(_LayerMaskMap);
SAMPLER2D(sampler_LayerMaskMap);
float _BlendUsingHeight1;
float _BlendUsingHeight2;

175
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


#pragma multi_compile _ SSS_FILTER_HORIZONTAL_AND_COMBINE
// <<< Old SSS Model
// Tweak parameters for the Disney SSS below.
#define SSS_BILATERAL_FILTER 1
#define SSS_USE_TANGENT_PLANE 0
#define SSS_CLAMP_ARTIFACT 0
#define SSS_DEBUG_LOD 0
#define SSS_DEBUG_NORMAL_VS 0
// Do not modify these.
#define SSS_BILATERAL 1
#define SSS_DEBUG 0
#ifdef SSS_MODEL_BASIC
#define RBG_BILATERAL_WEIGHTS 0
#endif
//-------------------------------------------------------------------------------------
// Include

// Inputs & outputs
//-------------------------------------------------------------------------------------
float4x4 _ViewMatrix, _ProjMatrix; // TEMP: make these global
float _FilterKernelsNearField[SSS_N_PROFILES][SSS_N_SAMPLES_NEAR_FIELD][2]; // 0 = radius, 1 = reciprocal of the PDF
float _FilterKernelsFarField[SSS_N_PROFILES][SSS_N_SAMPLES_FAR_FIELD][2]; // 0 = radius, 1 = reciprocal of the PDF
#else

return /* 0.25 * */ S * (expOneThird + expOneThird * expOneThird * expOneThird);
}
// Computes F(x)/P(x), s.t. x = sqrt(r^2 + t^2).
float3 ComputeBilateralWeight(float3 S, float r, float t, float rcpDistScale, float rcpPdf)
// Computes F(r)/P(r), s.t. r = sqrt(a^2 + b^2).
// Rescaling of the PDF is handled by 'totalWeight'.
float3 ComputeBilateralWeight(float a2, float b, float mmPerUnit, float3 S, float rcpPdf)
#if (SSS_BILATERAL == 0)
t = 0;
#if (SSS_BILATERAL_FILTER == 0)
b = 0;
// Reducing the integration distance is equivalent to stretching the integration axis.
float3 val = KernelValCircle(sqrt(r * r + t * t) * rcpDistScale, S);
// Rescaling of the PDF is handled via 'totalWeight'.
return val * rcpPdf;
#if SSS_USE_TANGENT_PLANE
// Both 'a2' and 'b2' require unit conversion.
float r = sqrt(a2 + b * b) * mmPerUnit;
#else
// Only 'b2' requires unit conversion.
float r = sqrt(a2 + (b * mmPerUnit) * (b * mmPerUnit));
#endif
#if SSS_CLAMP_ARTIFACT
return saturate(KernelValCircle(r, S) * rcpPdf);
#else
return KernelValCircle(r, S) * rcpPdf;
#endif
#define SSS_ITER(i, n, kernel, profileID, shapeParam, centerPosUnSS, centerDepthVS, \
millimPerUnit, scaledPixPerMm, rcpDistScale, totalIrradiance, totalWeight) \
#define SSS_ITER(i, n, kernel, profileID, shapeParam, centerPosUnSS, centerPosVS, \
useTangentPlane, tangentX, tangentY, mmPerUnit, pixelsPerMm, \
totalIrradiance, totalWeight) \
float phi = TWO_PI * Fibonacci2d(i, n).y; \
float phi = SampleDiskFibonacci(i, n).y; \
float2 position = centerPosUnSS + vec * scaledPixPerMm; \
float3 irradiance = LOAD_TEXTURE2D(_IrradianceSource, position).rgb; \
/* Compute the screen-space position and the associated irradiance. */ \
float2 position; float3 irradiance; \
/* Compute the squared distance (in mm) in the screen-aligned plane. */ \
float dXY2; \
\
if (useTangentPlane) \
{ \
/* 'vec' is given relative to the tangent frame. */ \
float3 relPosVS = vec.x * tangentX + vec.y * tangentY; \
float3 positionVS = centerPosVS + relPosVS; \
float4 positionCS = mul(_ProjMatrix, float4(positionVS, 1)); \
float2 positionSS = positionCS.xy * (rcp(positionCS.w) * 0.5) + 0.5; \
\
position = positionSS * _ScreenSize.xy; \
irradiance = LOAD_TEXTURE2D(_IrradianceSource, position).rgb; \
dXY2 = dot(relPosVS.xy, relPosVS.xy); \
} \
else \
{ \
/* 'vec' is given directly in screen-space. */ \
position = centerPosUnSS + vec * pixelsPerMm; \
irradiance = LOAD_TEXTURE2D(_IrradianceSource, position).rgb; \
dXY2 = r * r; \
} \
\
/* TODO: see if making this a [branch] improves performance. */ \
[flatten] \

float z = LOAD_TEXTURE2D(_MainDepthTexture, position).r; \
float d = LinearEyeDepth(z, _ZBufferParams); \
float t = millimPerUnit * d - (millimPerUnit * centerDepthVS); \
float t = d - centerPosVS.z; \
float3 w = ComputeBilateralWeight(shapeParam, r, t, rcpDistScale, p); \
float3 w = ComputeBilateralWeight(dXY2, t, mmPerUnit, shapeParam, p); \
\
totalIrradiance += w * irradiance; \
totalWeight += w; \

/* Our blur is energy-preserving, so 'centerWeight' should be set to 0. */ \
/* We do not terminate the loop since we want to gather the contribution */ \
/* of the remaining samples (e.g. in case of hair covering skin). */ \
/* Note: See comment in the output of deferred.shader */ \
#define SSS_LOOP(n, kernel, profileID, shapeParam, centerPosUnSS, centerDepthVS, \
millimPerUnit, scaledPixPerMm, rcpDistScale, totalIrradiance, totalWeight) \
#define SSS_LOOP(n, kernel, profileID, shapeParam, centerPosUnSS, centerPosVS, \
useTangentPlane, tangentX, tangentY, mmPerUnit, pixelsPerMm, \
totalIrradiance, totalWeight) \
float centerRadius = kernel[profileID][0][0]; \
float3 centerWeight = KernelValCircle(0, shapeParam) * centerRcpPdf; \
float3 centerWeight = KernelValCircle(centerRadius, shapeParam) * centerRcpPdf; \
/* Perform integration over the screen-aligned plane in the view space. */ \
/* TODO: it would be more accurate to use the tangent plane instead. */ \
/* Integrate over the screen-aligned or tangent plane in the view space. */ \
SSS_ITER(i, n, kernel, profileID, shapeParam, centerPosUnSS, centerDepthVS, \
millimPerUnit, scaledPixPerMm, rcpDistScale, totalIrradiance, totalWeight) \
SSS_ITER(i, n, kernel, profileID, shapeParam, centerPosUnSS, centerPosVS, \
useTangentPlane, tangentX, tangentY, mmPerUnit, pixelsPerMm, \
totalIrradiance, totalWeight) \
} \
}

float maxDistance = _FilterKernelsBasic[profileID][SSS_BASIC_N_SAMPLES - 1].a;
#endif
// Take the first (central) sample.
// TODO: copy its neighborhood into LDS.
float2 centerPosition = posInput.unPositionSS;
float3 centerIrradiance = LOAD_TEXTURE2D(_IrradianceSource, centerPosition).rgb;
float centerDepth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.unPositionSS).r;
float centerDepth = LOAD_TEXTURE2D(_MainDepthTexture, centerPosition).r;
// Compute the view-space dimensions of the pixel as a quad projected onto geometry.
float2 unitsPerPixel = 2 * (cornerPosVS.xy - centerPosVS.xy);
float metersPerUnit = _WorldScales[profileID];
float millimPerUnit = MILLIMETERS_PER_METER * metersPerUnit;
float2 scaledPixPerMm = distScale * rcp(millimPerUnit * unitsPerPixel);
// Take the first (central) sample.
// TODO: copy its neighborhood into LDS.
float2 centerPosition = posInput.unPositionSS;
float3 centerIrradiance = LOAD_TEXTURE2D(_IrradianceSource, centerPosition).rgb;
// Rescaling the filter is equivalent to inversely scaling the world.
float mmPerUnit = MILLIMETERS_PER_METER * (_WorldScales[profileID] / distScale);
float unitsPerMm = rcp(mmPerUnit);
float maxDistInPixels = maxDistance * max(scaledPixPerMm.x, scaledPixPerMm.y);
// Compute the view-space dimensions of the pixel as a quad projected onto geometry.
float2 unitsPerPixel = 2 * abs(cornerPosVS.xy - centerPosVS.xy);
float2 pixelsPerMm = rcp(unitsPerPixel) * unitsPerMm;
// N.b.: our LoD selection algorithm is the same regardless of
// whether we integrate over the tangent plane or not, since we
// don't want the orientation of the tangent plane to create
// divergence of execution across the warp.
float maxDistInPixels = maxDistance * max(pixelsPerMm.x, pixelsPerMm.y);
#if SSS_DEBUG
#if SSS_DEBUG_LOD
return float4(0, 0, 1, 1);
#else
return float4(bsdfData.diffuseColor * centerIrradiance, 1);

const bool useTangentPlane = SSS_USE_TANGENT_PLANE != 0;
// Compute the tangent frame in view space.
float3 normalVS = mul((float3x3)_ViewMatrix, bsdfData.normalWS);
float3 tangentX = GetLocalFrame(normalVS)[0] * unitsPerMm;
float3 tangentY = GetLocalFrame(normalVS)[1] * unitsPerMm;
#if SSS_DEBUG_NORMAL_VS
// We expect the view-space normal to be front-facing.
if (normalVS.z >= 0) return float4(1, 0, 0, 1);
#endif
// Accumulate filtered irradiance and bilateral weights (for renormalization).
float3 totalIrradiance, totalWeight;

{
#if SSS_DEBUG
#if SSS_DEBUG_LOD
profileID, shapeParam, centerPosition, centerPosVS.z,
millimPerUnit, scaledPixPerMm, rcp(distScale),
profileID, shapeParam, centerPosition, centerPosVS,
useTangentPlane, tangentX, tangentY, mmPerUnit, pixelsPerMm,
#if SSS_DEBUG
#if SSS_DEBUG_LOD
profileID, shapeParam, centerPosition, centerPosVS.z,
millimPerUnit, scaledPixPerMm, rcp(distScale),
profileID, shapeParam, centerPosition, centerPosVS,
useTangentPlane, tangentX, tangentY, mmPerUnit, pixelsPerMm,
float metersPerUnit = _WorldScales[profileID] * SSS_BASIC_DISTANCE_SCALE;
float centimPerUnit = CENTIMETERS_PER_METER * metersPerUnit;
float2 scaledPixPerCm = distScale * rcp(centimPerUnit * unitsPerPixel);
float unitScale = centimPerUnit / distScale;
// Rescaling the filter is equivalent to inversely scaling the world.
float metersPerUnit = _WorldScales[profileID] / distScale * SSS_BASIC_DISTANCE_SCALE;
float centimPerUnit = CENTIMETERS_PER_METER * metersPerUnit;
// Compute the view-space dimensions of the pixel as a quad projected onto geometry.
float2 unitsPerPixel = 2 * abs(cornerPosVS.xy - centerPosVS.xy);
float2 pixelsPerCm = rcp(centimPerUnit * unitsPerPixel);
float scaledStepSize = scaledPixPerCm.x;
float2 unitDirection = float2(1, 0);
float2 unitDirection = float2(1, 0);
float scaledStepSize = scaledPixPerCm.y;
float2 unitDirection = float2(0, 1);
float2 unitDirection = float2(0, 1);
float2 scaledDirection = scaledPixPerCm * unitDirection;
float2 scaledDirection = pixelsPerCm * unitDirection;
#if (RBG_BILATERAL_WEIGHTS != 0)
#if RBG_BILATERAL_WEIGHTS
float3 halfRcpVariance = _HalfRcpWeightedVariances[profileID].rgb;
#else
float halfRcpVariance = _HalfRcpWeightedVariances[profileID].a;

// We perform point sampling. Therefore, we can avoid the cost
// of filtering if we stay within the bounds of the current pixel.
// We use the value of 1 instead of 0.5 as an optimization.
float maxDistInPixels = scaledStepSize * maxDistance;
float maxDistInPixels = maxDistance * max(pixelsPerCm.x, pixelsPerCm.y);
[branch]
if (distScale == 0 || maxDistInPixels < 1)

// Ref #2: Separable SSS, Supplementary Materials, Section E.
float rawDepth = LOAD_TEXTURE2D(_MainDepthTexture, samplePosition).r;
float sampleDepth = LinearEyeDepth(rawDepth, _ZBufferParams);
float zDistance = unitScale * sampleDepth - (unitScale * centerPosVS.z);
float zDistance = centimPerUnit * sampleDepth - (centimPerUnit * centerPosVS.z);
sampleWeight *= exp(-zDistance * zDistance * halfRcpVariance);
totalIrradiance += sampleWeight * sampleIrradiance;

14
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs


// Clamp to avoid artifacts.
m_ShapeParam = new Vector3();
m_ShapeParam.x = Mathf.Min(1000f, 1.0f / scatteringDistance.r);
m_ShapeParam.y = Mathf.Min(1000f, 1.0f / scatteringDistance.g);
m_ShapeParam.z = Mathf.Min(1000f, 1.0f / scatteringDistance.b);
m_ShapeParam.x = 1.0f / Mathf.Max(0.001f, scatteringDistance.r);
m_ShapeParam.y = 1.0f / Mathf.Max(0.001f, scatteringDistance.g);
m_ShapeParam.z = 1.0f / Mathf.Max(0.001f, scatteringDistance.b);
// We importance sample the color channel with the widest scattering distance.
float s = Mathf.Min(m_ShapeParam.x, m_ShapeParam.y, m_ShapeParam.z);

// ------------------------------------------------------------------------------------
// Importance sample the near field kernel.
for (int i = 0; i < SssConstants.SSS_N_SAMPLES_NEAR_FIELD; i++)
for (int i = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; i < n; i++)
float p = i * (1.0f / SssConstants.SSS_N_SAMPLES_NEAR_FIELD);
float p = (i + 0.5f) * (1.0f / n);
float r = KernelCdfInverse(p, s);
// N.b.: computation of normalized weights, and multiplication by the surface albedo

m_MaxRadius = m_FilterKernelNearField[SssConstants.SSS_N_SAMPLES_NEAR_FIELD - 1].x;
// Importance sample the far field kernel.
for (int i = 0; i < SssConstants.SSS_N_SAMPLES_FAR_FIELD; i++)
for (int i = 0, n = SssConstants.SSS_N_SAMPLES_FAR_FIELD; i < n; i++)
float p = i * (1.0f / SssConstants.SSS_N_SAMPLES_FAR_FIELD);
float p = (i + 0.5f) * (1.0f / n);
float r = KernelCdfInverse(p, s);
// N.b.: computation of normalized weights, and multiplication by the surface albedo

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/MaterialUtilities.hlsl


positionCS.xy = positionCS.xy / positionCS.w;
previousPositionCS.xy = previousPositionCS.xy / previousPositionCS.w;
return (positionCS.xy - previousPositionCS.xy) * _ForceNoMotion;
return (positionCS.xy - previousPositionCS.xy) * unity_MotionVectorsParams.y;
#else
return float2(0.0, 0.0);
#endif

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset


buildMaterialFlagsShader: {fileID: 7200000, guid: fb3eda953cd6e634e877fb777be2cd08,
type: 3}
shadeOpaqueShader: {fileID: 7200000, guid: 0b64f79746d2daf4198eaf6eab9af259, type: 3}
cameraMotionVectors: {fileID: 4800000, guid: 035941b63024d1943af48811c1db20d9, type: 3}
blitCubemap: {fileID: 4800000, guid: d05913e251bed7a4992c921c62e1b647, type: 3}
buildProbabilityTables: {fileID: 7200000, guid: b9f26cf340afe9145a699753531b2a4c,
type: 3}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset.meta


fileFormatVersion: 2
guid: 42086e81f4f0c724f96f7f09cc995354
timeCreated: 1497363538
timeCreated: 1497525010
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs


// TODO skybox/cubemap
[UnityEditor.MenuItem("RenderPipeline/HDRenderPipeline/Create Resources Asset")]
[UnityEditor.MenuItem("RenderPipeline/HDRenderPipeline/Create Resources Asset", false, 15)]
static void CreateRenderPipelineResources()
{
var instance = CreateInstance<RenderPipelineResources>();

// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime (only to draw in editor)
// instance.drawSssProfile = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/DrawSssProfile.shader");
// instance.drawTransmittanceGraphShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/DrawTransmittanceGraph.shader");
instance.cameraMotionVectors = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/CameraMotionVectors.shader");
// Sky
instance.blitCubemap = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/BlitCubemap.shader");

// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime (only to draw in editor)
// public Shader drawSssProfile;
// public Shader drawTransmittanceGraphShader;
public Shader cameraMotionVectors;
// Sky
public Shader blitCubemap;

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs


[GenerateHLSL(PackingRules.Exact)]
public enum ShaderOptions
{
// TODO: Currently it is not yet possible to use this feature, we need to provide previousPositionCS to the vertex shader as part of Attribute for GBuffer pass
// TODO: How to enable this feature only on mesh that effectively require it like skinned and moving mesh (other can be done with depth reprojection. But TAA can be an issue)
// TODO: It is not possible to use VelocityInGBuffer feature yet. This feature allow to render motion vectors during Gbuffer pass. However Unity have limitation today that forbid to do that.
// 1) Currently previousPositionCS is provide to the vertex shader with a hard coded NORMAL semantic (in the vertex declaration - See MeshRenderingData.cpp "pSecondaryFormat = gMotionVectorRenderFormat.GetVertexFormat();") mean it will overwrite the normal
// 2) All current available semantic (see ShaderChannelMask) are used in our Lit shader. Mean just changing the semantic is not enough, Unity need to unlock other Texcoord semantic
// 3) When this is solve (i.e move previousPositionCS to a free attribute semantic), Unity only support one pSecondaryFormat. Mean if we ahve a vertex color instance stream and motion vector, motion vector will overwrite vertex color stream. See MeshRenderingData.cpp
// All this could be fix we a new Mesh API not ready yet. Note that this feature only affect animated mesh (vertex or skin) as others use depth reprojection.
// TODO: not working yet, waiting for UINT16 RT format support
PackGBufferInU16 = 0
};

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl


// It is not possible to correctly generate the motion vector for tesselated geometry as tessellation parameters can change
// from one frame to another (adaptative, lod) + in Unity we only receive information for one non tesselated vertex.
// So motion vetor will be based on interpolate previous position at vertex level instead.
varyingsType.vpass.positionCS = mul(_NonJitteredVP, mul(unity_ObjectToWorld, float4(inputMesh.positionOS, 1.0)));
varyingsType.vpass.previousPositionCS = mul(_PreviousVP, mul(_PreviousM, _HasLastPositionData ? float4(inputPass.previousPositionOS, 1.0) : float4(inputMesh.positionOS, 1.0)));
varyingsType.vpass.positionCS = mul(_ViewProjMatrix, mul(unity_ObjectToWorld, float4(inputMesh.positionOS, 1.0)));
varyingsType.vpass.previousPositionCS = mul(_PrevViewProjMatrix, mul(unity_MatrixPreviousM, unity_MotionVectorsParams.x ? float4(inputPass.previousPositionOS, 1.0) : float4(inputMesh.positionOS, 1.0)));
return PackVaryingsType(varyingsType);
}

11
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl


SAMPLER3D(samplerunity_ProbeVolumeSH);
CBUFFER_START(UnityVelocityPass)
float4x4 _NonJitteredVP;
float4x4 _PreviousVP;
float4x4 _PreviousM;
bool _HasLastPositionData;
bool _ForceNoMotion;
float _MotionVectorDepthBias;
float4x4 unity_MatrixNonJitteredVP;
float4x4 unity_MatrixPreviousVP;
float4x4 unity_MatrixPreviousM;
float4 unity_MotionVectorsParams;
CBUFFER_END
// ----------------------------------------------------------------------------

float4x4 _ViewProjMatrix; // Looks like using UNITY_MATRIX_VP in pixel shader doesn't work ??? need to setup my own...
float4x4 _PrevViewProjMatrix;
float4x4 _InvViewProjMatrix;
float4x4 _InvProjMatrix;
float4 _InvProjParam;

42
Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs


return gpuVP;
}
public static HDCamera GetHDCamera(Camera camera)
{
HDCamera hdCamera = new HDCamera();
hdCamera.camera = camera;
hdCamera.screenSize = new Vector4(camera.pixelWidth, camera.pixelHeight, 1.0f / camera.pixelWidth, 1.0f / camera.pixelHeight);
// The actual projection matrix used in shaders is actually massaged a bit to work across all platforms
// (different Z value ranges etc.)
var gpuProj = GL.GetGPUProjectionMatrix(camera.projectionMatrix, false);
var gpuVP = gpuProj * camera.worldToCameraMatrix;
// Ref: An Efficient Depth Linearization Method for Oblique View Frustums, Eq. 6.
Vector4 invProjectionParam = new Vector4(gpuProj.m20 / (gpuProj.m00 * gpuProj.m23),
gpuProj.m21 / (gpuProj.m11 * gpuProj.m23),
-1.0f / gpuProj.m23,
(-gpuProj.m22
+ gpuProj.m20 * gpuProj.m02 / gpuProj.m00
+ gpuProj.m21 * gpuProj.m12 / gpuProj.m11) / gpuProj.m23);
hdCamera.viewProjectionMatrix = gpuVP;
hdCamera.invViewProjectionMatrix = gpuVP.inverse;
hdCamera.invProjectionMatrix = gpuProj.inverse;
hdCamera.invProjectionParam = invProjectionParam;
return hdCamera;
}
public static void SetupMaterialHDCamera(HDCamera hdCamera, Material material)
{
material.SetVector("_ScreenSize", hdCamera.screenSize);
material.SetMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);
material.SetMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix);
material.SetMatrix("_InvProjMatrix", hdCamera.invProjectionMatrix);
material.SetVector("_InvProjParam", hdCamera.invProjectionParam);
}
// TEMP: These functions should be implemented C++ side, for now do it in C#
static List<float> m_FloatListdata = new List<float>();
public static void SetMatrixCS(CommandBuffer cmd, ComputeShader shadercs, string name, Matrix4x4 mat)

RenderTargetIdentifier colorBuffer,
MaterialPropertyBlock properties = null, int shaderPassID = 0)
{
SetupMaterialHDCamera(camera, material);
camera.SetupMaterial(material);
commandBuffer.SetRenderTarget(colorBuffer);
commandBuffer.DrawProcedural(Matrix4x4.identity, material, shaderPassID, MeshTopology.Triangles, 3, 1, properties);
}

RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthStencilBuffer,
MaterialPropertyBlock properties = null, int shaderPassID = 0)
{
SetupMaterialHDCamera(camera, material);
camera.SetupMaterial(material);
commandBuffer.SetRenderTarget(colorBuffer, depthStencilBuffer);
commandBuffer.DrawProcedural(Matrix4x4.identity, material, shaderPassID, MeshTopology.Triangles, 3, 1, properties);
}

RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthStencilBuffer,
MaterialPropertyBlock properties = null, int shaderPassID = 0)
{
SetupMaterialHDCamera(camera, material);
camera.SetupMaterial(material);
commandBuffer.SetRenderTarget(colorBuffers, depthStencilBuffer);
commandBuffer.DrawProcedural(Matrix4x4.identity, material, shaderPassID, MeshTopology.Triangles, 3, 1, properties);
}

2
Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl


#define FLT_MIN 1.175494351e-38 // Minimum representable positive floating-point number
#define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number
#define HFLT_MIN 0.00006103515625 // 2^14 it is the same for 10, 11 and 16bit float. ref: https://www.khronos.org/opengl/wiki/Small_Float_Formats
float DegToRad(float deg)
{
return deg * PI / 180.0;

36
Assets/ScriptableRenderPipeline/ShaderLibrary/CommonLighting.hlsl


return N;
}
// Generates an orthonormal basis from a unit vector.
// Generates an orthonormal right-handed basis from a unit vector.
// Ref: http://marc-b-reynolds.github.io/quaternions/2016/07/06/Orthonormal.html
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));
float3 localY = cross(localZ, localX);
return float3x3(localX, localY, localZ);
}
float x = localZ.x;
float y = localZ.y;
float z = localZ.z;
float sz = z >= 0 ? 1 : -1;
float a = 1 / (sz + z);
float ya = y * a;
float b = x * ya;
float c = x * sz;
// TODO: test
/*
// http://orbit.dtu.dk/files/57573287/onb_frisvad_jgt2012.pdf
void GetLocalFrame(float3 N, out float3 tangentX, out float3 tangentY)
{
if (N.z < -0.999) // Handle the singularity
{
tangentX = float3(0.0, -1.0, 0.0);
tangentY = float3(-1.0, 0.0, 0.0);
return ;
}
float3 localX = float3(c * x * a - 1, sz * b, c);
float3 localY = float3(b, y * ya - sz, y);
float a = 1.0 / (1.0 + N.z);
float b = -N.x * N.y * a;
tangentX = float3(1.0 - N.x * N.x * a , b, -N.x);
tangentY = float3(b, 1.0 - N.y * N.y * a, -N.y);
return float3x3(localX, localY, localZ);
*/
#endif // UNITY_COMMON_LIGHTING_INCLUDED

427
Assets/ScriptableRenderPipeline/ShaderLibrary/Fibonacci.hlsl


// Computes a point using the Fibonacci sequence of length N.
// Input: Fib[N - 1], Fib[N - 2], and the index 'i' of the point.
// Ref: Integration of nonperiodic functions of two variables by Fibonacci lattice rules
// Ref: Efficient Quadrature Rules for Illumination Integrals
return float2(i / fibN1, frac(i * (fibN2 / fibN1)));
// N.b.: According to Swinbank and Pusser [SP06], the uniformity of the distribution
// can be slightly improved by introducing an offset of 1/N to the Z (or R) coordinates.
return float2(i / fibN1 + (0.5f / fibN1), frac(i * (fibN2 / fibN1)));
}
static const int k_FibonacciSeq[] = {

static const float2 k_Fibonacci2dSeq21[] = {
float2(0.00000000, 0.00000000),
float2(0.04761905, 0.61904764),
float2(0.09523810, 0.23809528),
float2(0.14285715, 0.85714293),
float2(0.19047619, 0.47619057),
float2(0.23809524, 0.09523821),
float2(0.28571430, 0.71428585),
float2(0.33333334, 0.33333349),
float2(0.38095239, 0.95238113),
float2(0.42857143, 0.57142878),
float2(0.47619048, 0.19047642),
float2(0.52380955, 0.80952406),
float2(0.57142860, 0.42857170),
float2(0.61904764, 0.04761887),
float2(0.66666669, 0.66666698),
float2(0.71428573, 0.28571510),
float2(0.76190478, 0.90476227),
float2(0.80952382, 0.52380943),
float2(0.85714287, 0.14285755),
float2(0.90476191, 0.76190567),
float2(0.95238096, 0.38095284)
float2(0.02380952, 0.00000000),
float2(0.07142857, 0.61904764),
float2(0.11904762, 0.23809528),
float2(0.16666667, 0.85714293),
float2(0.21428572, 0.47619057),
float2(0.26190478, 0.09523821),
float2(0.30952382, 0.71428585),
float2(0.35714287, 0.33333349),
float2(0.40476191, 0.95238113),
float2(0.45238096, 0.57142878),
float2(0.50000000, 0.19047642),
float2(0.54761904, 0.80952406),
float2(0.59523809, 0.42857170),
float2(0.64285713, 0.04761887),
float2(0.69047618, 0.66666698),
float2(0.73809522, 0.28571510),
float2(0.78571427, 0.90476227),
float2(0.83333331, 0.52380943),
float2(0.88095236, 0.14285755),
float2(0.92857140, 0.76190567),
float2(0.97619045, 0.38095284)
float2(0.00000000, 0.00000000),
float2(0.02941176, 0.61764705),
float2(0.05882353, 0.23529410),
float2(0.08823530, 0.85294116),
float2(0.11764706, 0.47058821),
float2(0.14705883, 0.08823538),
float2(0.17647059, 0.70588231),
float2(0.20588236, 0.32352924),
float2(0.23529412, 0.94117641),
float2(0.26470590, 0.55882359),
float2(0.29411766, 0.17647076),
float2(0.32352942, 0.79411745),
float2(0.35294119, 0.41176462),
float2(0.38235295, 0.02941132),
float2(0.41176471, 0.64705849),
float2(0.44117647, 0.26470566),
float2(0.47058824, 0.88235283),
float2(0.50000000, 0.50000000),
float2(0.52941179, 0.11764717),
float2(0.55882353, 0.73529434),
float2(0.58823532, 0.35294151),
float2(0.61764705, 0.97058773),
float2(0.64705884, 0.58823490),
float2(0.67647058, 0.20588207),
float2(0.70588237, 0.82352924),
float2(0.73529410, 0.44117641),
float2(0.76470590, 0.05882263),
float2(0.79411763, 0.67646980),
float2(0.82352942, 0.29411697),
float2(0.85294116, 0.91176414),
float2(0.88235295, 0.52941132),
float2(0.91176468, 0.14705849),
float2(0.94117647, 0.76470566),
float2(0.97058821, 0.38235283)
float2(0.01470588, 0.00000000),
float2(0.04411765, 0.61764705),
float2(0.07352941, 0.23529410),
float2(0.10294118, 0.85294116),
float2(0.13235295, 0.47058821),
float2(0.16176471, 0.08823538),
float2(0.19117647, 0.70588231),
float2(0.22058824, 0.32352924),
float2(0.25000000, 0.94117641),
float2(0.27941176, 0.55882359),
float2(0.30882353, 0.17647076),
float2(0.33823529, 0.79411745),
float2(0.36764705, 0.41176462),
float2(0.39705881, 0.02941132),
float2(0.42647058, 0.64705849),
float2(0.45588234, 0.26470566),
float2(0.48529410, 0.88235283),
float2(0.51470590, 0.50000000),
float2(0.54411763, 0.11764717),
float2(0.57352942, 0.73529434),
float2(0.60294116, 0.35294151),
float2(0.63235295, 0.97058773),
float2(0.66176468, 0.58823490),
float2(0.69117647, 0.20588207),
float2(0.72058821, 0.82352924),
float2(0.75000000, 0.44117641),
float2(0.77941179, 0.05882263),
float2(0.80882353, 0.67646980),
float2(0.83823532, 0.29411697),
float2(0.86764705, 0.91176414),
float2(0.89705884, 0.52941132),
float2(0.92647058, 0.14705849),
float2(0.95588237, 0.76470566),
float2(0.98529410, 0.38235283)
float2(0.00000000, 0.00000000),
float2(0.01818182, 0.61818182),
float2(0.03636364, 0.23636365),
float2(0.05454545, 0.85454547),
float2(0.07272727, 0.47272730),
float2(0.09090909, 0.09090900),
float2(0.10909091, 0.70909095),
float2(0.12727273, 0.32727289),
float2(0.14545454, 0.94545460),
float2(0.16363636, 0.56363630),
float2(0.18181819, 0.18181801),
float2(0.20000000, 0.80000019),
float2(0.21818182, 0.41818190),
float2(0.23636363, 0.03636360),
float2(0.25454545, 0.65454578),
float2(0.27272728, 0.27272701),
float2(0.29090908, 0.89090919),
float2(0.30909091, 0.50909138),
float2(0.32727271, 0.12727261),
float2(0.34545454, 0.74545479),
float2(0.36363637, 0.36363602),
float2(0.38181818, 0.98181820),
float2(0.40000001, 0.60000038),
float2(0.41818181, 0.21818161),
float2(0.43636364, 0.83636379),
float2(0.45454547, 0.45454597),
float2(0.47272727, 0.07272720),
float2(0.49090910, 0.69090843),
float2(0.50909090, 0.30909157),
float2(0.52727270, 0.92727280),
float2(0.54545456, 0.54545403),
float2(0.56363636, 0.16363716),
float2(0.58181816, 0.78181839),
float2(0.60000002, 0.39999962),
float2(0.61818182, 0.01818275),
float2(0.63636363, 0.63636398),
float2(0.65454543, 0.25454521),
float2(0.67272729, 0.87272835),
float2(0.69090909, 0.49090958),
float2(0.70909089, 0.10909081),
float2(0.72727275, 0.72727203),
float2(0.74545455, 0.34545517),
float2(0.76363635, 0.96363640),
float2(0.78181821, 0.58181763),
float2(0.80000001, 0.20000076),
float2(0.81818181, 0.81818199),
float2(0.83636361, 0.43636322),
float2(0.85454547, 0.05454636),
float2(0.87272727, 0.67272758),
float2(0.89090908, 0.29090881),
float2(0.90909094, 0.90909195),
float2(0.92727274, 0.52727318),
float2(0.94545454, 0.14545441),
float2(0.96363634, 0.76363754),
float2(0.98181820, 0.38181686)
float2(0.00909091, 0.00000000),
float2(0.02727273, 0.61818182),
float2(0.04545455, 0.23636365),
float2(0.06363636, 0.85454547),
float2(0.08181818, 0.47272730),
float2(0.10000000, 0.09090900),
float2(0.11818182, 0.70909095),
float2(0.13636364, 0.32727289),
float2(0.15454546, 0.94545460),
float2(0.17272727, 0.56363630),
float2(0.19090909, 0.18181801),
float2(0.20909090, 0.80000019),
float2(0.22727273, 0.41818190),
float2(0.24545455, 0.03636360),
float2(0.26363635, 0.65454578),
float2(0.28181818, 0.27272701),
float2(0.30000001, 0.89090919),
float2(0.31818181, 0.50909138),
float2(0.33636364, 0.12727261),
float2(0.35454544, 0.74545479),
float2(0.37272727, 0.36363602),
float2(0.39090911, 0.98181820),
float2(0.40909091, 0.60000038),
float2(0.42727274, 0.21818161),
float2(0.44545454, 0.83636379),
float2(0.46363637, 0.45454597),
float2(0.48181817, 0.07272720),
float2(0.50000000, 0.69090843),
float2(0.51818180, 0.30909157),
float2(0.53636366, 0.92727280),
float2(0.55454546, 0.54545403),
float2(0.57272726, 0.16363716),
float2(0.59090906, 0.78181839),
float2(0.60909092, 0.39999962),
float2(0.62727273, 0.01818275),
float2(0.64545453, 0.63636398),
float2(0.66363639, 0.25454521),
float2(0.68181819, 0.87272835),
float2(0.69999999, 0.49090958),
float2(0.71818179, 0.10909081),
float2(0.73636365, 0.72727203),
float2(0.75454545, 0.34545517),
float2(0.77272725, 0.96363640),
float2(0.79090911, 0.58181763),
float2(0.80909091, 0.20000076),
float2(0.82727271, 0.81818199),
float2(0.84545457, 0.43636322),
float2(0.86363637, 0.05454636),
float2(0.88181818, 0.67272758),
float2(0.89999998, 0.29090881),
float2(0.91818184, 0.90909195),
float2(0.93636364, 0.52727318),
float2(0.95454544, 0.14545441),
float2(0.97272730, 0.76363754),
float2(0.99090910, 0.38181686)
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)
float2(0.00561798, 0.00000000),
float2(0.01685393, 0.61797750),
float2(0.02808989, 0.23595500),
float2(0.03932584, 0.85393250),
float2(0.05056180, 0.47191000),
float2(0.06179775, 0.08988762),
float2(0.07303371, 0.70786500),
float2(0.08426967, 0.32584238),
float2(0.09550562, 0.94382000),
float2(0.10674157, 0.56179762),
float2(0.11797753, 0.17977524),
float2(0.12921348, 0.79775238),
float2(0.14044943, 0.41573000),
float2(0.15168539, 0.03370762),
float2(0.16292135, 0.65168476),
float2(0.17415731, 0.26966286),
float2(0.18539326, 0.88764000),
float2(0.19662921, 0.50561714),
float2(0.20786516, 0.12359524),
float2(0.21910113, 0.74157238),
float2(0.23033708, 0.35955048),
float2(0.24157304, 0.97752762),
float2(0.25280899, 0.59550476),
float2(0.26404494, 0.21348286),
float2(0.27528089, 0.83146000),
float2(0.28651685, 0.44943714),
float2(0.29775280, 0.06741524),
float2(0.30898875, 0.68539238),
float2(0.32022473, 0.30336952),
float2(0.33146068, 0.92134666),
float2(0.34269664, 0.53932571),
float2(0.35393259, 0.15730286),
float2(0.36516854, 0.77528000),
float2(0.37640449, 0.39325714),
float2(0.38764045, 0.01123428),
float2(0.39887640, 0.62921333),
float2(0.41011235, 0.24719048),
float2(0.42134830, 0.86516762),
float2(0.43258426, 0.48314476),
float2(0.44382024, 0.10112190),
float2(0.45505619, 0.71910095),
float2(0.46629214, 0.33707809),
float2(0.47752810, 0.95505524),
float2(0.48876405, 0.57303238),
float2(0.50000000, 0.19100952),
float2(0.51123595, 0.80898666),
float2(0.52247190, 0.42696571),
float2(0.53370786, 0.04494286),
float2(0.54494381, 0.66292000),
float2(0.55617976, 0.28089714),
float2(0.56741571, 0.89887428),
float2(0.57865167, 0.51685333),
float2(0.58988762, 0.13483047),
float2(0.60112357, 0.75280762),
float2(0.61235952, 0.37078476),
float2(0.62359548, 0.98876190),
float2(0.63483149, 0.60673904),
float2(0.64606744, 0.22471619),
float2(0.65730339, 0.84269333),
float2(0.66853935, 0.46067429),
float2(0.67977530, 0.07865143),
float2(0.69101125, 0.69662857),
float2(0.70224720, 0.31460571),
float2(0.71348315, 0.93258286),
float2(0.72471911, 0.55056000),
float2(0.73595506, 0.16853714),
float2(0.74719101, 0.78651428),
float2(0.75842696, 0.40449142),
float2(0.76966292, 0.02246857),
float2(0.78089887, 0.64044571),
float2(0.79213482, 0.25842667),
float2(0.80337077, 0.87640381),
float2(0.81460673, 0.49438095),
float2(0.82584268, 0.11235809),
float2(0.83707863, 0.73033524),
float2(0.84831458, 0.34831238),
float2(0.85955054, 0.96628952),
float2(0.87078649, 0.58426666),
float2(0.88202250, 0.20224380),
float2(0.89325845, 0.82022095),
float2(0.90449440, 0.43820190),
float2(0.91573036, 0.05617905),
float2(0.92696631, 0.67415619),
float2(0.93820226, 0.29213333),
float2(0.94943821, 0.91011047),
float2(0.96067417, 0.52808762),
float2(0.97191012, 0.14606476),
float2(0.98314607, 0.76404190),
float2(0.99438202, 0.38201904)
// Loads elements from one of the precomputed tables for sample counts of 21, 34, 55.
// Loads elements from one of the precomputed tables for sample counts of 21, 34, 55, and 89.
// Computes sample positions at runtime otherwise.
// Sample count must be a Fibonacci number (see 'k_FibonacciSeq').
float2 Fibonacci2d(uint i, uint sampleCount)

return Fibonacci2dSeq(fibN1, fibN2, i);
}
}
}
// Returns the radius as the X coordinate, and the angle as the Y coordinate.
float2 SampleDiskFibonacci(uint i, uint sampleCount)
{
float2 f = Fibonacci2d(i, sampleCount);
return float2(f.x, TWO_PI * f.y);
}
// Returns the zenith as the X coordinate, and the azimuthal angle as the Y coordinate.
float2 SampleHemisphereFibonacci(uint i, uint sampleCount)
{
float2 f = Fibonacci2d(i, sampleCount);
return float2(1 - f.x, TWO_PI * f.y);
}
// Returns the zenith as the X coordinate, and the azimuthal angle as the Y coordinate.
float2 SampleSphereFibonacci(uint i, uint sampleCount)
{
float2 f = Fibonacci2d(i, sampleCount);
return float2(1 - 2 * f.x, TWO_PI * f.y);
}
#endif // UNITY_FIBONACCI_INCLUDED

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.2.0a4
m_EditorVersion: 2017.2.0b1

54
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/CameraMotionVectors.shader


Shader "Hidden/HDRenderPipeline/CameraMotionVectors"
{
HLSLINCLUDE
#pragma target 4.5
#include "../../ShaderLibrary/Common.hlsl"
#include "../ShaderVariables.hlsl"
#include "../ShaderPass/FragInputs.hlsl"
#include "../ShaderPass/VaryingMesh.hlsl"
#include "../ShaderPass/VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
float4 Frag(PackedVaryingsToPS packedInput) : SV_Target
{
PositionInputs posInput = GetPositionInput(packedInput.vmesh.positionCS.xy, _ScreenSize.zw);
float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.unPositionSS).x;
float3 vPos = ComputeViewSpacePosition(posInput.positionSS, depth, _InvProjMatrix);
float4 worldPos = mul(unity_CameraToWorld, float4(vPos, 1.0));
float4 prevClipPos = mul(_PrevViewProjMatrix, worldPos);
float4 curClipPos = mul(_ViewProjMatrix, worldPos);
float2 prevHPos = prevClipPos.xy / prevClipPos.w;
float2 curHPos = curClipPos.xy / curClipPos.w;
float2 previousPositionCS = (prevHPos + 1.0) / 2.0;
float2 positionCS = (curHPos + 1.0) / 2.0;
return float4(positionCS - previousPositionCS, 0.0, 1.0);
}
ENDHLSL
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
}
}
}

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/CameraMotionVectors.shader.meta


fileFormatVersion: 2
guid: 035941b63024d1943af48811c1db20d9
timeCreated: 1497432609
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存