浏览代码

Refactor and fixes for reflection probe editor

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
cd1edff6
共有 8 个文件被更改,包括 226 次插入150 次删除
  1. 14
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  2. 16
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  3. 60
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  4. 71
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  5. 66
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditorOld.cs
  6. 82
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs
  7. 56
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.ProbeUtility.cs
  8. 11
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.ProbeUtility.cs.meta

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


nearClip = so.FindProperty("m_NearClip");
farClip = so.FindProperty("m_FarClip");
influenceShape = addso.Find((HDAdditionalReflectionData d) => d.m_InfluenceShape);
influenceSphereRadius = addso.Find((HDAdditionalReflectionData d) => d.m_InfluenceSphereRadius);
useSeparateProjectionVolume = addso.Find((HDAdditionalReflectionData d) => d.m_UseSeparateProjectionVolume);
boxReprojectionVolumeSize = addso.Find((HDAdditionalReflectionData d) => d.m_BoxReprojectionVolumeSize);
boxReprojectionVolumeCenter = addso.Find((HDAdditionalReflectionData d) => d.m_BoxReprojectionVolumeCenter);
sphereReprojectionVolumeRadius = addso.Find((HDAdditionalReflectionData d) => d.m_SphereReprojectionVolumeRadius);
dimmer = addso.Find((HDAdditionalReflectionData d) => d.m_Dimmer);
influenceShape = addso.Find((HDAdditionalReflectionData d) => d.influenceShape);
influenceSphereRadius = addso.Find((HDAdditionalReflectionData d) => d.influenceSphereRadius);
useSeparateProjectionVolume = addso.Find((HDAdditionalReflectionData d) => d.useSeparateProjectionVolume);
boxReprojectionVolumeSize = addso.Find((HDAdditionalReflectionData d) => d.boxReprojectionVolumeSize);
boxReprojectionVolumeCenter = addso.Find((HDAdditionalReflectionData d) => d.boxReprojectionVolumeCenter);
sphereReprojectionVolumeRadius = addso.Find((HDAdditionalReflectionData d) => d.sphereReprojectionVolumeRadius);
dimmer = addso.Find((HDAdditionalReflectionData d) => d.dimmer);
}
}

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


var probe = p.so.targetObject as ReflectionProbe;
if (mode == 0)
{
ResetProbeSceneTextureInMaterial(probe);
}
BakeCustomReflectionProbe((ReflectionProbe)p.so.targetObject, true, true);
var probe = (ReflectionProbe)p.so.targetObject;
BakeCustomReflectionProbe(probe, true, true);
ResetProbeSceneTextureInMaterial(probe);
}
}
break;
}

{
var mode = (int)data;
if (mode == 0)
{
ResetAllProbeSceneTextureInMaterial();
}
BakeReflectionProbeSnapshot((ReflectionProbe)p.so.targetObject);
var probe = (ReflectionProbe)p.so.targetObject;
BakeReflectionProbeSnapshot(probe);
ResetProbeSceneTextureInMaterial(probe);
GUIUtility.ExitGUI();
}

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


{
partial class HDReflectionProbeEditor
{
internal static Color kGizmoReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0x94 / 255f, 0x80 / 255f);
internal static Color kGizmoReflectionProbeDisabled = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x60 / 255f);
internal static Color kGizmoHandleReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0xAA / 255f, 0xFF / 255f);
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_GizmoHandleReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0xAA / 255f, 0xFF / 255f);
void OnSceneGUI()
{

static void Handle_InfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
var p = (ReflectionProbe)sp.so.targetObject;
var a = p.GetComponent<HDAdditionalReflectionData>();
using (new Handles.DrawingScope(GetLocalSpace(p)))
{

using (new Handles.DrawingScope(GetLocalSpace(p)))
{
s.boxProjectionBoundsHandle.center = reflectionData.m_BoxReprojectionVolumeCenter;
s.boxProjectionBoundsHandle.size = reflectionData.m_BoxReprojectionVolumeSize;
s.boxProjectionBoundsHandle.center = reflectionData.boxReprojectionVolumeCenter;
s.boxProjectionBoundsHandle.size = reflectionData.boxReprojectionVolumeSize;
EditorGUI.BeginChangeCheck();
s.boxProjectionBoundsHandle.DrawHandle();

var center = s.boxProjectionBoundsHandle.center;
var size = s.boxProjectionBoundsHandle.size;
ValidateAABB(p, ref center, ref size);
reflectionData.m_BoxReprojectionVolumeCenter = center;
reflectionData.m_BoxReprojectionVolumeSize = size;
reflectionData.boxReprojectionVolumeCenter = center;
reflectionData.boxReprojectionVolumeSize = size;
EditorUtility.SetDirty(reflectionData);
}
}

using (new Handles.DrawingScope(GetLocalSpace(p)))
{
s.influenceSphereHandle.center = p.center;
s.influenceSphereHandle.radius = reflectionData.m_InfluenceSphereRadius;
s.influenceSphereHandle.radius = reflectionData.influenceSphereRadius;
s.sphereBlendHandle.radius = Mathf.Min(reflectionData.m_InfluenceSphereRadius - p.blendDistance * 2, reflectionData.m_InfluenceSphereRadius);
s.sphereBlendHandle.radius = Mathf.Min(reflectionData.influenceSphereRadius - p.blendDistance * 2, reflectionData.influenceSphereRadius);
EditorGUI.BeginChangeCheck();
s.influenceSphereHandle.DrawHandle();

var radius = new Vector3(s.influenceSphereHandle.radius, s.influenceSphereHandle.radius, s.influenceSphereHandle.radius);
var blendDistance = (s.influenceSphereHandle.radius - s.sphereBlendHandle.radius) / 2;
ValidateAABB(p, ref center, ref radius);
reflectionData.m_InfluenceSphereRadius = radius.x;
reflectionData.influenceSphereRadius = radius.x;
p.blendDistance = blendDistance;
EditorUtility.SetDirty(p);
EditorUtility.SetDirty(reflectionData);

using (new Handles.DrawingScope(GetLocalSpace(p)))
{
s.projectionSphereHandle.center = p.center;
s.projectionSphereHandle.radius = reflectionData.m_SphereReprojectionVolumeRadius;
s.projectionSphereHandle.radius = reflectionData.sphereReprojectionVolumeRadius;
EditorGUI.BeginChangeCheck();
s.projectionSphereHandle.DrawHandle();

var center = s.projectionSphereHandle.center;
var radius = s.projectionSphereHandle.radius;
//ValidateAABB(ref center, ref radius);
reflectionData.m_SphereReprojectionVolumeRadius = radius;
reflectionData.sphereReprojectionVolumeRadius = radius;
EditorUtility.SetDirty(reflectionData);
}
}

if (e.sceneViewEditing && EditMode.editMode == EditMode.SceneViewEditMode.ReflectionProbeBox)
{
var oldColor = Gizmos.color;
Gizmos.color = kGizmoReflectionProbe;
Gizmos.color = k_GizmoReflectionProbe;
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
{
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
}

static void DrawSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
{
Color oldColor = Gizmos.color;
Gizmos.color = reflectionProbe.isActiveAndEnabled ? kGizmoReflectionProbe : kGizmoReflectionProbeDisabled;
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoReflectionProbe : k_GizmoReflectionProbeDisabled;
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
if (reflectionData.m_UseSeparateProjectionVolume)
if (reflectionData.useSeparateProjectionVolume)
{
DrawReprojectionVolumeGizmo(reflectionProbe, reflectionData);
}

reflectionData.ChangeVisibility(true);
ChangeVisibility(reflectionProbe, true);
}
[DrawGizmo(GizmoType.NonSelected)]

if (reflectionData != null)
reflectionData.ChangeVisibility(false);
ChangeVisibility(reflectionProbe, false);
}
static void DrawBoxInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor)

static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor, HDAdditionalReflectionData reflectionData)
{
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius - 2 * reflectionProbe.blendDistance);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - 2 * reflectionProbe.blendDistance);
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;

Color reprojectionColor = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.3f);
Gizmos.color = reprojectionColor;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawWireCube(reflectionData.m_BoxReprojectionVolumeCenter, reflectionData.m_BoxReprojectionVolumeSize);
Gizmos.DrawWireCube(reflectionData.boxReprojectionVolumeCenter, reflectionData.boxReprojectionVolumeSize);
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_SphereReprojectionVolumeRadius);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.sphereReprojectionVolumeRadius);
}
Gizmos.matrix = Matrix4x4.identity;
}

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


using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor.Experimental.Rendering;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

void HideAdditionalComponents(bool visible)
{
var adds = CoreEditorUtils.GetAdditionalData<HDAdditionalReflectionData>(targets);
var flags = visible ? HideFlags.None : HideFlags.HideInInspector;
for (var i = 0 ; i < targets.Length; ++i)
{
var target = targets[i];

var meshFilter = p.GetComponent<MeshFilter>();
addData.hideFlags = visible ? HideFlags.None : HideFlags.HideInInspector;
meshRenderer.hideFlags = visible ? HideFlags.None : HideFlags.HideInInspector;
meshFilter.hideFlags = visible ? HideFlags.None : HideFlags.HideInInspector;
addData.hideFlags = flags;
meshRenderer.hideFlags = flags;
meshFilter.hideFlags = flags;
}
}

return true;
}
static bool IsCollidingWithOtherProbes(string targetPath, ReflectionProbe targetProbe, out ReflectionProbe collidingProbe)
{
ReflectionProbe[] probes = FindObjectsOfType<ReflectionProbe>().ToArray();
collidingProbe = null;
foreach (var probe in probes)
{
if (probe == targetProbe || probe.customBakedTexture == null)
continue;
string path = AssetDatabase.GetAssetPath(probe.customBakedTexture);
if (path == targetPath)
{
collidingProbe = probe;
return true;
}
}
return false;
}
static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode)
{
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin;
}
static void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath, bool custom)
{
if (!custom && probe.bakedTexture != null)

EditorUtility.ClearProgressBar();
}
static bool IsCollidingWithOtherProbes(string targetPath, ReflectionProbe targetProbe, out ReflectionProbe collidingProbe)
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic);
static bool BakeReflectionProbeSnapshot(ReflectionProbe probe)
ReflectionProbe[] probes = FindObjectsOfType<ReflectionProbe>().ToArray();
collidingProbe = null;
foreach (var probe in probes)
{
if (probe == targetProbe || probe.customBakedTexture == null)
continue;
string path = AssetDatabase.GetAssetPath(probe.customBakedTexture);
if (path == targetPath)
{
collidingProbe = probe;
return true;
}
}
return false;
return (bool)k_Lightmapping_BakeReflectionProbeSnapshot.Invoke(null, new object[] { probe });
static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode)
static MethodInfo k_Lightmapping_BakeAllReflectionProbesSnapshots = typeof(UnityEditor.Lightmapping).GetMethod("BakeAllReflectionProbesSnapshots", BindingFlags.Static | BindingFlags.NonPublic);
static bool BakeAllReflectionProbesSnapshots()
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox ||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin;
return (bool)k_Lightmapping_BakeAllReflectionProbesSnapshots.Invoke(null, new object[0]);
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic);
static bool BakeReflectionProbeSnapshot(ReflectionProbe probe)
static void ResetProbeSceneTextureInMaterial(ReflectionProbe p)
return (bool)k_Lightmapping_BakeReflectionProbeSnapshot.Invoke(null, new object[] { probe });
var renderer = p.GetComponent<Renderer>();
renderer.sharedMaterial.SetTexture(_Cubemap, p.texture);
static MethodInfo k_Lightmapping_BakeAllReflectionProbesSnapshots = typeof(UnityEditor.Lightmapping).GetMethod("BakeAllReflectionProbesSnapshots", BindingFlags.Static | BindingFlags.NonPublic);
static bool BakeAllReflectionProbesSnapshots()
static void ResetAllProbeSceneTextureInMaterial()
return (bool)k_Lightmapping_BakeAllReflectionProbesSnapshots.Invoke(null, new object[0]);
foreach (var data in HDAdditionalReflectionData.AllDatas)
{
var p = data.GetComponent<ReflectionProbe>();
ResetProbeSceneTextureInMaterial(p);
}
}
}
}

66
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditorOld.cs


foreach (Material mat in m_CachedGizmoMaterials.Values)
DestroyImmediate(mat);
m_CachedGizmoMaterials.Clear();
((HDAdditionalReflectionData)additionalReflectionDataSerializedObject.targetObject).ChangeVisibility(false);
//((HDAdditionalReflectionData)additionalReflectionDataSerializedObject.targetObject).ChangeVisibility(false);
}
private bool IsCollidingWithOtherProbes(string targetPath, ReflectionProbe targetProbe, out ReflectionProbe collidingProbe)

Gizmos.color = kGizmoReflectionProbe;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
if(reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
if(reflectionData.influenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;
}

Gizmos.color = reflectionProbe.isActiveAndEnabled ? kGizmoReflectionProbe : kGizmoReflectionProbeDisabled;
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
if (reflectionData.m_UseSeparateProjectionVolume)
if (reflectionData.useSeparateProjectionVolume)
{
DrawReprojectionVolumeGizmo(reflectionProbe, reflectionData);
}

reflectionData.ChangeVisibility(true);
//reflectionData.ChangeVisibility(true);
}
static void DrawVerticalRay(Transform transform)

//[DrawGizmo(GizmoType.NonSelected)]
static void DrawNonSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType)
{
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
if (reflectionData != null)
reflectionData.ChangeVisibility(false);
//var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
//if (reflectionData != null)
// reflectionData.ChangeVisibility(false);
}
static void DrawReprojectionVolumeGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData)

Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawWireCube(reflectionData.m_BoxReprojectionVolumeCenter, reflectionData.m_BoxReprojectionVolumeSize);
Gizmos.DrawWireCube(reflectionData.boxReprojectionVolumeCenter, reflectionData.boxReprojectionVolumeSize);
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_SphereReprojectionVolumeRadius);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.sphereReprojectionVolumeRadius);
}
Gizmos.matrix = Matrix4x4.identity;
}

static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor, HDAdditionalReflectionData reflectionData)
{
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.m_InfluenceSphereRadius - 2 * reflectionProbe.blendDistance);
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - 2 * reflectionProbe.blendDistance);
}
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;

using (new Handles.DrawingScope(GetLocalSpace(p)))
{
m_BoxProjectionBoundsHandle.center = reflectionData.m_BoxReprojectionVolumeCenter;
m_BoxProjectionBoundsHandle.size = reflectionData.m_BoxReprojectionVolumeSize;
m_BoxProjectionBoundsHandle.center = reflectionData.boxReprojectionVolumeCenter;
m_BoxProjectionBoundsHandle.size = reflectionData.boxReprojectionVolumeSize;
EditorGUI.BeginChangeCheck();
m_BoxProjectionBoundsHandle.DrawHandle();

Vector3 center = m_BoxProjectionBoundsHandle.center;
Vector3 size = m_BoxProjectionBoundsHandle.size;
ValidateAABB(ref center, ref size);
reflectionData.m_BoxReprojectionVolumeCenter = center;
reflectionData.m_BoxReprojectionVolumeSize = size;
reflectionData.boxReprojectionVolumeCenter = center;
reflectionData.boxReprojectionVolumeSize = size;
EditorUtility.SetDirty(reflectionData);
}
}

using (new Handles.DrawingScope(GetLocalSpace(p)))
{
m_InfluenceSphereHandle.center = p.center;
m_InfluenceSphereHandle.radius = reflectionData.m_InfluenceSphereRadius;
m_InfluenceSphereHandle.radius = reflectionData.influenceSphereRadius;
m_SphereBlendHandle.radius = Mathf.Min(reflectionData.m_InfluenceSphereRadius - p.blendDistance * 2, reflectionData.m_InfluenceSphereRadius);
m_SphereBlendHandle.radius = Mathf.Min(reflectionData.influenceSphereRadius - p.blendDistance * 2, reflectionData.influenceSphereRadius);
EditorGUI.BeginChangeCheck();
m_InfluenceSphereHandle.DrawHandle();

Vector3 radius = new Vector3(m_InfluenceSphereHandle.radius, m_InfluenceSphereHandle.radius, m_InfluenceSphereHandle.radius);
float blendDistance = (m_InfluenceSphereHandle.radius - m_SphereBlendHandle.radius) / 2;
ValidateAABB(ref center, ref radius);
reflectionData.m_InfluenceSphereRadius = radius.x;
reflectionData.influenceSphereRadius = radius.x;
p.blendDistance = blendDistance;
EditorUtility.SetDirty(target);
EditorUtility.SetDirty(reflectionData);

using (new Handles.DrawingScope(GetLocalSpace(p)))
{
m_ProjectionSphereHandle.center = p.center;
m_ProjectionSphereHandle.radius = reflectionData.m_SphereReprojectionVolumeRadius;
m_ProjectionSphereHandle.radius = reflectionData.sphereReprojectionVolumeRadius;
EditorGUI.BeginChangeCheck();
m_ProjectionSphereHandle.DrawHandle();

Vector3 center = m_ProjectionSphereHandle.center;
float radius = m_ProjectionSphereHandle.radius;
//ValidateAABB(ref center, ref radius);
reflectionData.m_SphereReprojectionVolumeRadius = radius;
reflectionData.sphereReprojectionVolumeRadius = radius;
EditorUtility.SetDirty(reflectionData);
}
}

Debug.Log("lower"+lowerEstimatedBounds);
}
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Box)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
if(reflectionData.m_UseSeparateProjectionVolume)
if(reflectionData.useSeparateProjectionVolume)
reflectionData.m_BoxReprojectionVolumeSize = newSize;
reflectionData.m_BoxReprojectionVolumeCenter = newCenter;
reflectionData.boxReprojectionVolumeSize = newSize;
reflectionData.boxReprojectionVolumeCenter = newCenter;
if(!reflectionData.m_UseSeparateProjectionVolume)
if(!reflectionData.useSeparateProjectionVolume)
{
newSize += Vector3.one * reflectionProbeTarget.blendDistance;
reflectionProbeTarget.size = newSize;

Debug.DrawLine(reflectionProbeTarget.transform.position + newCenter, reflectionProbeTarget.transform.position + newCenter + Vector3.up * 0.1f,Color.red,5f);
}
if (reflectionData.m_InfluenceShape == ReflectionInfluenceShape.Sphere)
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
reflectionData.m_SphereReprojectionVolumeRadius = newSize;
reflectionData.sphereReprojectionVolumeRadius = newSize;
}
}
else

82
ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs


#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using System.Collections.Generic;
public ReflectionInfluenceShape m_InfluenceShape;
[Range(0.0f,1.0f)]
public float m_Dimmer = 1.0f;
public float m_InfluenceSphereRadius = 3.0f;
public float m_SphereReprojectionVolumeRadius = 1.0f;
public bool m_UseSeparateProjectionVolume = false;
public Vector3 m_BoxReprojectionVolumeSize = Vector3.one;
public Vector3 m_BoxReprojectionVolumeCenter = Vector3.zero;
public float m_MaxSearchDistance = 8.0f;
private MeshRenderer m_PreviewMeshRenderer;
public Texture m_PreviewCubemap;
private MeshFilter m_PreviewMeshFilter;
private static Mesh m_SphereMesh;
private static Material m_PreviewMaterial;
private bool m_Visible;
#region Registration
// We need to notify when a data is enabled
// So it can be properly initialized in the editor
public static event Action<HDAdditionalReflectionData> OnNewItem;
static List<HDAdditionalReflectionData> s_AllDatas = new List<HDAdditionalReflectionData>();
public static IEnumerable<HDAdditionalReflectionData> AllDatas { get { return s_AllDatas; } }
#if UNITY_EDITOR
private static Mesh sphereMesh
static void AddData(HDAdditionalReflectionData value)
get { return m_SphereMesh ?? (m_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh); }
s_AllDatas.Add(value);
if (OnNewItem != null)
OnNewItem(value);
public Material previewMaterial
static void RemoveData(HDAdditionalReflectionData value)
get
{
if (m_PreviewMaterial == null )
{
//m_PreviewMaterial = (Material)Instantiate(AssetDatabase.LoadAssetAtPath("Assets/ScriptableRenderPipeline/ScriptableRenderPipeline/HDRenderPipeline/Debug/PreviewCubemapMaterial.mat", typeof(Material)));
m_PreviewMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview"));
}
if(m_PreviewCubemap != null)
m_PreviewMaterial.SetTexture("_Cubemap", m_PreviewCubemap);
m_PreviewMaterial.hideFlags = HideFlags.HideAndDontSave;
return m_PreviewMaterial;
}
s_AllDatas.Remove(value);
#endregion
public ReflectionInfluenceShape influenceShape;
[Range(0.0f,1.0f)]
public float dimmer = 1.0f;
public float influenceSphereRadius = 3.0f;
public float sphereReprojectionVolumeRadius = 1.0f;
public bool useSeparateProjectionVolume = false;
public Vector3 boxReprojectionVolumeSize = Vector3.one;
public Vector3 boxReprojectionVolumeCenter = Vector3.zero;
public float maxSearchDistance = 8.0f;
public Texture previewCubemap;
private void OnEnable()
void OnEnable()
m_PreviewMeshFilter = gameObject.GetComponent<MeshFilter>() != null ? gameObject.GetComponent<MeshFilter>() : gameObject.AddComponent<MeshFilter>();
m_PreviewMeshRenderer = gameObject.GetComponent<MeshRenderer>() != null ? gameObject.GetComponent<MeshRenderer>() : gameObject.AddComponent<MeshRenderer>();
m_PreviewMeshFilter.sharedMesh = sphereMesh;
//m_PreviewMeshRenderer.sharedMaterial = previewMaterial;
m_PreviewMeshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
m_PreviewMeshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
m_PreviewMeshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
AddData(this);
public void ChangeVisibility(bool visible)
void OnDisable()
if(visible != m_Visible)
{
m_PreviewMeshRenderer.sharedMaterial = previewMaterial;
m_PreviewMeshRenderer.enabled = visible ? true : false;
m_Visible = visible;
}
RemoveData(this);
#endif
}
}

56
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.ProbeUtility.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using Object = UnityEngine.Object;
namespace UnityEditor.Experimental.Rendering
{
partial class HDReflectionProbeEditor
{
static Material s_PreviewMaterial;
static Mesh s_SphereMesh;
static int _Cubemap = Shader.PropertyToID("_Cubemap");
[InitializeOnLoadMethod]
static void Initialize()
{
s_PreviewMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview"))
{
hideFlags = HideFlags.HideAndDontSave
};
s_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh;
HDAdditionalReflectionData.OnNewItem += OnNewProbe;
foreach (var data in HDAdditionalReflectionData.AllDatas)
OnNewProbe(data);
}
static void OnNewProbe(HDAdditionalReflectionData value)
{
InitializeProbe(value.GetComponent<ReflectionProbe>(), value);
}
static void InitializeProbe(ReflectionProbe p, HDAdditionalReflectionData data)
{
var meshFilter = p.GetComponent<MeshFilter>() ?? p.gameObject.AddComponent<MeshFilter>();
var meshRenderer = p.GetComponent<MeshRenderer>() ?? p.gameObject.AddComponent<MeshRenderer>();
meshFilter.sharedMesh = s_SphereMesh;
var material = Object.Instantiate(s_PreviewMaterial);
material.SetTexture(_Cubemap, p.texture);
material.hideFlags = HideFlags.HideAndDontSave;
meshRenderer.material = material;
meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
meshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
}
static void ChangeVisibility(ReflectionProbe p, bool visible)
{
var meshRenderer = p.GetComponent<MeshRenderer>() ?? p.gameObject.AddComponent<MeshRenderer>();
meshRenderer.enabled = visible;
}
}
}

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


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