浏览代码

Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderPipeline

/feature-ReflectionProbeFit
sebastienlagarde 7 年前
当前提交
20c2964d
共有 11 个文件被更改,包括 761 次插入287 次删除
  1. 60
      ScriptableRenderPipeline/Core/CoreRP/Editor/CoreEditorUtils.cs
  2. 31
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  3. 128
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  4. 464
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  5. 103
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.cs
  6. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/HDAdditionalReflectionData.cs
  7. 23
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs
  8. 72
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl
  9. 21
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  10. 25
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtilities.hlsl
  11. 106
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

60
ScriptableRenderPipeline/Core/CoreRP/Editor/CoreEditorUtils.cs


using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

}
return group.isExpanded;
}
static readonly GUIContent[] k_DrawVector6Slider_LabelPositives =
{
new GUIContent("+X"),
new GUIContent("+Y"),
new GUIContent("+Z"),
};
static readonly GUIContent[] k_DrawVector6Slider_LabelNegatives =
{
new GUIContent("-X"),
new GUIContent("-Y"),
new GUIContent("-Z"),
};
const int k_DrawVector6Slider_LabelSize = 60;
const int k_DrawVector6Slider_FieldSize = 80;
public static void DrawVector6Slider(GUIContent label, SerializedProperty positive, SerializedProperty negative, Vector3 min, Vector3 max)
{
GUILayout.BeginVertical();
EditorGUILayout.LabelField(label);
++EditorGUI.indentLevel;
var rect = GUILayoutUtility.GetRect(0, float.MaxValue, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);
var v = positive.vector3Value;
EditorGUI.BeginChangeCheck();
v = DrawVector3Slider(rect, k_DrawVector6Slider_LabelPositives, v, min, max);
if (EditorGUI.EndChangeCheck())
positive.vector3Value = v;
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
rect = GUILayoutUtility.GetRect(0, float.MaxValue, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);
v = negative.vector3Value;
EditorGUI.BeginChangeCheck();
v = DrawVector3Slider(rect, k_DrawVector6Slider_LabelNegatives, v, min, max);
if (EditorGUI.EndChangeCheck())
negative.vector3Value = v;
--EditorGUI.indentLevel;
GUILayout.EndVertical();
}
static Vector3 DrawVector3Slider(Rect rect, GUIContent[] labels, Vector3 value, Vector3 min, Vector3 max)
{
// Use a corrected width due to the hacks used for layouting the slider properly below
rect.width -= 20;
var fieldWidth = rect.width / 3f;
for (var i = 0; i < 3; ++i)
{
var c = new Rect(rect.x + fieldWidth * i, rect.y, fieldWidth, rect.height);
var labelRect = new Rect(c.x, c.y, k_DrawVector6Slider_LabelSize, c.height);
var sliderRect = new Rect(labelRect.x + labelRect.width, c.y, c.width - k_DrawVector6Slider_LabelSize - k_DrawVector6Slider_FieldSize + 45, c.height);
var fieldRect = new Rect(sliderRect.x + sliderRect.width - 25, c.y, k_DrawVector6Slider_FieldSize, c.height);
EditorGUI.LabelField(labelRect, labels[i]);
value[i] = GUI.HorizontalSlider(sliderRect, value[i], min[i], max[i]);
value[i] = EditorGUI.FloatField(fieldRect, value[i]);
}
return value;
}
public static void RemoveMaterialKeywords(Material material)

31
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.Data.cs


{
internal class SerializedReflectionProbe
{
internal ReflectionProbe target;
internal HDAdditionalReflectionData targetData;
internal SerializedObject so;
internal SerializedProperty mode;

internal SerializedProperty timeSlicingMode;
internal SerializedProperty intensityMultiplier;
internal SerializedProperty blendDistance;
internal SerializedProperty legacyBlendDistance;
internal SerializedProperty boxSize;
internal SerializedProperty boxOffset;
internal SerializedProperty resolution;

internal SerializedProperty boxReprojectionVolumeSize;
internal SerializedProperty boxReprojectionVolumeCenter;
internal SerializedProperty sphereReprojectionVolumeRadius;
internal SerializedProperty blendDistancePositive;
internal SerializedProperty blendDistanceNegative;
internal SerializedProperty blendNormalDistancePositive;
internal SerializedProperty blendNormalDistanceNegative;
internal SerializedProperty boxSideFadePositive;
internal SerializedProperty boxSideFadeNegative;
target = (ReflectionProbe)so.targetObject;
targetData = target.GetComponent<HDAdditionalReflectionData>();
mode = so.FindProperty("m_Mode");
customBakedTexture = so.FindProperty("m_CustomBakedTexture");

intensityMultiplier = so.FindProperty("m_IntensityMultiplier");
blendDistance = so.FindProperty("m_BlendDistance");
boxSize = so.FindProperty("m_BoxSize");
boxOffset = so.FindProperty("m_BoxOffset");
resolution = so.FindProperty("m_Resolution");

nearClip = so.FindProperty("m_NearClip");
farClip = so.FindProperty("m_FarClip");
boxProjection = so.FindProperty("m_BoxProjection");
legacyBlendDistance = so.FindProperty("m_BlendDistance");
influenceShape = addso.Find((HDAdditionalReflectionData d) => d.influenceShape);
influenceSphereRadius = addso.Find((HDAdditionalReflectionData d) => d.influenceSphereRadius);

sphereReprojectionVolumeRadius = addso.Find((HDAdditionalReflectionData d) => d.sphereReprojectionVolumeRadius);
dimmer = addso.Find((HDAdditionalReflectionData d) => d.dimmer);
blendDistancePositive = addso.Find((HDAdditionalReflectionData d) => d.blendDistancePositive);
blendDistanceNegative = addso.Find((HDAdditionalReflectionData d) => d.blendDistanceNegative);
blendNormalDistancePositive = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistancePositive);
blendNormalDistanceNegative = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistanceNegative);
boxSideFadePositive = addso.Find((HDAdditionalReflectionData d) => d.boxSideFadePositive);
boxSideFadeNegative = addso.Find((HDAdditionalReflectionData d) => d.boxSideFadeNegative);
}
}

public void ClearOperation(Operation op) { operations &= ~op; }
public void AddOperation(Operation op) { operations |= op; }
public BoxBoundsHandle boxInfluenceBoundsHandle = new BoxBoundsHandle();
public BoxBoundsHandle boxProjectionBoundsHandle = new BoxBoundsHandle();
public BoxBoundsHandle boxInfluenceHandle = new BoxBoundsHandle();
public BoxBoundsHandle boxProjectionHandle = new BoxBoundsHandle();
public SphereBoundsHandle influenceSphereHandle = new SphereBoundsHandle();
public SphereBoundsHandle projectionSphereHandle = new SphereBoundsHandle();
public BoxBoundsHandle boxBlendNormalHandle = new BoxBoundsHandle();
public SphereBoundsHandle sphereInfluenceHandle = new SphereBoundsHandle();
public SphereBoundsHandle sphereProjectionHandle = new SphereBoundsHandle();
public SphereBoundsHandle sphereBlendNormalHandle = new SphereBoundsHandle();
public Matrix4x4 oldLocalSpace = Matrix4x4.identity;
public bool HasAndClearOperation(Operation op)

128
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs


static readonly CED.IDrawer k_InfluenceVolumeSection = CED.FoldoutGroup(
"Influence volume settings",
(s, p, o) => p.blendDistance,
(s, p, o) => p.blendDistancePositive,
CED.Action(Drawer_DistanceBlend),
CED.FadeGroup(
(s, p, o, i) => s.GetShapeFaded((ReflectionInfluenceShape)i),
false,

p.resolution.intValue = renderPipelineAsset.GetRenderPipelineSettings().lightLoopSettings.reflectionCubemapSize;
EditorGUILayout.LabelField(CoreEditorUtils.GetContent("Resolution"), CoreEditorUtils.GetContent(p.resolution.intValue.ToString()));
EditorGUILayout.PropertyField(p.shadowDistance);
EditorGUILayout.PropertyField(p.cullingMask);
EditorGUILayout.PropertyField(p.useOcclusionCulling);
EditorGUILayout.PropertyField(p.nearClip);
EditorGUILayout.PropertyField(p.farClip);
EditorGUILayout.PropertyField(p.shadowDistance, CoreEditorUtils.GetContent("Shadow Distance"));
EditorGUILayout.PropertyField(p.cullingMask, CoreEditorUtils.GetContent("Culling Mask"));
EditorGUILayout.PropertyField(p.useOcclusionCulling, CoreEditorUtils.GetContent("Use Occlusion Culling"));
EditorGUILayout.PropertyField(p.nearClip, CoreEditorUtils.GetContent("Near Clip"));
EditorGUILayout.PropertyField(p.farClip, CoreEditorUtils.GetContent("Far Clip"));
}
static void Drawer_AdditionalSettings(UIState s, SerializedReflectionProbe p, Editor owner)

if (p.so.targetObjects.Length == 1)
{
var probe = (ReflectionProbe)p.so.targetObject;
var probe = p.target;
if (probe.mode == ReflectionProbeMode.Custom && probe.customBakedTexture != null)
{
var cubemap = probe.customBakedTexture as Cubemap;

{
if (p.mode.intValue == (int)ReflectionProbeMode.Realtime)
{
EditorGUILayout.HelpBox("Baking of this reflection probe should be initiated from the scripting API because the type is 'Realtime'", MessageType.Info);
EditorGUILayout.HelpBox("Refresh of this reflection probe should be initiated from the scripting API because the type is 'Realtime'", MessageType.Info);
if (!QualitySettings.realtimeReflectionProbes)
EditorGUILayout.HelpBox("Realtime reflection probes are disabled in Quality Settings", MessageType.Warning);

{
var mode = (int)data;
var probe = p.so.targetObject as ReflectionProbe;
var probe = p.target;
if (mode == 0)
{
BakeCustomReflectionProbe(probe, false, true);

GUILayout.ExpandWidth(true)))
{
var probe = (ReflectionProbe)p.so.targetObject;
var probe = p.target;
BakeCustomReflectionProbe(probe, true, true);
ResetProbeSceneTextureInMaterial(probe);
GUIUtility.ExitGUI();

case ReflectionProbeMode.Baked:
{
GUI.enabled = ((ReflectionProbe)p.so.targetObject).enabled;
GUI.enabled = p.target.enabled;
// Bake button in non-continous mode
if (ButtonWithDropdownList(

},
GUILayout.ExpandWidth(true)))
{
var probe = (ReflectionProbe)p.so.targetObject;
var probe = p.target;
BakeReflectionProbeSnapshot(probe);
ResetProbeSceneTextureInMaterial(probe);
GUIUtility.ExitGUI();

}
#region Influence Volume
static void Drawer_DistanceBlend(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.Slider(p.blendDistance, 0, CalculateMaxBlendDistance(s, p, owner), CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."));
EditorGUI.BeginChangeCheck();
}
var maxBlendDistance = CalculateBoxMaxBlendDistance(s, p, owner);
CoreEditorUtils.DrawVector6Slider(
CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."),
p.blendDistancePositive, p.blendDistanceNegative, Vector3.zero, maxBlendDistance);
CoreEditorUtils.DrawVector6Slider(
CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."),
p.blendNormalDistancePositive, p.blendNormalDistanceNegative, Vector3.zero, maxBlendDistance);
CoreEditorUtils.DrawVector6Slider(
CoreEditorUtils.GetContent("Face fade|Fade faces of the cubemap."),
p.boxSideFadePositive, p.boxSideFadeNegative, Vector3.zero, Vector3.one);
EditorGUILayout.Space();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(p.boxSize, CoreEditorUtils.GetContent("Box Size|The size of the box in which the reflections will be applied to objects. The value is not affected by the Transform of the Game Object."));
EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Box Offset|The center of the box in which the reflections will be applied to objects. The value is relative to the position of the Game Object."));

{
var center = p.boxOffset.vector3Value;
var size = p.boxSize.vector3Value;
if (ValidateAABB((ReflectionProbe)p.so.targetObject, ref center, ref size))
if (ValidateAABB(p.target, ref center, ref size))
{
p.boxOffset.vector3Value = center;
p.boxSize.vector3Value = size;

static void Drawer_InfluenceSphereSettings(UIState s, SerializedReflectionProbe p, Editor owner)
{
var maxBlendDistance = CalculateSphereMaxBlendDistance(s, p, owner);
var blendDistance = p.blendDistancePositive.vector3Value.x;
EditorGUI.BeginChangeCheck();
blendDistance = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."), blendDistance, 0, maxBlendDistance);
if (EditorGUI.EndChangeCheck())
{
p.blendDistancePositive.vector3Value = Vector3.one * blendDistance;
p.blendDistanceNegative.vector3Value = Vector3.one * blendDistance;
}
var blendNormalDistance = p.blendNormalDistancePositive.vector3Value.x;
EditorGUI.BeginChangeCheck();
blendNormalDistance = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."), blendNormalDistance, 0, maxBlendDistance);
if (EditorGUI.EndChangeCheck())
{
p.blendNormalDistancePositive.vector3Value = Vector3.one * blendNormalDistance;
p.blendNormalDistanceNegative.vector3Value = Vector3.one * blendNormalDistance;
}
EditorGUILayout.PropertyField(p.influenceSphereRadius, CoreEditorUtils.GetContent("Radius"));
EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Sphere Projection|Sphere projection causes reflections to appear to change based on the object's position within the probe's sphere, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting sphere projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings"));
}

static readonly EditMode.SceneViewEditMode[] k_Toolbar_SceneViewEditModes =
{
EditMode.SceneViewEditMode.ReflectionProbeBox,
//EditMode.SceneViewEditMode.GridBox,
EditMode.SceneViewEditMode.GridBox,
EditMode.SceneViewEditMode.Collider,
EditMode.SceneViewEditMode.ReflectionProbeOrigin
};
static GUIContent[] s_Toolbar_Contents = null;

{
return s_Toolbar_Contents ?? (s_Toolbar_Contents = new []
{
EditorGUIUtility.IconContent("EditCollider", "|Modify the influence volume of the reflection probe."),
//EditorGUIUtility.IconContent("PreMatCube", "|Modify the projection volume of the reflection probe."),
EditorGUIUtility.IconContent("EditCollider", "|Modify the extents of the reflection probe. (SHIFT+1)"),
EditorGUIUtility.IconContent("PreMatCube", "|Modify the influence volume of the reflection probe. (SHIFT+2)"),
EditorGUIUtility.IconContent("SceneViewOrtho", "|Modify the influence normal volume of the reflection probe. (SHIFT+3)"),
EditorGUIUtility.IconContent("MoveTool", "|Move the selected objects.")
});
}

GUI.changed = false;
var oldEditMode = EditMode.editMode;
Func<Bounds> getBounds = () =>
{
var bounds = new Bounds();
foreach (var targetObject in p.so.targetObjects)
{
var rp = (ReflectionProbe)targetObject;
var b = rp.bounds;
bounds.Encapsulate(b);
}
return bounds;
};
EditMode.DoInspectorToolbar(k_Toolbar_SceneViewEditModes, toolbar_Contents, getBounds, owner);
EditMode.DoInspectorToolbar(k_Toolbar_SceneViewEditModes, toolbar_Contents, GetBoundsGetter(p), owner);
//if (GUILayout.Button(EditorGUIUtility.IconContent("Navigation", "|Fit the reflection probe volume to the surrounding colliders.")))
// s.AddOperation(Operation.FitVolumeToSurroundings);

switch (EditMode.editMode)
{
case EditMode.SceneViewEditMode.ReflectionProbeOrigin:
s.UpdateOldLocalSpace((ReflectionProbe)p.so.targetObject);
s.UpdateOldLocalSpace(p.target);
break;
}
}

}
static Func<Bounds> GetBoundsGetter(SerializedReflectionProbe p)
{
return () =>
{
var bounds = new Bounds();
foreach (var targetObject in p.so.targetObjects)
{
var rp = (ReflectionProbe)targetObject;
var b = rp.bounds;
bounds.Encapsulate(b);
}
return bounds;
};
}
#endregion
#region Mode Specific Settings

}
#endregion
static float CalculateMaxBlendDistance(UIState s, SerializedReflectionProbe p, Editor o)
static float CalculateSphereMaxBlendDistance(UIState s, SerializedReflectionProbe p, Editor o)
var shape = (ReflectionInfluenceShape)p.influenceShape.intValue;
switch (shape)
{
case ReflectionInfluenceShape.Sphere:
return p.influenceSphereRadius.floatValue * 0.5f;
default:
case ReflectionInfluenceShape.Box:
{
var size = p.boxSize.vector3Value;
var v = Mathf.Min(size.x, Mathf.Min(size.y, size.z));
return v * 0.5f;
}
}
return p.influenceSphereRadius.floatValue;
}
static Vector3 CalculateBoxMaxBlendDistance(UIState s, SerializedReflectionProbe p, Editor o)
{
return p.boxSize.vector3Value * 0.5f;
}
static MethodInfo k_EditorGUI_ButtonWithDropdownList = typeof(EditorGUI).GetMethod("ButtonWithDropdownList", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any, new [] { typeof(GUIContent), typeof(string[]), typeof(GenericMenu.MenuFunction2), typeof(GUILayoutOption[]) }, new ParameterModifier[0]);

464
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.Handles.cs


using System;
using UnityEditor.IMGUI.Controls;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

{
partial class HDReflectionProbeEditor
{
internal static Color k_GizmoReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0x94 / 255f, 0x20 / 255f);
internal static Color k_GizmoReflectionProbeDisabled = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x10 / 255f);
internal static Color k_GizmoHandleReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0xAA / 255f, 0xFF / 255f);
enum InfluenceType
{
Standard,
Normal
}
internal static Color k_GizmoThemeColorExtent = new Color(255f / 255f, 229f / 255f, 148f / 255f, 80f / 255f);
internal static Color k_GizmoThemeColorExtentFace = new Color(255f / 255f, 229f / 255f, 148f / 255f, 45f / 255f);
internal static Color k_GizmoThemeColorInfluenceBlend = new Color(83f / 255f, 255f / 255f, 95f / 255f, 75f / 255f);
internal static Color k_GizmoThemeColorInfluenceBlendFace = new Color(83f / 255f, 255f / 255f, 95f / 255f, 17f / 255f);
internal static Color k_GizmoThemeColorInfluenceNormalBlend = new Color(0f / 255f, 229f / 255f, 255f / 255f, 80f / 255f);
internal static Color k_GizmoThemeColorInfluenceNormalBlendFace = new Color(0f / 255f, 229f / 255f, 255f / 255f, 36f / 255f);
internal static Color k_GizmoThemeColorProjection = new Color(0x00 / 255f, 0xE5 / 255f, 0xFF / 255f, 0x20 / 255f);
internal static Color k_GizmoThemeColorProjectionFace = new Color(0x00 / 255f, 0xE5 / 255f, 0xFF / 255f, 0x20 / 255f);
internal static Color k_GizmoThemeColorDisabled = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x10 / 255f);
internal static Color k_GizmoThemeColorDisabledFace = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x10 / 255f);
void OnSceneGUI()
{

BakeRealtimeProbeIfPositionChanged(s, p, o);
DoShortcutKey(p, o);
if (!s.sceneViewEditing)
return;

switch (EditMode.editMode)
{
// Influence editing
if (p.influenceShape.enumValueIndex == 0)
Handle_InfluenceBoxEditing(s, p, o);
if (p.influenceShape.enumValueIndex == 1)
Handle_InfluenceSphereEditing(s, p, o);
Handle_InfluenceEditing(s, p, o);
// Influence fade editing
if (p.influenceShape.enumValueIndex == 0)
Handle_ProjectionBoxEditing(s, p, o);
if (p.influenceShape.enumValueIndex == 1)
Handle_ProjectionSphereEditing(s, p, o);
Handle_InfluenceFadeEditing(s, p, o, InfluenceType.Standard);
break;
// Influence normal fade editing
case EditMode.SceneViewEditMode.Collider:
Handle_InfluenceFadeEditing(s, p, o, InfluenceType.Normal);
// Origin editing
case EditMode.SceneViewEditMode.ReflectionProbeOrigin:
Handle_OriginEditing(s, p, o);
break;

Repaint();
void BakeRealtimeProbeIfPositionChanged(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_InfluenceFadeEditing(UIState s, SerializedReflectionProbe sp, Editor o, InfluenceType influenceType)
if (Application.isPlaying
|| ((ReflectionProbeMode)sp.mode.intValue) != ReflectionProbeMode.Realtime)
BoxBoundsHandle blendBox;
SphereBoundsHandle sphereHandle;
Vector3 probeBlendDistancePositive, probeBlendDistanceNegative;
Color color;
switch (influenceType)
m_PositionHash = 0;
return;
default:
case InfluenceType.Standard:
{
blendBox = s.boxBlendHandle;
sphereHandle = s.sphereBlendHandle;
probeBlendDistancePositive = sp.targetData.blendDistancePositive;
probeBlendDistanceNegative = sp.targetData.blendDistanceNegative;
color = k_GizmoThemeColorInfluenceBlend;
break;
}
case InfluenceType.Normal:
{
blendBox = s.boxBlendNormalHandle;
sphereHandle = s.sphereBlendNormalHandle;
probeBlendDistancePositive = sp.targetData.blendNormalDistancePositive;
probeBlendDistanceNegative = sp.targetData.blendNormalDistanceNegative;
color = k_GizmoThemeColorInfluenceNormalBlend;
break;
}
var hash = 0;
for (var i = 0; i < sp.so.targetObjects.Length; i++)
{
var p = (ReflectionProbe)sp.so.targetObjects[i];
var tr = p.GetComponent<Transform>();
hash ^= tr.position.GetHashCode();
}
if (hash != m_PositionHash)
var mat = Handles.matrix;
var col = Handles.color;
Handles.matrix = GetLocalSpace(sp.target);
switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
m_PositionHash = hash;
for (var i = 0; i < sp.so.targetObjects.Length; i++)
case ReflectionInfluenceShape.Box:
var p = (ReflectionProbe)sp.so.targetObjects[i];
p.RenderProbe();
}
}
}
blendBox.center = sp.target.center - (probeBlendDistancePositive - probeBlendDistanceNegative) * 0.5f;
blendBox.size = sp.target.size - probeBlendDistancePositive - probeBlendDistanceNegative;
static void Handle_InfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
Handles.color = k_GizmoThemeColorExtent;
EditorGUI.BeginChangeCheck();
Handles.color = color;
blendBox.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(sp.target, "Modified Reflection Probe Influence");
Undo.RecordObject(sp.targetData, "Modified Reflection Probe Influence");
using (new Handles.DrawingScope(GetLocalSpace(p)))
{
s.boxInfluenceBoundsHandle.center = p.center;
s.boxInfluenceBoundsHandle.size = p.size;
s.boxBlendHandle.center = p.center;
s.boxBlendHandle.size = p.size - Vector3.one * p.blendDistance * 2;
var center = sp.target.center;
var influenceSize = sp.target.size;
EditorGUI.BeginChangeCheck();
s.boxInfluenceBoundsHandle.DrawHandle();
var influenceChanged = EditorGUI.EndChangeCheck();
EditorGUI.BeginChangeCheck();
s.boxBlendHandle.DrawHandle();
if (influenceChanged || EditorGUI.EndChangeCheck())
var diff = 2 * (blendBox.center - center);
var sum = influenceSize - blendBox.size;
var positive = (sum - diff) * 0.5f;
var negative = (sum + diff) * 0.5f;
var blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positive, influenceSize));
var blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negative, influenceSize));
probeBlendDistancePositive = blendDistancePositive;
probeBlendDistanceNegative = blendDistanceNegative;
ApplyConstraintsOnTargets(s, sp, o);
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);
}
break;
}
case ReflectionInfluenceShape.Sphere:
Undo.RecordObject(p, "Modified Reflection Probe AABB");
var center = s.boxInfluenceBoundsHandle.center;
var influenceSize = s.boxInfluenceBoundsHandle.size;
var blendSize = s.boxBlendHandle.size;
ValidateAABB(p, ref center, ref influenceSize);
var blendDistance = influenceChanged
? p.blendDistance
: ((influenceSize.x - blendSize.x) * 0.5f + (influenceSize.y - blendSize.y) * 0.5f + (influenceSize.z - blendSize.z) * 0.5f) / 3;
p.center = center;
p.size = influenceSize;
p.blendDistance = Mathf.Max(blendDistance, 0);
EditorUtility.SetDirty(p);
sphereHandle.center = sp.target.center;
sphereHandle.radius = Mathf.Clamp(sp.targetData.influenceSphereRadius - probeBlendDistancePositive.x, 0, sp.targetData.influenceSphereRadius);
Handles.color = k_GizmoThemeColorExtent;
EditorGUI.BeginChangeCheck();
Handles.color = color;
sphereHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(sp.target, "Modified Reflection influence volume");
Undo.RecordObject(sp.targetData, "Modified Reflection influence volume");
var influenceRadius = sp.targetData.influenceSphereRadius;
var blendRadius = sphereHandle.radius;
var blendDistance = Mathf.Clamp(influenceRadius - blendRadius, 0, influenceRadius);
probeBlendDistancePositive = Vector3.one * blendDistance;
probeBlendDistanceNegative = probeBlendDistancePositive;
ApplyConstraintsOnTargets(s, sp, o);
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);
}
break;
}
Handles.matrix = mat;
Handles.color = col;
static void Handle_ProjectionBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();
using (new Handles.DrawingScope(GetLocalSpace(p)))
switch (influenceType)
s.boxProjectionBoundsHandle.center = reflectionData.boxReprojectionVolumeCenter;
s.boxProjectionBoundsHandle.size = reflectionData.boxReprojectionVolumeSize;
EditorGUI.BeginChangeCheck();
s.boxProjectionBoundsHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
default:
case InfluenceType.Standard:
Undo.RecordObject(reflectionData, "Modified Reflection Probe AABB");
var center = s.boxProjectionBoundsHandle.center;
var size = s.boxProjectionBoundsHandle.size;
ValidateAABB(p, ref center, ref size);
reflectionData.boxReprojectionVolumeCenter = center;
reflectionData.boxReprojectionVolumeSize = size;
EditorUtility.SetDirty(reflectionData);
sp.targetData.blendDistancePositive = probeBlendDistancePositive;
sp.targetData.blendDistanceNegative = probeBlendDistanceNegative;
break;
}
case InfluenceType.Normal:
{
sp.targetData.blendNormalDistancePositive = probeBlendDistancePositive;
sp.targetData.blendNormalDistanceNegative = probeBlendDistanceNegative;
break;
static void Handle_InfluenceSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_InfluenceEditing(UIState s, SerializedReflectionProbe sp, Editor o)
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();
using (new Handles.DrawingScope(GetLocalSpace(p)))
var mat = Handles.matrix;
var col = Handles.color;
Handles.matrix = GetLocalSpace(sp.target);
switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
s.influenceSphereHandle.center = p.center;
s.influenceSphereHandle.radius = reflectionData.influenceSphereRadius;
s.sphereBlendHandle.center = p.center;
s.sphereBlendHandle.radius = Mathf.Min(reflectionData.influenceSphereRadius - p.blendDistance * 2, reflectionData.influenceSphereRadius);
EditorGUI.BeginChangeCheck();
s.influenceSphereHandle.DrawHandle();
var influenceChanged = EditorGUI.EndChangeCheck();
EditorGUI.BeginChangeCheck();
s.sphereBlendHandle.DrawHandle();
if (influenceChanged || EditorGUI.EndChangeCheck())
case ReflectionInfluenceShape.Box:
Undo.RecordObject(reflectionData, "Modified Reflection influence volume");
var center = p.center;
var influenceRadius = s.influenceSphereHandle.radius;
var blendRadius = influenceChanged
? Mathf.Max(influenceRadius - p.blendDistance * 2, 0)
: s.sphereBlendHandle.radius;
s.boxInfluenceHandle.center = sp.target.center;
s.boxInfluenceHandle.size = sp.target.size;
var radius = Vector3.one * influenceRadius;
ValidateAABB(p, ref center, ref radius);
influenceRadius = radius.x;
var blendDistance = Mathf.Max(0, (influenceRadius - blendRadius) * 0.5f);
Handles.color = k_GizmoThemeColorExtent;
EditorGUI.BeginChangeCheck();
s.boxInfluenceHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(sp.target, "Modified Reflection Probe AABB");
Undo.RecordObject(sp.targetData, "Modified Reflection Probe AABB");
reflectionData.influenceSphereRadius = influenceRadius;
p.blendDistance = blendDistance;
EditorUtility.SetDirty(p);
EditorUtility.SetDirty(reflectionData);
}
}
}
var center = s.boxInfluenceHandle.center;
var size = s.boxInfluenceHandle.size;
static void Handle_ProjectionSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();
ValidateAABB(sp.target, ref center, ref size);
using (new Handles.DrawingScope(GetLocalSpace(p)))
{
s.projectionSphereHandle.center = p.center;
s.projectionSphereHandle.radius = reflectionData.sphereReprojectionVolumeRadius;
sp.target.center = center;
sp.target.size = size;
ApplyConstraintsOnTargets(s, sp, o);
EditorGUI.BeginChangeCheck();
s.projectionSphereHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);
}
break;
}
case ReflectionInfluenceShape.Sphere:
Undo.RecordObject(reflectionData, "Modified Reflection Probe projection volume");
var center = s.projectionSphereHandle.center;
var radius = s.projectionSphereHandle.radius;
//ValidateAABB(ref center, ref radius);
reflectionData.sphereReprojectionVolumeRadius = radius;
EditorUtility.SetDirty(reflectionData);
s.sphereInfluenceHandle.center = sp.target.center;
s.sphereInfluenceHandle.radius = sp.targetData.influenceSphereRadius;
Handles.color = k_GizmoThemeColorExtent;
EditorGUI.BeginChangeCheck();
s.sphereInfluenceHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(sp.target, "Modified Reflection Probe AABB");
Undo.RecordObject(sp.targetData, "Modified Reflection Probe AABB");
var center = sp.target.center;
var influenceRadius = s.sphereInfluenceHandle.radius;
var radius = Vector3.one * influenceRadius;
ValidateAABB(sp.target, ref center, ref radius);
influenceRadius = radius.x;
sp.targetData.influenceSphereRadius = influenceRadius;
ApplyConstraintsOnTargets(s, sp, o);
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);
}
break;
Handles.matrix = mat;
Handles.color = col;
}
static void Handle_OriginEditing(UIState s, SerializedReflectionProbe sp, Editor o)

static void RenderGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
{
var e = GetEditorFor(reflectionProbe);
if (e == null)
if (e == null || !e.sceneViewEditing)
if (e.sceneViewEditing && EditMode.editMode == EditMode.SceneViewEditMode.ReflectionProbeBox)
switch (EditMode.editMode)
var oldColor = Gizmos.color;
Gizmos.color = k_GizmoReflectionProbe;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
// Influence editing
case EditMode.SceneViewEditMode.ReflectionProbeBox:
Gizmos_Influence(reflectionProbe, reflectionData, e, true);
break;
// Influence fade editing
case EditMode.SceneViewEditMode.GridBox:
Gizmos_InfluenceFade(reflectionProbe, reflectionData, e, InfluenceType.Standard, true);
break;
// Influence normal fade editing
case EditMode.SceneViewEditMode.Collider:
Gizmos_InfluenceFade(reflectionProbe, reflectionData, e, InfluenceType.Normal, true);
break;
}
}

Color oldColor = Gizmos.color;
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoReflectionProbe : k_GizmoReflectionProbeDisabled;
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
{
DrawBoxInfluenceGizmo(reflectionProbe, oldColor);
}
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
{
DrawSphereInfluenceGizmo(reflectionProbe, oldColor, reflectionData);
}
if (reflectionData.useSeparateProjectionVolume)
{
DrawReprojectionVolumeGizmo(reflectionProbe, reflectionData);
}
Gizmos.color = oldColor;
Gizmos_Influence(reflectionProbe, reflectionData, null, false);
Gizmos_InfluenceFade(reflectionProbe, reflectionData, null, InfluenceType.Standard, false);
Gizmos_InfluenceFade(reflectionProbe, reflectionData, null, InfluenceType.Normal, false);
ChangeVisibility(reflectionProbe, true);
}

ChangeVisibility(reflectionProbe, false);
}
static void DrawBoxInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor)
static void Gizmos_InfluenceFade(ReflectionProbe p, HDAdditionalReflectionData a, Editor e, InfluenceType type, bool isEdit)
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireCube(reflectionProbe.center, reflectionProbe.size);
if (reflectionProbe.blendDistance > 0)
var col = Gizmos.color;
var mat = Gizmos.matrix;
Vector3 boxCenterOffset;
Vector3 boxSizeOffset;
float sphereRadiusOffset;
Color color;
switch (type)
Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 0.3f);
Gizmos.DrawWireCube(reflectionProbe.center, new Vector3(reflectionProbe.size.x - reflectionProbe.blendDistance * 2, reflectionProbe.size.y - reflectionProbe.blendDistance * 2, reflectionProbe.size.z - reflectionProbe.blendDistance * 2));
default:
case InfluenceType.Standard:
{
boxCenterOffset = a.boxBlendCenterOffset;
boxSizeOffset = a.boxBlendSizeOffset;
sphereRadiusOffset = a.sphereBlendRadiusOffset;
color = isEdit ? k_GizmoThemeColorInfluenceBlendFace : k_GizmoThemeColorInfluenceBlend;
break;
}
case InfluenceType.Normal:
{
boxCenterOffset = a.boxBlendNormalCenterOffset;
boxSizeOffset = a.boxBlendNormalSizeOffset;
sphereRadiusOffset = a.sphereBlendNormalRadiusOffset;
color = isEdit ? k_GizmoThemeColorInfluenceNormalBlendFace : k_GizmoThemeColorInfluenceNormalBlend;
break;
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
}
static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor, HDAdditionalReflectionData reflectionData)
{
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
if (reflectionProbe.blendDistance > 0)
Gizmos.matrix = GetLocalSpace(p);
switch (a.influenceShape)
Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 0.3f);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - 2 * reflectionProbe.blendDistance);
case ReflectionInfluenceShape.Box:
{
Gizmos.color = color;
if (isEdit)
Gizmos.DrawCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
else
Gizmos.DrawWireCube(p.center + boxCenterOffset, p.size + boxSizeOffset);
break;
}
case ReflectionInfluenceShape.Sphere:
{
Gizmos.color = color;
if (isEdit)
Gizmos.DrawSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
else
Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius + sphereRadiusOffset);
break;
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
Gizmos.matrix = mat;
Gizmos.color = col;
static void DrawReprojectionVolumeGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)
static void Gizmos_Influence(ReflectionProbe p, HDAdditionalReflectionData a, Editor e, bool isEdit)
Color reprojectionColor = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.3f);
Gizmos.color = reprojectionColor;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
{
Gizmos.DrawWireCube(reflectionData.boxReprojectionVolumeCenter, reflectionData.boxReprojectionVolumeSize);
}
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
var col = Gizmos.color;
var mat = Gizmos.matrix;
Gizmos.matrix = GetLocalSpace(p);
switch (a.influenceShape)
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.sphereReprojectionVolumeRadius);
case ReflectionInfluenceShape.Box:
{
Gizmos.color = isEdit ? k_GizmoThemeColorExtentFace : k_GizmoThemeColorExtent;
if (isEdit)
Gizmos.DrawCube(p.center, p.size);
else
Gizmos.DrawWireCube(p.center, p.size);
break;
}
case ReflectionInfluenceShape.Sphere:
{
Gizmos.color = k_GizmoThemeColorExtentFace;
if (isEdit)
Gizmos.DrawSphere(p.center, a.influenceSphereRadius);
else
Gizmos.DrawWireSphere(p.center, a.influenceSphereRadius);
break;
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.matrix = mat;
Gizmos.color = col;
}
static void DrawVerticalRay(Transform transform)

103
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditor.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
namespace UnityEditor.Experimental.Rendering

public override void OnInspectorGUI()
{
//InspectColorsGUI();
// Set the legacy blend distance to 0 so the legacy culling system use the probe extent
p.legacyBlendDistance.floatValue = 0;
//k_InfluenceNormalVolumeSection.Draw(s, p, this);
k_SeparateProjectionVolumeSection.Draw(s, p, this);
k_CaptureSection.Draw(s, p, this);
k_AdditionalSection.Draw(s, p, this);

serializedObject.ApplyModifiedProperties();
HideAdditionalComponents(false);
DoShortcutKey(p, this);
}
static void PerformOperations(UIState s, SerializedReflectionProbe p, HDReflectionProbeEditor o)

}
}
void BakeRealtimeProbeIfPositionChanged(UIState s, SerializedReflectionProbe sp, Editor o)
{
if (Application.isPlaying
|| ((ReflectionProbeMode)sp.mode.intValue) != ReflectionProbeMode.Realtime)
{
m_PositionHash = 0;
return;
}
var hash = 0;
for (var i = 0; i < sp.so.targetObjects.Length; i++)
{
var p = (ReflectionProbe)sp.so.targetObjects[i];
var tr = p.GetComponent<Transform>();
hash ^= tr.position.GetHashCode();
}
if (hash != m_PositionHash)
{
m_PositionHash = hash;
for (var i = 0; i < sp.so.targetObjects.Length; i++)
{
var p = (ReflectionProbe)sp.so.targetObjects[i];
p.RenderProbe();
}
}
}
static Matrix4x4 GetLocalSpace(ReflectionProbe probe)
{
var t = probe.transform.position;

{
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin;
}
static void InspectColorsGUI()
{
EditorGUILayout.LabelField("Color Theme", EditorStyles.largeLabel);
k_GizmoThemeColorExtent = EditorGUILayout.ColorField("Extent", k_GizmoThemeColorExtent);
k_GizmoThemeColorExtentFace = EditorGUILayout.ColorField("Extent Face", k_GizmoThemeColorExtentFace);
k_GizmoThemeColorInfluenceBlend = EditorGUILayout.ColorField("Influence Blend", k_GizmoThemeColorInfluenceBlend);
k_GizmoThemeColorInfluenceBlendFace = EditorGUILayout.ColorField("Influence Blend Face", k_GizmoThemeColorInfluenceBlendFace);
k_GizmoThemeColorInfluenceNormalBlend = EditorGUILayout.ColorField("Influence Normal Blend", k_GizmoThemeColorInfluenceNormalBlend);
k_GizmoThemeColorInfluenceNormalBlendFace = EditorGUILayout.ColorField("Influence Normal Blend Face", k_GizmoThemeColorInfluenceNormalBlendFace);
k_GizmoThemeColorProjection = EditorGUILayout.ColorField("Projection", k_GizmoThemeColorProjection);
k_GizmoThemeColorProjectionFace = EditorGUILayout.ColorField("Projection Face", k_GizmoThemeColorProjectionFace);
k_GizmoThemeColorDisabled = EditorGUILayout.ColorField("Disabled", k_GizmoThemeColorDisabled);
k_GizmoThemeColorDisabledFace = EditorGUILayout.ColorField("Disabled Face", k_GizmoThemeColorDisabledFace);
EditorGUILayout.Space();
}
static void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath, bool custom)

{
var renderer = p.GetComponent<Renderer>();
renderer.sharedMaterial.SetTexture(_Cubemap, p.texture);
}
static void ApplyConstraintsOnTargets(UIState s, SerializedReflectionProbe sp, Editor o)
{
switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
{
case ReflectionInfluenceShape.Box:
{
var maxBlendDistance = CalculateBoxMaxBlendDistance(s, sp, o);
sp.targetData.blendDistancePositive = Vector3.Min(sp.targetData.blendDistancePositive, maxBlendDistance);
sp.targetData.blendDistanceNegative = Vector3.Min(sp.targetData.blendDistanceNegative, maxBlendDistance);
sp.targetData.blendNormalDistancePositive = Vector3.Min(sp.targetData.blendNormalDistancePositive, maxBlendDistance);
sp.targetData.blendNormalDistanceNegative = Vector3.Min(sp.targetData.blendNormalDistanceNegative, maxBlendDistance);
break;
}
case ReflectionInfluenceShape.Sphere:
{
var maxBlendDistance = Vector3.one * CalculateSphereMaxBlendDistance(s, sp, o);
sp.targetData.blendDistancePositive = Vector3.Min(sp.targetData.blendDistancePositive, maxBlendDistance);
sp.targetData.blendDistanceNegative = Vector3.Min(sp.targetData.blendDistanceNegative, maxBlendDistance);
sp.targetData.blendNormalDistancePositive = Vector3.Min(sp.targetData.blendNormalDistancePositive, maxBlendDistance);
sp.targetData.blendNormalDistanceNegative = Vector3.Min(sp.targetData.blendNormalDistanceNegative, maxBlendDistance);
break;
}
}
}
static readonly KeyCode[] k_ShortCutKeys =
{
KeyCode.Alpha1,
KeyCode.Alpha2,
KeyCode.Alpha3,
};
static void DoShortcutKey(SerializedReflectionProbe p, Editor o)
{
var evt = Event.current;
if (evt.type != EventType.KeyDown || !evt.shift)
return;
for (var i = 0; i < k_ShortCutKeys.Length; ++i)
{
if (evt.keyCode == k_ShortCutKeys[i])
{
var mode = EditMode.editMode == k_Toolbar_SceneViewEditModes[i]
? EditMode.SceneViewEditMode.None
: k_Toolbar_SceneViewEditModes[i];
EditMode.ChangeEditMode(mode, GetBoundsGetter(p)(), o);
evt.Use();
break;
}
}
}
}
}

15
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/HDAdditionalReflectionData.cs


public Vector3 boxReprojectionVolumeCenter = Vector3.zero;
public float maxSearchDistance = 8.0f;
public Texture previewCubemap;
public Vector3 blendDistancePositive = Vector3.zero;
public Vector3 blendDistanceNegative = Vector3.zero;
public Vector3 blendNormalDistancePositive = Vector3.zero;
public Vector3 blendNormalDistanceNegative = Vector3.zero;
public Vector3 boxSideFadePositive = Vector3.one;
public Vector3 boxSideFadeNegative = Vector3.one;
public Vector3 boxBlendCenterOffset { get { return (blendDistanceNegative - blendDistancePositive) * 0.5f; } }
public Vector3 boxBlendSizeOffset { get { return -(blendDistancePositive + blendDistanceNegative); } }
public Vector3 boxBlendNormalCenterOffset { get { return (blendNormalDistanceNegative - blendNormalDistancePositive) * 0.5f; } }
public Vector3 boxBlendNormalSizeOffset { get { return -(blendNormalDistancePositive + blendNormalDistanceNegative); } }
public float sphereBlendRadiusOffset { get { return -blendDistancePositive.x; } }
public float sphereBlendNormalRadiusOffset { get { return -blendNormalDistancePositive.x; } }
}
}

23
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs


using UnityEngine;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

public int envIndex;
public Vector3 up;
public float blendDistance; // blend transition outside the volume
public float dimmer;
public Vector3 innerDistance; // equivalent to volume scale
public Vector3 innerDistance; // extents of the env light
public float dimmer;
public float unused1;
public Vector3 blendDistancePositive; //+X,+Y,+Z
public float unused2;
public Vector3 blendDistanceNegative; //-X,-Y,-Z
public float unused3;
public Vector3 blendNormalDistancePositive; //+X,+Y,+Z
public float unused4;
public Vector3 blendNormalDistanceNegative; //-X,-Y,-Z
public float unused5;
public Vector3 boxSideFadePositive; //+X,+Y,+Z
public float unused6;
public Vector3 boxSideFadeNegative; //-X,-Y,-Z
public float unused7;
};
// Usage of StencilBits.Lighting on 2 bits.

72
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs.hlsl


float3 forward;
int envIndex;
float3 up;
float blendDistance;
float dimmer;
float dimmer;
float unused1;
float3 blendDistancePositive;
float unused2;
float3 blendDistanceNegative;
float unused3;
float3 blendNormalDistancePositive;
float unused4;
float3 blendNormalDistanceNegative;
float unused5;
float3 boxSideFadePositive;
float unused6;
float3 boxSideFadeNegative;
float unused7;
};
//

{
return value.up;
}
float GetBlendDistance(EnvLightData value)
float GetDimmer(EnvLightData value)
return value.blendDistance;
return value.dimmer;
}
float3 GetRight(EnvLightData value)
{

{
return value.offsetLS;
}
float GetDimmer(EnvLightData value)
float GetUnused1(EnvLightData value)
return value.dimmer;
return value.unused1;
}
float3 GetBlendDistancePositive(EnvLightData value)
{
return value.blendDistancePositive;
}
float GetUnused2(EnvLightData value)
{
return value.unused2;
}
float3 GetBlendDistanceNegative(EnvLightData value)
{
return value.blendDistanceNegative;
}
float GetUnused3(EnvLightData value)
{
return value.unused3;
}
float3 GetBlendNormalDistancePositive(EnvLightData value)
{
return value.blendNormalDistancePositive;
}
float GetUnused4(EnvLightData value)
{
return value.unused4;
}
float3 GetBlendNormalDistanceNegative(EnvLightData value)
{
return value.blendNormalDistanceNegative;
}
float GetUnused5(EnvLightData value)
{
return value.unused5;
}
float3 GetBoxSideFadePositive(EnvLightData value)
{
return value.boxSideFadePositive;
}
float GetUnused6(EnvLightData value)
{
return value.unused6;
}
float3 GetBoxSideFadeNegative(EnvLightData value)
{
return value.boxSideFadeNegative;
}
float GetUnused7(EnvLightData value)
{
return value.unused7;
}

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


{
var additionalData = probe.probe.GetComponent<HDAdditionalReflectionData>();
var extents = probe.bounds.extents;
var influenceBlendDistancePositive = Vector3.one * probe.blendDistance;
var influenceBlendDistanceNegative = Vector3.one * probe.blendDistance;
// For now we won't display real time probe when rendering one.
// TODO: We may want to display last frame result but in this case we need to be careful not to update the atlas before all realtime probes are rendered (for frame coherency).

// CAUTION: localToWorld is the transform for the widget of the reflection probe. i.e the world position of the point use to do the cubemap capture (mean it include the local offset)
envLightData.positionWS = probe.localToWorld.GetColumn(3);
envLightData.boxSideFadePositive = Vector3.one;
envLightData.boxSideFadeNegative = Vector3.one;
if (additionalData != null)
{

case ReflectionInfluenceShape.Box:
{
envLightData.envShapeType = EnvShapeType.Box;
envLightData.boxSideFadePositive = additionalData.boxSideFadePositive;
envLightData.boxSideFadeNegative = additionalData.boxSideFadeNegative;
break;
}
case ReflectionInfluenceShape.Sphere:

envLightData.minProjectionDistance = 65504.0f;
envLightData.dimmer = additionalData.dimmer;
envLightData.blendNormalDistancePositive = additionalData.blendNormalDistancePositive;
envLightData.blendNormalDistanceNegative = additionalData.blendNormalDistanceNegative;
influenceBlendDistancePositive = additionalData.blendDistancePositive;
influenceBlendDistanceNegative = additionalData.blendDistanceNegative;
}
else
{

}
envLightData.dimmer = 1;
envLightData.blendDistancePositive = Vector3.zero;
envLightData.blendDistanceNegative = Vector3.zero;
}
// remove scale from the matrix (Scale in this matrix is use to scale the widget)

// So we let the current UI but we assume blendDistance is an inside factor instead
// Blend distance can't be larger than the max radius
// probe.bounds.extents is BoxSize / 2
float maxBlendDist = Mathf.Min(probe.bounds.extents.x, Mathf.Min(probe.bounds.extents.y, probe.bounds.extents.z));
float blendDistance = Mathf.Min(maxBlendDist, probe.blendDistance);
envLightData.innerDistance = extents - new Vector3(blendDistance, blendDistance, blendDistance);
var blendDistancePositive = Vector3.Min(probe.bounds.extents, influenceBlendDistancePositive);
var blendDistanceNegative = Vector3.Min(probe.bounds.extents, influenceBlendDistanceNegative);
envLightData.innerDistance = extents;
envLightData.blendDistance = blendDistance;
envLightData.blendDistancePositive = blendDistancePositive;
envLightData.blendDistanceNegative = blendDistanceNegative;
m_lightList.envLights.Add(envLightData);

25
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtilities.hlsl


EnvLightData InitSkyEnvLightData(int envIndex)
{
EnvLightData output;
output.envShapeType = ENVSHAPETYPE_SKY;
output.envIndex = envIndex;
output.forward = float3(0.0, 0.0, 1.0);
output.up = float3(0.0, 1.0, 0.0);
output.right = float3(1.0, 0.0, 0.0);
output.positionWS = float3(0.0, 0.0, 0.0);
output.offsetLS = float3(0.0, 0.0, 0.0);
output.innerDistance = float3(0.0, 0.0, 0.0);
output.blendDistance = 1.0;
output.dimmer = 1.0;
output.envShapeType = ENVSHAPETYPE_SKY;
output.envIndex = envIndex;
output.forward = float3(0.0, 0.0, 1.0);
output.up = float3(0.0, 1.0, 0.0);
output.right = float3(1.0, 0.0, 0.0);
output.positionWS = float3(0.0, 0.0, 0.0);
output.offsetLS = float3(0.0, 0.0, 0.0);
output.innerDistance = float3(0.0, 0.0, 0.0);
output.blendDistancePositive = float3(0.0, 0.0, 0.0);
output.blendDistanceNegative = float3(0.0, 0.0, 0.0);
output.blendNormalDistancePositive = float3(0.0, 0.0, 0.0);
output.blendNormalDistanceNegative = float3(0.0, 0.0, 0.0);
output.boxSideFadePositive = float3(0.0, 0.0, 0.0);
output.boxSideFadeNegative = float3(0.0, 0.0, 0.0);
output.dimmer = 1.0;
return output;
}

106
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


#define ENVMAP_FEATURE_PERFACEINFLUENCE
#define ENVMAP_FEATURE_INFLUENCENORMAL
#define ENVMAP_FEATURE_PERFACEFADE
//-----------------------------------------------------------------------------
// SurfaceData and BSDFData
//-----------------------------------------------------------------------------

float hitDistanceFromPosition = depthFromPosition / dot(-V, rayWS);
return positionWS + rayWS * hitDistanceFromPosition;
}
//------------------------------------------------------------------------------------
// Little helper to share code between sphere and box.
// These function will fade the mask of a reflection volume based on normal orientation compare to direction define by the center of the reflection volume.
//-----------------------------------------------------------------------------
float InfluenceFadeNormalWeight(float3 normal, float3 centerToPos)
{
// Start weight from 0.6f (1 fully transparent) to 0.2f (fully opaque).
return saturate((-1.0f / 0.4f) * dot(normal, centerToPos) + (0.6f / 0.4f));
}
//-----------------------------------------------------------------------------

{
// 1. First process the projection
float3 dirLS = mul(R, worldToLocal);
float sphereOuterDistance = lightData.innerDistance.x + lightData.blendDistance;
float dist = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance);
dist = max(dist, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
float sphereOuterDistance = lightData.innerDistance.x;
float projectionDistance = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance);
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
R = (positionWS + dist * R) - lightData.positionWS;
R = (positionWS + projectionDistance * R) - lightData.positionWS;
dist = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance);
coatR = (positionWS + dist * coatR) - lightData.positionWS;
projectionDistance = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance);
coatR = (positionWS + projectionDistance * coatR) - lightData.positionWS;
// 2. Process the influence
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0);
weight = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero
// 2. Process the position influence
float lengthPositionLS = length(positionLS);
float sphereInfluenceDistance = lightData.innerDistance.x - lightData.blendDistancePositive.x;
float distFade = max(lengthPositionLS - sphereInfluenceDistance, 0.0);
float alpha = saturate(1.0 - distFade / max(lightData.blendDistancePositive.x, 0.0001)); // avoid divide by zero
#if defined(ENVMAP_FEATURE_INFLUENCENORMAL)
// 3. Process the normal influence
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.innerDistance.x - lightData.blendNormalDistancePositive.x) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif
weight = alpha;
// 1. First process the projection
float3 boxOuterDistance = lightData.innerDistance + float3(lightData.blendDistance, lightData.blendDistance, lightData.blendDistance);
float dist = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
dist = max(dist, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
float3 boxOuterDistance = lightData.innerDistance;
float projectionDistance = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
projectionDistance = max(projectionDistance, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
R = (positionWS + dist * R) - lightData.positionWS;
R = (positionWS + projectionDistance * R) - lightData.positionWS;
// TODO: add distance based roughness

dirLS = mul(coatR, worldToLocal);
dist = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
coatR = (positionWS + dist * coatR) - lightData.positionWS;
projectionDistance = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
coatR = (positionWS + projectionDistance * coatR) - lightData.positionWS;
// Influence volume
// 2. Process the position influence
float distFade = DistancePointBox(positionLS, -lightData.innerDistance, lightData.innerDistance);
weight = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero
#if defined(ENVMAP_FEATURE_PERFACEINFLUENCE)
// Distance to each cube face
float3 negativeDistance = boxOuterDistance + positionLS;
float3 positiveDistance = boxOuterDistance - positionLS;
// Influence falloff for each face
float3 negativeFalloff = negativeDistance / max(0.0001, lightData.blendDistanceNegative);
float3 positiveFalloff = positiveDistance / max(0.0001, lightData.blendDistancePositive);
// Fallof is the min for all faces
float influenceFalloff = min(
min(min(negativeFalloff.x, negativeFalloff.y), negativeFalloff.z),
min(min(positiveFalloff.x, positiveFalloff.y), positiveFalloff.z));
float alpha = saturate(influenceFalloff);
#else
float distFace = DistancePointBox(positionLS, -lightData.innerDistance + lightData.blendDistancePositive.x, lightData.innerDistance - lightData.blendDistancePositive.x);
float alpha = saturate(1.0 - distFace / max(lightData.blendDistancePositive.x, 0.0001));
#endif
#if defined(ENVMAP_FEATURE_INFLUENCENORMAL)
// 3. Process the normal influence
// Calculate a falloff value to discard normals pointing outward the center of the environment light
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistancePositive);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistanceNegative);
float insideInfluenceNormalVolume = all(belowPositiveInfluenceNormalVolume >= 1.0) && all(aboveNegativeInfluenceNormalVolume >= 1.0) ? 1.0 : 0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif
#if defined(ENVMAP_FEATURE_PERFACEFADE)
// 4. Fade specific cubemap faces
// For each axes (both positive and negative ones), we want to fade from the center of one face to another
// So we normalized the sample direction (R) and use its component to fade for each axis
// We consider R.x as cos(X) and then fade as angle from 60°(=acos(1/2)) to 75°(=acos(1/4))
// For positive axes: axisFade = (R - 1/4) / (1/2 - 1/4)
// <=> axisFace = 4 * R - 1;
R = normalize(R);
float3 faceFade = saturate((4 * R - 1) * lightData.boxSideFadePositive) + saturate((-4 * R - 1) * lightData.boxSideFadeNegative);
alpha *= saturate(faceFade.x + faceFade.y + faceFade.z);
#endif
weight = alpha;
}
// Smooth weighting

正在加载...
取消
保存