浏览代码

[ReflectionProbeEditor] Several fixes

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
3e59504a
共有 4 个文件被更改,包括 89 次插入41 次删除
  1. 60
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  2. 28
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  3. 11
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  4. 31
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs

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


false,
CED.Action(Drawer_InfluenceBoxSettings), // Box
CED.Action(Drawer_InfluenceSphereSettings) // Sphere
),
CED.Action(Drawer_UseSeparateProjectionVolume)
)/*,
CED.Action(Drawer_UseSeparateProjectionVolume)*/
);
static readonly CED.IDrawer k_SeparateProjectionVolumeSection = CED.FadeGroup(

#region Influence Volume
static void Drawer_DistanceBlend(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.PropertyField(p.blendDistance, CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."));
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();
}
static void Drawer_InfluenceBoxSettings(UIState s, SerializedReflectionProbe p, Editor owner)

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

static readonly int[] k_Content_ReflectionProbeModeValues = { (int)ReflectionProbeMode.Baked, (int)ReflectionProbeMode.Custom, (int)ReflectionProbeMode.Realtime };
static void Drawer_ReflectionProbeMode(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUI.BeginChangeCheck();
s.SetModeTarget(p.mode.intValue);
if (EditorGUI.EndChangeCheck())
{
s.SetModeTarget(p.mode.intValue);
foreach (var targetObject in p.so.targetObjects)
ResetProbeSceneTextureInMaterial((ReflectionProbe)targetObject);
}
}
static void Drawer_InfluenceShape(UIState s, SerializedReflectionProbe p, Editor owner)

static readonly EditMode.SceneViewEditMode[] k_Toolbar_SceneViewEditModes =
{
EditMode.SceneViewEditMode.ReflectionProbeBox,
EditMode.SceneViewEditMode.GridBox,
//EditMode.SceneViewEditMode.GridBox,
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("PreMatCube", "|Modify the projection volume of the reflection probe."),
static readonly Bounds k_BoundsZero = new Bounds();
static Bounds DummyBound() { return k_BoundsZero; }
static Editor s_LastInteractedEditor = null;
static void Drawer_Toolbar(UIState s, SerializedReflectionProbe p, Editor owner)
{
if (p.so.targetObjects.Length > 1)

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

EditorGUILayout.PropertyField(p.timeSlicingMode, CoreEditorUtils.GetContent("Time Slicing|If enabled this probe will update over several frames, to help reduce the impact on the frame rate"));
}
#endregion
static float CalculateMaxBlendDistance(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.Max(size.x, Mathf.Max(size.y, size.z));
return v * 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]);
static bool ButtonWithDropdownList(GUIContent content, string[] buttonNames, GenericMenu.MenuFunction2 callback, params GUILayoutOption[] options)

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


using UnityEditorInternal;
using System;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

{
internal static Color k_GizmoReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0x94 / 255f, 0x80 / 255f);
internal static Color k_GizmoReflectionProbeDisabled = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x60 / 255f);
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);
void OnSceneGUI()

{
Undo.RecordObject(p, "Modified Reflection Probe AABB");
var center = s.boxInfluenceBoundsHandle.center;
var size = s.boxInfluenceBoundsHandle.size;
var blendDistance = ((p.size.x - s.boxBlendHandle.size.x) / 2 + (p.size.y - s.boxBlendHandle.size.y) / 2 + (p.size.z - s.boxBlendHandle.size.z) / 2) / 3;
ValidateAABB(p, ref center, ref size);
var influenceSize = s.boxInfluenceBoundsHandle.size;
var blendSize = s.boxBlendHandle.size;
ValidateAABB(p, ref center, ref influenceSize);
var blendDistance = ((influenceSize.x - blendSize.x) * 0.5f + (influenceSize.y - blendSize.y) * 0.5f + (influenceSize.z - blendSize.z) * 0.5f) / 3;
p.size = size;
p.size = influenceSize;
p.blendDistance = Mathf.Max(blendDistance, 0);
EditorUtility.SetDirty(p);
}

{
Undo.RecordObject(reflectionData, "Modified Reflection influence volume");
var center = s.influenceSphereHandle.center;
var radius = new Vector3(s.influenceSphereHandle.radius, s.influenceSphereHandle.radius, s.influenceSphereHandle.radius);
var blendDistance = (s.influenceSphereHandle.radius - s.sphereBlendHandle.radius) / 2;
var influenceRadius = Mathf.Max(s.influenceSphereHandle.radius, s.sphereBlendHandle.radius);
var blendRadius = Mathf.Min(s.influenceSphereHandle.radius, s.sphereBlendHandle.radius);
var radius = Vector3.one * influenceRadius;
influenceRadius = radius.x;
var blendDistance = (influenceRadius - blendRadius) * 0.5f;
reflectionData.influenceSphereRadius = radius.x;
p.blendDistance = blendDistance;
EditorUtility.SetDirty(p);

if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
{
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;

11
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs


k_InfluenceVolumeSection.Draw(s, p, this);
k_SeparateProjectionVolumeSection.Draw(s, p, this);
k_CaptureSection.Draw(s, p, this);
k_AdditionalSection.Draw(s, p, this);
//k_AdditionalSection.Draw(s, p, this);
k_BakingActions.Draw(s, p, this);
PerformOperations(s, p, this);

static Quaternion GetLocalSpaceRotation(ReflectionProbe probe)
{
bool supportsRotation = (SupportedRenderingFeatures.active.reflectionProbeSupportFlags & SupportedRenderingFeatures.ReflectionProbeSupportFlags.Rotation) != 0;
if (supportsRotation)
return probe.transform.rotation;
else
return Quaternion.identity;
var supportsRotation = (SupportedRenderingFeatures.active.reflectionProbeSupportFlags & SupportedRenderingFeatures.ReflectionProbeSupportFlags.Rotation) != 0;
return supportsRotation
? probe.transform.rotation
: Quaternion.identity;
}
// Ensures that probe's AABB encapsulates probe's position

31
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System;

public bool GetEnvLightData(CommandBuffer cmd, Camera camera, VisibleReflectionProbe probe)
{
var additionalData = probe.probe.GetComponent<HDAdditionalReflectionData>();
// 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).
// Unfortunately we don't have this information at the moment.

// 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);
// TODO: Support sphere influence in UI
if (probe.boxProjection == 0)
if (additionalData != null)
envLightData.envShapeType = EnvShapeType.Box;
// If user request to have no projection, then setup a high number for minProjectionDistance
// this will mimic infinite shape projection
envLightData.minProjectionDistance = 65504.0f;
envLightData.minProjectionDistance = 0;
switch (additionalData.influenceShape)
{
case ReflectionInfluenceShape.Box: envLightData.envShapeType = EnvShapeType.Box; break;
case ReflectionInfluenceShape.Sphere: envLightData.envShapeType = EnvShapeType.Sphere; break;
}
envLightData.envShapeType = EnvShapeType.Box;
envLightData.minProjectionDistance = 0.0f;
if (probe.boxProjection == 0)
{
envLightData.envShapeType = EnvShapeType.Box;
// If user request to have no projection, then setup a high number for minProjectionDistance
// this will mimic infinite shape projection
envLightData.minProjectionDistance = 65504.0f;
}
else
{
envLightData.envShapeType = EnvShapeType.Box;
envLightData.minProjectionDistance = 0.0f;
}
}
// remove scale from the matrix (Scale in this matrix is use to scale the widget)

正在加载...
取消
保存