浏览代码

[ReflectionProbeEditor] (wip) influence normal

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
f8b60f97
共有 8 个文件被更改,包括 149 次插入49 次删除
  1. 9
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  2. 30
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  3. 147
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  4. 1
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs
  6. 2
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  8. 2
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs

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


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

internal SerializedProperty boxReprojectionVolumeSize;
internal SerializedProperty boxReprojectionVolumeCenter;
internal SerializedProperty sphereReprojectionVolumeRadius;
internal SerializedProperty blendNormalDistance;
target = (ReflectionProbe)so.targetObject;
targetData = target.GetComponent<HDAdditionalReflectionData>();
mode = so.FindProperty("m_Mode");
customBakedTexture = so.FindProperty("m_CustomBakedTexture");

boxReprojectionVolumeCenter = addso.Find((HDAdditionalReflectionData d) => d.boxReprojectionVolumeCenter);
sphereReprojectionVolumeRadius = addso.Find((HDAdditionalReflectionData d) => d.sphereReprojectionVolumeRadius);
dimmer = addso.Find((HDAdditionalReflectionData d) => d.dimmer);
blendNormalDistance = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistance);
}
}

public BoxBoundsHandle boxInfluenceBoundsHandle = new BoxBoundsHandle();
public BoxBoundsHandle boxProjectionBoundsHandle = new BoxBoundsHandle();
public BoxBoundsHandle boxBlendHandle = new BoxBoundsHandle();
public BoxBoundsHandle boxBlendNormalHandle = new BoxBoundsHandle();
public SphereBoundsHandle sphereBlendNormalHandle = new SphereBoundsHandle();
public Matrix4x4 oldLocalSpace = Matrix4x4.identity;
public bool HasAndClearOperation(Operation op)

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


CED.Action(Drawer_UseSeparateProjectionVolume)*/
);
static readonly CED.IDrawer k_InfluenceNormalVolumeSection = CED.FoldoutGroup(
"Influence normal volume settings",
(s, p, o) => p.blendNormalDistance,
true,
CED.Action(Drawer_DistanceBlendNormal)
);
static readonly CED.IDrawer k_SeparateProjectionVolumeSection = CED.FadeGroup(
(s, p, o, i) => s.useSeparateProjectionVolumeDisplay.faded,
false,

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;

{
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();

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_DistanceBlendNormal(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.Slider(p.blendNormalDistance, 0, CalculateMaxBlendDistance(s, p, owner), CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."));
EditorGUI.BeginChangeCheck();
}
static void Drawer_InfluenceBoxSettings(UIState s, SerializedReflectionProbe p, Editor owner)
{

{
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 readonly EditMode.SceneViewEditMode[] k_Toolbar_SceneViewEditModes =
{
EditMode.SceneViewEditMode.ReflectionProbeBox,
//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("PreMatCube", "|Modify the influence normal volume of the reflection probe."),
EditorGUIUtility.IconContent("MoveTool", "|Move the selected objects.")
});
}

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

147
ScriptableRenderPipeline/HDRenderPipeline/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_GizmoInfluenceVolume = new Color(0xFF / 255f, 0xE5 / 255f, 0x94 / 255f, 0x20 / 255f);
internal static Color k_GizmoInfluenceNormalVolume = new Color(0x00 / 255f, 0xE5 / 255f, 0xFF / 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);

switch (EditMode.editMode)
{
case EditMode.SceneViewEditMode.ReflectionProbeBox:
{
}
{
}
case EditMode.SceneViewEditMode.Collider:
{
if (p.influenceShape.enumValueIndex == 0)
Handle_InfluenceNormalBoxEditing(s, p, o);
if (p.influenceShape.enumValueIndex == 1)
Handle_InfluenceNormalSphereEditing(s, p, o);
break;
}
case EditMode.SceneViewEditMode.ReflectionProbeOrigin:
Handle_OriginEditing(s, p, o);
break;

Repaint();
}
void BakeRealtimeProbeIfPositionChanged(UIState s, SerializedReflectionProbe sp, Editor o)

static void Handle_InfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var blendDistance = sp.target.blendDistance;
Handle_InfluenceBoxEditing_Internal(s, sp, o, s.boxBlendHandle, k_GizmoInfluenceVolume, ref blendDistance);
sp.target.blendDistance = blendDistance;
}
static void Handle_InfluenceNormalBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
Handle_InfluenceBoxEditing_Internal(s, sp, o, s.boxBlendHandle, k_GizmoInfluenceNormalVolume, ref sp.targetData.blendNormalDistance);
}
static void Handle_InfluenceBoxEditing_Internal(UIState s, SerializedReflectionProbe sp, Editor o, BoxBoundsHandle blendBox, Color blendHandleColor, ref float probeBlendDistance)
{
var p = (ReflectionProbe)sp.so.targetObject;
using (new Handles.DrawingScope(GetLocalSpace(p)))

s.boxBlendHandle.center = p.center;
s.boxBlendHandle.size = p.size - Vector3.one * p.blendDistance * 2;
blendBox.center = p.center;
blendBox.size = p.size - Vector3.one * probeBlendDistance * 2;
s.boxBlendHandle.DrawHandle();
Handles.color = blendHandleColor;
blendBox.DrawHandle();
var blendSize = s.boxBlendHandle.size;
var blendSize = blendBox.size;
? p.blendDistance
? probeBlendDistance
p.blendDistance = Mathf.Max(blendDistance, 0);
probeBlendDistance = Mathf.Max(blendDistance, 0);
EditorUtility.SetDirty(p);
}
}

static void Handle_InfluenceSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var blendDistance = sp.target.blendDistance;
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, ref blendDistance);
sp.target.blendDistance = blendDistance;
}
static void Handle_InfluenceNormalSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, ref sp.targetData.blendNormalDistance);
}
static void Handle_InfluenceSphereEditing_Internal(UIState s, SerializedReflectionProbe sp, Editor o, SphereBoundsHandle sphereBlend, ref float probeBlendDistance)
{
var p = (ReflectionProbe)sp.so.targetObject;
var reflectionData = p.GetComponent<HDAdditionalReflectionData>();

s.influenceSphereHandle.radius = reflectionData.influenceSphereRadius;
s.sphereBlendHandle.center = p.center;
s.sphereBlendHandle.radius = Mathf.Min(reflectionData.influenceSphereRadius - p.blendDistance * 2, reflectionData.influenceSphereRadius);
sphereBlend.center = p.center;
sphereBlend.radius = Mathf.Min(reflectionData.influenceSphereRadius - probeBlendDistance * 2, reflectionData.influenceSphereRadius);
s.sphereBlendHandle.DrawHandle();
sphereBlend.DrawHandle();
if (influenceChanged || EditorGUI.EndChangeCheck())
{
Undo.RecordObject(reflectionData, "Modified Reflection influence volume");

? Mathf.Max(influenceRadius - p.blendDistance * 2, 0)
: s.sphereBlendHandle.radius;
? Mathf.Max(influenceRadius - probeBlendDistance * 2, 0)
: sphereBlend.radius;
p.blendDistance = blendDistance;
probeBlendDistance = blendDistance;
EditorUtility.SetDirty(p);
EditorUtility.SetDirty(reflectionData);
}

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;
case EditMode.SceneViewEditMode.ReflectionProbeBox:
{
var oldColor = Gizmos.color;
Gizmos.color = k_GizmoInfluenceVolume;
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;
break;
}
case EditMode.SceneViewEditMode.Collider:
{
var oldColor = Gizmos.color;
Gizmos.color = k_GizmoInfluenceNormalVolume;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size + Vector3.one * 2f * reflectionData.blendNormalDistance);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - reflectionData.blendNormalDistance * 2f);
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;
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
break;
}
}
}

Color oldColor = Gizmos.color;
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoReflectionProbe : k_GizmoReflectionProbeDisabled;
var oldColor = Gizmos.color;
DrawBoxInfluenceGizmo(reflectionProbe, oldColor);
DrawBoxInfluenceGizmo(reflectionProbe, reflectionData);
DrawSphereInfluenceGizmo(reflectionProbe, oldColor, reflectionData);
DrawSphereInfluenceGizmo(reflectionProbe, reflectionData);
}
if (reflectionData.useSeparateProjectionVolume)
{

ChangeVisibility(reflectionProbe, false);
}
static void DrawBoxInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor)
static void DrawBoxInfluenceGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)
var influenceColor = reflectionProbe.isActiveAndEnabled ? k_GizmoInfluenceVolume : k_GizmoReflectionProbeDisabled;
var influenceNormalColor = reflectionProbe.isActiveAndEnabled ? k_GizmoInfluenceNormalVolume : k_GizmoReflectionProbeDisabled;
Gizmos.color = influenceColor;
Gizmos.DrawWireCube(reflectionProbe.center, new Vector3(reflectionProbe.size.x - reflectionProbe.blendDistance * 2, reflectionProbe.size.y - reflectionProbe.blendDistance * 2, reflectionProbe.size.z - reflectionProbe.blendDistance * 2));
Gizmos.DrawWireCube(reflectionProbe.center, GetBlendBoxSize(reflectionProbe, reflectionProbe.blendDistance));
}
if (reflectionData.blendNormalDistance > 0)
{
Gizmos.color = new Color(influenceNormalColor.r, influenceNormalColor.g, Gizmos.color.b, 0.3f);
Gizmos.DrawWireCube(reflectionProbe.center, GetBlendBoxSize(reflectionProbe, reflectionData.blendNormalDistance));
Gizmos.color = oldColor;
}
static Vector3 GetBlendBoxSize(ReflectionProbe reflectionProbe, float blendDistance)
{
return new Vector3(reflectionProbe.size.x - blendDistance * 2, reflectionProbe.size.y - blendDistance * 2, reflectionProbe.size.z - blendDistance * 2);
static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor, HDAdditionalReflectionData reflectionData)
static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)
var influenceColor = reflectionProbe.isActiveAndEnabled ? k_GizmoInfluenceVolume : k_GizmoReflectionProbeDisabled;
var influenceNormalColor = reflectionProbe.isActiveAndEnabled ? k_GizmoInfluenceNormalVolume : k_GizmoReflectionProbeDisabled;
Gizmos.color = influenceColor;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
if (reflectionProbe.blendDistance > 0)

}
if (reflectionData.blendNormalDistance > 0)
{
Gizmos.color = new Color(influenceNormalColor.r, influenceNormalColor.g, influenceNormalColor.b, 0.3f);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - 2 * reflectionData.blendNormalDistance);
}
Gizmos.color = oldColor;
}
static void DrawReprojectionVolumeGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)

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


k_PrimarySection.Draw(s, p, this);
k_InfluenceVolumeSection.Draw(s, p, this);
k_InfluenceNormalVolumeSection.Draw(s, p, this);
k_SeparateProjectionVolumeSection.Draw(s, p, this);
k_CaptureSection.Draw(s, p, this);
k_AdditionalSection.Draw(s, p, this);

1
ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs


public Vector3 boxReprojectionVolumeCenter = Vector3.zero;
public float maxSearchDistance = 8.0f;
public Texture previewCubemap;
public float blendNormalDistance = 0f;
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


public float minProjectionDistance;
public Vector3 innerDistance; // equivalent to volume scale
public float unused0;
public float blendNormalDistance;
public Vector3 offsetLS;
public float dimmer;

6
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


float3 right;
float minProjectionDistance;
float3 innerDistance;
float unused0;
float blendNormalDistance;
float3 offsetLS;
float dimmer;
};

{
return value.innerDistance;
}
float GetUnused0(EnvLightData value)
float GetBlendNormalDistance(EnvLightData value)
return value.unused0;
return value.blendNormalDistance;
}
float3 GetOffsetLS(EnvLightData value)
{

2
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


envLightData.minProjectionDistance = 65504.0f;
envLightData.dimmer = additionalData.dimmer;
envLightData.blendNormalDistance = additionalData.blendNormalDistance;
}
else
{

}
envLightData.dimmer = 1;
envLightData.blendNormalDistance = 0;
}
// remove scale from the matrix (Scale in this matrix is use to scale the widget)

正在加载...
取消
保存