浏览代码

Merge branch 'master' into tests/hdrp/distortion

/main
Remy 6 年前
当前提交
be0eb3c8
共有 54 个文件被更改,包括 646 次插入356 次删除
  1. 12
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/UnityInstancing.hlsl
  2. 4
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  3. 6
      com.unity.render-pipelines.high-definition/HDRP/Debug/DebugFullScreen.shader
  4. 21
      com.unity.render-pipelines.high-definition/HDRP/Debug/DebugViewMaterialGBuffer.shader
  5. 4
      com.unity.render-pipelines.high-definition/HDRP/Debug/MaterialDebug.cs
  6. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  7. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  8. 5
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/BaseShaderPreprocessor.cs
  9. 7
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/FrameSettingsUI.cs
  10. 15
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs
  11. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs
  12. 28
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs
  13. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRPass.template
  14. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitPassForward.template
  15. 13
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Deferred.shader
  16. 25
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs
  17. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs
  18. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl
  19. 8
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  20. 13
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/Deferred.compute
  21. 5
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  22. 38
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl
  23. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute
  24. 17
      com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.cs
  25. 30
      com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.cs.hlsl
  26. 64
      com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.hlsl
  27. 6
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/ShaderVariablesDecal.hlsl
  28. 141
      com.unity.render-pipelines.high-definition/HDRP/Material/GBufferManager.cs
  29. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader
  30. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
  31. 78
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.cs
  32. 52
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.cs.hlsl
  33. 139
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl
  34. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader
  35. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitBuiltinData.hlsl
  36. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader
  37. 64
      com.unity.render-pipelines.high-definition/HDRP/Material/Material.hlsl
  38. 16
      com.unity.render-pipelines.high-definition/HDRP/Material/MaterialEvaluation.hlsl
  39. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/NormalBufferManager.cs
  40. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/RenderPipelineMaterial.cs
  41. 26
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl
  42. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  43. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl
  44. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
  45. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Unlit/UnlitData.hlsl
  46. 17
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
  47. 37
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipelineAsset.cs
  48. 3
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  49. 21
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/FrameSettings.cs
  50. 19
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/RenderPipelineSettings.cs
  51. 2
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/ApplyDistorsion.compute
  52. 9
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassForward.hlsl
  53. 7
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassGBuffer.hlsl
  54. 4
      com.unity.render-pipelines.high-definition/HDRP/ShaderVariables.hlsl

12
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/UnityInstancing.hlsl


#define UNITY_USE_LODFADE_ARRAY
#endif
#if defined(UNITY_INSTANCED_RENDERING_LAYER)
#define UNITY_USE_RENDERINGLAYER_ARRAY
#endif
#ifdef UNITY_INSTANCED_LIGHTMAPSTS
#ifdef LIGHTMAP_ON
#define UNITY_USE_LIGHTMAPST_ARRAY

UNITY_DEFINE_INSTANCED_PROP(float2, unity_LODFadeArray)
#define unity_LODFade UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_LODFadeArray).xyxx
#endif
#if defined(UNITY_USE_RENDERINGLAYER_ARRAY) && defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
UNITY_DEFINE_INSTANCED_PROP(float, unity_RenderingLayerArray)
#define unity_RenderingLayer UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_RenderingLayerArray).xxxx
#endif
UNITY_INSTANCING_BUFFER_END(unity_Builtins0)
UNITY_INSTANCING_BUFFER_START(PerDraw1)

#if defined(UNITY_USE_LODFADE_ARRAY) && !defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
UNITY_DEFINE_INSTANCED_PROP(float2, unity_LODFadeArray)
#define unity_LODFade UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_LODFadeArray).xyxx
#endif
#if defined(UNITY_USE_RENDERINGLAYER_ARRAY) && !defined(UNITY_INSTANCING_SUPPORT_FLEXIBLE_ARRAY_SIZE)
UNITY_DEFINE_INSTANCED_PROP(float, unity_RenderingLayerArray)
#define unity_RenderingLayer UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_RenderingLayerArray).xxxx
#endif
UNITY_INSTANCING_BUFFER_END(unity_Builtins1)

4
com.unity.render-pipelines.high-definition/CHANGELOG.md


- Decal now support per channel selection mask. There is now two mode. One with BaseColor, Normal and Smoothness and another one more expensive with BaseColor, Normal, Smoothness, Metal and AO. Control is on HDRP Asset. This may require to launch an update script for old scene: 'Edit/Render Pipeline/Single step upgrade script/Upgrade all DecalMaterial MaskBlendMode'.
- Decal now supports depth bias for decal mesh, to prevent z-fighting
- Decal material now supports draw order for decal projectors
- Added LightLayers support (Base on mask from renderers name RenderingLayers and mask from light name LightLayers - if they match, the light apply) - cost an extra GBuffer in deferred (more bandwidth)
- When LightLayers is enabled, the AmbientOclusion is store in the GBuffer in deferred path allowing to avoid double occlusion with SSAO. In forward the double occlusion is now always avoided.
### Fixed
- Fixed an issue with PreIntegratedFGD texture being sometimes destroyed and not regenerated causing rendering to break

- Update detail map formula for smoothness and albedo, goal it to bright and dark perceptually and scale factor is use to control gradient speed
- Refactor the Upgrade material system. Now a material can be update from older version at any time. Call Edit/Render Pipeline/Upgrade all Materials to newer version
- Change name EnableDBuffer to EnableDecals at several place (shader, hdrp asset...), this require a call to Edit/Render Pipeline/Upgrade all Materials to newer version to have up to date material.
- Refactor shader code: BakeLightingData structure have been replace by BuiltinData. Lot of shader code have been remove/change.
- Refactor shader code: All GBuffer are now handled by the deferred material. Mean ShadowMask and LightLayers are control by lit material in lit.hlsl and not outside anymore. Lot of shader code have been remove/change.
### Added
- Added support for RendererPriority on Renderer. This allow to control order of transparent rendering manually. HDRP have now two stage of sorting for transparent in addition to bact to front. Material have a priority then Renderer have a priority.

6
com.unity.render-pipelines.high-definition/HDRP/Debug/DebugFullScreen.shader


#include "CoreRP/ShaderLibrary/Color.hlsl"
#include "CoreRP/ShaderLibrary/Debug.hlsl"
#include "HDRP/Material/Lit/Lit.cs.hlsl"
#include "../ShaderVariables.hlsl"
#include "../Debug/DebugDisplay.cs.hlsl"
#include "../Material/Builtin/BuiltinData.hlsl"
#include "HDRP/ShaderVariables.hlsl"
#include "HDRP/Debug/DebugDisplay.cs.hlsl"
#include "HDRP/Material/Builtin/BuiltinData.hlsl"
CBUFFER_START (UnityDebug)
float _FullScreenDebugMode;

21
com.unity.render-pipelines.high-definition/HDRP/Debug/DebugViewMaterialGBuffer.shader


#include "../Debug/DebugDisplay.hlsl"
#include "../Material/Material.hlsl"
#ifdef SHADOWS_SHADOWMASK
TEXTURE2D(_ShadowMaskTexture);
#endif
struct Attributes
{
uint vertexID : SV_VertexID;

PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
BSDFData bsdfData;
BakeLightingData bakeLightingData;
DECODE_FROM_GBUFFER(posInput.positionSS, UINT_MAX, bsdfData, bakeLightingData.bakeDiffuseLighting);
#ifdef SHADOWS_SHADOWMASK
DecodeShadowMask(LOAD_TEXTURE2D(_ShadowMaskTexture, posInput.positionSS), bakeLightingData.bakeShadowMask);
#endif
BuiltinData builtinData;
DECODE_FROM_GBUFFER(posInput.positionSS, UINT_MAX, bsdfData, builtinData);
// Init to not expected value
float3 result = float3(-666.0, 0.0, 0.0);

// Caution: This value is not the same than the builtin data bakeDiffuseLighting. It also include emissive and multiply by the albedo
else if (_DebugViewMaterial == DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING_WITH_ALBEDO_PLUS_EMISSIVE)
{
result = bakeLightingData.bakeDiffuseLighting;;
result = builtinData.bakeDiffuseLighting;;
result *= exp2(_DebugExposure);
needLinearToSRGB = true;
}

result = bakeLightingData.bakeShadowMask.xxx;
result = builtinData.shadowMask0.xxx;
result = bakeLightingData.bakeShadowMask.yyy;
result = builtinData.shadowMask1.xxx;
result = bakeLightingData.bakeShadowMask.zzz;
result = builtinData.shadowMask2.xxx;
result = bakeLightingData.bakeShadowMask.www;
result = builtinData.shadowMask3.xxx;
}
#endif

4
com.unity.render-pipelines.high-definition/HDRP/Debug/MaterialDebug.cs


List<RenderPipelineMaterial> materialList = HDUtils.GetRenderPipelineMaterialList();
// TODO: Share this code to retrieve deferred material with HDRenderPipeline
// Find first material that have non 0 Gbuffer count and assign it as deferredMaterial
// Find first material that is a deferredMaterial
if (material.GetMaterialGBufferCount() > 0)
if (material.IsDefferedMaterial())
{
bsdfDataDeferredType = material.GetType().GetNestedType("BSDFData");
}

1
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs


public readonly GUIContent shapeHeightBox = new GUIContent("Size Y", "");
public readonly GUIContent applyRangeAttenuation = new GUIContent("Apply Range Attenuation", "Allows disabling range attenuation. This is useful indoor (like a room) to avoid having to setup a large range for a light to get correct inverse square attenuation that may leak out of the indoor");
public readonly GUIContent displayAreaLightEmissiveMesh = new GUIContent("Display Emissive Mesh", "Generate an emissive mesh using the size, color and intensity of the area light");
public readonly GUIContent lightLayer = new GUIContent("Light Layer", "Specifies the current light layers that the light affect. Corresponding renderer with the same flags will be lit by this light.");
public readonly GUIContent shape = new GUIContent("Type", "Specifies the current type of light. Possible types are Directional, Spot, Point, Rectangle and Line lights.");
public readonly GUIContent[] shapeNames;

3
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs


public SerializedProperty volumetricDimmer;
public SerializedProperty lightUnit;
public SerializedProperty displayAreaLightEmissiveMesh;
public SerializedProperty lightLayers;
// Editor stuff
public SerializedProperty useOldInspector;

volumetricDimmer = o.Find(x => x.volumetricDimmer),
lightUnit = o.Find(x => x.lightUnit),
displayAreaLightEmissiveMesh = o.Find(x => x.displayAreaLightEmissiveMesh),
lightLayers = o.Find(x => x.lightLayers),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),
affectSpecular = o.Find(x => x.affectSpecular),

EditorGUILayout.Space();
EditorGUILayout.LabelField("Additional Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_AdditionalLightData.lightLayers.intValue = Convert.ToInt32(EditorGUILayout.EnumFlagsField(s_Styles.lightLayer, (LightLayerEnum)m_AdditionalLightData.lightLayers.intValue));
EditorGUILayout.PropertyField(m_AdditionalLightData.affectDiffuse, s_Styles.affectDiffuse);
EditorGUILayout.PropertyField(m_AdditionalLightData.affectSpecular, s_Styles.affectSpecular);
if (m_LightShape != LightShape.Directional)

5
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/BaseShaderPreprocessor.cs


protected ShaderKeyword m_DecalsOFF;
protected ShaderKeyword m_Decals3RT;
protected ShaderKeyword m_Decals4RT;
protected ShaderKeyword m_LightLayers;
public BaseShaderPreprocessor()
{

m_DecalsOFF = new ShaderKeyword("DECALS_OFF");
m_Decals3RT = new ShaderKeyword("DECALS_3RT");
m_Decals4RT = new ShaderKeyword("DECALS_4RT");
m_LightLayers = new ShaderKeyword("LIGHT_LAYERS");
}
public virtual void AddStripperFuncs(Dictionary<string, VariantStrippingFunc> stripperFuncs) {}

return true;
}
if (inputData.shaderKeywordSet.IsEnabled(m_LightLayers) && !hdrpAsset.renderPipelineSettings.supportLightLayers)
return true;
return false;
}

7
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/FrameSettingsUI.cs


static void Drawer_SectionLightingSettings(FrameSettingsUI s, SerializedFrameSettings p, Editor owner)
{
EditorGUILayout.PropertyField(p.enableShadow, _.GetContent("Enable Shadow"));
EditorGUILayout.PropertyField(p.enableContactShadow, _.GetContent("Enable Contact Shadows"));
EditorGUILayout.PropertyField(p.enableShadowMask, _.GetContent("Enable Shadow Masks"));
EditorGUILayout.PropertyField(p.enableSSR, _.GetContent("Enable SSR"));
EditorGUILayout.PropertyField(p.enableSSAO, _.GetContent("Enable SSAO"));
EditorGUILayout.PropertyField(p.enableSubsurfaceScattering, _.GetContent("Enable Subsurface Scattering"));

EditorGUILayout.PropertyField(p.enableShadow, _.GetContent("Enable Shadow"));
EditorGUILayout.PropertyField(p.enableContactShadow, _.GetContent("Enable Contact Shadows"));
EditorGUILayout.PropertyField(p.enableShadowMask, _.GetContent("Enable Shadow Masks"));
EditorGUILayout.PropertyField(p.enableLightLayers, _.GetContent("Enable LightLayers"));
}
}
}

15
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs


{
EditorGUILayout.LabelField(_.GetContent("Render Pipeline Settings"), EditorStyles.boldLabel);
++EditorGUI.indentLevel;
// Lighting
EditorGUILayout.PropertyField(d.supportSubsurfaceScattering, _.GetContent("Support Subsurface Scattering"));
EditorGUILayout.PropertyField(d.increaseSssSampleCount, _.GetContent("Increase SSS Sample Count|This allows for better SSS quality. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportVolumetrics, _.GetContent("Support volumetrics|Enable memory and shader variant for volumetric."));
EditorGUILayout.PropertyField(d.increaseResolutionOfVolumetrics, _.GetContent("Increase resolution of volumetrics|Increase the resolution of volumetric lighting buffers. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportLightLayers, _.GetContent("Support LightLayers|Enable light layers. In deferred this imply an extra render target in memory and extra cost."));
EditorGUILayout.PropertyField(d.supportOnlyForward, _.GetContent("Support Only Forward|Remove all the memory and shader variant of GBuffer. The renderer can be switch to deferred anymore."));
// Engine
EditorGUILayout.PropertyField(d.supportSubsurfaceScattering, _.GetContent("Support Subsurface Scattering"));
EditorGUILayout.PropertyField(d.supportOnlyForward, _.GetContent("Support Only Forward|Remove all the memory and shader variant of GBuffer. The renderer can be switch to deferred anymore."));
EditorGUILayout.PropertyField(d.increaseSssSampleCount, _.GetContent("Increase SSS Sample Count|This allows for better SSS quality. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportVolumetrics, _.GetContent("Support volumetrics|Enable memory and shader variant for volumetric."));
EditorGUILayout.PropertyField(d.increaseResolutionOfVolumetrics, _.GetContent("Increase resolution of volumetrics|Increase the resolution of volumetric lighting buffers. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportRuntimeDebugDisplay, _.GetContent("Support runtime debug display|Remove all debug display shader variant only in the player. Allow faster build."));
EditorGUILayout.PropertyField(d.supportDitheringCrossFade, _.GetContent("Support dithering cross fade|Remove all dithering cross fade shader variant only in the player. Allow faster build."));

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs


public SerializedProperty enableTransmission;
public SerializedProperty enableAtmosphericScattering;
public SerializedProperty enableVolumetric;
public SerializedProperty enableLightLayers;
public SerializedProperty diffuseGlobalDimmer;
public SerializedProperty specularGlobalDimmer;

enableTransmission = root.Find((FrameSettings d) => d.enableTransmission);
enableAtmosphericScattering = root.Find((FrameSettings d) => d.enableAtmosphericScattering);
enableVolumetric = root.Find((FrameSettings d) => d.enableVolumetrics);
enableLightLayers = root.Find((FrameSettings d) => d.enableLightLayers);
diffuseGlobalDimmer = root.Find((FrameSettings d) => d.diffuseGlobalDimmer);
specularGlobalDimmer = root.Find((FrameSettings d) => d.specularGlobalDimmer);
enableForwardRenderingOnly = root.Find((FrameSettings d) => d.enableForwardRenderingOnly);

28
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs


public SerializedProperty supportShadowMask;
public SerializedProperty supportSSR;
public SerializedProperty supportSSAO;
public SerializedProperty supportDecals;
public SerializedProperty supportMSAA;
public SerializedProperty MSAASampleCount;
public SerializedProperty supportOnlyForward;
public SerializedProperty supportMotionVectors;
public SerializedProperty supportStereo;
public SerializedProperty supportLightLayers;
public SerializedProperty supportOnlyForward;
public SerializedProperty supportDecals;
public SerializedProperty supportMSAA;
public SerializedProperty MSAASampleCount;
public SerializedProperty supportMotionVectors;
public SerializedProperty supportStereo;
public SerializedProperty supportRuntimeDebugDisplay;
public SerializedProperty supportDitheringCrossFade;

supportShadowMask = root.Find((RenderPipelineSettings s) => s.supportShadowMask);
supportSSR = root.Find((RenderPipelineSettings s) => s.supportSSR);
supportSSAO = root.Find((RenderPipelineSettings s) => s.supportSSAO);
supportDecals = root.Find((RenderPipelineSettings s) => s.supportDecals);
supportMSAA = root.Find((RenderPipelineSettings s) => s.supportMSAA);
MSAASampleCount = root.Find((RenderPipelineSettings s) => s.msaaSampleCount);
supportOnlyForward = root.Find((RenderPipelineSettings s) => s.supportOnlyForward);
supportMotionVectors = root.Find((RenderPipelineSettings s) => s.supportMotionVectors);
supportStereo = root.Find((RenderPipelineSettings s) => s.supportStereo);
supportLightLayers = root.Find((RenderPipelineSettings s) => s.supportLightLayers);
supportOnlyForward = root.Find((RenderPipelineSettings s) => s.supportOnlyForward);
supportDecals = root.Find((RenderPipelineSettings s) => s.supportDecals);
supportMSAA = root.Find((RenderPipelineSettings s) => s.supportMSAA);
MSAASampleCount = root.Find((RenderPipelineSettings s) => s.msaaSampleCount);
supportMotionVectors = root.Find((RenderPipelineSettings s) => s.supportMotionVectors);
supportStereo = root.Find((RenderPipelineSettings s) => s.supportStereo);
supportRuntimeDebugDisplay = root.Find((RenderPipelineSettings s) => s.supportRuntimeDebugDisplay);
supportDitheringCrossFade = root.Find((RenderPipelineSettings s) => s.supportDitheringCrossFade);

2
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRPass.template


#endif
builtinData.distortion = float2(0.0, 0.0); // surfaceDescription.Distortion -- if distortion pass
builtinData.distortionBlur = 0.0; // surfaceDescription.DistortionBlur -- if distortion pass
// Use uniform directly - The float need to be cast to uint (as unity don't support to set a uint as uniform)
builtinData.renderingLayers = _EnableLightLayers ? asuint(unity_RenderingLayer.x) : DEFAULT_LIGHT_LAYERS;
builtinData.depthOffset = 0.0; // ApplyPerPixelDisplacement(input, V, layerTexCoord, blendMasks); #ifdef _DEPTHOFFSET_ON : ApplyDepthOffsetPositionInput(V, depthOffset, GetWorldToHClipMatrix(), posInput);
}

1
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitPassForward.template


builtinData.distortion = float2(0.0, 0.0); // surfaceDescription.Distortion -- if distortion pass
builtinData.distortionBlur = 0.0; // surfaceDescription.DistortionBlur -- if distortion pass
builtinData.renderingLayers = 0.0;
builtinData.depthOffset = 0.0; // ApplyPerPixelDisplacement(input, V, layerTexCoord, blendMasks); #ifdef _DEPTHOFFSET_ON : ApplyDepthOffsetPositionInput(V, depthOffset, GetWorldToHClipMatrix(), posInput);
}

13
com.unity.render-pipelines.high-definition/HDRP/Lighting/Deferred.shader


// variable declaration
//-------------------------------------------------------------------------------------
#ifdef SHADOWS_SHADOWMASK
TEXTURE2D(_ShadowMaskTexture);
#endif
struct Attributes
{
uint vertexID : SV_VertexID;

float3 V = GetWorldSpaceNormalizeViewDir(posInput.positionWS);
BSDFData bsdfData;
BakeLightingData bakeLightingData;
DECODE_FROM_GBUFFER(posInput.positionSS, UINT_MAX, bsdfData, bakeLightingData.bakeDiffuseLighting);
#ifdef SHADOWS_SHADOWMASK
DecodeShadowMask(LOAD_TEXTURE2D(_ShadowMaskTexture, posInput.positionSS), bakeLightingData.bakeShadowMask);
#endif
BuiltinData builtinData;
DECODE_FROM_GBUFFER(posInput.positionSS, UINT_MAX, bsdfData, builtinData);
LightLoop(V, posInput, preLightData, bsdfData, bakeLightingData, LIGHT_FEATURE_MASK_FLAGS_OPAQUE, diffuseLighting, specularLighting);
LightLoop(V, posInput, preLightData, bsdfData, builtinData, LIGHT_FEATURE_MASK_FLAGS_OPAQUE, diffuseLighting, specularLighting);
Outputs outputs;

25
com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs


using System;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Experimental.Rendering.HDPipeline;

Candela,
Lux,
Luminance,
}
// Light layering
public enum LightLayerEnum
{
Nothing = 0, // Custom name for "Nothing" option
LightLayerDefault = 1 << 0,
LightLayer1 = 1 << 1,
LightLayer2 = 1 << 2,
LightLayer3 = 1 << 3,
LightLayer4 = 1 << 4,
LightLayer5 = 1 << 5,
LightLayer6 = 1 << 6,
LightLayer7 = 1 << 7,
Everything = 0xFF, // Custom name for "Everything" option
}
// This structure contains all the old values for every recordable fields from the HD light editor

// Duplication of HDLightEditor.k_MinAreaWidth, maybe do something about that
const float k_MinAreaWidth = 0.01f; // Provide a small size of 1cm for line light
public LightLayerEnum lightLayers = LightLayerEnum.LightLayerDefault;
// This function return a mask of light layers as uint and handle the case of Everything as being 0xFF and not -1
public uint GetLightLayers()
{
int value = Convert.ToInt32(lightLayers);
return value < 0 ? (uint)LightLayerEnum.Everything : (uint)value;
}
#if UNITY_EDITOR
// We need these old states to make timeline and the animator record the intensity value and the emissive mesh changes (editor-only)

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs


public struct DirectionalLightData
{
// Packing order depends on chronological access to avoid cache misses
public uint lightLayers;
public Vector3 positionRWS;
public Vector3 color;

public struct LightData
{
// Packing order depends on chronological access to avoid cache misses
public uint lightLayers;
public Vector3 positionRWS;
public Vector3 color;

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl


// PackingRules = Exact
struct DirectionalLightData
{
uint lightLayers;
float3 positionRWS;
float3 color;
int cookieIndex;

// PackingRules = Exact
struct LightData
{
uint lightLayers;
float3 positionRWS;
float3 color;
float rangeAttenuationScale;

8
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl


// None of the outputs are premultiplied.
// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
void EvaluateLight_Directional(LightLoopContext lightLoopContext, PositionInputs posInput,
DirectionalLightData lightData, BakeLightingData bakeLightingData,
DirectionalLightData lightData, BuiltinData builtinData,
float3 N, float3 L,
out float3 color, out float attenuation)
{

#ifdef SHADOWS_SHADOWMASK
// shadowMaskSelector.x is -1 if there is no shadow mask
// Note that we override shadow value (in case we don't have any dynamic shadow)
shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(BUILTIN_DATA_SHADOW_MASK, lightData.shadowMaskSelector) : 1.0;
#endif
// We test NdotL >= 0.0 to not sample the shadow map if it is not required.

// distances = {d, d^2, 1/d, d_proj}, where d_proj = dot(lightToSample, lightData.forward).
// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
void EvaluateLight_Punctual(LightLoopContext lightLoopContext, PositionInputs posInput,
LightData lightData, BakeLightingData bakeLightingData,
LightData lightData, BuiltinData builtinData,
float3 N, float3 L, float3 lightToSample, float4 distances,
out float3 color, out float attenuation)
{

#ifdef SHADOWS_SHADOWMASK
// shadowMaskSelector.x is -1 if there is no shadow mask
// Note that we override shadow value (in case we don't have any dynamic shadow)
shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(BUILTIN_DATA_SHADOW_MASK, lightData.shadowMaskSelector) : 1.0;
#endif
// We test NdotL >= 0.0 to not sample the shadow map if it is not required.

13
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/Deferred.compute


// variable declaration
//-------------------------------------------------------------------------------------
#ifdef SHADOWS_SHADOWMASK
TEXTURE2D(_ShadowMaskTexture);
#endif
RWTexture2D<float3> diffuseLightingUAV;
RWTexture2D<float4> specularLightingUAV;

float3 V = GetWorldSpaceNormalizeViewDir(posInput.positionWS);
BSDFData bsdfData;
BakeLightingData bakeLightingData;
DECODE_FROM_GBUFFER(posInput.positionSS, featureFlags, bsdfData, bakeLightingData.bakeDiffuseLighting);
#ifdef SHADOWS_SHADOWMASK
DecodeShadowMask(LOAD_TEXTURE2D(_ShadowMaskTexture, posInput.positionSS), bakeLightingData.bakeShadowMask);
#endif
BuiltinData builtinData;
DECODE_FROM_GBUFFER(posInput.positionSS, UINT_MAX, bsdfData, builtinData);
LightLoop(V, posInput, preLightData, bsdfData, bakeLightingData, featureFlags, diffuseLighting, specularLighting);
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))
{

5
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs


float specularDimmer = m_FrameSettings.specularGlobalDimmer * additionalData.lightDimmer;
if (diffuseDimmer <= 0.0f && specularDimmer <= 0.0f)
return false;
directionalLightData.lightLayers = additionalData.GetLightLayers();
// Light direction for directional is opposite to the forward direction
directionalLightData.forward = light.light.transform.forward;
// Rescale for cookies and windowing.

int lightIndex, ref Vector3 lightDimensions)
{
var lightData = new LightData();
lightData.lightLayers = additionalLightData.GetLightLayers();
lightData.lightType = gpuLightType;

38
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl


#endif
}
// Factor all test so we can disable it easily
bool IsMatchingLightLayer(uint lightLayers, uint renderingLayers)
{
return (lightLayers & renderingLayers) != 0;
}
void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, BakeLightingData bakeLightingData, uint featureFlags,
void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, uint featureFlags,
out float3 diffuseLighting,
out float3 specularLighting)
{

{
for (i = 0; i < _DirectionalLightCount; ++i)
{
DirectLighting lighting = EvaluateBSDF_Directional(context, V, posInput, preLightData, _DirectionalLightDatas[i], bsdfData, bakeLightingData);
AccumulateDirectLighting(lighting, aggregateLighting);
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
{
DirectLighting lighting = EvaluateBSDF_Directional(context, V, posInput, preLightData, _DirectionalLightDatas[i], bsdfData, builtinData);
AccumulateDirectLighting(lighting, aggregateLighting);
}
}
}

{
LightData lightData = FetchLight(lightStart, i);
DirectLighting lighting = EvaluateBSDF_Punctual(context, V, posInput, preLightData, lightData, bsdfData, bakeLightingData);
AccumulateDirectLighting(lighting, aggregateLighting);
if (IsMatchingLightLayer(lightData.lightLayers, builtinData.renderingLayers))
{
DirectLighting lighting = EvaluateBSDF_Punctual(context, V, posInput, preLightData, lightData, bsdfData, builtinData);
AccumulateDirectLighting(lighting, aggregateLighting);
}
}
}

{
lightData.lightType = GPULIGHTTYPE_LINE; // Enforce constant propagation
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, lightData, bsdfData, bakeLightingData);
AccumulateDirectLighting(lighting, aggregateLighting);
if (IsMatchingLightLayer(lightData.lightLayers, builtinData.renderingLayers))
{
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, lightData, bsdfData, builtinData);
AccumulateDirectLighting(lighting, aggregateLighting);
}
lightData = FetchLight(lightStart, min(++i, last));
}

lightData.lightType = GPULIGHTTYPE_RECTANGLE; // Enforce constant propagation
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, lightData, bsdfData, bakeLightingData);
AccumulateDirectLighting(lighting, aggregateLighting);
if (IsMatchingLightLayer(lightData.lightLayers, builtinData.renderingLayers))
{
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, lightData, bsdfData, builtinData);
AccumulateDirectLighting(lighting, aggregateLighting);
}
lightData = FetchLight(lightStart, min(++i, last));
}

// Also Apply indiret diffuse (GI)
// PostEvaluateBSDF will perform any operation wanted by the material and sum everything into diffuseLighting and specularLighting
PostEvaluateBSDF( context, V, posInput, preLightData, bsdfData, bakeLightingData, aggregateLighting,
PostEvaluateBSDF( context, V, posInput, preLightData, bsdfData, builtinData, aggregateLighting,
diffuseLighting, specularLighting);
ApplyDebug(context, posInput.positionWS, diffuseLighting, specularLighting);

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute


VoxelLighting lighting;
ZERO_INITIALIZE(VoxelLighting, lighting);
BakeLightingData unused; // Unused for now, so define once
BuiltinData unused; // Unused for now, so define once
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
{

17
com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.cs


[SurfaceDataAttributes("Distortion Blur")]
public float distortionBlur; // Define the color buffer mipmap level to use
[SurfaceDataAttributes("RenderingLayers")]
public uint renderingLayers;
// Depth
[SurfaceDataAttributes("Depth Offset")]
public float depthOffset; // define the depth in unity unit to add in Z forward direction

// LightTransportData
// This struct is use to store information for Enlighten/Progressive light mapper. both at runtime or off line.
//-----------------------------------------------------------------------------
[GenerateHLSL(PackingRules.Exact, false, true, 150)]
[GenerateHLSL(PackingRules.Exact, false)]
public struct LightTransportData
{
[SurfaceDataAttributes("", false, true)]

public static RenderTextureFormat GetLightingBufferFormat()
{
return RenderTextureFormat.RGB111110Float;
}
public static bool GetLightingBufferSRGBFlag()
{
return false;
}
public static bool GetShadowMaskSRGBFlag()
public static bool GetShadowMaskBufferSRGBFlag()
{
return false;
}

30
com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.cs.hlsl


#define DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY (107)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION (108)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR (109)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET (110)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Builtin+LightTransportData: static fields
//
#define DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_DIFFUSE_COLOR (150)
#define DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_EMISSIVE_COLOR (151)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_RENDERING_LAYERS (110)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET (111)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Builtin+BuiltinData
// PackingRules = Exact

float2 velocity;
float2 distortion;
float distortionBlur;
uint renderingLayers;
float depthOffset;
};

case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR:
result = builtindata.distortionBlur.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_RENDERING_LAYERS:
result = GetIndexColor(builtindata.renderingLayers);
break;
break;
}
}
//
// Debug functions
//
void GetGeneratedLightTransportDataDebug(uint paramId, LightTransportData lighttransportdata, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_DIFFUSE_COLOR:
result = lighttransportdata.diffuseColor;
needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_EMISSIVE_COLOR:
result = lighttransportdata.emissiveColor;
break;
}
}

64
com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.hlsl


// Note: These parameters can be store in GBuffer if the writer wants
//-----------------------------------------------------------------------------
#include "CoreRP/ShaderLibrary/Debug.hlsl" // Require for GetIndexColor auto generated
// common Encode/Decode functions
// helper macro
struct BakeLightingData
{
float3 bakeDiffuseLighting;
#ifdef SHADOWS_SHADOWMASK
float4 bakeShadowMask;
#endif
};
// 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 shadowmask/velocity/distortion in a buffer (either forward of deferred)
#define BUILTIN_DATA_SHADOW_MASK float4(builtinData.shadowMask0, builtinData.shadowMask1, builtinData.shadowMask2, builtinData.shadowMask3)
// Design note: We assume that shadowmask/velocity/distortion fit into a single buffer (i.e not spread on several buffer)
void EncodeShadowMask(float4 shadowMask, out float4 outBuffer)
{
// RT - RGBA
outBuffer = shadowMask;
}
//-----------------------------------------------------------------------------
// common Encode/Decode functions
//-----------------------------------------------------------------------------
void DecodeShadowMask(float4 inBuffer, out float4 shadowMask)
{
shadowMask = inBuffer;
}
// Guideline for velocity buffer.
// The object velocity buffer is potentially fill in several pass.
// - In gbuffer pass with extra RT (Not supported currently)
// - In forward prepass pass
// - In dedicated velocity pass
// So same velocity buffer is use for all scenario, so if deferred define a velocity buffer, the same is reuse for forward case.
// THis is similar to NormalBuffer
// TODO: CAUTION: current DecodeVelocity is not used in motion vector / TAA pass as it come from Postprocess stack
// This will be fix when postprocess will be integrated into HD, but it mean that we must not change the

break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION:
result = float3((builtinData.distortion / (abs(builtinData.distortion) + 1) + 1) * 0.5, 0.5);
break;
}
}
void GetLightTransportDataDebug(uint paramId, LightTransportData lightTransportData, inout float3 result, inout bool needLinearToSRGB)
{
GetGeneratedLightTransportDataDebug(paramId, lightTransportData, result, needLinearToSRGB);
switch (paramId)
{
case DEBUGVIEW_BUILTIN_LIGHTTRANSPORTDATA_EMISSIVE_COLOR:
// TODO: Need a tonemap ?
result = lightTransportData.emissiveColor;
break;
}
}

6
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/ShaderVariablesDecal.hlsl


#ifdef SHADER_VARIABLES_INCLUDE_CB
uint _EnableDecals;
float2 _DecalAtlasResolution;
uint _DecalCount;
uint _EnableDecals;
float2 _DecalAtlasResolution;
uint _DecalCount;
#else
#include "HDRP/Material/Decal//Decal.cs.hlsl"

141
com.unity.render-pipelines.high-definition/HDRP/Material/GBufferManager.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// This enum allow to identify which render target is used for a specific feature
public enum GBufferUsage
{
None,
SubsurfaceScattering,
Normal,
LightLayers,
ShadowMask
}
int m_GBufferCount = 0;
bool m_SupportShadowMask = false;
protected RenderTargetIdentifier[] m_RTIDsNoShadowMask;
// This contain the usage for all allocated buffer
protected GBufferUsage[] m_GBufferUsage;
// This is the index of the gbuffer use for shadowmask and lightlayers, if any
protected int m_ShadowMaskIndex = -1;
protected int m_LightLayers = -1;
protected HDRenderPipelineAsset m_asset;
// We need to store current set of RT to bind exactly, as we can have dynamic RT (LightLayers, ShadowMask), we allocated an array for each possible size (to avoid gardbage collect pressure)
protected RenderTargetIdentifier[][] m_RTIDsArray = new RenderTargetIdentifier[8][];
public GBufferManager(RenderPipelineMaterial deferredMaterial, bool enableBakeShadowMask)
: base(deferredMaterial.GetMaterialGBufferCount() + (enableBakeShadowMask ? 1 : 0))
public GBufferManager(HDRenderPipelineAsset asset, RenderPipelineMaterial deferredMaterial)
: base(deferredMaterial.GetMaterialGBufferCount(asset))
m_DeferredMaterial = deferredMaterial;
m_GBufferCount = deferredMaterial.GetMaterialGBufferCount();
m_SupportShadowMask = enableBakeShadowMask;
for (int i = 0; i < m_BufferCount; ++i)
{
m_RTIDsArray[i] = new RenderTargetIdentifier[i + 1];
}
m_RTIDsNoShadowMask = new RenderTargetIdentifier[m_GBufferCount];
m_DeferredMaterial = deferredMaterial;
m_asset = asset;
bool[] sRGBFlags;
m_DeferredMaterial.GetMaterialGBufferDescription(out rtFormat, out sRGBFlags);
bool[] sRGBFlags;
m_DeferredMaterial.GetMaterialGBufferDescription(m_asset, out rtFormat, out sRGBFlags, out m_GBufferUsage);
for (int gbufferIndex = 0; gbufferIndex < m_GBufferCount; ++gbufferIndex)
for (int gbufferIndex = 0; gbufferIndex < m_BufferCount; ++gbufferIndex)
m_RTIDsNoShadowMask[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex];
if (m_GBufferUsage[gbufferIndex] == GBufferUsage.ShadowMask)
m_ShadowMaskIndex = gbufferIndex;
else if (m_GBufferUsage[gbufferIndex] == GBufferUsage.LightLayers)
m_LightLayers = gbufferIndex;
}
if (m_SupportShadowMask)
public override void BindBufferAsTextures(CommandBuffer cmd)
{
for (int i = 0; i < m_BufferCount; ++i)
m_RTs[m_GBufferCount] = RTHandles.Alloc(Vector2.one, colorFormat: Builtin.GetShadowMaskBufferFormat(), sRGB: Builtin.GetShadowMaskSRGBFlag(), filterMode: FilterMode.Point, name: "GBufferShadowMask");
m_RTIDs[m_GBufferCount] = new RenderTargetIdentifier(m_RTs[m_GBufferCount]);
m_TextureShaderIDs[m_GBufferCount] = HDShaderIDs._ShadowMaskTexture;
cmd.SetGlobalTexture(m_TextureShaderIDs[i], m_RTs[i]);
// Bind alias for gbuffer usage to simplify shader code (not need to check which gbuffer is the shadowmask or lightlayers)
if (m_ShadowMaskIndex >= 0)
cmd.SetGlobalTexture(HDShaderIDs._ShadowMaskTexture, m_RTs[m_ShadowMaskIndex]);
if (m_LightLayers >= 0)
cmd.SetGlobalTexture(HDShaderIDs._LightLayersTexture, m_RTs[m_LightLayers]);
else
cmd.SetGlobalTexture(HDShaderIDs._LightLayersTexture, RuntimeUtilities.whiteTexture); // This is never use but need to be bind as the read is inside a if
public override void BindBufferAsTextures(CommandBuffer cmd)
// This function will setup the required render target array. This take into account if shadow mask and light layers are enabled or not.
// Note for the future: Setup works fine as we don't have change per object (like velocity for example). If in the future it is the case
// the changing per object buffer MUST be the last one so the shader can decide if it write to it or not
public RenderTargetIdentifier[] GetBuffersRTI(FrameSettings frameSettings)
// We do two loop to avoid to have to allocate an array every frame
// Do a first step to know how many RT we require
int gbufferIndex = 0;
cmd.SetGlobalTexture(m_TextureShaderIDs[i], m_RTs[i]);
if (m_GBufferUsage[i] == GBufferUsage.ShadowMask && !frameSettings.enableShadowMask)
continue; // Skip
if (m_GBufferUsage[i] == GBufferUsage.LightLayers && !frameSettings.enableLightLayers)
continue; // Skip
gbufferIndex++;
// When shadow mask are disabled (i.e we haven't created shadow mask texture, bind a white texture).
if (!m_SupportShadowMask)
// Now select the correct array and do another loop to fill the array
RenderTargetIdentifier[] m_RTIDsArrayCurrent = m_RTIDsArray[gbufferIndex - 1];
gbufferIndex = 0;
// nameID can change from one frame to another depending on the msaa flag so so we need to update this array to be sure it's up to date.
for (int i = 0; i < m_BufferCount; ++i)
cmd.SetGlobalTexture(HDShaderIDs._ShadowMaskTexture, RuntimeUtilities.whiteTexture);
if (m_GBufferUsage[i] == GBufferUsage.ShadowMask && !frameSettings.enableShadowMask)
continue; // Skip
if (m_GBufferUsage[i] == GBufferUsage.LightLayers && !frameSettings.enableLightLayers)
continue; // Skip
m_RTIDsArrayCurrent[gbufferIndex] = m_RTs[i].nameID;
gbufferIndex++;
return m_RTIDsArrayCurrent;
public RenderTargetIdentifier[] GetBuffersRTI(bool enableShadowMask)
public RTHandleSystem.RTHandle GetNormalBuffer(int index)
if (!enableShadowMask)
int currentIndex = 0;
for (int gbufferIndex = 0; gbufferIndex < m_BufferCount; ++gbufferIndex)
// nameID can change from one frame to another depending on the msaa flag so so we need to update this array to be sure it's up to date.
// Moreover, if we don't have shadow masks we only need to bind the first GBuffers
// This is important because in the shader the shadowmask buffer gets optimized out so anything bound after (like the DBuffer HTile) has a different bind point.
for (int i = 0; i < m_GBufferCount; ++i)
if (m_GBufferUsage[gbufferIndex] == GBufferUsage.Normal)
m_RTIDsNoShadowMask[i] = m_RTs[i].nameID;
}
return m_RTIDsNoShadowMask;
if (currentIndex == index)
return m_RTs[gbufferIndex];
// This is not the index we are looking for, find the next one
currentIndex++;
}
else
return null;
}
public RTHandleSystem.RTHandle GetSubsurfaceScatteringBuffer(int index)
{
int currentIndex = 0;
for (int gbufferIndex = 0; gbufferIndex < m_BufferCount; ++gbufferIndex)
return GetBuffersRTI();
if (m_GBufferUsage[gbufferIndex] == GBufferUsage.SubsurfaceScattering)
{
if (currentIndex == index)
return m_RTs[gbufferIndex];
// This is not the index we are looking for, find the next one
currentIndex++;
}
}
public int GetBufferCount(bool enableShadowMask)
{
return enableShadowMask ? m_BufferCount : m_GBufferCount;
return null;
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLit.shader


//enable GPU instancing support
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
//-------------------------------------------------------------------------------------
// Define

#pragma multi_compile _ SHADOWS_SHADOWMASK
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#pragma multi_compile _ LIGHT_LAYERS
#ifdef _ALPHATEST_ON
// When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer

2
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitTessellation.shader


// enable GPU instancing
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
//-------------------------------------------------------------------------------------
// Define

#pragma multi_compile _ SHADOWS_SHADOWMASK
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#pragma multi_compile _ LIGHT_LAYERS
#ifdef _ALPHATEST_ON
// When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer

78
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.cs


public Vector3 diffuseColor;
public Vector3 fresnel0;
public float ambientOcclusion; // Caution: This is accessible only if light layer is enabled, otherwise it is 1
public float specularOcclusion;
[SurfaceDataAttributes(new string[] { "Normal WS", "Normal View Space" }, true)]

};
//-----------------------------------------------------------------------------
// RenderLoop management
// GBuffer management
[GenerateHLSL(PackingRules.Exact)]
public enum GBufferMaterial
public override bool IsDefferedMaterial() { return true; }
protected void GetGBufferOptions(HDRenderPipelineAsset asset, out int gBufferCount, out bool supportShadowMask, out bool supportLightLayers)
// Note: This count doesn't include the velocity buffer. On shader and csharp side the velocity buffer will be added by the framework
Count = 4
};
//-----------------------------------------------------------------------------
// GBuffer management
//-----------------------------------------------------------------------------
// Caution: This must be in sync with GBUFFERMATERIAL_COUNT definition in
supportShadowMask = asset.renderPipelineSettings.supportShadowMask;
supportLightLayers = asset.renderPipelineSettings.supportLightLayers;
gBufferCount = 4 + (supportShadowMask ? 1 : 0) + (supportLightLayers ? 1 : 0);
}
public override int GetMaterialGBufferCount() { return (int)GBufferMaterial.Count; }
// This must return the number of GBuffer to allocate
public override int GetMaterialGBufferCount(HDRenderPipelineAsset asset)
{
int gBufferCount;
bool unused0;
bool unused1;
GetGBufferOptions(asset, out gBufferCount, out unused0, out unused1);
RenderTextureFormat[] m_RTFormat4 = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.RGB111110Float };
bool[] m_RTsRGBFlag4 = { true, false, false, false };
return gBufferCount;
}
public override void GetMaterialGBufferDescription(out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag)
public override void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage)
RTFormat = m_RTFormat4;
sRGBFlag = m_RTsRGBFlag4;
int gBufferCount;
bool supportShadowMask;
bool supportLightLayers;
GetGBufferOptions(asset, out gBufferCount, out supportShadowMask, out supportLightLayers);
RTFormat = new RenderTextureFormat[gBufferCount];
sRGBFlag = new bool[gBufferCount];
gBufferUsage = new GBufferUsage[gBufferCount];
RTFormat[0] = RenderTextureFormat.ARGB32; // Albedo sRGB / SSSBuffer
sRGBFlag[0] = true;
gBufferUsage[0] = GBufferUsage.SubsurfaceScattering;
RTFormat[1] = RenderTextureFormat.ARGB32; // Normal Buffer
sRGBFlag[1] = false;
gBufferUsage[1] = GBufferUsage.Normal;
RTFormat[2] = RenderTextureFormat.ARGB32; // Data
sRGBFlag[2] = false;
gBufferUsage[2] = GBufferUsage.None;
RTFormat[3] = Builtin.GetLightingBufferFormat();
sRGBFlag[3] = Builtin.GetLightingBufferSRGBFlag();
gBufferUsage[3] = GBufferUsage.None;
int index = 4;
if (supportLightLayers)
{
RTFormat[index] = RenderTextureFormat.ARGB32;
sRGBFlag[index] = false;
gBufferUsage[index] = GBufferUsage.LightLayers;
index++;
}
// All buffer above are fixed. However shadow mask buffer can be setup or not depends on light in view.
// Thus it need to be the last one, so all indexes stay the same
if (supportShadowMask)
{
RTFormat[index] = Builtin.GetShadowMaskBufferFormat();
sRGBFlag[index] = Builtin.GetShadowMaskBufferSRGBFlag();
gBufferUsage[index] = GBufferUsage.ShadowMask;
index++;
}
//-----------------------------------------------------------------------------
// Init precomputed texture

52
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.cs.hlsl


#define DEBUGVIEW_LIT_BSDFDATA_MATERIAL_FEATURES (1050)
#define DEBUGVIEW_LIT_BSDFDATA_DIFFUSE_COLOR (1051)
#define DEBUGVIEW_LIT_BSDFDATA_FRESNEL0 (1052)
#define DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION (1053)
#define DEBUGVIEW_LIT_BSDFDATA_NORMAL_WS (1054)
#define DEBUGVIEW_LIT_BSDFDATA_NORMAL_VIEW_SPACE (1055)
#define DEBUGVIEW_LIT_BSDFDATA_PERCEPTUAL_ROUGHNESS (1056)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_MASK (1057)
#define DEBUGVIEW_LIT_BSDFDATA_DIFFUSION_PROFILE (1058)
#define DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_MASK (1059)
#define DEBUGVIEW_LIT_BSDFDATA_THICKNESS (1060)
#define DEBUGVIEW_LIT_BSDFDATA_USE_THICK_OBJECT_MODE (1061)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE (1062)
#define DEBUGVIEW_LIT_BSDFDATA_TANGENT_WS (1063)
#define DEBUGVIEW_LIT_BSDFDATA_BITANGENT_WS (1064)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_T (1065)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B (1066)
#define DEBUGVIEW_LIT_BSDFDATA_ANISOTROPY (1067)
#define DEBUGVIEW_LIT_BSDFDATA_IRIDESCENCE_THICKNESS (1068)
#define DEBUGVIEW_LIT_BSDFDATA_IRIDESCENCE_MASK (1069)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS (1070)
#define DEBUGVIEW_LIT_BSDFDATA_IOR (1071)
#define DEBUGVIEW_LIT_BSDFDATA_ABSORPTION_COEFFICIENT (1072)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE_MASK (1073)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+GBufferMaterial: static fields
//
#define GBUFFERMATERIAL_COUNT (4)
#define DEBUGVIEW_LIT_BSDFDATA_AMBIENT_OCCLUSION (1053)
#define DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION (1054)
#define DEBUGVIEW_LIT_BSDFDATA_NORMAL_WS (1055)
#define DEBUGVIEW_LIT_BSDFDATA_NORMAL_VIEW_SPACE (1056)
#define DEBUGVIEW_LIT_BSDFDATA_PERCEPTUAL_ROUGHNESS (1057)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_MASK (1058)
#define DEBUGVIEW_LIT_BSDFDATA_DIFFUSION_PROFILE (1059)
#define DEBUGVIEW_LIT_BSDFDATA_SUBSURFACE_MASK (1060)
#define DEBUGVIEW_LIT_BSDFDATA_THICKNESS (1061)
#define DEBUGVIEW_LIT_BSDFDATA_USE_THICK_OBJECT_MODE (1062)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE (1063)
#define DEBUGVIEW_LIT_BSDFDATA_TANGENT_WS (1064)
#define DEBUGVIEW_LIT_BSDFDATA_BITANGENT_WS (1065)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_T (1066)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B (1067)
#define DEBUGVIEW_LIT_BSDFDATA_ANISOTROPY (1068)
#define DEBUGVIEW_LIT_BSDFDATA_IRIDESCENCE_THICKNESS (1069)
#define DEBUGVIEW_LIT_BSDFDATA_IRIDESCENCE_MASK (1070)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS (1071)
#define DEBUGVIEW_LIT_BSDFDATA_IOR (1072)
#define DEBUGVIEW_LIT_BSDFDATA_ABSORPTION_COEFFICIENT (1073)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE_MASK (1074)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Lit+SurfaceData
// PackingRules = Exact

uint materialFeatures;
float3 diffuseColor;
float3 fresnel0;
float ambientOcclusion;
float specularOcclusion;
float3 normalWS;
float perceptualRoughness;

break;
case DEBUGVIEW_LIT_BSDFDATA_FRESNEL0:
result = bsdfdata.fresnel0;
break;
case DEBUGVIEW_LIT_BSDFDATA_AMBIENT_OCCLUSION:
result = bsdfdata.ambientOcclusion.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION:
result = bsdfdata.specularOcclusion.xxx;

139
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl


TEXTURE2D(_GBufferTexture0);
TEXTURE2D(_GBufferTexture1);
TEXTURE2D(_GBufferTexture2);
TEXTURE2D(_GBufferTexture3);
TEXTURE2D(_GBufferTexture3); // Bake lighting and/or emissive
TEXTURE2D(_GBufferTexture4); // Light layer or shadow mask
TEXTURE2D(_GBufferTexture5); // shadow mask
TEXTURE2D(_LightLayersTexture);
#ifdef SHADOWS_SHADOWMASK
TEXTURE2D(_ShadowMaskTexture); // Alias for shadow mask, so we don't need to know which gbuffer is used for shadow mask
#endif
#include "HDRP/Material/LTCAreaLight/LTCAreaLight.hlsl"
#include "HDRP/Material/PreIntegratedFGD/PreIntegratedFGD.hlsl"

#define GBufferType1 float4
#define GBufferType2 float4
#define GBufferType3 float4
#define GBufferType4 float4
#define GBufferType5 float4
#ifdef LIGHT_LAYERS
#define GBUFFERMATERIAL_LIGHT_LAYERS 1
#else
#define GBUFFERMATERIAL_LIGHT_LAYERS 0
#endif
#ifdef SHADOWS_SHADOWMASK
#define GBUFFERMATERIAL_SHADOWMASK 1
#else
#define GBUFFERMATERIAL_SHADOWMASK 0
#endif
// Caution: This must be in sync with Lit.cs GetMaterialGBufferCount()
#define GBUFFERMATERIAL_COUNT (4 + GBUFFERMATERIAL_LIGHT_LAYERS + GBUFFERMATERIAL_SHADOWMASK)
#if defined(LIGHT_LAYERS) && defined(SHADOWS_SHADOWMASK)
#define OUT_GBUFFER_LIGHT_LAYERS outGBuffer4
#define OUT_GBUFFER_SHADOWMASK outGBuffer5
#elif defined(LIGHT_LAYERS)
#define OUT_GBUFFER_LIGHT_LAYERS outGBuffer4
#elif defined(SHADOWS_SHADOWMASK)
#define OUT_GBUFFER_SHADOWMASK outGBuffer4
#endif
#define HAS_REFRACTION (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE)) && (defined(_REFRACTION_SSRAY_PROXY) || defined(_REFRACTION_SSRAY_HIZ))

bsdfData.materialFeatures = surfaceData.materialFeatures;
// Standard material
bsdfData.ambientOcclusion = surfaceData.ambientOcclusion;
bsdfData.specularOcclusion = surfaceData.specularOcclusion;
bsdfData.normalWS = surfaceData.normalWS;
bsdfData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness);

// Encode SurfaceData (BSDF parameters) into GBuffer
// Must be in sync with RT declared in HDRenderPipeline.cs ::Rebuild
void EncodeIntoGBuffer( SurfaceData surfaceData,
float3 bakeDiffuseLighting,
uint2 positionSS,
out GBufferType0 outGBuffer0,
out GBufferType1 outGBuffer1,
out GBufferType2 outGBuffer2,
out GBufferType3 outGBuffer3
void EncodeIntoGBuffer( SurfaceData surfaceData
, BuiltinData builtinData
, uint2 positionSS
, out GBufferType0 outGBuffer0
, out GBufferType1 outGBuffer1
, out GBufferType2 outGBuffer2
, out GBufferType3 outGBuffer3
#if GBUFFERMATERIAL_COUNT > 4
, out GBufferType4 outGBuffer4
#endif
#if GBUFFERMATERIAL_COUNT > 5
, out GBufferType5 outGBuffer5
#endif
)
{
// RT0 - 8:8:8:8 sRGB

outGBuffer2.a = PackFloatInt8bit(coatMask, materialFeatureId, 8);
// RT3 - 11f:11f:10f
outGBuffer3 = float4(bakeDiffuseLighting, 0.0);
outGBuffer3 = float4(builtinData.bakeDiffuseLighting, 0.0);
#ifdef LIGHT_LAYERS
// If we have light layers, take the opportunity to save AO and avoid double occlusion with SSAO
OUT_GBUFFER_LIGHT_LAYERS = float4(0.0, 0.0, surfaceData.ambientOcclusion, builtinData.renderingLayers / 255.0);
#endif
#ifdef SHADOWS_SHADOWMASK
OUT_GBUFFER_SHADOWMASK = BUILTIN_DATA_SHADOW_MASK;
#endif
}
// Fills the BSDFData. Also returns the (per-pixel) material feature flags inferred

// If you're not using the feature classification system, pass UINT_MAX.
// Also, see comment in TileVariantToFeatureFlags. When we are the worse case (i.e last variant), we read the featureflags
// from the structured buffer use to generate the indirect draw call. It allow to not go through all branch and the branch is scalar (not VGPR)
uint DecodeFromGBuffer(uint2 positionSS, uint tileFeatureFlags, out BSDFData bsdfData, out float3 bakeDiffuseLighting)
uint DecodeFromGBuffer(uint2 positionSS, uint tileFeatureFlags, out BSDFData bsdfData, out BuiltinData builtinData)
// Note: Some properties of builtinData are not used, just init all at 0 to silent the compiler
ZERO_INITIALIZE(BuiltinData, builtinData);
// Isolate material features.
tileFeatureFlags &= MATERIAL_FEATURE_MASK_FLAGS;

GBufferType2 inGBuffer2 = LOAD_TEXTURE2D(_GBufferTexture2, positionSS);
GBufferType3 inGBuffer3 = LOAD_TEXTURE2D(_GBufferTexture3, positionSS);
// BuiltinData
builtinData.bakeDiffuseLighting = LOAD_TEXTURE2D(_GBufferTexture3, positionSS).rgb; // This also contain emissive
// Avoid to introduce a new variant for light layer as it is already long to compile
if (_EnableLightLayers)
{
float4 inGBuffer4 = LOAD_TEXTURE2D(_LightLayersTexture, positionSS);
// If we have light layers, take the opportunity to save AO and avoid double occlusion with SSAO
bsdfData.ambientOcclusion = inGBuffer4.z;
builtinData.renderingLayers = uint(inGBuffer4.w * 255.5);
}
else
{
bsdfData.ambientOcclusion = 1.0; // No value available, just settings 1.0. This mean double occlusion with SSAO.
builtinData.renderingLayers = DEFAULT_LIGHT_LAYERS;
}
// We know the GBufferType no need to use abstraction
#ifdef SHADOWS_SHADOWMASK
float4 shadowMaskGbuffer = LOAD_TEXTURE2D(_ShadowMaskTexture, positionSS);
builtinData.shadowMask0 = shadowMaskGbuffer.x;
builtinData.shadowMask1 = shadowMaskGbuffer.y;
builtinData.shadowMask2 = shadowMaskGbuffer.z;
builtinData.shadowMask3 = shadowMaskGbuffer.w;
#else
builtinData.shadowMask0 = 1.0;
builtinData.shadowMask1 = 1.0;
builtinData.shadowMask2 = 1.0;
builtinData.shadowMask3 = 1.0;
#endif
// SurfaceData
// Material classification only uses the G-Buffer 2.
float coatMask;

bsdfData.normalWS = normalData.normalWS;
bsdfData.perceptualRoughness = normalData.perceptualRoughness;
bakeDiffuseLighting = inGBuffer3.rgb;
// Decompress feature-specific data from the G-Buffer.
bool pixelHasMetallic = HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_ANISOTROPY | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE);

uint MaterialFeatureFlagsFromGBuffer(uint2 positionSS)
{
BSDFData bsdfData;
float3 unused;
BuiltinData unused;
// Call the regular function, compiler will optimized out everything not used.
// Note that all material feature flag bellow are in the same GBuffer (inGBuffer2) and thus material classification only sample one Gbuffer
return DecodeFromGBuffer(positionSS, UINT_MAX, bsdfData, unused);

DirectLighting EvaluateBSDF_Directional(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput, PreLightData preLightData,
DirectionalLightData lightData, BSDFData bsdfData,
BakeLightingData bakeLightingData)
BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

float3 color;
float attenuation;
EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, N, L, color, attenuation);
EvaluateLight_Directional(lightLoopContext, posInput, lightData, builtinData, N, L, color, attenuation);
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light)

DirectLighting EvaluateBSDF_Punctual(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData)
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

float3 color;
float attenuation;
EvaluateLight_Punctual(lightLoopContext, posInput, lightData, bakeLightingData, N, L,
EvaluateLight_Punctual(lightLoopContext, posInput, lightData, builtinData, N, L,
lightToSample, distances, color, attenuation);
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light)

DirectLighting EvaluateBSDF_Line( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData)
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

DirectLighting EvaluateBSDF_Rect( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData)
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData,
BSDFData bsdfData, BakeLightingData bakeLightingData)
BSDFData bsdfData, BuiltinData builtinData)
return EvaluateBSDF_Line(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, bakeLightingData);
return EvaluateBSDF_Line(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, builtinData);
return EvaluateBSDF_Rect(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, bakeLightingData);
return EvaluateBSDF_Rect(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, builtinData);
}
}

void PostEvaluateBSDF( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, BSDFData bsdfData, BakeLightingData bakeLightingData, AggregateLighting lighting,
PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting,
GetScreenSpaceAmbientOcclusion(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, 1.0, bsdfData.specularOcclusion, aoFactor);
GetScreenSpaceAmbientOcclusion(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, aoFactor);
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, 1.0, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
ApplyAmbientOcclusionFactor(aoFactor, bakeLightingData, lighting);
ApplyAmbientOcclusionFactor(aoFactor, builtinData, lighting);
// Subsurface scattering mode
float3 modifiedDiffuseColor = GetModifiedDiffuseColorForSSS(bsdfData);

diffuseLighting = modifiedDiffuseColor * lighting.direct.diffuse + bakeLightingData.bakeDiffuseLighting;
diffuseLighting = modifiedDiffuseColor * lighting.direct.diffuse + builtinData.bakeDiffuseLighting;
// If refraction is enable we use the transmittanceMask to lerp between current diffuse lighting and refraction value
// Physically speaking, transmittanceMask should be 1, but for artistic reasons, we let the value vary

specularLighting *= 1.0 + bsdfData.fresnel0 * preLightData.energyCompensation;
#ifdef DEBUG_DISPLAY
PostEvaluateBSDFDebugDisplay(aoFactor, bakeLightingData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
#endif
}

3
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.shader


#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#pragma enable_d3d11_debug_symbols
//-------------------------------------------------------------------------------------
// Variant
//-------------------------------------------------------------------------------------

//enable GPU instancing support
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
//-------------------------------------------------------------------------------------
// Define

#pragma multi_compile _ SHADOWS_SHADOWMASK
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#pragma multi_compile _ LIGHT_LAYERS
#ifdef _ALPHATEST_ON
// When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer

3
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitBuiltinData.hlsl


builtinData.distortionBlur = 0.0;
#endif
// Use uniform directly - The float need to be cast to uint (as unity don't support to set a uint as uniform)
builtinData.renderingLayers = _EnableLightLayers ? asuint(unity_RenderingLayer.x) : DEFAULT_LIGHT_LAYERS;
builtinData.depthOffset = depthOffset;
}

3
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitTessellation.shader


//enable GPU instancing support
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
//-------------------------------------------------------------------------------------
// Define

#pragma multi_compile _ SHADOWS_SHADOWMASK
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
// We need to define OFF version for variant stripper
#pragma multi_compile _ LIGHT_LAYERS
#ifdef _ALPHATEST_ON
// When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer

64
com.unity.render-pipelines.high-definition/HDRP/Material/Material.hlsl


out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out GBufferType1 MERGE_NAME(NAME, 1) : SV_Target1
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1))
#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target2
#endif
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1))
#elif GBUFFERMATERIAL_COUNT == 3

out GBufferType2 MERGE_NAME(NAME, 2) : SV_Target2
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target3
#endif
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#elif GBUFFERMATERIAL_COUNT == 4

out GBufferType2 MERGE_NAME(NAME, 2) : SV_Target2, \
out GBufferType3 MERGE_NAME(NAME, 3) : SV_Target3
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target4
#endif
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#elif GBUFFERMATERIAL_COUNT == 5

out GBufferType3 MERGE_NAME(NAME, 3) : SV_Target3, \
out GBufferType4 MERGE_NAME(NAME, 4) : SV_Target4
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target5
#endif
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#elif GBUFFERMATERIAL_COUNT == 6

out GBufferType4 MERGE_NAME(NAME, 4) : SV_Target4, \
out GBufferType5 MERGE_NAME(NAME, 5) : SV_Target5
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4), MERGE_NAME(NAME, 5))
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4), MERGE_NAME(NAME, 5))
#ifdef SHADOWS_SHADOWMASK
#define OUTPUT_GBUFFER_SHADOWMASK(NAME) ,out float4 NAME : SV_Target6
#endif
#elif GBUFFERMATERIAL_COUNT == 7
#endif
#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, \
out GBufferType5 MERGE_NAME(NAME, 5) : SV_Target5, \
out GBufferType6 MERGE_NAME(NAME, 6) : SV_Target6
#define DECODE_FROM_GBUFFER(UNPOSITIONSS, FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(UNPOSITIONSS, FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define MATERIAL_FEATURE_FLAGS_FROM_GBUFFER(UNPOSITIONSS) MaterialFeatureFlagsFromGBuffer(UNPOSITIONSS)
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4), MERGE_NAME(NAME, 5), MERGE_NAME(NAME, 6))
#ifdef SHADOWS_SHADOWMASK
#define ENCODE_SHADOWMASK_INTO_GBUFFER(SHADOWMASK, NAME) EncodeShadowMask(SHADOWMASK, NAME)
#else
#define OUTPUT_GBUFFER_SHADOWMASK(NAME)
#define ENCODE_SHADOWMASK_INTO_GBUFFER(SHADOWMASK, NAME)
#elif GBUFFERMATERIAL_COUNT == 8
#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, \
out GBufferType5 MERGE_NAME(NAME, 5) : SV_Target5, \
out GBufferType6 MERGE_NAME(NAME, 6) : SV_Target6, \
out GBufferType7 MERGE_NAME(NAME, 7) : SV_Target7
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, NAME) EncodeIntoGBuffer(SURFACE_DATA, BUILTIN_DATA, UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4), MERGE_NAME(NAME, 5), MERGE_NAME(NAME, 6), MERGE_NAME(NAME, 7))
#define DECODE_FROM_GBUFFER(UNPOSITIONSS, FEATURE_FLAGS, BSDF_DATA, BUILTIN_DATA) DecodeFromGBuffer(UNPOSITIONSS, FEATURE_FLAGS, BSDF_DATA, BUILTIN_DATA)
#define MATERIAL_FEATURE_FLAGS_FROM_GBUFFER(UNPOSITIONSS) MaterialFeatureFlagsFromGBuffer(UNPOSITIONSS)
#endif // #ifdef GBUFFERMATERIAL_COUNT

16
com.unity.render-pipelines.high-definition/HDRP/Material/MaterialEvaluation.hlsl


aoFactor.directAmbientOcclusion = GTAOMultiBounce(directAmbientOcclusion, diffuseColor);
}
void ApplyAmbientOcclusionFactor(AmbientOcclusionFactor aoFactor, inout BakeLightingData bakeLightingData, inout AggregateLighting lighting)
void ApplyAmbientOcclusionFactor(AmbientOcclusionFactor aoFactor, inout BuiltinData builtinData, inout AggregateLighting lighting)
// Note: in case of Lit, bakeLightingData.bakeDiffuseLighting contain indirect diffuse + emissive,
// Note: in case of deferred Lit, builtinData.bakeDiffuseLighting contain indirect diffuse + emissive,
bakeLightingData.bakeDiffuseLighting *= aoFactor.indirectAmbientOcclusion;
builtinData.bakeDiffuseLighting *= aoFactor.indirectAmbientOcclusion;
lighting.indirect.specularReflected *= aoFactor.indirectSpecularOcclusion;
lighting.direct.diffuse *= aoFactor.directAmbientOcclusion;
}

void PostEvaluateBSDFDebugDisplay( AmbientOcclusionFactor aoFactor, BakeLightingData bakeLightingData, AggregateLighting lighting, float3 mipmapColor,
void PostEvaluateBSDFDebugDisplay( AmbientOcclusionFactor aoFactor, BuiltinData builtinData, AggregateLighting lighting, float3 mipmapColor,
inout float3 diffuseLighting, inout float3 specularLighting)
{
if (_DebugLightingMode != 0)

switch (_DebugLightingMode)
{
case DEBUGLIGHTINGMODE_LUX_METER:
diffuseLighting = lighting.direct.diffuse + bakeLightingData.bakeDiffuseLighting;
diffuseLighting = lighting.direct.diffuse + builtinData.bakeDiffuseLighting;
//Compress lighting values for color picker if enabled
if (_ColorPickerMode != COLORPICKERDEBUGMODE_NONE)

case DEBUGLIGHTINGMODE_VISUALIZE_SHADOW_MASKS:
#ifdef SHADOWS_SHADOWMASK
diffuseLighting = float3(
bakeLightingData.bakeShadowMask.r / 2 + bakeLightingData.bakeShadowMask.g / 2,
bakeLightingData.bakeShadowMask.g / 2 + bakeLightingData.bakeShadowMask.b / 2,
bakeLightingData.bakeShadowMask.b / 2 + bakeLightingData.bakeShadowMask.a / 2
builtinData.shadowMask0 / 2 + builtinData.shadowMask1 / 2,
builtinData.shadowMask1 / 2 + builtinData.shadowMask2 / 2,
builtinData.shadowMask2 / 2 + builtinData.shadowMask3 / 2
);
specularLighting = float3(0, 0, 0);
#endif

2
com.unity.render-pipelines.high-definition/HDRP/Material/NormalBufferManager.cs


else
{
// In case of deferred, we must be in sync with NormalBuffer.hlsl and lit.hlsl files and setup the correct buffers
m_ColorMRTs[0] = gbufferManager.GetBuffer(1); // Normal + Roughness is GBuffer(1)
m_ColorMRTs[0] = gbufferManager.GetNormalBuffer(0); // Normal + Roughness
m_ExternalBuffer[0] = true;
}
}

8
com.unity.render-pipelines.high-definition/HDRP/Material/RenderPipelineMaterial.cs


public class RenderPipelineMaterial : Object
{
// GBuffer management
public virtual int GetMaterialGBufferCount() { return 0; }
public virtual void GetMaterialGBufferDescription(out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag)
public virtual bool IsDefferedMaterial() { return false; }
public virtual int GetMaterialGBufferCount(HDRenderPipelineAsset asset) { return 0; }
public virtual void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage)
}
gBufferUsage = null;
}
// Regular interface
public virtual void Build(HDRenderPipelineAsset hdAsset) {}

26
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl


DirectLighting EvaluateBSDF_Directional(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput, PreLightData preLightData,
DirectionalLightData lightData, BSDFData bsdfData,
BakeLightingData bakeLightingData)
BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

// color and attenuation are outputted by EvaluateLight:
float3 color;
float attenuation;
EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, shadowBiasNormal, L, color, attenuation);
EvaluateLight_Directional(lightLoopContext, posInput, lightData, builtinData, shadowBiasNormal, L, color, attenuation);
float intensity = max(0, attenuation); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light)

DirectLighting EvaluateBSDF_Punctual(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData)
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

float3 color;
float attenuation;
EvaluateLight_Punctual(lightLoopContext, posInput, lightData, bakeLightingData, shadowBiasNormal, L,
EvaluateLight_Punctual(lightLoopContext, posInput, lightData, builtinData, shadowBiasNormal, L,
lightToSample, distances, color, attenuation);

DirectLighting EvaluateBSDF_Line( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData)
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

DirectLighting EvaluateBSDF_Rect( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BakeLightingData bakeLightingData)
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);

DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, LightData lightData,
BSDFData bsdfData, BakeLightingData bakeLightingData)
BSDFData bsdfData, BuiltinData builtinData)
return EvaluateBSDF_Line(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, bakeLightingData);
return EvaluateBSDF_Line(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, builtinData);
return EvaluateBSDF_Rect(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, bakeLightingData);
return EvaluateBSDF_Rect(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, builtinData);
}
}

void PostEvaluateBSDF( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, BSDFData bsdfData, BakeLightingData bakeLightingData, AggregateLighting lighting,
PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting,
out float3 diffuseLighting, out float3 specularLighting)
{
float3 N;

// Use GTAOMultiBounce approximation for ambient occlusion (allow to get a tint from the baseColor)
//GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, lerp(bsdfData.perceptualRoughnessA, bsdfData.perceptualRoughnessB, bsdfData.lobeMix), bsdfData.ambientOcclusion, 1.0, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, unclampedNdotV, lerp(bsdfData.perceptualRoughnessA, bsdfData.perceptualRoughnessB, bsdfData.lobeMix), bsdfData.ambientOcclusion, 1.0, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
ApplyAmbientOcclusionFactor(aoFactor, bakeLightingData, lighting);
ApplyAmbientOcclusionFactor(aoFactor, builtinData, lighting);
// Subsurface scattering mode
float3 modifiedDiffuseColor = GetModifiedDiffuseColorForSSS(bsdfData);

diffuseLighting = modifiedDiffuseColor * lighting.direct.diffuse + bakeLightingData.bakeDiffuseLighting;
diffuseLighting = modifiedDiffuseColor * lighting.direct.diffuse + builtinData.bakeDiffuseLighting;
PostEvaluateBSDFDebugDisplay(aoFactor, bakeLightingData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
#endif
}

1
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader


//enable GPU instancing support
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
//-------------------------------------------------------------------------------------
// Define

3
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl


builtinData.distortionBlur = 0.0;
#endif
// Use uniform directly - The float need to be cast to uint (as unity don't support to set a uint as uniform)
builtinData.renderingLayers = _EnableLightLayers ? asuint(unity_RenderingLayer.x) : DEFAULT_LIGHT_LAYERS;
builtinData.depthOffset = 0.0;
}

2
com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs


else
{
// In case of deferred, we must be in sync with SubsurfaceScattering.hlsl and lit.hlsl files and setup the correct buffers
m_ColorMRTs[0] = gbufferManager.GetBuffer(0); // Note: This buffer must be sRGB (which is the case with Lit.shader)
m_ColorMRTs[0] = gbufferManager.GetSubsurfaceScatteringBuffer(0); // Note: This buffer must be sRGB (which is the case with Lit.shader)
m_ExternalBuffer[0] = true;
}

2
com.unity.render-pipelines.high-definition/HDRP/Material/Unlit/UnlitData.hlsl


builtinData.distortionBlur = 0.0;
#endif
builtinData.renderingLayers = 0;
builtinData.depthOffset = 0.0;
#if defined(DEBUG_DISPLAY)

17
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs


m_DeferredMaterial = null;
foreach (var material in m_MaterialList)
{
if (material.GetMaterialGBufferCount() > 0)
if (material.IsDefferedMaterial())
m_DeferredMaterial = material;
}

// Debug.Assert(m_DeferredMaterial != null);
m_GbufferManager = new GBufferManager(m_DeferredMaterial, m_Asset.renderPipelineSettings.supportShadowMask);
m_GbufferManager = new GBufferManager(asset, m_DeferredMaterial);
m_DbufferManager = new DBufferManager();
m_SSSBufferManager.Build(asset);

m_currentDebugViewMaterialGBuffer = enableBakeShadowMask ? m_DebugViewMaterialGBufferShadowMask : m_DebugViewMaterialGBuffer;
}
public void ConfigureForLightLayers(bool enableLightLayers, CommandBuffer cmd)
{
CoreUtils.SetKeyword(cmd, "LIGHT_LAYERS", enableLightLayers);
cmd.SetGlobalInt(HDShaderIDs._EnableLightLayers, enableLightLayers ? 1 : 0);
}
public void ConfigureForDecal(CommandBuffer cmd)
{
if (m_Asset.renderPipelineSettings.supportDecals)

enableBakeShadowMask = m_LightLoop.PrepareLightsForGPU(cmd, hdCamera, m_ShadowSettings, m_CullResults, m_ReflectionProbeCullResults, densityVolumes);
}
ConfigureForShadowMask(enableBakeShadowMask, cmd);
ConfigureForLightLayers(hdCamera.frameSettings.enableLightLayers, cmd);
ConfigureForDecal(cmd);
StartStereoRendering(renderContext, hdCamera);

// This will bind the depth buffer if needed for DBuffer)
RenderDBuffer(hdCamera, cmd, renderContext, m_CullResults);
RenderGBuffer(m_CullResults, hdCamera, enableBakeShadowMask, renderContext, cmd);
RenderGBuffer(m_CullResults, hdCamera, renderContext, cmd);
// We can now bind the normal buffer to be use by any effect
m_NormalBufferManager.BindNormalBuffers(cmd);

// RenderGBuffer do the gbuffer pass. This is solely call with deferred. If we use a depth prepass, then the depth prepass will perform the alpha testing for opaque apha tested and we don't need to do it anymore
// during Gbuffer pass. This is handled in the shader and the depth test (equal and no depth write) is done here.
void RenderGBuffer(CullResults cull, HDCamera hdCamera, bool enableShadowMask, ScriptableRenderContext renderContext, CommandBuffer cmd)
void RenderGBuffer(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (hdCamera.frameSettings.enableForwardRenderingOnly)
return;

// setup GBuffer for rendering
HDUtils.SetRenderTarget(cmd, hdCamera, m_GbufferManager.GetBuffersRTI(enableShadowMask), m_CameraDepthStencilBuffer);
HDUtils.SetRenderTarget(cmd, hdCamera, m_GbufferManager.GetBuffersRTI(hdCamera.frameSettings), m_CameraDepthStencilBuffer);
RenderOpaqueRenderList(cull, hdCamera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, HDRenderQueue.k_RenderQueue_AllOpaque);
m_GbufferManager.BindBufferAsTextures(cmd);

37
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipelineAsset.cs


[SerializeField]
public DiffusionProfileSettings diffusionProfileSettings;
// HDRP use GetRenderingLayerMaskNames to create its light linking system
// Mean here we define our name for light linking.
[System.NonSerialized]
string[] m_RenderingLayerNames = null;
string[] renderingLayerNames
{
get
{
if (m_RenderingLayerNames == null)
{
m_RenderingLayerNames = new string[32];
// By design we can't touch this one, but we can rename it
m_RenderingLayerNames[0] = "Light Layer default";
// We only support up to 7 layer + default.
for (int i = 1; i < 8; ++i)
{
m_RenderingLayerNames[i] = string.Format("Light Layer {0}", i);
}
// Unused
for (int i = 8; i < m_RenderingLayerNames.Length; ++i)
{
m_RenderingLayerNames[i] = string.Format("Unused {0}", i);
}
}
return m_RenderingLayerNames;
}
}
public override string[] GetRenderingLayerMaskNames()
{
return renderingLayerNames;
}
public override Shader GetDefaultShader()
{
return m_RenderPipelineResources.defaultShader;

3
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _VelocityTexture = Shader.PropertyToID("_VelocityTexture");
public static readonly int _ShadowMaskTexture = Shader.PropertyToID("_ShadowMaskTexture");
public static readonly int _LightLayersTexture = Shader.PropertyToID("_LightLayersTexture");
public static readonly int _DistortionTexture = Shader.PropertyToID("_DistortionTexture");
public static readonly int _ColorPyramidTexture = Shader.PropertyToID("_ColorPyramidTexture");
public static readonly int _DepthPyramidTexture = Shader.PropertyToID("_DepthPyramidTexture");

public static readonly int _NumVisibleDensityVolumes = Shader.PropertyToID("_NumVisibleDensityVolumes");
public static readonly int _VolumeMaskAtlas = Shader.PropertyToID("_VolumeMaskAtlas");
public static readonly int _VolumeMaskDimensions = Shader.PropertyToID("_VolumeMaskDimensions");
public static readonly int _EnableLightLayers = Shader.PropertyToID("_EnableLightLayers");
// Preintegrated texture name
public static readonly int _PreIntegratedFGD_GGXDisneyDiffuse = Shader.PropertyToID("_PreIntegratedFGD_GGXDisneyDiffuse");

21
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/FrameSettings.cs


// Setup by users
public bool enableShadow = true;
public bool enableContactShadows = true;
public bool enableShadowMask = true;
public bool enableSSR = true; // Depends on DepthPyramid
public bool enableSSAO = true;
public bool enableSubsurfaceScattering = true;

public bool enableLightLayers = true;
// Setup by system
public float diffuseGlobalDimmer = 1.0f;

public bool enableMSAA = false;
public MSAASamples msaaSampleCount { get; private set; }
public bool enableShadowMask = true;
public LightLoopSettings lightLoopSettings = new LightLoopSettings();
public void CopyTo(FrameSettings frameSettings)

frameSettings.enableShadowMask = this.enableShadowMask;
frameSettings.enableSSR = this.enableSSR;
frameSettings.enableSSAO = this.enableSSAO;
frameSettings.enableSubsurfaceScattering = this.enableSubsurfaceScattering;

frameSettings.enableLightLayers = this.enableLightLayers;
frameSettings.diffuseGlobalDimmer = this.diffuseGlobalDimmer;
frameSettings.specularGlobalDimmer = this.specularGlobalDimmer;

frameSettings.enableMSAA = this.enableMSAA;
frameSettings.enableShadowMask = this.enableShadowMask;
this.lightLoopSettings.CopyTo(frameSettings.lightLoopSettings);
}

aggregate.enableShadow = srcFrameSettings.enableShadow;
aggregate.enableContactShadows = srcFrameSettings.enableContactShadows;
aggregate.enableShadowMask = srcFrameSettings.enableShadowMask && renderPipelineSettings.supportShadowMask;
aggregate.enableSSR = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableSSR && renderPipelineSettings.supportSSR;
aggregate.enableSSAO = srcFrameSettings.enableSSAO && renderPipelineSettings.supportSSAO;
aggregate.enableSubsurfaceScattering = camera.cameraType != CameraType.Reflection && srcFrameSettings.enableSubsurfaceScattering && renderPipelineSettings.supportSubsurfaceScattering;

// TODO: Add support of volumetric in planar reflection
if (camera.cameraType == CameraType.Reflection)
aggregate.enableVolumetrics = false;
aggregate.enableLightLayers = srcFrameSettings.enableLightLayers && renderPipelineSettings.supportLightLayers;
// We have to fall back to forward-only rendering when scene view is using wireframe rendering mode
// as rendering everything in wireframe + deferred do not play well together

aggregate.enableMSAA = srcFrameSettings.enableMSAA && renderPipelineSettings.supportMSAA;
aggregate.enableShadowMask = srcFrameSettings.enableShadowMask && renderPipelineSettings.supportShadowMask;
aggregate.ConfigureMSAADependentSettings();
aggregate.ConfigureStereoDependentSettings();

aggregate.enableShadow = false;
aggregate.enableContactShadows = false;
aggregate.enableShadowMask = false;
aggregate.enableLightLayers = false;
aggregate.enableTransparentPrepass = false;
aggregate.enableMotionVectors = false;
aggregate.enableObjectMotionVectors = false;

aggregate.enablePostprocess = false;
aggregate.enableStereo = false;
aggregate.enableShadowMask = false;
aggregate.enableStereo = false;
}
LightLoopSettings.InitializeLightLoopSettings(camera, aggregate, renderPipelineSettings, srcFrameSettings, ref aggregate.lightLoopSettings);

new DebugUI.BoolField { displayName = "Enable Contact Shadows", getter = () => frameSettings.enableContactShadows, setter = value => frameSettings.enableContactShadows = value },
new DebugUI.BoolField { displayName = "Enable ShadowMask", getter = () => frameSettings.enableShadowMask, setter = value => frameSettings.enableShadowMask = value },
new DebugUI.BoolField { displayName = "Enable Atmospheric Scattering", getter = () => frameSettings.enableAtmosphericScattering, setter = value => frameSettings.enableAtmosphericScattering = value },
new DebugUI.BoolField { displayName = "Enable volumetrics", getter = () => frameSettings.enableVolumetrics, setter = value => frameSettings.enableVolumetrics = value },
new DebugUI.BoolField { displayName = "Enable Volumetrics", getter = () => frameSettings.enableVolumetrics, setter = value => frameSettings.enableVolumetrics = value },
new DebugUI.BoolField { displayName = "Enable LightLayers", getter = () => frameSettings.enableLightLayers, setter = value => frameSettings.enableLightLayers = value },
}
}
});

19
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/Settings/RenderPipelineSettings.cs


public bool supportSSR = true;
public bool supportSSAO = true;
public bool supportSubsurfaceScattering = true;
public bool increaseSssSampleCount = false;
public bool supportOnlyForward = false;
public bool increaseSssSampleCount = false;
// reduce variant
public bool supportRuntimeDebugDisplay = true;
public bool supportDitheringCrossFade = true;
public bool supportLightLayers = false;
public bool supportOnlyForward = false;
public bool supportDecals = true;
public bool supportMSAA = false;
public bool supportDecals = true;
public bool supportMSAA = false;
public bool supportMotionVectors = true;
public bool supportStereo = false;
public bool supportMotionVectors = true;
public bool supportStereo = false;
public bool supportRuntimeDebugDisplay = true;
public bool supportDitheringCrossFade = true;
public GlobalLightLoopSettings lightLoopSettings = new GlobalLightLoopSettings();
public ShadowInitParameters shadowInitParams = new ShadowInitParameters();

2
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/ApplyDistorsion.compute


#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "../Material/Builtin/BuiltinData.hlsl"
#include "HDRP/Material/Builtin/BuiltinData.hlsl"
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

9
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassForward.hlsl


#endif
float3 diffuseLighting;
float3 specularLighting;
BakeLightingData bakeLightingData;
bakeLightingData.bakeDiffuseLighting = GetBakedDiffuseLighting(surfaceData, builtinData, bsdfData, preLightData);
#ifdef SHADOWS_SHADOWMASK
bakeLightingData.bakeShadowMask = float4(builtinData.shadowMask0, builtinData.shadowMask1, builtinData.shadowMask2, builtinData.shadowMask3);
#endif
LightLoop(V, posInput, preLightData, bsdfData, bakeLightingData, featureFlags, diffuseLighting, specularLighting);
builtinData.bakeDiffuseLighting = GetBakedDiffuseLighting(surfaceData, builtinData, bsdfData, preLightData);
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
#ifdef OUTPUT_SPLIT_LIGHTING
if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))

7
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassGBuffer.hlsl


void Frag( PackedVaryingsToPS packedInput,
OUTPUT_GBUFFER(outGBuffer)
OUTPUT_GBUFFER_SHADOWMASK(outShadowMaskBuffer)
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth
#endif

PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
float3 bakeDiffuseLighting = GetBakedDiffuseLighting(surfaceData, builtinData, bsdfData, preLightData);
ENCODE_INTO_GBUFFER(surfaceData, bakeDiffuseLighting, posInput.positionSS, outGBuffer);
ENCODE_SHADOWMASK_INTO_GBUFFER(float4(builtinData.shadowMask0, builtinData.shadowMask1, builtinData.shadowMask2, builtinData.shadowMask3), outShadowMaskBuffer);
builtinData.bakeDiffuseLighting = GetBakedDiffuseLighting(surfaceData, builtinData, bsdfData, preLightData);
ENCODE_INTO_GBUFFER(surfaceData, builtinData, posInput.positionSS, outGBuffer);
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth;

4
com.unity.render-pipelines.high-definition/HDRP/ShaderVariables.hlsl


float4x4 unity_WorldToObject;
float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
float4 unity_RenderingLayer;
float4 unity_LightmapST;
float4 unity_DynamicLightmapST;

#include "Lighting/AtmosphericScattering/ShaderVariablesAtmosphericScattering.hlsl"
#include "Material/SubsurfaceScattering/ShaderVariablesSubsurfaceScattering.hlsl"
#include "Material/Decal/ShaderVariablesDecal.hlsl"
#define DEFAULT_LIGHT_LAYERS 0xFF
uint _EnableLightLayers;
CBUFFER_END

正在加载...
取消
保存