浏览代码

[ReflectionProbeEditor] refactor and influence normal

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
1a567e02
共有 4 个文件被更改,包括 311 次插入272 次删除
  1. 4
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  2. 6
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  3. 560
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  4. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl

4
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs


public void ClearOperation(Operation op) { operations &= ~op; }
public void AddOperation(Operation op) { operations |= op; }
public BoxBoundsHandle boxExtentHandle = new BoxBoundsHandle();
public BoxBoundsHandle boxInfluenceHandle = new BoxBoundsHandle();
public SphereBoundsHandle sphereExtentHandle = new SphereBoundsHandle();
public SphereBoundsHandle sphereInfluenceHandle = new SphereBoundsHandle();
public SphereBoundsHandle sphereProjectionHandle = new SphereBoundsHandle();
public SphereBoundsHandle sphereBlendHandle = new SphereBoundsHandle();
public SphereBoundsHandle sphereBlendNormalHandle = new SphereBoundsHandle();

6
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs


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

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

560
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs


{
partial class HDReflectionProbeEditor
{
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);

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);
}
// Influence normal fade editing
{
if (p.influenceShape.enumValueIndex == 0)
Handle_InfluenceNormalBoxEditing(s, p, o);
if (p.influenceShape.enumValueIndex == 1)
Handle_InfluenceNormalSphereEditing(s, p, o);
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.blendDistance;
probeBlendDistanceNegative = sp.targetData.blendDistance2;
color = k_GizmoThemeColorInfluenceBlend;
break;
}
case InfluenceType.Normal:
{
blendBox = s.boxBlendNormalHandle;
sphereHandle = s.sphereBlendNormalHandle;
probeBlendDistancePositive = sp.targetData.blendNormalDistance;
probeBlendDistanceNegative = sp.targetData.blendNormalDistance2;
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)
{
Handle_InfluenceBoxEditing_Internal(
s, sp, o,
s.boxBlendHandle, k_GizmoThemeColorInfluenceBlend,
ref sp.targetData.blendDistance, ref sp.targetData.blendDistance2);
}
static void Handle_InfluenceNormalBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
Handle_InfluenceBoxEditing_Internal(
s, sp, o,
s.boxBlendHandle, k_GizmoThemeColorInfluenceNormalBlend,
ref sp.targetData.blendNormalDistance, ref sp.targetData.blendNormalDistance2);
}
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");
static void Handle_InfluenceBoxEditing_Internal(
UIState s, SerializedReflectionProbe sp, Editor o,
BoxBoundsHandle blendBox,
Color blendHandleColor,
ref Vector3 probeBlendDistancePositive,
ref Vector3 probeBlendDistanceNegative)
{
var p = sp.target;
var center = sp.target.center;
var influenceSize = sp.target.size;
using (new Handles.DrawingScope(GetLocalSpace(p)))
{
s.boxExtentHandle.center = p.center;
s.boxExtentHandle.size = p.size;
blendBox.center = p.center - (probeBlendDistancePositive - probeBlendDistanceNegative) * 0.5f;
blendBox.size = p.size - probeBlendDistancePositive - probeBlendDistanceNegative;
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));
Handles.color = k_GizmoThemeColorExtent;
EditorGUI.BeginChangeCheck();
s.boxExtentHandle.DrawHandle();
var extentChanged = EditorGUI.EndChangeCheck();
EditorGUI.BeginChangeCheck();
Handles.color = blendHandleColor;
blendBox.DrawHandle();
if (extentChanged || EditorGUI.EndChangeCheck())
{
Undo.RecordObject(p, "Modified Reflection Probe AABB");
var center = s.boxExtentHandle.center;
var extents = s.boxExtentHandle.size;
ValidateAABB(p, ref center, ref extents);
probeBlendDistancePositive = blendDistancePositive;
probeBlendDistanceNegative = blendDistanceNegative;
Vector3 blendDistancePositive, blendDistanceNegative;
ApplyConstraintsOnTargets(s, sp, o);
if (extentChanged)
{
blendDistancePositive = Vector3.Min(probeBlendDistancePositive, extents);
blendDistanceNegative = Vector3.Min(probeBlendDistanceNegative, extents);
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);
else
break;
}
case ReflectionInfluenceShape.Sphere:
{
sphereHandle.center = sp.target.center;
sphereHandle.radius = Mathf.Min(sp.targetData.influenceSphereRadius - probeBlendDistancePositive.x * 2, sp.targetData.influenceSphereRadius);
Handles.color = k_GizmoThemeColorExtent;
EditorGUI.BeginChangeCheck();
Handles.color = color;
sphereHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
var diff = 2 * (blendBox.center - center);
var sum = extents - blendBox.size;
var positive = (sum - diff) * 0.5f;
var negative = (sum + diff) * 0.5f;
blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positive, extents));
blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negative, extents));
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.Max(0, (influenceRadius - blendRadius) * 0.5f);
probeBlendDistancePositive = Vector3.one * blendDistance;
ApplyConstraintsOnTargets(s, sp, o);
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);
p.center = center;
p.size = extents;
probeBlendDistancePositive = blendDistancePositive;
probeBlendDistanceNegative = blendDistanceNegative;
EditorUtility.SetDirty(p);
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.boxProjectionHandle.center = reflectionData.boxReprojectionVolumeCenter;
s.boxProjectionHandle.size = reflectionData.boxReprojectionVolumeSize;
EditorGUI.BeginChangeCheck();
s.boxProjectionHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
default:
case InfluenceType.Standard:
Undo.RecordObject(reflectionData, "Modified Reflection Probe AABB");
var center = s.boxProjectionHandle.center;
var size = s.boxProjectionHandle.size;
ValidateAABB(p, ref center, ref size);
reflectionData.boxReprojectionVolumeCenter = center;
reflectionData.boxReprojectionVolumeSize = size;
EditorUtility.SetDirty(reflectionData);
sp.targetData.blendDistance = probeBlendDistancePositive;
sp.targetData.blendDistance2 = probeBlendDistanceNegative;
break;
}
case InfluenceType.Normal:
{
sp.targetData.blendNormalDistance = probeBlendDistancePositive;
sp.targetData.blendNormalDistance2 = probeBlendDistancePositive;
break;
static void Handle_InfluenceSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void Handle_InfluenceEditing(UIState s, SerializedReflectionProbe sp, Editor o)
var blendDistance = sp.targetData.blendDistance.x;
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, k_GizmoThemeColorInfluenceBlend, ref blendDistance);
sp.targetData.blendDistance.x = blendDistance;
}
var mat = Handles.matrix;
var col = Handles.color;
Handles.matrix = GetLocalSpace(sp.target);
switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
{
case ReflectionInfluenceShape.Box:
{
s.boxInfluenceHandle.center = sp.target.center;
s.boxInfluenceHandle.size = sp.target.size;
static void Handle_InfluenceNormalSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var blendDistance = sp.targetData.blendNormalDistance.x;
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, k_GizmoThemeColorInfluenceNormalBlend, ref blendDistance);
sp.targetData.blendNormalDistance.x = blendDistance;
}
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");
static void Handle_InfluenceSphereEditing_Internal(
UIState s, SerializedReflectionProbe sp, Editor o,
SphereBoundsHandle sphereBlend,
Color blendHandleColor,
ref float probeBlendDistance)
{
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();
var blendDistancePositive = Vector3.Min(sp.targetData.blendDistance, s.boxInfluenceHandle.size);
var blendDistanceNegative = Vector3.Min(sp.targetData.blendDistance2, s.boxInfluenceHandle.size);
using (new Handles.DrawingScope(GetLocalSpace(p)))
{
s.sphereExtentHandle.center = p.center;
s.sphereExtentHandle.radius = reflectionData.influenceSphereRadius;
sphereBlend.center = p.center;
sphereBlend.radius = Mathf.Min(reflectionData.influenceSphereRadius - probeBlendDistance * 2, reflectionData.influenceSphereRadius);
sp.target.center = s.boxInfluenceHandle.center;
sp.target.size = s.boxInfluenceHandle.size;
sp.targetData.blendDistance = blendDistancePositive;
sp.targetData.blendDistance2 = blendDistanceNegative;
Handles.color = k_GizmoThemeColorExtent;
EditorGUI.BeginChangeCheck();
s.sphereExtentHandle.DrawHandle();
var influenceChanged = EditorGUI.EndChangeCheck();
EditorGUI.BeginChangeCheck();
Handles.color = blendHandleColor;
sphereBlend.DrawHandle();
if (influenceChanged || EditorGUI.EndChangeCheck())
ApplyConstraintsOnTargets(s, sp, o);
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);
}
break;
}
case ReflectionInfluenceShape.Sphere:
Undo.RecordObject(reflectionData, "Modified Reflection influence volume");
var center = p.center;
var influenceRadius = s.sphereExtentHandle.radius;
var blendRadius = influenceChanged
? Mathf.Max(influenceRadius - probeBlendDistance * 2, 0)
: sphereBlend.radius;
s.sphereInfluenceHandle.center = sp.target.center;
s.sphereInfluenceHandle.radius = sp.targetData.influenceSphereRadius;
var radius = Vector3.one * influenceRadius;
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");
ValidateAABB(p, ref center, ref radius);
influenceRadius = radius.x;
var blendDistance = Mathf.Max(0, (influenceRadius - blendRadius) * 0.5f);
var center = sp.target.center;
var influenceRadius = s.sphereInfluenceHandle.radius;
var radius = Vector3.one * influenceRadius;
reflectionData.influenceSphereRadius = influenceRadius;
probeBlendDistance = blendDistance;
EditorUtility.SetDirty(p);
EditorUtility.SetDirty(reflectionData);
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_ProjectionSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
static void ApplyConstraintsOnTargets(UIState s, SerializedReflectionProbe sp, Editor o)
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();
switch ((ReflectionInfluenceShape)sp.influenceShape.enumValueIndex)
{
case ReflectionInfluenceShape.Box:
{
var maxBlendDistance = CalculateBoxMaxBlendDistance(s, sp, o);
sp.targetData.blendDistance = Vector3.Min(sp.targetData.blendDistance, maxBlendDistance);
sp.targetData.blendDistance2 = Vector3.Min(sp.targetData.blendDistance2, maxBlendDistance);
sp.targetData.blendNormalDistance = Vector3.Min(sp.targetData.blendNormalDistance, maxBlendDistance);
sp.targetData.blendNormalDistance2 = Vector3.Min(sp.targetData.blendNormalDistance2, maxBlendDistance);
break;
}
case ReflectionInfluenceShape.Sphere:
{
var maxBlendDistance = Vector3.one * CalculateSphereMaxBlendDistance(s, sp, o);
sp.targetData.blendDistance = Vector3.Min(sp.targetData.blendDistance, maxBlendDistance);
sp.targetData.blendDistance2 = Vector3.Min(sp.targetData.blendDistance2, maxBlendDistance);
sp.targetData.blendNormalDistance = Vector3.Min(sp.targetData.blendNormalDistance, maxBlendDistance);
sp.targetData.blendNormalDistance2 = Vector3.Min(sp.targetData.blendNormalDistance2, maxBlendDistance);
break;
}
}
}
using (new Handles.DrawingScope(GetLocalSpace(p)))
void BakeRealtimeProbeIfPositionChanged(UIState s, SerializedReflectionProbe sp, Editor o)
{
if (Application.isPlaying
|| ((ReflectionProbeMode)sp.mode.intValue) != ReflectionProbeMode.Realtime)
s.sphereProjectionHandle.center = p.center;
s.sphereProjectionHandle.radius = reflectionData.sphereReprojectionVolumeRadius;
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();
}
EditorGUI.BeginChangeCheck();
s.sphereProjectionHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
if (hash != m_PositionHash)
{
m_PositionHash = hash;
for (var i = 0; i < sp.so.targetObjects.Length; i++)
Undo.RecordObject(reflectionData, "Modified Reflection Probe projection volume");
var center = s.sphereProjectionHandle.center;
var radius = s.sphereProjectionHandle.radius;
//ValidateAABB(ref center, ref radius);
reflectionData.sphereReprojectionVolumeRadius = radius;
EditorUtility.SetDirty(reflectionData);
var p = (ReflectionProbe)sp.so.targetObjects[i];
p.RenderProbe();
}
}
}

switch (EditMode.editMode)
{
// Influence editing
{
var oldColor = Gizmos.color;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
{
Gizmos.color = k_GizmoThemeColorExtentFace;
Gizmos.DrawCube(reflectionProbe.center, reflectionProbe.size);
Gizmos.color = k_GizmoThemeColorInfluenceBlendFace;
Gizmos.DrawCube(reflectionProbe.center + reflectionData.boxBlendCenterOffset, reflectionProbe.size + reflectionData.boxBlendSizeOffset);
}
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
{
Gizmos.color = k_GizmoThemeColorExtentFace;
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
Gizmos.color = k_GizmoThemeColorInfluenceBlendFace;
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius + reflectionData.sphereBlendRadiusOffset);
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
Gizmos_Influence(reflectionProbe, reflectionData, e, true);
break;
// Influence fade editing
case EditMode.SceneViewEditMode.GridBox:
Gizmos_InfluenceFade(reflectionProbe, reflectionData, e, InfluenceType.Standard, true);
}
// Influence normal fade editing
{
var oldColor = Gizmos.color;
Gizmos.color = k_GizmoThemeColorInfluenceNormalBlendFace;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawCube(reflectionProbe.center + reflectionData.boxBlendNormalCenterOffset, reflectionProbe.size + reflectionData.boxBlendNormalSizeOffset);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius + reflectionData.sphereBlendNormalRadiusOffset);
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
break;
}
Gizmos_InfluenceFade(reflectionProbe, reflectionData, e, InfluenceType.Normal, true);
break;
}
}

var oldColor = Gizmos.color;
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
{
DrawBoxInfluenceGizmo(reflectionProbe, reflectionData);
}
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
{
DrawSphereInfluenceGizmo(reflectionProbe, 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, HDAdditionalReflectionData reflectionData)
static void Gizmos_InfluenceFade(ReflectionProbe p, HDAdditionalReflectionData a, HDReflectionProbeEditor e, InfluenceType type, bool isEdit)
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorExtent : k_GizmoThemeColorDisabled;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireCube(reflectionProbe.center, reflectionProbe.size);
var col = Gizmos.color;
var mat = Gizmos.matrix;
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireCube(reflectionProbe.center + reflectionData.boxBlendCenterOffset, reflectionProbe.size + reflectionData.boxBlendSizeOffset);
Vector3 boxCenterOffset;
Vector3 boxSizeOffset;
float sphereRadiusOffset;
Color color;
switch (type)
{
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.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceNormalBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireCube(reflectionProbe.center + reflectionData.boxBlendNormalCenterOffset, reflectionProbe.size + reflectionData.boxBlendNormalSizeOffset);
Gizmos.matrix = GetLocalSpace(p);
switch (a.influenceShape)
{
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.matrix = mat;
Gizmos.color = col;
static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)
static void Gizmos_Influence(ReflectionProbe p, HDAdditionalReflectionData a, HDReflectionProbeEditor e, bool isEdit)
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorExtent : k_GizmoThemeColorDisabled;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius + reflectionData.sphereBlendRadiusOffset);
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceNormalBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius + reflectionData.sphereBlendNormalRadiusOffset);
Gizmos.matrix = Matrix4x4.identity;
}
var col = Gizmos.color;
var mat = Gizmos.matrix;
static void DrawReprojectionVolumeGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)
{
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.matrix = GetLocalSpace(p);
switch (a.influenceShape)
Gizmos.DrawWireCube(reflectionData.boxReprojectionVolumeCenter, reflectionData.boxReprojectionVolumeSize);
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;
}
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
{
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.sphereReprojectionVolumeRadius);
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.matrix = mat;
Gizmos.color = col;
}
static void DrawVerticalRay(Transform transform)

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


// Influence volume
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection.
// Calculate distance to cube face
// Distance to each cube face
// Influence falloff for each face
// 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));

// Influence Normal volume
//float3 insideBox = saturate(abs(positionLS) - lightData.innerDistance + float3(lightData.blendNormalDistance, lightData.blendNormalDistance, lightData.blendNormalDistance));
//float insideWeight = influenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
//alpha *= any(insideBox > 0.0) ? insideWeight : 1.0;
// Calculate a falloff value to discard normals pointing outward the center of the environment light
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistance);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistance2);
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;
//float3 rn = normalize(R);
//float3 faceFade = saturate(float3(6.0, 6.0, 6.0) * rn - float3(2.0, 2.0, 2.0));

正在加载...
取消
保存