比较提交

...
此合并请求有变更与目标分支冲突。
/com.unity.render-pipelines.high-definition/HDRP/Debug/DebugLightVolume.shader
/com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
/com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs
/com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
/com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDProbe.cs
/com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalProjectorComponent.cs
/com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDCustomSamplerId.cs
/com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
/com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
/com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
/com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
/com.unity.render-pipelines.high-definition/CHANGELOG.md

31 次代码提交

作者 SHA1 备注 提交日期
Evgenii Golubev bee9896f Stop NaN propagation within volumetric lighting shader (v2) 6 年前
JulienIgnace-Unity 195a1aa2 Hdrp/fix/light gizmos and handles (#1905) 6 年前
GitHub f3dcf1c9 Merge pull request #1906 from Unity-Technologies/fix-guid-probe 6 年前
Remi Slysz c5855b88 fix guid conflict 6 年前
GitHub 80cd2648 Stop NaN propagation within volumetric lighting shader 6 年前
GitHub ab50aaeb Remove SSS jitter if TAA is off 6 年前
GitHub 4f070935 Merge pull request #1897 from Unity-Technologies/HDRP/decals/projector_api 6 年前
Paul Melamed 60654ec9 updated changelog 6 年前
Paul Melamed ab1ae523 Add API call to add and update projector decals without specifying their transform 6 年前
GitHub 3e708a4a Merge pull request #1893 from EvgeniiG/fade_for_density_volumes 6 年前
Evgenii Golubev 6539e33d Slightly improve the UX 6 年前
Evgenii Golubev 6f85ea50 Optimize a bit 6 年前
Evgenii Golubev 2b4bfe09 Update the changelog 6 年前
Evgenii Golubev b80d80b6 Implement linear boundary fade for density volumes 6 年前
GitHub b8eff734 Merge pull request #1888 from Unity-Technologies/HDRP/fix/migration-process-at-creation-of-HDReflectionProbe 6 年前
RSlysz af8f1923 Clean migration scheme for HDReflectionProbe 6 年前
GitHub d5be0410 Merge pull request #1889 from Unity-Technologies/HDRP/fix/HDReflectionProbe-preview-multiselection 6 年前
RSlysz c569ce67 Fix multi gizmo texture previews 6 年前
RSlysz 4a8e1197 Lauch migration at creation to version 6 年前
GitHub 8cdaae66 Merge pull request #1887 from Unity-Technologies/HDRP/fix-deferred-shadow-init 6 年前
Julien Ignace f31bc3c7 Merge branch 'HDRP/fix-deferred-shadow-init' of https://github.com/Unity-Technologies/ScriptableRenderPipeline into HDRP/fix-deferred-shadow-init 6 年前
Julien Ignace 6f9e37b3 Merge branch 'HDRP/staging' of https://github.com/Unity-Technologies/ScriptableRenderPipeline into HDRP/fix-deferred-shadow-init 6 年前
GitHub bb90e2f2 Update HDRenderPipeline.cs 6 年前
Julien Ignace 0effd1af Update changelog 6 年前
Julien Ignace 29a7899c Fixed an issue where sometimes the deferred shadow texture would not be valid, causing wrong rendering. 6 年前
GitHub da90dff9 Merge pull request #1886 from Unity-Technologies/HDRP/fix-decal-normal-stencil 6 年前
Julien Ignace 45d1ed50 Update changelog 6 年前
Julien Ignace a9b03372 - Fixed stencil for decal normal pass (stencil test does not apply before UAV updates by default) 6 年前
GitHub 92fa3473 Merge pull request #1857 from Unity-Technologies/HDRP/decals/v2_1/normal_buffer 6 年前
GitHub ac20dcb1 Merge pull request #1877 from Unity-Technologies/fabric-light-vol-fix 6 年前
GitHub d5d3d79d Merge pull request #1880 from Unity-Technologies/fabric_normal_decal 6 年前
共有 47 个文件被更改,包括 1127 次插入348 次删除
  1. 341
      com.unity.render-pipelines.core/CoreRP/Editor/Lighting/CoreLightEditorUtilities.cs
  2. 11
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  3. 6
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  4. 3
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  5. 7
      com.unity.render-pipelines.high-definition/HDRP/Debug/DebugLightVolume.shader
  6. 5
      com.unity.render-pipelines.high-definition/HDRP/Material/RenderPipelineMaterial.cs
  7. 7
      com.unity.render-pipelines.high-definition/HDRP/Material/GBufferManager.cs
  8. 10
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  9. 5
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl
  10. 9
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.cs
  11. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.hlsl
  12. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.shader
  13. 7
      com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricData.hlsl
  14. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalProjectorComponent.cs
  15. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl
  16. 150
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader
  17. 49
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalSystem.cs
  18. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/NormalBufferManager.cs
  19. 6
      com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute
  20. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs
  21. 7
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  22. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs
  23. 18
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Gizmos.cs
  24. 12
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Preview.cs
  25. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.cs
  26. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.ContextualMenu.cs.meta
  27. 52
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
  28. 66
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDAdditionalLightDataEditor.cs
  29. 126
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  30. 78
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDAdditionalReflectionData.cs
  31. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDProbe.cs
  32. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/InfluenceVolume.cs
  33. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  34. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/AtmosphericScattering/AtmosphericScattering.cs
  35. 4
      com.unity.render-pipelines.high-definition/HDRP/Lighting/AtmosphericScattering/VolumetricFog.cs
  36. 72
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/DensityVolume.cs
  37. 41
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs.hlsl
  38. 43
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
  39. 24
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute
  40. 74
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  41. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDCustomSamplerId.cs
  42. 45
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDRenderPipeline.cs
  43. 9
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  44. 9
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader.meta
  45. 89
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader
  46. 34
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs
  47. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs.meta

341
com.unity.render-pipelines.core/CoreRP/Editor/Lighting/CoreLightEditorUtilities.cs


{
public static class CoreLightEditorUtilities
{
static Vector2 SliderPlaneHandle(Vector3 origin, Vector3 axis1, Vector3 axis2, Vector2 position)
{
Vector3 pos = origin + position.x * axis1 + position.y * axis2;
float sizeHandle = HandleUtility.GetHandleSize(pos);
bool temp = GUI.changed;
GUI.changed = false;
pos = Handles.Slider2D(pos, Vector3.forward, axis1, axis2, sizeHandle * 0.03f, Handles.DotHandleCap, 0f);
if (GUI.changed)
{
position = new Vector2(Vector3.Dot(pos, axis1), Vector3.Dot(pos, axis2));
}
GUI.changed |= temp;
return position;
}
static float SliderLineHandle(Vector3 position, Vector3 direction, float value)
{
Vector3 pos = position + direction * value;
float sizeHandle = HandleUtility.GetHandleSize(pos);
bool temp = GUI.changed;
GUI.changed = false;
pos = Handles.Slider(pos, direction, sizeHandle * 0.03f, Handles.DotHandleCap, 0f);
if (GUI.changed)
{
value = Vector3.Dot(pos - position, direction);
}
GUI.changed |= temp;
return value;
}
static float SliderCircleHandle(Vector3 position, Vector3 normal, Vector3 zeroValueDirection, float angleValue, float radius)
{
zeroValueDirection.Normalize();
normal.Normalize();
Quaternion rot = Quaternion.AngleAxis(angleValue, normal);
Vector3 pos = position + rot * zeroValueDirection * radius;
float sizeHandle = HandleUtility.GetHandleSize(pos);
bool temp = GUI.changed;
GUI.changed = false;
Vector3 tangeant = Vector3.Cross(normal, (pos - position).normalized);
pos = Handles.Slider(pos, tangeant, sizeHandle * 0.03f, Handles.DotHandleCap, 0f);
if (GUI.changed)
{
Vector3 dir = (pos - position).normalized;
Vector3 cross = Vector3.Cross(zeroValueDirection, dir);
int sign = ((cross - normal).sqrMagnitude < (-cross - normal).sqrMagnitude) ? 1 : -1;
angleValue = Mathf.Acos(Vector3.Dot(zeroValueDirection, dir)) * Mathf.Rad2Deg * sign;
}
GUI.changed |= temp;
return angleValue;
}
public static Color GetLightHandleColor(Color wireframeColor)
{
Color color = wireframeColor;
color.a = Mathf.Clamp01(color.a * 2);
return (QualitySettings.activeColorSpace == ColorSpace.Linear) ? color.linear : color;
}
public static Color GetLightBehindObjectWireframeColor(Color wireframeColor)
{
Color color = wireframeColor;
color.a = 0.2f;
return (QualitySettings.activeColorSpace == ColorSpace.Linear) ? color.linear : color;
}
// Don't use Handles.Disc as it break the highlight of the gizmo axis, use our own draw disc function instead for gizmo
public static void DrawWireDisc(Quaternion q, Vector3 position, Vector3 axis, float radius)
{

Gizmos.DrawWireSphere(arealight.transform.position, arealight.range);
}
[Obsolete("Should use the legacy gizmo draw")]
public static void DrawPointlightGizmo(Light pointlight, bool selected)
{
if (pointlight.shadows != LightShadows.None && selected) Gizmos.DrawWireSphere(pointlight.transform.position, pointlight.shadowNearPlane);

// Same as Gizmo.DrawFrustum except that when aspect is below one, fov represent fovX instead of fovY
// Use to match our light frustum pyramid behavior
public static void DrawLightPyramidFrustum(Vector3 center, float fov, float maxRange, float minRange, float aspect)
public static void DrawPyramidFrustumWireframe(Vector4 aspectFovMaxRangeMinRange)
fov = Mathf.Deg2Rad * fov * 0.5f;
float tanfov = Mathf.Tan(fov);
float aspect = aspectFovMaxRangeMinRange.x;
float fov = aspectFovMaxRangeMinRange.y;
float maxRange = aspectFovMaxRangeMinRange.z;
float minRange = aspectFovMaxRangeMinRange.w;
float tanfov = Mathf.Tan(Mathf.Deg2Rad * fov * 0.5f);
float minXYFarEndSize = maxRange * tanfov;
Vector3 farEnd = new Vector3(0, 0, maxRange);
Vector3 endSizeX;
Vector3 endSizeY;

endSizeX = new Vector3(maxRange * tanfov * aspect, 0, 0);
endSizeY = new Vector3(0, maxRange * tanfov, 0);
endSizeX = new Vector3(minXYFarEndSize * aspect, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize, 0);
endSizeX = new Vector3(maxRange * tanfov, 0, 0);
endSizeY = new Vector3(0, maxRange * tanfov / aspect, 0);
endSizeX = new Vector3(minXYFarEndSize, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize / aspect, 0);
Vector3 s1, s2, s3, s4;
Vector3 s1 = Vector3.zero;
Vector3 s2 = Vector3.zero;
Vector3 s3 = Vector3.zero;
Vector3 s4 = Vector3.zero;
if (minRange <= 0.0f)
{
s1 = s2 = s3 = s4 = center;
}
else
if (minRange > 0.0f)
Vector3 nearEnd = new Vector3(0, 0, minRange);
float minXYStartSize = minRange * tanfov;
startSizeX = new Vector3(minRange * tanfov * aspect, 0, 0);
startSizeY = new Vector3(0, minRange * tanfov, 0);
startSizeX = new Vector3(minXYStartSize * aspect, 0, 0);
startSizeY = new Vector3(0, minXYStartSize, 0);
startSizeY = new Vector3(minRange * tanfov / aspect, 0, 0);
startSizeX = new Vector3(0, minRange * tanfov, 0);
startSizeX = new Vector3(minXYStartSize, 0, 0);
startSizeY = new Vector3(0, minXYStartSize / aspect, 0);
Vector3 startPoint = center;
s1 = startPoint + startSizeX + startSizeY;
s2 = startPoint - startSizeX + startSizeY;
s3 = startPoint - startSizeX - startSizeY;
s4 = startPoint + startSizeX - startSizeY;
Gizmos.DrawLine(s1, s2);
Gizmos.DrawLine(s2, s3);
Gizmos.DrawLine(s3, s4);
Gizmos.DrawLine(s4, s1);
Vector3 startPoint = nearEnd;
s1 = startPoint + startSizeX + startSizeY;
s2 = startPoint - startSizeX + startSizeY;
s3 = startPoint - startSizeX - startSizeY;
s4 = startPoint + startSizeX - startSizeY;
Handles.DrawLine(s1, s2);
Handles.DrawLine(s2, s3);
Handles.DrawLine(s3, s4);
Handles.DrawLine(s4, s1);
Gizmos.DrawLine(e1, e2);
Gizmos.DrawLine(e2, e3);
Gizmos.DrawLine(e3, e4);
Gizmos.DrawLine(e4, e1);
Handles.DrawLine(s1, e1);
Handles.DrawLine(s2, e2);
Handles.DrawLine(s3, e3);
Handles.DrawLine(s4, e4);
Gizmos.DrawLine(s1, e1);
Gizmos.DrawLine(s2, e2);
Gizmos.DrawLine(s3, e3);
Gizmos.DrawLine(s4, e4);
Handles.DrawLine(e1, e2);
Handles.DrawLine(e2, e3);
Handles.DrawLine(e3, e4);
Handles.DrawLine(e4, e1);
public static void DrawLightOrthoFrustum(Vector3 center, float width, float height, float maxRange, float minRange)
public static Vector4 DrawPyramidFrustumHandle(Vector4 aspectFovMaxRangeMinRange, bool useNearPlane, float minAspect = 0.05f, float maxAspect = 20f, float minFov = 1f)
float aspect = aspectFovMaxRangeMinRange.x;
float fov = aspectFovMaxRangeMinRange.y;
float maxRange = aspectFovMaxRangeMinRange.z;
float minRange = aspectFovMaxRangeMinRange.w;
float tanfov = Mathf.Tan(Mathf.Deg2Rad * fov * 0.5f);
float minXYFarEndSize = maxRange * tanfov;
Vector3 endSizeX = new Vector3(width, 0, 0);
Vector3 endSizeY = new Vector3(0, height, 0);
Vector3 endSizeX;
Vector3 endSizeY;
Vector3 s1, s2, s3, s4;
Vector3 e1 = farEnd + endSizeX + endSizeY;
Vector3 e2 = farEnd - endSizeX + endSizeY;
Vector3 e3 = farEnd - endSizeX - endSizeY;
Vector3 e4 = farEnd + endSizeX - endSizeY;
if (minRange <= 0.0f)
if (aspect >= 1.0f)
s1 = s2 = s3 = s4 = center;
endSizeX = new Vector3(minXYFarEndSize * aspect, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize, 0);
Vector3 startSizeX = new Vector3(width, 0, 0);
Vector3 startSizeY = new Vector3(0, height, 0);
endSizeX = new Vector3(minXYFarEndSize, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize / aspect, 0);
}
Vector3[] e = new Vector3[]
{
farEnd + endSizeX + endSizeY,
farEnd - endSizeX + endSizeY,
farEnd - endSizeX - endSizeY,
farEnd + endSizeX - endSizeY
};
if (useNearPlane)
{
minRange = SliderLineHandle(Vector3.zero, Vector3.forward, minRange);
}
Vector3 startPoint = center;
s1 = startPoint + startSizeX + startSizeY;
s2 = startPoint - startSizeX + startSizeY;
s3 = startPoint - startSizeX - startSizeY;
s4 = startPoint + startSizeX - startSizeY;
Gizmos.DrawLine(s1, s2);
Gizmos.DrawLine(s2, s3);
Gizmos.DrawLine(s3, s4);
Gizmos.DrawLine(s4, s1);
maxRange = SliderLineHandle(Vector3.zero, Vector3.forward, maxRange);
//find the righttop corner in screen
Vector2[] screenPositions = new Vector2[]
{
Camera.current.WorldToScreenPoint(Handles.matrix * e[0]),
Camera.current.WorldToScreenPoint(Handles.matrix * e[1]),
Camera.current.WorldToScreenPoint(Handles.matrix * e[2]),
Camera.current.WorldToScreenPoint(Handles.matrix * e[3])
};
float maxWeight = float.MinValue;
int maxIndex = 0;
Vector2 support = new Vector2(Camera.current.pixelWidth, Camera.current.pixelHeight);
Vector2 supportOrtho = new Vector2(support.y, -support.x);
for (int i = 0; i < 4; ++i)
{
float weight = Vector3.Dot(screenPositions[i], support) - 0.5f * Mathf.Abs(Vector3.Dot(screenPositions[i], supportOrtho));
if (weight > maxWeight)
{
maxWeight = weight;
maxIndex = i;
}
Gizmos.DrawLine(e1, e2);
Gizmos.DrawLine(e2, e3);
Gizmos.DrawLine(e3, e4);
Gizmos.DrawLine(e4, e1);
Vector2 send = e[maxIndex];
EditorGUI.BeginChangeCheck();
Vector2 received = SliderPlaneHandle(farEnd, Vector3.right, Vector3.up, send);
if (EditorGUI.EndChangeCheck())
{
bool fixedFov = Event.current.control && !Event.current.shift;
bool fixedAspect = Event.current.shift && !Event.current.control;
Gizmos.DrawLine(s1, e1);
Gizmos.DrawLine(s2, e2);
Gizmos.DrawLine(s3, e3);
Gizmos.DrawLine(s4, e4);
//work on positive quadrant
int xSign = send.x < 0f ? -1 : 1;
int ySign = send.y < 0f ? -1 : 1;
Vector2 corrected = new Vector2(received.x * xSign, received.y * ySign);
//fixed aspect correction
if (fixedAspect)
{
corrected.x = corrected.y * aspect;
}
//remove aspect deadzone
if (corrected.x > maxAspect * corrected.y)
{
corrected.y = corrected.x * minAspect;
}
if (corrected.x < minAspect * corrected.y)
{
corrected.x = corrected.y / maxAspect;
}
//remove fov deadzone
float deadThresholdFoV = Mathf.Tan(Mathf.Deg2Rad * minFov * 0.5f) * maxRange;
corrected.x = Mathf.Max(corrected.x, deadThresholdFoV);
corrected.y = Mathf.Max(corrected.y, deadThresholdFoV, Mathf.Epsilon * 100); //prevent any division by zero
if (!fixedAspect)
{
aspect = corrected.x / corrected.y;
}
float min = Mathf.Min(corrected.x, corrected.y);
if (!fixedFov && maxRange > Mathf.Epsilon * 100)
{
fov = Mathf.Atan(min / maxRange) * 2f * Mathf.Rad2Deg;
}
}
return new Vector4(aspect, fov, maxRange, minRange);
public static void DrawOrthoFrustumWireframe(Vector4 widthHeightMaxRangeMinRange)
{
float halfWidth = widthHeightMaxRangeMinRange.x * 0.5f;
float halfHeight = widthHeightMaxRangeMinRange.y * 0.5f;
float maxRange = widthHeightMaxRangeMinRange.z;
float minRange = widthHeightMaxRangeMinRange.w;
Vector3 sizeX = new Vector3(halfWidth, 0, 0);
Vector3 sizeY = new Vector3(0, halfHeight, 0);
Vector3 nearEnd = new Vector3(0, 0, minRange);
Vector3 farEnd = new Vector3(0, 0, maxRange);
Vector3 s1 = nearEnd + sizeX + sizeY;
Vector3 s2 = nearEnd - sizeX + sizeY;
Vector3 s3 = nearEnd - sizeX - sizeY;
Vector3 s4 = nearEnd + sizeX - sizeY;
Vector3 e1 = farEnd + sizeX + sizeY;
Vector3 e2 = farEnd - sizeX + sizeY;
Vector3 e3 = farEnd - sizeX - sizeY;
Vector3 e4 = farEnd + sizeX - sizeY;
Handles.DrawLine(s1, s2);
Handles.DrawLine(s2, s3);
Handles.DrawLine(s3, s4);
Handles.DrawLine(s4, s1);
Handles.DrawLine(e1, e2);
Handles.DrawLine(e2, e3);
Handles.DrawLine(e3, e4);
Handles.DrawLine(e4, e1);
Handles.DrawLine(s1, e1);
Handles.DrawLine(s2, e2);
Handles.DrawLine(s3, e3);
Handles.DrawLine(s4, e4);
}
public static Vector4 DrawOrthoFrustumHandle(Vector4 widthHeightMaxRangeMinRange, bool useNearHandle)
{
float halfWidth = widthHeightMaxRangeMinRange.x * 0.5f;
float halfHeight = widthHeightMaxRangeMinRange.y * 0.5f;
float maxRange = widthHeightMaxRangeMinRange.z;
float minRange = widthHeightMaxRangeMinRange.w;
Vector3 farEnd = new Vector3(0, 0, maxRange);
if (useNearHandle)
{
minRange = SliderLineHandle(Vector3.zero, Vector3.forward, minRange);
}
maxRange = SliderLineHandle(Vector3.zero, Vector3.forward, maxRange);
EditorGUI.BeginChangeCheck();
halfWidth = SliderLineHandle(farEnd, Vector3.right, halfWidth);
halfWidth = SliderLineHandle(farEnd, Vector3.left, halfWidth);
if (EditorGUI.EndChangeCheck())
{
halfWidth = Mathf.Max(0f, halfWidth);
}
EditorGUI.BeginChangeCheck();
halfHeight = SliderLineHandle(farEnd, Vector3.up, halfHeight);
halfHeight = SliderLineHandle(farEnd, Vector3.down, halfHeight);
if (EditorGUI.EndChangeCheck())
{
halfHeight = Mathf.Max(0f, halfHeight);
}
return new Vector4(halfWidth * 2f, halfHeight * 2f, maxRange, minRange);
}
[Obsolete("Should use the legacy gizmo draw")]
public static void DrawDirectionalLightGizmo(Light directionalLight)
{
var gizmoSize = 0.2f;

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


The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [3.4.0-preview]
### Added
- Added controls for linear fade at the boundary of density volumes
- Added new API to control decals without monobehaviour object
### Fixed
- Stencil test during decals normal buffer update is now properly applied
- Fixed an issue where sometimes the deferred shadow texture would not be valid, causing wrong rendering.
## [3.3.0-preview]
### Added

- Fix display correct target platform when showing message to inform user that a platform is not supported
- Remove workaround for metal and vulkan in normal buffer encoding/decoding
- Fixed an issue with color picker not working in forward
- Decals corectly update normal buffer in forward
- Fixed an issue where reseting HDLight do not reset all of its parameters
### Changed

6
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public Shader shadowClearShader;
public ComputeShader shadowBlurMoments;
public Shader debugShadowMapShader;
// Decal
public Shader decalNormalBuffer;
#if UNITY_EDITOR
public void UpgradeIfNeeded()

shadowClearShader = Load<Shader>(CorePath + "Shadow/ShadowClear.shader");
shadowBlurMoments = Load<ComputeShader>(CorePath + "Shadow/ShadowBlurMoments.compute");
debugShadowMapShader = Load<Shader>(CorePath + "Shadow/DebugDisplayShadowMap.shader");
// decal
decalNormalBuffer = Load<Shader>(HDRenderPipelinePath + "Material/Decal/DecalNormalBuffer.shader");
}
#endif
}

3
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


m_Script: {fileID: 11500000, guid: 8b6f86e1523e69a4282e92d393be89a4, type: 3}
m_Name: HDRenderPipelineResources
m_EditorClassIdentifier:
m_Version: 2
m_Version: 3
defaultDiffuseMaterial: {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17, type: 2}
defaultMirrorMaterial: {fileID: 2100000, guid: 6b17274157b33bc45b6a40e7d4ff51fe, type: 2}
defaultDecalMaterial: {fileID: 2100000, guid: 500e733574922d04ea961553b1b26a63, type: 2}

shadowClearShader: {fileID: 4800000, guid: e3cab24f27741f44d8af1e94d006267c, type: 3}
shadowBlurMoments: {fileID: 7200000, guid: fb36979473602464fa32deacb9630c08, type: 3}
debugShadowMapShader: {fileID: 4800000, guid: ee25e539f5594f44085e0a9000c15d9b, type: 3}
decalNormalBuffer: {fileID: 4800000, guid: fd532bf1795188c4daaa66ea798b8b0a, type: 3}

7
com.unity.render-pipelines.high-definition/HDRP/Debug/DebugLightVolume.shader


struct AttributesDefault
{
float4 positionOS : POSITION;
float3 positionOS : POSITION;
};
struct VaryingsDefault

float3 _Range;
float3 _Offset;
float4 _Color;
float _RequireToFlipInputTexture;
VaryingsDefault vert(AttributesDefault att)
{

output.positionCS = TransformWorldToHClip(positionRWS);
if (_RequireToFlipInputTexture > 0.0)
{
output.positionCS.y = 1.0 - output.positionCS.y;
}
return output;
}

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


// GBuffer management
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)
public virtual void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage, out bool[] enableWrite)
}
enableWrite = null;
}
// Regular interface
public virtual void Build(HDRenderPipelineAsset hdAsset) {}

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


public override void CreateBuffers()
{
RenderTextureFormat[] rtFormat;
bool[] sRGBFlags;
m_DeferredMaterial.GetMaterialGBufferDescription(m_asset, out rtFormat, out sRGBFlags, out m_GBufferUsage);
bool[] sRGBFlags;
bool[] enableWrite;
m_DeferredMaterial.GetMaterialGBufferDescription(m_asset, out rtFormat, out sRGBFlags, out m_GBufferUsage, out enableWrite);
m_RTs[gbufferIndex] = RTHandles.Alloc(Vector2.one, colorFormat: rtFormat[gbufferIndex], sRGB: sRGBFlags[gbufferIndex], filterMode: FilterMode.Point, name: string.Format("GBuffer{0}", gbufferIndex));
m_RTs[gbufferIndex] = RTHandles.Alloc(Vector2.one, colorFormat: rtFormat[gbufferIndex], sRGB: sRGBFlags[gbufferIndex], filterMode: FilterMode.Point, name: string.Format("GBuffer{0}", gbufferIndex), enableRandomWrite: enableWrite[gbufferIndex]);
m_RTIDs[gbufferIndex] = m_RTs[gbufferIndex].nameID;
m_TextureShaderIDs[gbufferIndex] = HDShaderIDs._GBufferTexture[gbufferIndex];

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


[HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 7 // StencilMask.Lighting (fixed at compile time)
[HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 128 // StencilLightingUsage.RegularLighting (fixed at compile time)
[HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 128 // StencilMask.ObjectsVelocity (fixed at compile time)
[HideInInspector] _StencilDepthPrepassRef("_StencilDepthPrepassRef", Int) = 16
[HideInInspector] _StencilDepthPrepassWriteMask("_StencilDepthPrepassWriteMask", Int) = 16
// Blending state
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0

Cull[_CullMode]
ZWrite On
Stencil
{
WriteMask[_StencilDepthPrepassWriteMask]
Ref[_StencilDepthPrepassRef]
Comp Always
Pass Replace
}
HLSLPROGRAM

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


#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#include "HDRP/Material/BuiltinUtilities.hlsl"
#include "HDRP/Material/MaterialUtilities.hlsl"
#include "HDRP/Material/Decal/DecalUtilities.hlsl"
//-----------------------------------------------------------------------------
// Texture Mapping

surfaceData.coatNormalWS = SurfaceGradientResolveNormal(input.worldToTangent[2], coatGradient.xyz);
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
#if HAVE_DECALS
AddDecalContribution(posInput, surfaceData, alpha);
#endif
if ((_GeometricNormalFilteringEnabled + _TextureNormalFilteringEnabled) > 0.0)
{

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


return gBufferCount;
}
public override void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage)
public override void GetMaterialGBufferDescription(HDRenderPipelineAsset asset, out RenderTextureFormat[] RTFormat, out bool[] sRGBFlag, out GBufferUsage[] gBufferUsage, out bool[] enableWrite)
{
int gBufferCount;
bool supportShadowMask;

RTFormat = new RenderTextureFormat[gBufferCount];
sRGBFlag = new bool[gBufferCount];
gBufferUsage = new GBufferUsage[gBufferCount];
gBufferUsage = new GBufferUsage[gBufferCount];
enableWrite = new bool[gBufferCount];
enableWrite[0] = false;
enableWrite[1] = true; // normal buffer is used as RWTexture to composite decals in forward
enableWrite[2] = false;
enableWrite[3] = false;
int index = 4;

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


#endif
}
NormalData ConvertSurfaceDataToNormalData(SurfaceData surfaceData)
{
NormalData normalData;
normalData.normalWS = surfaceData.normalWS;
normalData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness);
return normalData;
}
//-----------------------------------------------------------------------------
// conversion function for forward
//-----------------------------------------------------------------------------

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


HLSLPROGRAM
#define WRITE_NORMAL_BUFFER
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "HDRP/ShaderVariables.hlsl"
#include "HDRP/Material/Material.hlsl"

//#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS
#define LIGHTLOOP_TILE_PASS
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#define SHADERPASS SHADERPASS_FORWARD
#include "HDRP/ShaderVariables.hlsl"

7
com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricData.hlsl


#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl"
#include "HDRP/Material/MaterialUtilities.hlsl"
#include "HDRP/Material/BuiltinUtilities.hlsl"
#include "HDRP/Material/Decal/DecalUtilities.hlsl"
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{

DoAlphaTest(alpha, _AlphaCutoff);
#endif
#if HAVE_DECALS
AddDecalContribution(posInput, surfaceData, alpha);
#endif
#if defined(DEBUG_DISPLAY)
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{

InitBuiltinData(alpha, surfaceData.normalWS, -input.worldToTangent[2], input.positionRWS, input.texCoord1, input.texCoord2, builtinData);
// Support the emissive color and map
builtinData.emissiveColor = _EmissiveColor * lerp(float3(1.0, 1.0, 1.0), surfaceData.baseColor.rgb, _AlbedoAffectEmissive);
builtinData.emissiveColor = _EmissiveColor.rgb * lerp(float3(1.0, 1.0, 1.0), surfaceData.baseColor.rgb, _AlbedoAffectEmissive);
#ifdef _EMISSIVE_COLOR_MAP
// Generate the primart uv coordinates
float2 uvEmissive = _UVMappingMaskEmissive.x * input.texCoord0 +

3
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalProjectorComponent.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
#if UNITY_EDITOR
[CanEditMultipleObjects]
#endif
public class DecalProjectorComponent : MonoBehaviour
{
public Material m_Material = null;

8
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl


if (mask & DBUFFERHTILEBIT_MASK)
{
#ifdef DECALS_4RT // only smoothness in 3RT mode
#if !defined(UNITY_MATERIAL_FABRIC)
#endif
#if defined(UNITY_MATERIAL_STACKLIT)
surfaceData.perceptualSmoothnessA = surfaceData.perceptualSmoothnessA * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
surfaceData.perceptualSmoothnessB = surfaceData.perceptualSmoothnessB * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
surfaceData.coatPerceptualSmoothness = surfaceData.coatPerceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
#else
#endif
}
}
}

150
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.shader


[ToggleUI] _MaskmapSmoothness("_MaskmapSmoothness", Range(0.0, 1.0)) = 1.0
[HideInInspector] _DecalMeshDepthBias("_DecalMeshDepthBias", Float) = 0.0
[HideInInspector] _DrawOrder("_DrawOrder", Int) = 0
// Stencil state
[HideInInspector] _DecalStencilRef("_DecalStencilRef", Int) = 8
[HideInInspector] _DecalStencilWriteMask("_DecalStencilWriteMask", Int) = 8
}
HLSLINCLUDE

Pass
{
Name "DBufferMesh_3RT" // Name is not used
Tags{"LightMode" = "DBufferMesh_3RT"} // Smoothness
Tags{"LightMode" = "DBufferMesh_3RT"} // Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

Pass
{
Name "DBufferProjector_M" // Name is not used
Tags{"LightMode" = "DBufferProjector_M"} // Metalness
Tags{"LightMode" = "DBufferProjector_M"} // Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

Name "DBufferProjector_AO" // Name is not used
Tags{"LightMode" = "DBufferProjector_AO"} // AO only
// back faces with zfail, for cases when camera is inside the decal volume
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
Cull Front
ZWrite Off
ZTest Greater

Name "DBufferProjector_MAO" // Name is not used
Tags{"LightMode" = "DBufferProjector_MAO"} // AO + Metalness
// back faces with zfail, for cases when camera is inside the decal volume
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
Cull Front
ZWrite Off
ZTest Greater

Pass
{
Name "DBufferProjector_S" // Name is not used
Tags{"LightMode" = "DBufferProjector_S"} // Smoothness
Tags{"LightMode" = "DBufferProjector_S"} // Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

Pass
{
Name "DBufferProjector_MS" // Name is not used
Tags{"LightMode" = "DBufferProjector_MS"} // Smoothness and Metalness
Tags{"LightMode" = "DBufferProjector_MS"} // Smoothness and Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

{
Name "DBufferProjector_AOS" // Name is not used
Tags{"LightMode" = "DBufferProjector_AOS"} // AO + Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

{
Name "DBufferProjector_MAOS" // Name is not used
Tags { "LightMode" = "DBufferProjector_MAOS" } // Metalness AO and Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
// back faces with zfail, for cases when camera is inside the decal volume
Cull Front
ZWrite Off

Pass
{
Name "DBufferMesh_M" // Name is not used
Tags{"LightMode" = "DBufferMesh_M"} // Metalness
Tags{"LightMode" = "DBufferMesh_M"} // Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_AO" // Name is not used
Tags{"LightMode" = "DBufferMesh_AO"} // AO only
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_MAO" // Name is not used
Tags{"LightMode" = "DBufferMesh_MAO"} // AO + Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

Pass
{
Name "DBufferMesh_S" // Name is not used
Tags{"LightMode" = "DBufferMesh_S"} // Smoothness
Tags{"LightMode" = "DBufferMesh_S"} // Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

Pass
{
Name "DBufferMesh_MS" // Name is not used
Tags{"LightMode" = "DBufferMesh_MS"} // Smoothness and Metalness
Tags{"LightMode" = "DBufferMesh_MS"} // Smoothness and Metalness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_AOS" // Name is not used
Tags{"LightMode" = "DBufferMesh_AOS"} // AO + Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

{
Name "DBufferMesh_MAOS" // Name is not used
Tags{"LightMode" = "DBufferMesh_MAOS"} // Metalness AO and Smoothness
Stencil
{
WriteMask[_DecalStencilWriteMask]
Ref[_DecalStencilRef]
Comp Always
Pass Replace
}
ZWrite Off
ZTest LEqual
// using alpha compositing https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html

49
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalSystem.cs


return res;
}
public void UpdateCachedData(Transform transform, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, DecalHandle handle)
public void UpdateCachedData(Matrix4x4 localToWorld, Quaternion rotation, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, DecalHandle handle)
if (m_Material == null)
return;
m_CachedDecalToWorld[index] = transform.localToWorldMatrix * sizeOffset;
m_CachedDecalToWorld[index] = localToWorld * sizeOffset;
Matrix4x4 decalRotation = Matrix4x4.Rotate(rotation);
Matrix4x4 decalRotation = Matrix4x4.Rotate(transform.rotation);
// z/y axis swap for normal to decal space, Unity is column major
float y0 = decalRotation.m01;
float y1 = decalRotation.m11;

m_BoundingSpheres[index] = GetDecalProjectBoundingSphere(m_CachedDecalToWorld[index]);
}
public DecalHandle AddDecal(Transform transform, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, int materialID)
public void UpdateCachedData(Transform transform, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, DecalHandle handle)
{
if (m_Material == null)
return;
UpdateCachedData(transform.localToWorldMatrix, transform.rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, handle);
}
public DecalHandle AddDecal(Matrix4x4 localToWorld, Quaternion rotation, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, int materialID)
{
// increase array size if no space left
if (m_DecalsCount == m_Handles.Length)

DecalHandle decalHandle = new DecalHandle(m_DecalsCount, materialID);
m_Handles[m_DecalsCount] = decalHandle;
UpdateCachedData(transform, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, decalHandle);
UpdateCachedData(localToWorld, rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, decalHandle);
m_DecalsCount++;
return decalHandle;
}

private Vector4 m_BaseColor;
private Vector3 m_BlendParams;
public DecalHandle AddDecal(Transform transform, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, Material material)
DecalHandle AddDecal(Matrix4x4 localToWorld, Quaternion rotation, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, Material material)
{
DecalSet decalSet = null;
int key = material != null ? material.GetInstanceID() : kNullMaterialIndex;

m_DecalSets.Add(key, decalSet);
}
return decalSet.AddDecal(transform, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, key);
return decalSet.AddDecal(localToWorld, rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, key);
}
public DecalHandle AddDecal(Vector3 position, Quaternion rotation, Vector3 scale, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, Material material)
{
return AddDecal(Matrix4x4.TRS(position, rotation, scale), rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, material);
}
public DecalHandle AddDecal(Transform transform, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, Material material)
{
return AddDecal(transform.localToWorldMatrix, transform.rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, material);
}
public void RemoveDecal(DecalHandle handle)

}
}
public void UpdateCachedData(Transform transform, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, DecalHandle handle)
void UpdateCachedData(Matrix4x4 localToWorld, Quaternion rotation, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, DecalHandle handle)
{
if (!DecalHandle.IsValid(handle))
return;

if (m_DecalSets.TryGetValue(key, out decalSet))
{
decalSet.UpdateCachedData(transform, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, handle);
decalSet.UpdateCachedData(localToWorld, rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, handle);
}
public void UpdateCachedData(Vector3 position, Quaternion rotation, Vector3 scale, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, DecalHandle handle)
{
UpdateCachedData(Matrix4x4.TRS(position, rotation, scale), rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, handle);
}
public void UpdateCachedData(Transform transform, Matrix4x4 sizeOffset, float drawDistance, float fadeScale, Vector4 uvScaleBias, bool affectsTransparency, DecalHandle handle)
{
UpdateCachedData(transform.localToWorldMatrix, transform.rotation, sizeOffset, drawDistance, fadeScale, uvScaleBias, affectsTransparency, handle);
}
public void BeginCull()

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


{
// In case of full forward we must allocate the render target for normal buffer (or reuse one already existing)
// TODO: Provide a way to reuse a render target
m_ColorMRTs[0] = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGB32, sRGB: false, name: "NormalBuffer");
m_ColorMRTs[0] = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGB32, sRGB: false, enableRandomWrite: true, name: "NormalBuffer");
m_ExternalBuffer[0] = false;
}
else

6
com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute


#endif
#if SSS_RANDOM_ROTATION
float startAngle = TWO_PI * GenerateHashedRandomFloat(asuint(centerPosVS));
// Previously, we used asuint(centerPosVS) as the seed.
// This was not temporarily stable for some reason (pattern changed every frame),
// even if both the camera and the scene were completely static.
// Note that GenerateHashedRandomFloat() only uses the 23 low bits, hence the 2^24 factor.
float startAngle = TWO_PI * GenerateHashedRandomFloat(uint3(pixelCoord, (uint)(centerDepth * 16777216)));
#else
float startAngle = 0;
#endif

1
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs


namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[CustomEditor(typeof(DecalProjectorComponent))]
[CanEditMultipleObjects]
public class DecalProjectorComponentEditor : Editor
{
private MaterialEditor m_MaterialEditor = null;

7
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs


protected MaterialProperty drawOrder = new MaterialProperty();
protected const string kDrawOrder = "_DrawOrder";
protected const string kDecalStencilWriteMask = "_DecalStencilWriteMask";
protected const string kDecalStencilRef = "_DecalStencilRef";
protected MaterialEditor m_MaterialEditor;
// This is call by the inspector

CoreUtils.SetKeyword(material, "_ALBEDOCONTRIBUTION", material.GetFloat(kAlbedoMode) == 1.0f);
CoreUtils.SetKeyword(material, "_COLORMAP", material.GetTexture(kBaseColorMap));
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap));
CoreUtils.SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
CoreUtils.SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
material.SetInt(kDecalStencilWriteMask, (int)HDRenderPipeline.StencilBitMask.Decals);
material.SetInt(kDecalStencilRef, (int)HDRenderPipeline.StencilBitMask.Decals);
material.SetShaderPassEnabled(HDShaderPassNames.s_MeshDecalsMStr, false);
material.SetShaderPassEnabled(HDShaderPassNames.s_MeshDecalsAOStr, false);
material.SetShaderPassEnabled(HDShaderPassNames.s_MeshDecalsMAOStr, false);

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs


protected const string kStencilWriteMask = "_StencilWriteMask";
protected const string kStencilRefMV = "_StencilRefMV";
protected const string kStencilWriteMaskMV = "_StencilWriteMaskMV";
protected const string kStencilDepthPrepassRef = "_StencilDepthPrepassRef";
protected const string kStencilDepthPrepassWriteMask = "_StencilDepthPrepassWriteMask";
protected const string k_GeometricNormalFilteringEnabled = "_GeometricNormalFilteringEnabled";
protected const string k_TextureNormalFilteringEnabled = "_TextureNormalFilteringEnabled";

material.SetInt(kStencilWriteMask, (int)HDRenderPipeline.StencilBitMask.LightingMask);
material.SetInt(kStencilRefMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);
material.SetInt(kStencilWriteMaskMV, (int)HDRenderPipeline.StencilBitMask.ObjectVelocity);
// for depth only pass to be used in decal to normal buffer compositing
material.SetInt(kStencilDepthPrepassRef, (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer);
material.SetInt(kStencilDepthPrepassWriteMask, (int)HDRenderPipeline.StencilBitMask.DecalsForwardOutputNormalBuffer);
}
}
} // namespace UnityEditor

18
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Gizmos.cs


return;
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
Gizmos_CapturePoint(reflectionProbe, reflectionData, e);
if (reflectionProbe == e.target)
{
//will draw every preview, thus no need to do it multiple times
Gizmos_CapturePoint(e);
}
var mat = Matrix4x4.TRS(reflectionProbe.transform.position, reflectionProbe.transform.rotation, Vector3.one);
InfluenceVolumeUI.DrawGizmos(e.m_UIState.influenceVolume, reflectionData.influenceVolume, mat, InfluenceVolumeUI.HandleType.None, InfluenceVolumeUI.HandleType.Base);

}
}
static void Gizmos_CapturePoint(ReflectionProbe p, HDAdditionalReflectionData a, HDReflectionProbeEditor e)
static void Gizmos_CapturePoint(HDReflectionProbeEditor e)
{
if(sphere == null)
{

{
material = new Material(Shader.Find("Debug/ReflectionProbePreview"));
}
material.SetTexture("_Cubemap", e.GetTexture());
material.SetPass(0);
Graphics.DrawMeshNow(sphere, Matrix4x4.TRS(p.transform.position, Quaternion.identity, Vector3.one));
foreach (ReflectionProbe target in e.targets)
{
material.SetTexture("_Cubemap", GetTexture(e, target));
material.SetPass(0);
Graphics.DrawMeshNow(sphere, Matrix4x4.TRS(target.transform.position, Quaternion.identity, Vector3.one));
}
}
}
}

12
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Preview.cs


return false; // We only handle one preview for reflection probes
// Ensure valid cube map editor (if possible)
Texture texture = GetTexture();
Texture texture = GetTexture(this, target);
if (m_CubemapEditor != null && m_CubemapEditor.target as Texture != texture)
{
DestroyImmediate(m_CubemapEditor);

{
Editor editor = m_CubemapEditor;
CreateCachedEditor(GetTexture(), typeof(HDCubemapInspector), ref editor);
CreateCachedEditor(GetTexture(this, target), typeof(HDCubemapInspector), ref editor);
m_CubemapEditor = editor as HDCubemapInspector;
}

return;
}
Texture tex = GetTexture();
Texture tex = GetTexture(this, target);
if (tex != null && targets.Length == 1)
m_CubemapEditor.DrawPreview(position);
}

return GetTexture() != null;
return GetTexture(this, target) != null;
Texture GetTexture()
static Texture GetTexture(HDReflectionProbeEditor e, Object target)
HDProbe additional = GetTarget(target);
HDProbe additional = e.GetTarget(target);
if (additional != null && additional.mode == UnityEngine.Rendering.ReflectionProbeMode.Realtime)
{
return additional.realtimeTexture;

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.cs


using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Experimental.Rendering.HDPipeline;
using System.Linq;
using UnityEngine.Rendering;
namespace UnityEditor.Experimental.Rendering.HDPipeline

internal override HDProbe GetTarget(Object editorTarget)
{
return (HDProbe)s_ReflectionProbeEditors[(ReflectionProbe)editorTarget].m_AdditionalDataSerializedObject.targetObject;
HDReflectionProbeEditor e = s_ReflectionProbeEditors[(ReflectionProbe)editorTarget];
return (HDProbe)e.m_AdditionalDataSerializedObject.targetObjects.First(a => ((HDAdditionalReflectionData)a).reflectionProbe == editorTarget);
}
protected override void Draw(HDProbeUI s, SerializedHDProbe serialized, Editor owner)

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDProbeUI.ContextualMenu.cs.meta


fileFormatVersion: 2
guid: 3f4d3bee74f54434ca6db826ccc28f6f
guid: f9ddf94c77394c14986865eb30c51d79
MonoImporter:
externalObjects: {}
serializedVersion: 2

52
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs


static GUIContent s_TextureScrollLabel = new GUIContent("Texture Scroll Speed");
static GUIContent s_TextureTileLabel = new GUIContent("Texture Tiling Amount");
static GUIContent s_TextureSettingsTitle = new GUIContent("Volume Texture Settings");
static GUIContent s_PositiveFadeLabel = new GUIContent("Positive Fade", "Controls the [0, 1] distance from the +X/+Y/+Z face at which a linear fade ends. 0 means no fade, 1 means the fade ends at the opposite face.");
static GUIContent s_NegativeFadeLabel = new GUIContent("Negative Fade", "Controls the [0, 1] distance from the -X/-Y/-Z face at which a linear fade ends. 0 means no fade, 1 means the fade ends at the opposite face.");
private bool showTextureParams = false;

SerializedProperty textureScroll;
SerializedProperty textureTile;
SerializedProperty positiveFade;
SerializedProperty negativeFade;
albedo = densityParams.FindPropertyRelative("albedo");
meanFreePath = densityParams.FindPropertyRelative("meanFreePath");
albedo = densityParams.FindPropertyRelative("albedo");
meanFreePath = densityParams.FindPropertyRelative("meanFreePath");
textureTile = densityParams.FindPropertyRelative("textureTiling");
textureTile = densityParams.FindPropertyRelative("textureTiling");
positiveFade = densityParams.FindPropertyRelative("positiveFade");
negativeFade = densityParams.FindPropertyRelative("negativeFade");
if (volumeTexture != null && volumeTexture.objectReferenceValue != null)
{

public override void OnInspectorGUI()
{
albedo.colorValue = EditorGUILayout.ColorField(s_AlbedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, s_MeanFreePathLabel);
EditorGUILayout.Space();
serializedObject.Update();
showTextureParams = EditorGUILayout.Foldout(showTextureParams, s_TextureSettingsTitle, true);
if (showTextureParams)
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
albedo.colorValue = EditorGUILayout.ColorField(s_AlbedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, s_MeanFreePathLabel);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(positiveFade, s_PositiveFadeLabel);
EditorGUILayout.PropertyField(negativeFade, s_NegativeFadeLabel);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(textureTile, s_TextureTileLabel);
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(textureTile, s_TextureTileLabel);
}
if (EditorGUI.EndChangeCheck())
{
Vector3 posFade = new Vector3();
posFade.x = Mathf.Clamp01(positiveFade.vector3Value.x);
posFade.y = Mathf.Clamp01(positiveFade.vector3Value.y);
posFade.z = Mathf.Clamp01(positiveFade.vector3Value.z);
Vector3 negFade = new Vector3();
negFade.x = Mathf.Clamp01(negativeFade.vector3Value.x);
negFade.y = Mathf.Clamp01(negativeFade.vector3Value.y);
negFade.z = Mathf.Clamp01(negativeFade.vector3Value.z);
positiveFade.vector3Value = posFade;
negativeFade.vector3Value = negFade;
}
serializedObject.ApplyModifiedProperties();

66
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDAdditionalLightDataEditor.cs


{
}
}
public class HDAdditionalLightDataGizmoDrawer
{
[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
static void DrawGizmoForHDAdditionalLightData(HDAdditionalLightData src, GizmoType gizmoType)
{
bool selected = (gizmoType & GizmoType.Selected) != 0;
var light = src.gameObject.GetComponent<Light>();
var gizmoColor = light.color;
gizmoColor.a = selected ? 1.0f : 0.3f; // Fade for the gizmo
Gizmos.color = Handles.color = gizmoColor;
if (src.lightTypeExtent == LightTypeExtent.Punctual)
{
switch (light.type)
{
case LightType.Directional:
CoreLightEditorUtilities.DrawDirectionalLightGizmo(light);
break;
case LightType.Point:
CoreLightEditorUtilities.DrawPointlightGizmo(light, selected);
break;
case LightType.Spot:
if (src.spotLightShape == SpotLightShape.Cone)
CoreLightEditorUtilities.DrawSpotlightGizmo(light, src.GetInnerSpotPercent01(), selected);
else if (src.spotLightShape == SpotLightShape.Pyramid)
HDLightEditorUtilities.DrawFrustumlightGizmo(light);
else if (src.spotLightShape == SpotLightShape.Box)
HDLightEditorUtilities.DrawFrustumlightGizmo(light);
break;
}
}
else
{
switch (src.lightTypeExtent)
{
case LightTypeExtent.Rectangle:
CoreLightEditorUtilities.DrawArealightGizmo(light);
break;
case LightTypeExtent.Line:
CoreLightEditorUtilities.DrawArealightGizmo(light);
break;
}
}
if (selected)
{
// Trace a ray down to better locate the light location
Ray ray = new Ray(src.gameObject.transform.position, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Handles.color = Color.green;
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
Handles.color = Color.red;
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
}
}
}
}
}

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


UpdateAreaLightEmissiveMeshComponents();
}
protected override void OnSceneGUI()
{
m_SerializedAdditionalLightData.Update();
HDAdditionalLightData src = (HDAdditionalLightData)m_SerializedAdditionalLightData.targetObject;
Light light = (Light)target;
Color wireframeColorAbove = light.enabled ? LightEditor.kGizmoLight : LightEditor.kGizmoDisabledLight;
Color handleColorAbove = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorAbove);
Color wireframeColorBehind = CoreLightEditorUtilities.GetLightBehindObjectWireframeColor(wireframeColorAbove);
Color handleColorBehind = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorBehind);
switch (src.lightTypeExtent)
{
case LightTypeExtent.Punctual:
switch (light.type)
{
case LightType.Directional:
case LightType.Point:
base.OnSceneGUI(); //use legacy handles
break;
case LightType.Spot:
switch (src.spotLightShape)
{
case SpotLightShape.Cone:
CoreLightEditorUtilities.DrawSpotlightGizmo(light, src.GetInnerSpotPercent01(), true);
break;
case SpotLightShape.Pyramid:
using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
{
Vector4 aspectFovMaxRangeMinRange = new Vector4(src.aspectRatio, light.spotAngle, light.range);
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = wireframeColorBehind;
CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = wireframeColorAbove;
CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange);
EditorGUI.BeginChangeCheck();
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = handleColorBehind;
aspectFovMaxRangeMinRange = CoreLightEditorUtilities.DrawPyramidFrustumHandle(aspectFovMaxRangeMinRange, false);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = handleColorAbove;
aspectFovMaxRangeMinRange = CoreLightEditorUtilities.DrawPyramidFrustumHandle(aspectFovMaxRangeMinRange, false);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObjects(new UnityEngine.Object[] { target, src }, "Adjust Pyramid Spot Light");
src.aspectRatio = aspectFovMaxRangeMinRange.x;
light.spotAngle = aspectFovMaxRangeMinRange.y;
light.range = aspectFovMaxRangeMinRange.z;
}
// Handles.color reseted at end of scope
}
break;
case SpotLightShape.Box:
using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
{
Vector4 widthHeightMaxRangeMinRange = new Vector4(src.shapeWidth, src.shapeHeight, light.range);
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = wireframeColorBehind;
CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = wireframeColorAbove;
CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange);
EditorGUI.BeginChangeCheck();
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = handleColorBehind;
widthHeightMaxRangeMinRange = CoreLightEditorUtilities.DrawOrthoFrustumHandle(widthHeightMaxRangeMinRange, false);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = handleColorAbove;
widthHeightMaxRangeMinRange = CoreLightEditorUtilities.DrawOrthoFrustumHandle(widthHeightMaxRangeMinRange, false);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObjects(new UnityEngine.Object[] { target, src }, "Adjust Box Spot Light");
src.shapeWidth = widthHeightMaxRangeMinRange.x;
src.shapeHeight = widthHeightMaxRangeMinRange.y;
light.range = widthHeightMaxRangeMinRange.z;
}
// Handles.color reseted at end of scope
}
break;
}
break;
}
break;
}
}
void DrawFoldout(SerializedProperty foldoutProperty, string title, Action func)
{
CoreEditorUtils.DrawSplitter();

break;
}
}
}
[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
static void DrawGizmoForHDAdditionalLightData(HDAdditionalLightData src, GizmoType gizmoType)
{
bool selected = (gizmoType & GizmoType.Selected) != 0;
var light = src.gameObject.GetComponent<Light>();
Color previousColor = Gizmos.color;
Gizmos.color = light.enabled ? LightEditor.kGizmoLight : LightEditor.kGizmoDisabledLight;
if (selected)
{
// Trace a ray down to better locate the light location
Ray ray = new Ray(src.gameObject.transform.position, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
using (new Handles.DrawingScope(Color.green))
{
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
}
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
using (new Handles.DrawingScope(Color.red))
{
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
}
}
}
Gizmos.color = previousColor;
}
}
}

78
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDAdditionalReflectionData.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[RequireComponent(typeof(ReflectionProbe))]
public class HDAdditionalReflectionData : HDProbe, ISerializationCallbackReceiver
public class HDAdditionalReflectionData : HDProbe
{
enum Version
{

data.weight = weight;
}
public void OnBeforeSerialize()
bool CheckMigrationRequirement()
}
//exit as quicker as possible
if (m_Version == (int)Version.Current)
return false;
public void OnAfterDeserialize()
{
if (m_Version != (int)Version.Current)
//it is mandatory to call them in order
//they can be grouped (without 'else' or not
if (m_Version < (int)Version.HDProbeChild)
{
needMigrateToHDProbeChild = true;
}
if (m_Version < (int)Version.UseInfluenceVolume)
// Add here data migration code that use other component
// Note impossible to access other component at deserialization time
if (m_Version < (int)Version.HDProbeChild)
{
needMigrateToHDProbeChild = true;
}
else if (m_Version < (int)Version.UseInfluenceVolume)
{
needMigrateToUseInfluenceVolume = true;
}
else if (m_Version < (int)Version.MergeEditors)
{
needMigrateToMergeEditors = true;
}
else
{
// Add here data migration code that do not use other component
m_Version = (int)Version.Current;
}
needMigrateToUseInfluenceVolume = true;
if (m_Version < (int)Version.MergeEditors)
{
needMigrateToMergeEditors = true;
}
//mandatory 'else' to only update version if other migrations done
else if (m_Version < (int)Version.Current)
{
m_Version = (int)Version.Current;
return false;
}
return true;
void OnEnable()
void ApplyMigration()
//it is mandatory to call them in order
if (needMigrateToHDProbeChild)
MigrateToHDProbeChild();
if (needMigrateToUseInfluenceVolume)

}
void Migrate()
{
//Must not be called at deserialisation time if require other component
while (CheckMigrationRequirement())
{
ApplyMigration();
}
}
internal override void Awake()
{
base.Awake();
//launch migration at creation too as m_Version could not have an
//existance in older version
Migrate();
}
void OnEnable()
{
ReflectionSystem.RegisterProbe(this);
}

refreshMode = reflectionProbe.refreshMode;
m_Version = (int)Version.HDProbeChild;
needMigrateToHDProbeChild = false;
OnAfterDeserialize(); //continue migrating if needed
}
void MigrateToUseInfluenceVolume()

#pragma warning restore CS0618 // Type or member is obsolete
m_Version = (int)Version.UseInfluenceVolume;
needMigrateToUseInfluenceVolume = false;
OnAfterDeserialize(); //continue migrating if needed
//Note: former editor parameters will be recreated as if non existent.
//User will lose parameters corresponding to non used mode between simplified and advanced

reflectionProbe.boxProjection = false;
m_Version = (int)Version.MergeEditors;
needMigrateToMergeEditors = false;
OnAfterDeserialize(); //continue migrating if needed
}
public override ReflectionProbeMode mode

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


}
}
internal void Awake()
internal virtual void Awake()
{
if (influenceVolume == null)
influenceVolume = new InfluenceVolume();

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/InfluenceVolume.cs


// Sphere
[SerializeField, FormerlySerializedAs("m_SphereBaseRadius")]
float m_SphereRadius = 1;
float m_SphereRadius = 3f;
[SerializeField, FormerlySerializedAs("m_SphereInfluenceFade")]
float m_SphereBlendDistance;
[SerializeField, FormerlySerializedAs("m_SphereInfluenceNormalFade")]

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


if (currentHDRLight == null) continue;
MaterialPropertyBlock materialBlock = new MaterialPropertyBlock();
materialBlock.SetFloat(HDShaderIDs._RequireToFlipInputTexture, hdCamera.camera.cameraType != CameraType.SceneView ? 1.0f : 0.0f);
Matrix4x4 positionMat = Matrix4x4.Translate(currentLegacyLight.transform.position);
if(currentLegacyLight.type == LightType.Point || currentLegacyLight.type == LightType.Area)

HDAdditionalReflectionData currentHDProbe = currentLegacyProbe.GetComponent<HDAdditionalReflectionData>();
MaterialPropertyBlock materialBlock = new MaterialPropertyBlock();
materialBlock.SetFloat(HDShaderIDs._RequireToFlipInputTexture, hdCamera.camera.cameraType != CameraType.SceneView ? 1.0f : 0.0f);
Mesh targetMesh = null;
if (currentHDProbe.influenceVolume.shape == InfluenceShape.Sphere)
{

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


// (not just the atmospheric scattering one) receive neutral parameters.
if (hdCamera.frameSettings.enableVolumetrics)
{
var data = DensityVolumeData.GetNeutralValues();
var data = DensityVolumeEngineData.GetNeutralValues();
cmd.SetGlobalVector(HDShaderIDs._GlobalScattering, data.scattering);
cmd.SetGlobalFloat(HDShaderIDs._GlobalExtinction, data.extinction);

4
com.unity.render-pipelines.high-definition/HDRP/Lighting/AtmosphericScattering/VolumetricFog.cs


public override void PushShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
{
DensityVolumeParameters param = new DensityVolumeParameters(albedo, meanFreePath, anisotropy);
DensityVolumeArtistParameters param = new DensityVolumeArtistParameters(albedo, meanFreePath, anisotropy);
DensityVolumeData data = param.GetData();
DensityVolumeEngineData data = param.GetData();
cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, (int)FogType.Volumetric);

72
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/DensityVolume.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public struct DensityVolumeParameters
public struct DensityVolumeArtistParameters
public Color albedo; // Single scattering albedo [0, 1]. Alpha is ignored
public float meanFreePath; // In meters [1, inf]. Should be chromatic - this is an optimization!
public float asymmetry; // Only used if (isLocal == false)
public Color albedo; // Single scattering albedo [0, 1]. Alpha is ignored
public float meanFreePath; // In meters [1, inf]. Should be chromatic - this is an optimization!
public float asymmetry; // Only used if (isLocal == false)
public int textureIndex;
public Vector3 textureScrollingSpeed;
public Vector3 textureTiling;
public Vector3 textureScrollingSpeed;
public Vector3 textureTiling;
private Vector3 volumeScrollingAmount;
public Vector3 positiveFade;
public Vector3 negativeFade;
public DensityVolumeParameters(Color color, float _meanFreePath, float _asymmetry)
public int textureIndex; // This shouldn't be public... Internal, maybe?
private Vector3 volumeScrollingAmount;
public DensityVolumeArtistParameters(Color color, float _meanFreePath, float _asymmetry)
albedo = color;
meanFreePath = _meanFreePath;
asymmetry = _asymmetry;
albedo = color;
meanFreePath = _meanFreePath;
asymmetry = _asymmetry;
volumeMask = null;
textureIndex = -1;
volumeMask = null;
textureIndex = -1;
textureTiling = Vector3.one;
textureTiling = Vector3.one;
positiveFade = Vector3.zero;
negativeFade = Vector3.zero;
}
public void Update(bool animate, float time)

volumeScrollingAmount = Vector3.zero;
}
public DensityVolumeData GetData()
public DensityVolumeEngineData GetData()
DensityVolumeData data = new DensityVolumeData();
DensityVolumeEngineData data = new DensityVolumeEngineData();
data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);
data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);
data.textureIndex = textureIndex;
data.textureScroll = volumeScrollingAmount;
data.textureTiling = textureTiling;
data.textureIndex = textureIndex;
data.textureScroll = volumeScrollingAmount;
data.textureTiling = textureTiling;
// Avoid numerical problems by clamping extreme values.
data.rcpPosFade.x = Mathf.Clamp(1.0f / positiveFade.x, 0.00001526f, 65536.0f);
data.rcpNegFade.x = Mathf.Clamp(1.0f / negativeFade.x, 0.00001526f, 65536.0f);
data.rcpPosFade.y = Mathf.Clamp(1.0f / positiveFade.y, 0.00001526f, 65536.0f);
data.rcpNegFade.y = Mathf.Clamp(1.0f / negativeFade.y, 0.00001526f, 65536.0f);
data.rcpPosFade.z = Mathf.Clamp(1.0f / positiveFade.z, 0.00001526f, 65536.0f);
data.rcpNegFade.z = Mathf.Clamp(1.0f / negativeFade.z, 0.00001526f, 65536.0f);
return data;
}

[AddComponentMenu("Rendering/Density Volume", 1100)]
public class DensityVolume : MonoBehaviour
{
public DensityVolumeParameters parameters = new DensityVolumeParameters(Color.white, 10.0f, 0.0f);
public DensityVolumeArtistParameters parameters = new DensityVolumeArtistParameters(Color.white, 10.0f, 0.0f);
private Texture3D previousVolumeMask = null;

void OnDrawGizmos()
{
Gizmos.color = parameters.albedo;
// Positive fade box.
Gizmos.color = Color.red;
Gizmos.DrawWireCube(-0.5f * parameters.positiveFade, Vector3.one - parameters.positiveFade);
// Negative fade box.
Gizmos.color = Color.blue;
Gizmos.DrawWireCube(0.5f * parameters.negativeFade, Vector3.one - parameters.negativeFade);
// Bounding box.
Gizmos.color = parameters.albedo;
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
}
}

41
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs.hlsl


#ifndef VOLUMETRICLIGHTING_CS_HLSL
#define VOLUMETRICLIGHTING_CS_HLSL
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.DensityVolumeData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.DensityVolumeEngineData
struct DensityVolumeData
struct DensityVolumeEngineData
{
float3 scattering;
float extinction;

float pad0;
float3 rcpPosFade;
float pad1;
float3 rcpNegFade;
float pad2;
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DensityVolumeData
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DensityVolumeEngineData
float3 GetScattering(DensityVolumeData value)
float3 GetScattering(DensityVolumeEngineData value)
float GetExtinction(DensityVolumeData value)
float GetExtinction(DensityVolumeEngineData value)
float3 GetTextureTiling(DensityVolumeData value)
float3 GetTextureTiling(DensityVolumeEngineData value)
int GetTextureIndex(DensityVolumeData value)
int GetTextureIndex(DensityVolumeEngineData value)
float3 GetTextureScroll(DensityVolumeData value)
float3 GetTextureScroll(DensityVolumeEngineData value)
}
float GetPad0(DensityVolumeEngineData value)
{
return value.pad0;
}
float3 GetRcpPosFade(DensityVolumeEngineData value)
{
return value.rcpPosFade;
}
float GetPad1(DensityVolumeEngineData value)
{
return value.pad1;
}
float3 GetRcpNegFade(DensityVolumeEngineData value)
{
return value.rcpNegFade;
}
float GetPad2(DensityVolumeEngineData value)
{
return value.pad2;
}

43
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute


//--------------------------------------------------------------------------------------------------
StructuredBuffer<OrientedBBox> _VolumeBounds;
StructuredBuffer<DensityVolumeData> _VolumeData;
StructuredBuffer<DensityVolumeEngineData> _VolumeData;
TEXTURE3D(_VolumeMaskAtlas);

CBUFFER_START(UnityVolumetricLighting)
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _VBufferSampleOffset; // Not used by this shader
float4 _VolumeMaskDimensions; // x = 1/numTextures , y = width, z = depth = width * numTextures, w = maxLod
float4 _VolumeMaskDimensions; //x = 1/numTextures , y = width, z = depth = width * numTextures, w = maxLod
float _CornetteShanksConstant; // Not used by this shader
uint _VBufferLightingHistoryIsValid; // Not used by this shader
float SampleVolumeMask(DensityVolumeData volumeData, float3 voxelCenterUVW, float3 duvw_dx, float3 duvw_dy, float3 duvw_dz)
float ComputeFadeFactor(float3 coordNDC, float3 rcpPosFade, float3 rcpNegFade)
{
// We have to account for handedness.
coordNDC.z = 1 - coordNDC.z;
float3 posT = saturate(coordNDC * rcpPosFade - rcpPosFade + 1);
float3 negT = saturate(1 - coordNDC * rcpNegFade);
return lerp(1, 0, posT.x) * lerp(1, 0, posT.y) * lerp(1, 0, posT.z)
* lerp(1, 0, negT.x) * lerp(1, 0, negT.y) * lerp(1, 0, negT.z);
}
float SampleVolumeMask(DensityVolumeEngineData volumeData, float3 voxelCenterNDC, float3 duvw_dx, float3 duvw_dy, float3 duvw_dz)
voxelCenterUVW = frac(voxelCenterUVW * volumeData.textureTiling + volumeData.textureScroll);
float3 voxelCenterUVW = frac(voxelCenterNDC * volumeData.textureTiling + volumeData.textureScroll);
float rcpNumTextures = _VolumeMaskDimensions.x;
float textureWidth = _VolumeMaskDimensions.y;

int mipSize = textureSize >> (int)ceil(lod);
float halfTexelSize = 0.5f * rcp(mipSize);
voxelCenterUVW.z = clamp(voxelCenterUVW.z, offset + halfTexelSize, offset + rcpNumTextures - halfTexelSize);
void FillVolumetricDensityBuffer(PositionInputs posInput, float3 rayOriginWS, float3 rayUnDirWS,
float3 voxelAxisRight, float3 voxelAxisUp, float3 voxelAxisForward)

if (overlapFraction > 0)
{
float densityMask = 1.0f;
float3 voxelCenterNDC = voxelCenterCS * 0.5 + 0.5;
overlapFraction *= ComputeFadeFactor(voxelCenterNDC, _VolumeData[volumeIndex].rcpPosFade, _VolumeData[volumeIndex].rcpNegFade);
//Sample the volumeMask
if (_VolumeData[volumeIndex].textureIndex != -1)
{

float3 voxelGradForwardUVW = halfDZ * voxelAxisForwardBS / obbExtents;
float3 voxelCenterUVW = voxelCenterCS * 0.5 + 0.5;
densityMask = SampleVolumeMask(_VolumeData[volumeIndex], voxelCenterUVW, voxelGradRightUVW, voxelGradUpUVW, voxelGradForwardUVW);
overlapFraction *= SampleVolumeMask(_VolumeData[volumeIndex], voxelCenterNDC, voxelGradRightUVW, voxelGradUpUVW, voxelGradForwardUVW);
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering * densityMask;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction * densityMask;
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction;
}
#ifndef USE_CLUSTERED_LIGHTLIST

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


// TODO: avoid creating another Constant Buffer...
CBUFFER_START(UnityVolumetricLighting)
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
uint _NumVisibleDensityVolumes;
float4 _VBufferSampleOffset;
float4 _VolumeMaskDimensions; // Not used by this shader
uint _NumVisibleDensityVolumes; // Not used by this shader
float _CornetteShanksConstant;
uint _VBufferLightingHistoryIsValid;
CBUFFER_END
//--------------------------------------------------------------------------------------------------

float ds = ConvertJitterDistToCenterRayDist(ray, dt);
float centerTransmInt = TransmittanceIntegralHomogeneousMedium(extinction, ds);
bool reprojSuccess = reprojValue.a != 0;
float blendFactor = reprojSuccess ? historyWeight : 0;
float reprojScale = reprojSuccess ? (centerTransmInt * rcp(reprojValue.a)) : 0;
float3 reprojRadiance = reprojValue.rgb;
float3 blendedRadiance = (1 - blendFactor) * lighting.radianceNoPhase + blendFactor * reprojScale * reprojRadiance;
float3 blendedRadiance = lighting.radianceNoPhase;
bool reprojSuccess = (_VBufferLightingHistoryIsValid != 0) && (reprojValue.a != 0);
if (reprojSuccess)
{
float reprojScale = centerTransmInt * rcp(reprojValue.a);
float3 reprojRadiance = reprojValue.rgb * reprojScale;
blendedRadiance = lerp(lighting.radianceNoPhase, reprojRadiance, historyWeight);
}
// Store the feedback for the voxel.
// TODO: dynamic lights (which update their position, rotation, cookie or shadow at runtime)

74
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// TODO: pack better. This data structure contains a bunch of UNORMs.
public struct DensityVolumeData
public struct DensityVolumeEngineData
{
public Vector3 scattering; // [0, 1]
public float extinction; // [0, 1]

public float pad0;
public Vector3 rcpPosFade;
public float pad1;
public Vector3 rcpNegFade;
public float pad2;
public static DensityVolumeData GetNeutralValues()
public static DensityVolumeEngineData GetNeutralValues()
DensityVolumeData data;
DensityVolumeEngineData data;
data.scattering = Vector3.zero;
data.extinction = 0;

data.rcpPosFade = new Vector3(65536.0f, 65536.0f, 65536.0f);
data.rcpNegFade = new Vector3(65536.0f, 65536.0f, 65536.0f);
data.pad0 = 0;
data.pad1 = 0;
data.pad2 = 0;
return data;
}

public struct DensityVolumeList
{
public List<OrientedBBox> bounds;
public List<DensityVolumeData> density;
public List<DensityVolumeEngineData> density;
}
public class VolumetricLightingSystem

public VolumetricLightingPreset preset = VolumetricLightingPreset.Off;
static ComputeShader m_VolumeVoxelizationCS = null;
static ComputeShader m_VolumetricLightingCS = null;
static ComputeShader m_VolumeVoxelizationCS = null;
static ComputeShader m_VolumetricLightingCS = null;
List<OrientedBBox> m_VisibleVolumeBounds = null;
List<DensityVolumeData> m_VisibleVolumeData = null;
public const int k_MaxVisibleVolumeCount = 512;
List<OrientedBBox> m_VisibleVolumeBounds = null;
List<DensityVolumeEngineData> m_VisibleVolumeData = null;
public const int k_MaxVisibleVolumeCount = 512;
static ComputeBuffer s_VisibleVolumeBoundsBuffer = null;
static ComputeBuffer s_VisibleVolumeDataBuffer = null;
static ComputeBuffer s_VisibleVolumeBoundsBuffer = null;
static ComputeBuffer s_VisibleVolumeDataBuffer = null;
RTHandleSystem.RTHandle m_DensityBufferHandle;
RTHandleSystem.RTHandle m_LightingBufferHandle;
RTHandleSystem.RTHandle m_DensityBufferHandle;
RTHandleSystem.RTHandle m_LightingBufferHandle;
bool m_supportVolumetrics = false;
bool m_SupportVolumetrics = false;
// The history buffer starts in the uninitialized state after being created or resized,
// and contains arbitrary data. Therefore, we must initialize it before use.
Vector3Int m_PreviousResolutionOfHistoryBuffer = Vector3Int.zero;
m_supportVolumetrics = asset.renderPipelineSettings.supportVolumetrics;
m_SupportVolumetrics = asset.renderPipelineSettings.supportVolumetrics;
if (!m_supportVolumetrics)
if (!m_SupportVolumetrics)
return;
preset = asset.renderPipelineSettings.increaseResolutionOfVolumetrics ? VolumetricLightingPreset.High :

Debug.Assert(m_VolumetricLightingCS != null);
m_VisibleVolumeBounds = new List<OrientedBBox>();
m_VisibleVolumeData = new List<DensityVolumeData>();
m_VisibleVolumeData = new List<DensityVolumeEngineData>();
s_VisibleVolumeDataBuffer = new ComputeBuffer(k_MaxVisibleVolumeCount, Marshal.SizeOf(typeof(DensityVolumeData)));
s_VisibleVolumeDataBuffer = new ComputeBuffer(k_MaxVisibleVolumeCount, Marshal.SizeOf(typeof(DensityVolumeEngineData)));
int d = ComputeVBufferSliceCount(preset);

{
// Note: Here we can't test framesettings as they are not initialize yet
// TODO: Here we allocate history even for camera that may not use volumetric
if (!m_supportVolumetrics)
if (!m_SupportVolumetrics)
return;
// Start with the same parameters for both frames. Then update them one by one every frame.

cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingIntegral, m_LightingBufferHandle); // Write
if (enableReprojection)
{
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingHistory, hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting));// Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingFeedback, hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting)); // Write
var historyRT = hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting);
var feedbackRT = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.VolumetricLighting);
// Detect if the history buffer has been recreated or resized.
Vector3Int currentResolutionOfHistoryBuffer = new Vector3Int();
currentResolutionOfHistoryBuffer.x = historyRT.rt.width;
currentResolutionOfHistoryBuffer.y = historyRT.rt.height;
currentResolutionOfHistoryBuffer.z = historyRT.rt.volumeDepth;
// We allow downsizing, as this does not cause a reallocation.
bool validHistory = (currentResolutionOfHistoryBuffer.x <= m_PreviousResolutionOfHistoryBuffer.x &&
currentResolutionOfHistoryBuffer.y <= m_PreviousResolutionOfHistoryBuffer.y &&
currentResolutionOfHistoryBuffer.z <= m_PreviousResolutionOfHistoryBuffer.z);
cmd.SetComputeIntParam( m_VolumetricLightingCS, HDShaderIDs._VBufferLightingHistoryIsValid, validHistory ? 1 : 0);
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingHistory, historyRT); // Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingFeedback, feedbackRT); // Write
m_PreviousResolutionOfHistoryBuffer = currentResolutionOfHistoryBuffer;
}
int w = (int)resolution.x;

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDCustomSamplerId.cs


GBuffer,
DBufferRender,
DBufferPrepareDrawData,
DBufferNormal,
DisplayDebugDecalsAtlas,
DisplayDebugViewMaterial,
DebugViewMaterialGBuffer,

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


int m_applyDistortionKernel;
Material m_CameraMotionVectorsMaterial;
Material m_DecalNormalBufferMaterial;
// Debug material
Material m_DebugViewMaterialGBuffer;

[Flags]
public enum StencilBitMask
{
Clear = 0, // 0x0
LightingMask = 7, // 0x7 - 3 bit
ObjectVelocity = 128, // 0x80 - 1 bit
All = 255 // 0xFF - 8 bit
Clear = 0, // 0x0
LightingMask = 7, // 0x7 - 3 bit
Decals = 8, // 0x8 - 1 bit
DecalsForwardOutputNormalBuffer = 16, // 0x10 - 1 bit
ObjectVelocity = 128, // 0x80 - 1 bit
All = 255 // 0xFF - 8 bit
}
RenderStateBlock m_DepthStateOpaque;

m_CopyStencilForNoLighting.SetInt(HDShaderIDs._StencilRef, (int)StencilLightingUsage.NoLighting);
m_CopyStencilForNoLighting.SetInt(HDShaderIDs._StencilMask, (int)StencilBitMask.LightingMask);
m_CameraMotionVectorsMaterial = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.cameraMotionVectors);
m_DecalNormalBufferMaterial = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.decalNormalBuffer);
m_CopyDepth = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.copyDepthBuffer);

CoreUtils.Destroy(m_CopyStencilForNoLighting);
CoreUtils.Destroy(m_CameraMotionVectorsMaterial);
CoreUtils.Destroy(m_DecalNormalBufferMaterial);
CoreUtils.Destroy(m_DebugViewMaterialGBuffer);
CoreUtils.Destroy(m_DebugViewMaterialGBufferShadowMask);

// We can now bind the normal buffer to be use by any effect
m_NormalBufferManager.BindNormalBuffers(cmd);
if (!hdCamera.frameSettings.enableMSAA) // MSAA not supported
{
using (new ProfilingSample(cmd, "DBuffer Normal (forward)", CustomSamplerId.DBufferNormal.GetSampler()))
{
int stencilMask;
int stencilRef;
if (hdCamera.frameSettings.enableForwardRenderingOnly) // in forward rendering all pixels that decals wrote into have to be composited
{
stencilMask = (int)StencilBitMask.Decals;
stencilRef = (int)StencilBitMask.Decals;
}
else // in deferred rendering only pixels affected by both forward materials and decals need to be composited
{
stencilMask = (int)StencilBitMask.Decals | (int)StencilBitMask.DecalsForwardOutputNormalBuffer;
stencilRef = (int)StencilBitMask.Decals | (int)StencilBitMask.DecalsForwardOutputNormalBuffer;
}
m_DecalNormalBufferMaterial.SetInt(HDShaderIDs._DecalNormalBufferStencilReadMask, stencilMask);
m_DecalNormalBufferMaterial.SetInt(HDShaderIDs._DecalNormalBufferStencilRef, stencilRef);
HDUtils.SetRenderTarget(cmd, hdCamera, m_CameraDepthStencilBuffer);
cmd.SetRandomWriteTarget(1, m_NormalBufferManager.GetNormalBuffer(0));
cmd.DrawProcedural(Matrix4x4.identity, m_DecalNormalBufferMaterial, 0, MeshTopology.Triangles, 3, 1);
cmd.ClearRandomWriteTargets();
}
}
// In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing.
CopyDepthBufferIfNeeded(cmd);
// Depth texture is now ready, bind it (Depth buffer could have been bind before if DBuffer is enable)

{
HDUtils.SetRenderTarget(cmd, hdCamera, m_ScreenSpaceShadowsBuffer, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}
// In some cases when loading a project for the first time in the editor, the internal resource is destroyed.
// When used as render target, the C++ code will re-create the resource automatically. Since here it's used directly as an UAV, we need to check manually
if (!m_ScreenSpaceShadowsBuffer.rt.IsCreated())
m_ScreenSpaceShadowsBuffer.rt.Create();
m_LightLoop.RenderScreenSpaceShadows(hdCamera, m_ScreenSpaceShadowsBuffer, GetDepthTexture(), cmd);
PushFullScreenDebugTexture(hdCamera, cmd, m_ScreenSpaceShadowsBuffer, FullScreenDebugMode.ScreenSpaceShadows);

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


public static readonly string s_MeshDecalsAOSStr = "DBufferMesh_AOS";
public static readonly string s_MeshDecalsMAOSStr = "DBufferMesh_MAOS";
public static readonly string s_MeshDecals3RTStr = "DBufferMesh_3RT";
// ShaderPass name
public static readonly ShaderPassName s_EmptyName = new ShaderPassName(s_EmptyStr);
public static readonly ShaderPassName s_ForwardName = new ShaderPassName(s_ForwardStr);

public static readonly int _NumTileFtplY = Shader.PropertyToID("_NumTileFtplY");
public static readonly int _NumTileClusteredX = Shader.PropertyToID("_NumTileClusteredX");
public static readonly int _NumTileClusteredY = Shader.PropertyToID("_NumTileClusteredY");
public static readonly int _IndirectLightingMultiplier = Shader.PropertyToID("_IndirectLightingMultiplier");
public static readonly int g_isLogBaseBufferEnabled = Shader.PropertyToID("g_isLogBaseBufferEnabled");

public static readonly int _DecalIndexShift = Shader.PropertyToID("_DecalIndexShift");
public static readonly int _DecalCount = Shader.PropertyToID("_DecalCount");
public static readonly int _DecalDatas = Shader.PropertyToID("_DecalDatas");
public static readonly int _DecalNormalBufferStencilReadMask = Shader.PropertyToID("_DecalNormalBufferStencilReadMask");
public static readonly int _DecalNormalBufferStencilRef = Shader.PropertyToID("_DecalNormalBufferStencilRef");
public static readonly int _WorldSpaceCameraPos = Shader.PropertyToID("_WorldSpaceCameraPos");
public static readonly int _ViewMatrix = Shader.PropertyToID("_ViewMatrix");

public static readonly int _VBufferLighting = Shader.PropertyToID("_VBufferLighting");
public static readonly int _VBufferLightingIntegral = Shader.PropertyToID("_VBufferLightingIntegral");
public static readonly int _VBufferLightingHistory = Shader.PropertyToID("_VBufferLightingHistory");
public static readonly int _VBufferLightingHistoryIsValid = Shader.PropertyToID("_VBufferLightingHistoryIsValid");
public static readonly int _VBufferLightingFeedback = Shader.PropertyToID("_VBufferLightingFeedback");
public static readonly int _VBufferSampleOffset = Shader.PropertyToID("_VBufferSampleOffset");
public static readonly int _VolumeBounds = Shader.PropertyToID("_VolumeBounds");

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

9
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader.meta


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

89
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalNormalBuffer.shader


Shader "Hidden/HDRenderPipeline/Material/Decal/DecalNormalBuffer"
{
Properties
{
// Stencil state
[HideInInspector] _DecalNormalBufferStencilRef("_DecalNormalBufferStencilRef", Int) = 0 // set at runtime
[HideInInspector] _DecalNormalBufferStencilReadMask("_DecalNormalBufferStencilReadMask", Int) = 0 // set at runtime
}
HLSLINCLUDE
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "../../ShaderVariables.hlsl"
#include "Decal.hlsl"
#include "../NormalBuffer.hlsl"
RW_TEXTURE2D(float4, _NormalBuffer);
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
DECLARE_DBUFFER_TEXTURE(_DBufferTexture);
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID);
return output;
}
// Force the stencil test before the UAV write.
[earlydepthstencil]
float4 FragNearest(Varyings input) : SV_Target
{
FETCH_DBUFFER(DBuffer, _DBufferTexture, input.texcoord * _ScreenSize.xy);
DecalSurfaceData decalSurfaceData;
DECODE_FROM_DBUFFER(DBuffer, decalSurfaceData);
float4 GBufferNormal = _NormalBuffer[input.texcoord * _ScreenSize.xy];
NormalData normalData;
DecodeFromNormalBuffer(GBufferNormal, uint2(0, 0), normalData);
normalData.normalWS.xyz = normalize(normalData.normalWS.xyz * decalSurfaceData.normalWS.w + decalSurfaceData.normalWS.xyz);
EncodeIntoNormalBuffer(normalData, uint2(0, 0), GBufferNormal);
_NormalBuffer[input.texcoord * _ScreenSize.xy] = GBufferNormal;
return float4(0, 0, 0, 0); // normal buffer is written into as a RWTexture
}
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline" }
Pass
{
ZWrite Off
ZTest Always
Blend Off
Cull Off
Stencil
{
ReadMask[_DecalNormalBufferStencilReadMask]
Ref[_DecalNormalBufferStencilRef]
Comp Equal
Pass Zero // doesn't really matter, but clear to 0 for debugging
}
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearest
ENDHLSL
}
}
Fallback Off
}

34
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs


using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public static class HDLightEditorUtilities
{
public static void DrawFrustumlightGizmo(Light frustumlight)
{
var additionalLightData = frustumlight.GetComponent<HDAdditionalLightData>();
if (additionalLightData == null)
return;
Matrix4x4 matrix = new Matrix4x4(frustumlight.transform.right, frustumlight.transform.up, frustumlight.transform.forward, frustumlight.transform.position);
Gizmos.matrix = matrix;
if (additionalLightData.spotLightShape == SpotLightShape.Pyramid)
{
CoreLightEditorUtilities.DrawLightPyramidFrustum(Vector3.zero, frustumlight.spotAngle, frustumlight.range, 0.0f, additionalLightData.aspectRatio);
}
else // Ortho frustum
{
//DrawLightOrthoFrustum(Vector3.zero, additionalLightData.shapeWidth, additionalLightData.shapeHeight, frustumlight.range, 0.0f);
Vector3 frustumCenter = new Vector3(0.0f, 0.0f, 0.5f * frustumlight.range);
Vector3 frustumsize = new Vector3(additionalLightData.shapeWidth, additionalLightData.shapeHeight, frustumlight.range);
Gizmos.DrawWireCube(frustumCenter, frustumsize);
}
Gizmos.matrix = Matrix4x4.identity;
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs.meta


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