浏览代码

[ReflectionProbeEditor] Influence Normal edition

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
8f629854
共有 3 个文件被更改,包括 65 次插入63 次删除
  1. 70
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  2. 54
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  3. 4
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs

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


var blendDistance = Mathf.Max(0, (influenceRadius - blendRadius) * 0.5f);
probeBlendDistancePositive = Vector3.one * blendDistance;
probeBlendDistanceNegative = probeBlendDistancePositive;
ApplyConstraintsOnTargets(s, sp, o);
ApplyConstraintsOnTargets(s, sp, o);
EditorUtility.SetDirty(sp.target);
EditorUtility.SetDirty(sp.targetData);

case InfluenceType.Normal:
{
sp.targetData.blendNormalDistance = probeBlendDistancePositive;
sp.targetData.blendNormalDistance2 = probeBlendDistancePositive;
sp.targetData.blendNormalDistance2 = probeBlendDistanceNegative;
break;
}
}

Undo.RecordObject(sp.target, "Modified Reflection Probe AABB");
Undo.RecordObject(sp.targetData, "Modified Reflection Probe AABB");
var blendDistancePositive = Vector3.Min(sp.targetData.blendDistance, s.boxInfluenceHandle.size);
var blendDistanceNegative = Vector3.Min(sp.targetData.blendDistance2, s.boxInfluenceHandle.size);
var center = s.boxInfluenceHandle.center;
var size = s.boxInfluenceHandle.size;
sp.target.center = s.boxInfluenceHandle.center;
sp.target.size = s.boxInfluenceHandle.size;
sp.targetData.blendDistance = blendDistancePositive;
sp.targetData.blendDistance2 = blendDistanceNegative;
ValidateAABB(sp.target, ref center, ref size);
sp.target.center = center;
sp.target.size = size;
ApplyConstraintsOnTargets(s, sp, o);

}
Handles.matrix = mat;
Handles.color = col;
}
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.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;
}
}
}
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 void Handle_OriginEditing(UIState s, SerializedReflectionProbe sp, Editor o)

54
ScriptableRenderPipeline/HDRenderPipeline/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

}
}
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;

{
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.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;
}
}
}
}
}

4
ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs


public Vector3 blendNormalDistance = Vector3.zero;
public Vector3 blendNormalDistance2 = Vector3.zero;
public Vector3 boxBlendCenterOffset { get { return (-blendDistance + blendDistance2) * 0.5f; } }
public Vector3 boxBlendCenterOffset { get { return (blendDistance2 - blendDistance) * 0.5f; } }
public Vector3 boxBlendNormalCenterOffset { get { return -(blendNormalDistance + blendNormalDistance2) * 0.5f; } }
public Vector3 boxBlendNormalCenterOffset { get { return (blendNormalDistance2 - blendNormalDistance) * 0.5f; } }
public Vector3 boxBlendNormalSizeOffset { get { return -(blendNormalDistance + blendNormalDistance2); } }

正在加载...
取消
保存