浏览代码

Reworked parameters and added a few new ones [incomplete]

/main
Thomas 7 年前
当前提交
641f9dc3
共有 9 个文件被更改,包括 588 次插入293 次删除
  1. 423
      ScriptableRenderPipeline/Core/Volume/VolumeParameter.cs
  2. 144
      ScriptableRenderPipeline/Core/Volume/Editor/Drawers/FloatParameterDrawer.cs
  3. 107
      ScriptableRenderPipeline/Core/Volume/Editor/Drawers/IntParameterDrawer.cs
  4. 77
      ScriptableRenderPipeline/Core/Volume/Editor/Drawers/ClampedFloatParameterDrawer.cs
  5. 77
      ScriptableRenderPipeline/Core/Volume/Editor/Drawers/ClampedIntParameterDrawer.cs
  6. 42
      ScriptableRenderPipeline/Core/Volume/Editor/Drawers/RangeParameterDrawer.cs
  7. 11
      ScriptableRenderPipeline/Core/Volume/Editor/Drawers/RangeParameterDrawer.cs.meta
  8. 0
      /ScriptableRenderPipeline/Core/Volume/Editor/Drawers/FloatParameterDrawer.cs.meta
  9. 0
      /ScriptableRenderPipeline/Core/Volume/Editor/Drawers/IntParameterDrawer.cs.meta

423
ScriptableRenderPipeline/Core/Volume/VolumeParameter.cs


set { m_Value = value; }
}
protected const float k_DefaultInterpSwap = 0f;
public VolumeParameter()
: this(default(T), false)
{

public virtual void Interp(T from, T to, float t)
{
// Returns `b` if `dt > 0` by default so we don't have to write overrides for bools and
// enumerations.
m_Value = t > 0f ? to : from;
// Default interpolation is naive
m_Value = t > k_DefaultInterpSwap ? to : from;
}
public void Override(T x)

}
}
public enum ParameterClampMode
{
Min,
Max,
MinMax
}
//
// The serialization system in Unity can't serialize generic types, the workaround is to extend
// and flatten pre-defined generic types.

//
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class BoolParameter : VolumeParameter<bool> { }
public sealed class BoolParameter : VolumeParameter<bool>
{
public BoolParameter(bool value, bool overrideState = false)
: base(value, overrideState) { }
}
public sealed class IntParameter : VolumeParameter<int>
public class IntParameter : VolumeParameter<int>
public override void Interp(int from, int to, float t)
public IntParameter(int value, bool overrideState = false)
: base(value, overrideState) { }
public sealed override void Interp(int from, int to, float t)
{
// Int snapping interpolation. Don't use this for enums as they don't necessarily have
// contiguous values. Use the default interpolator instead (same as bool).

[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class InstantIntParameter : VolumeParameter<int> { }
public sealed class NoInterpIntParameter : VolumeParameter<int>
{
public NoInterpIntParameter(int value, bool overrideState = false)
: base(value, overrideState) { }
}
public sealed class ClampedIntParameter : VolumeParameter<int>
public sealed class MinIntParameter : IntParameter
public ParameterClampMode clampMode = ParameterClampMode.MinMax;
public int min = 0;
public int max = 10;
public int min;
set
{
switch (clampMode)
{
case ParameterClampMode.Min: m_Value = Mathf.Max(min, value); break;
case ParameterClampMode.Max: m_Value = Mathf.Min(max, value); break;
case ParameterClampMode.MinMax: m_Value = Mathf.Clamp(value, min, max); break;
}
}
set { m_Value = Mathf.Max(value, min); }
public override void Interp(int from, int to, float t)
public MinIntParameter(int value, int min, bool overrideState = false)
: base(value, overrideState)
m_Value = (int)(from + (to - from) * t);
this.min = min;
public sealed class InstantClampedIntParameter : VolumeParameter<int>
public sealed class NoInterpMinIntParameter : VolumeParameter<int>
{
public int min;
public override int value
{
get { return m_Value; }
set { m_Value = Mathf.Max(value, min); }
}
public NoInterpMinIntParameter(int value, int min, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
}
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class MaxIntParameter : IntParameter
public ParameterClampMode clampMode = ParameterClampMode.MinMax;
public int min = 0;
public int max = 10;
public int max;
set
{
switch (clampMode)
{
case ParameterClampMode.Min: m_Value = Mathf.Max(min, value); break;
case ParameterClampMode.Max: m_Value = Mathf.Min(max, value); break;
case ParameterClampMode.MinMax: m_Value = Mathf.Clamp(value, min, max); break;
}
}
set { m_Value = Mathf.Min(value, max); }
}
public MaxIntParameter(int value, int max, bool overrideState = false)
: base(value, overrideState)
{
this.max = max;
public sealed class FloatParameter : VolumeParameter<float>
public sealed class NoInterpMaxIntParameter : VolumeParameter<int>
public override void Interp(float from, float to, float t)
public int max;
public override int value
{
get { return m_Value; }
set { m_Value = Mathf.Min(value, max); }
}
public NoInterpMaxIntParameter(int value, int max, bool overrideState = false)
: base(value, overrideState)
{
this.max = max;
}
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class ClampedIntParameter : IntParameter
{
public int min;
public int max;
public override int value
{
get { return m_Value; }
set { m_Value = Mathf.Clamp(value, min, max); }
}
public ClampedIntParameter(int value, int min, int max, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
this.max = max;
}
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class NoInterpClampedIntParameter : VolumeParameter<int>
{
public int min;
public int max;
public override int value
{
get { return m_Value; }
set { m_Value = Mathf.Clamp(value, min, max); }
}
public NoInterpClampedIntParameter(int value, int min, int max, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
this.max = max;
}
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public class FloatParameter : VolumeParameter<float>
{
public FloatParameter(float value, bool overrideState = false)
: base(value, overrideState) { }
public sealed override void Interp(float from, float to, float t)
{
m_Value = from + (to - from) * t;
}

public sealed class InstantFloatParameter : VolumeParameter<float> { }
public sealed class NoInterpFloatParameter : VolumeParameter<float>
{
public NoInterpFloatParameter(float value, bool overrideState = false)
: base(value, overrideState) { }
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class MinFloatParameter : FloatParameter
{
public float min;
public override float value
{
get { return m_Value; }
set { m_Value = Mathf.Max(value, min); }
}
public MinFloatParameter(float value, float min, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
}
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class NoInterpMinFloatParameter : VolumeParameter<float>
{
public float min;
public override float value
{
get { return m_Value; }
set { m_Value = Mathf.Max(value, min); }
}
public NoInterpMinFloatParameter(float value, float min, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
}
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class MaxFloatParameter : FloatParameter
{
public float max;
public override float value
{
get { return m_Value; }
set { m_Value = Mathf.Min(value, max); }
}
public MaxFloatParameter(float value, float max, bool overrideState = false)
: base(value, overrideState)
{
this.max = max;
}
}
public sealed class ClampedFloatParameter : VolumeParameter<float>
public sealed class NoInterpMaxFloatParameter : VolumeParameter<float>
public ParameterClampMode clampMode = ParameterClampMode.MinMax;
public float min = 0f;
public float max = 1f;
public float max;
set
{
switch (clampMode)
{
case ParameterClampMode.Min: m_Value = Mathf.Max(min, value); break;
case ParameterClampMode.Max: m_Value = Mathf.Min(max, value); break;
case ParameterClampMode.MinMax: m_Value = Mathf.Clamp(value, min, max); break;
}
}
set { m_Value = Mathf.Min(value, max); }
// We could override FloatParameter here but that would require making it not-sealed which
// will stop the compiler from doing specific optimizations on virtual methods - considering
// how often float is used, duplicating the code in this case is a definite win
public override void Interp(float from, float to, float t)
public NoInterpMaxFloatParameter(float value, float max, bool overrideState = false)
: base(value, overrideState)
m_Value = from + (to - from) * t;
this.max = max;
public sealed class InstantClampedFloatParameter : VolumeParameter<float>
public sealed class ClampedFloatParameter : FloatParameter
public ParameterClampMode clampMode = ParameterClampMode.MinMax;
public float min = 0f;
public float max = 1f;
public float min;
public float max;
set
{
switch (clampMode)
{
case ParameterClampMode.Min: m_Value = Mathf.Max(min, value); break;
case ParameterClampMode.Max: m_Value = Mathf.Min(max, value); break;
case ParameterClampMode.MinMax: m_Value = Mathf.Clamp(value, min, max); break;
}
}
set { m_Value = Mathf.Clamp(value, min, max); }
}
public ClampedFloatParameter(float value, float min, float max, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
this.max = max;
}
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class NoInterpClampedFloatParameter : VolumeParameter<float>
{
public float min;
public float max;
public override float value
{
get { return m_Value; }
set { m_Value = Mathf.Clamp(value, min, max); }
}
public NoInterpClampedFloatParameter(float value, float min, float max, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
this.max = max;
public sealed class RangeParameter : VolumeParameter<Vector2>
public sealed class FloatRangeParameter : VolumeParameter<Vector2>
public float min = 0;
public float max = 1;
public float min;
public float max;
public override Vector2 value
{

}
}
public FloatRangeParameter(Vector2 value, float min, float max, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
this.max = max;
}
public override void Interp(Vector2 from, Vector2 to, float t)
{
m_Value.x = from.x + (to.x - from.x) * t;

[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class InstantRangeParameter : VolumeParameter<Vector2>
public sealed class NoInterpFloatRangeParameter : VolumeParameter<Vector2>
public float min = 0;
public float max = 1;
public float min;
public float max;
public override Vector2 value
{

m_Value.y = Mathf.Min(value.y, max);
}
}
public NoInterpFloatRangeParameter(Vector2 value, float min, float max, bool overrideState = false)
: base(value, overrideState)
{
this.min = min;
this.max = max;
}
}
// 32-bit RGBA

public bool showAlpha = true;
public bool showEyeDropper = true;
public ColorParameter(Color value, bool overrideState = false)
: base(value, overrideState) { }
public ColorParameter(Color value, bool hdr, bool showAlpha, bool showEyeDropper, bool overrideState = false)
: base(value, overrideState)
{
this.hdr = hdr;
this.showAlpha = showAlpha;
this.overrideState = overrideState;
}
public override void Interp(Color from, Color to, float t)
{
// Lerping color values is a sensitive subject... We looked into lerping colors using

}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class InstantColorParameter : VolumeParameter<Color> { }
public sealed class NoInterpColorParameter : VolumeParameter<Color>
{
public bool hdr = false;
public bool showAlpha = true;
public bool showEyeDropper = true;
public NoInterpColorParameter(Color value, bool overrideState = false)
: base(value, overrideState) { }
public NoInterpColorParameter(Color value, bool hdr, bool showAlpha, bool showEyeDropper, bool overrideState = false)
: base(value, overrideState)
{
this.hdr = hdr;
this.showAlpha = showAlpha;
this.overrideState = overrideState;
}
}
public Vector2Parameter(Vector2 value, bool overrideState = false)
: base(value, overrideState) { }
public override void Interp(Vector2 from, Vector2 to, float t)
{
m_Value.x = from.x + (to.x - from.x) * t;

[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class InstantVector2Parameter : VolumeParameter<Vector2> { }
public sealed class NoInterpVector2Parameter : VolumeParameter<Vector2>
{
public NoInterpVector2Parameter(Vector2 value, bool overrideState = false)
: base(value, overrideState) { }
}
public Vector3Parameter(Vector3 value, bool overrideState = false)
: base(value, overrideState) { }
public override void Interp(Vector3 from, Vector3 to, float t)
{
m_Value.x = from.x + (to.x - from.x) * t;

}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class InstantVector3Parameter : VolumeParameter<Vector3> { }
public sealed class NoInterpVector3Parameter : VolumeParameter<Vector3>
{
public NoInterpVector3Parameter(Vector3 value, bool overrideState = false)
: base(value, overrideState) { }
}
public Vector4Parameter(Vector4 value, bool overrideState = false)
: base(value, overrideState) { }
public override void Interp(Vector4 from, Vector4 to, float t)
{
m_Value.x = from.x + (to.x - from.x) * t;

}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class InstantVector4Parameter : VolumeParameter<Vector4> { }
public sealed class NoInterpVector4Parameter : VolumeParameter<Vector4>
{
public NoInterpVector4Parameter(Vector4 value, bool overrideState = false)
: base(value, overrideState) { }
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class TextureParameter : VolumeParameter<Texture>
{
public TextureParameter(Texture value, bool overrideState = false)
: base(value, overrideState) { }
// TODO: Texture interpolation
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class NoInterpTextureParameter : VolumeParameter<Texture>
{
public NoInterpTextureParameter(Texture value, bool overrideState = false)
: base(value, overrideState) { }
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class RenderTextureParameter : VolumeParameter<RenderTexture>
{
public RenderTextureParameter(RenderTexture value, bool overrideState = false)
: base(value, overrideState) { }
// TODO: RenderTexture interpolation
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class NoInterpRenderTextureParameter : VolumeParameter<RenderTexture>
{
public NoInterpRenderTextureParameter(RenderTexture value, bool overrideState = false)
: base(value, overrideState) { }
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class CubemapParameter : VolumeParameter<Cubemap>
{
public CubemapParameter(Cubemap value, bool overrideState = false)
: base(value, overrideState) { }
// TODO: Cubemap interpolation
}
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class NoInterpCubemapParameter : VolumeParameter<Cubemap>
{
public NoInterpCubemapParameter(Cubemap value, bool overrideState = false)
: base(value, overrideState) { }
}
// Used as a container to store custom serialized classes/structs inside volume components
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]

.ToList()
.AsReadOnly();
}
}
public ObjectParameter(T value)
{
m_OverrideState = true;
this.value = value;
}
internal override void Interp(VolumeParameter from, VolumeParameter to, float t)

144
ScriptableRenderPipeline/Core/Volume/Editor/Drawers/FloatParameterDrawer.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering
{
[VolumeParameterDrawer(typeof(MinFloatParameter))]
sealed class MinFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<MinFloatParameter>();
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Max(v, o.min);
return true;
}
}
[VolumeParameterDrawer(typeof(NoInterpMinFloatParameter))]
sealed class NoInterpMinFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<NoInterpMinFloatParameter>();
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Max(v, o.min);
return true;
}
}
[VolumeParameterDrawer(typeof(MaxFloatParameter))]
sealed class MaxFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<MaxFloatParameter>();
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Min(v, o.max);
return true;
}
}
[VolumeParameterDrawer(typeof(NoInterpMaxFloatParameter))]
sealed class NoInterpMaxFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<NoInterpMaxFloatParameter>();
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Min(v, o.max);
return true;
}
}
[VolumeParameterDrawer(typeof(ClampedFloatParameter))]
sealed class ClampedFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<ClampedFloatParameter>();
EditorGUILayout.Slider(value, o.min, o.max, title);
value.floatValue = Mathf.Clamp(value.floatValue, o.min, o.max);
return true;
}
}
[VolumeParameterDrawer(typeof(NoInterpClampedFloatParameter))]
sealed class NoInterpClampedFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<NoInterpClampedFloatParameter>();
EditorGUILayout.Slider(value, o.min, o.max, title);
value.floatValue = Mathf.Clamp(value.floatValue, o.min, o.max);
return true;
}
}
[VolumeParameterDrawer(typeof(FloatRangeParameter))]
sealed class FloatRangeParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Vector2)
return false;
var o = parameter.GetObjectRef<FloatRangeParameter>();
var v = value.vector2Value;
// The layout system breaks alignement when mixing inspector fields with custom layouted
// fields as soon as a scrollbar is needed in the inspector, so we'll do the layout
// manually instead
const int kFloatFieldWidth = 50;
const int kSeparatorWidth = 5;
float indentOffset = EditorGUI.indentLevel * 15f;
var lineRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
lineRect.xMin += 4f;
lineRect.y += 2f;
var labelRect = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
var floatFieldLeft = new Rect(labelRect.xMax, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);
var sliderRect = new Rect(floatFieldLeft.xMax + kSeparatorWidth - indentOffset, lineRect.y, lineRect.width - labelRect.width - kFloatFieldWidth * 2 - kSeparatorWidth * 2, lineRect.height);
var floatFieldRight = new Rect(sliderRect.xMax + kSeparatorWidth - indentOffset, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);
EditorGUI.PrefixLabel(labelRect, title);
v.x = EditorGUI.FloatField(floatFieldLeft, v.x);
EditorGUI.MinMaxSlider(sliderRect, ref v.x, ref v.y, o.min, o.max);
v.y = EditorGUI.FloatField(floatFieldRight, v.y);
value.vector2Value = v;
return true;
}
}
}

107
ScriptableRenderPipeline/Core/Volume/Editor/Drawers/IntParameterDrawer.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering
{
[VolumeParameterDrawer(typeof(MinIntParameter))]
sealed class MinIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<MinIntParameter>();
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Max(v, o.min);
return true;
}
}
[VolumeParameterDrawer(typeof(NoInterpMinIntParameter))]
sealed class NoInterpMinIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<NoInterpMinIntParameter>();
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Max(v, o.min);
return true;
}
}
[VolumeParameterDrawer(typeof(MaxIntParameter))]
sealed class MaxIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<MaxIntParameter>();
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Min(v, o.max);
return true;
}
}
[VolumeParameterDrawer(typeof(NoInterpMaxIntParameter))]
sealed class NoInterpMaxIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<NoInterpMaxIntParameter>();
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Min(v, o.max);
return true;
}
}
[VolumeParameterDrawer(typeof(ClampedIntParameter))]
sealed class ClampedIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<ClampedIntParameter>();
EditorGUILayout.IntSlider(value, o.min, o.max, title);
value.intValue = Mathf.Clamp(value.intValue, o.min, o.max);
return true;
}
}
[VolumeParameterDrawer(typeof(NoInterpClampedIntParameter))]
sealed class NoInterpClampedIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<NoInterpClampedIntParameter>();
EditorGUILayout.IntSlider(value, o.min, o.max, title);
value.intValue = Mathf.Clamp(value.intValue, o.min, o.max);
return true;
}
}
}

77
ScriptableRenderPipeline/Core/Volume/Editor/Drawers/ClampedFloatParameterDrawer.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering
{
[VolumeParameterDrawer(typeof(ClampedFloatParameter))]
sealed class ClampedFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<ClampedFloatParameter>();
if (o.clampMode == ParameterClampMode.MinMax)
{
EditorGUILayout.Slider(value, o.min, o.max, title);
value.floatValue = Mathf.Clamp(value.floatValue, o.min, o.max);
}
else if (o.clampMode == ParameterClampMode.Min)
{
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Max(v, o.min);
}
else if (o.clampMode == ParameterClampMode.Max)
{
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Min(v, o.max);
}
else
{
return false;
}
return true;
}
}
[VolumeParameterDrawer(typeof(InstantClampedFloatParameter))]
sealed class InstantClampedFloatParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Float)
return false;
var o = parameter.GetObjectRef<InstantClampedFloatParameter>();
if (o.clampMode == ParameterClampMode.MinMax)
{
EditorGUILayout.Slider(value, o.min, o.max, title);
value.floatValue = Mathf.Clamp(value.floatValue, o.min, o.max);
}
else if (o.clampMode == ParameterClampMode.Min)
{
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Max(v, o.min);
}
else if (o.clampMode == ParameterClampMode.Max)
{
float v = EditorGUILayout.FloatField(title, value.floatValue);
value.floatValue = Mathf.Min(v, o.max);
}
else
{
return false;
}
return true;
}
}
}

77
ScriptableRenderPipeline/Core/Volume/Editor/Drawers/ClampedIntParameterDrawer.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering
{
[VolumeParameterDrawer(typeof(ClampedIntParameter))]
sealed class ClampedIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<ClampedIntParameter>();
if (o.clampMode == ParameterClampMode.MinMax)
{
EditorGUILayout.IntSlider(value, o.min, o.max, title);
value.intValue = Mathf.Clamp(value.intValue, o.min, o.max);
}
else if (o.clampMode == ParameterClampMode.Min)
{
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Max(v, o.min);
}
else if (o.clampMode == ParameterClampMode.Max)
{
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Min(v, o.max);
}
else
{
return false;
}
return true;
}
}
[VolumeParameterDrawer(typeof(InstantClampedIntParameter))]
sealed class InstantClampedIntParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Integer)
return false;
var o = parameter.GetObjectRef<InstantClampedIntParameter>();
if (o.clampMode == ParameterClampMode.MinMax)
{
EditorGUILayout.IntSlider(value, o.min, o.max, title);
value.intValue = Mathf.Clamp(value.intValue, o.min, o.max);
}
else if (o.clampMode == ParameterClampMode.Min)
{
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Max(v, o.min);
}
else if (o.clampMode == ParameterClampMode.Max)
{
int v = EditorGUILayout.IntField(title, value.intValue);
value.intValue = Mathf.Min(v, o.max);
}
else
{
return false;
}
return true;
}
}
}

42
ScriptableRenderPipeline/Core/Volume/Editor/Drawers/RangeParameterDrawer.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering
{
[VolumeParameterDrawer(typeof(RangeParameter))]
sealed class RangeParameterDrawer : VolumeParameterDrawer
{
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var value = parameter.value;
if (value.propertyType != SerializedPropertyType.Vector2)
return false;
var o = parameter.GetObjectRef<RangeParameter>();
var v = value.vector2Value;
// The layout system breaks alignement when mixing inspector fields with custom layouted
// fields as soon as a scrollbar is needed in the inspector, so we'll do the layout
// manually instead
const int kFloatFieldWidth = 50;
const int kSeparatorWidth = 5;
float indentOffset = EditorGUI.indentLevel * 15f;
var lineRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
lineRect.xMin += 4f;
lineRect.y += 2f;
var labelRect = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height);
var floatFieldLeft = new Rect(labelRect.xMax, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);
var sliderRect = new Rect(floatFieldLeft.xMax + kSeparatorWidth - indentOffset, lineRect.y, lineRect.width - labelRect.width - kFloatFieldWidth * 2 - kSeparatorWidth * 2, lineRect.height);
var floatFieldRight = new Rect(sliderRect.xMax + kSeparatorWidth - indentOffset, lineRect.y, kFloatFieldWidth + indentOffset, lineRect.height);
EditorGUI.PrefixLabel(labelRect, title);
v.x = EditorGUI.FloatField(floatFieldLeft, v.x);
EditorGUI.MinMaxSlider(sliderRect, ref v.x, ref v.y, o.min, o.max);
v.y = EditorGUI.FloatField(floatFieldRight, v.y);
value.vector2Value = v;
return true;
}
}
}

11
ScriptableRenderPipeline/Core/Volume/Editor/Drawers/RangeParameterDrawer.cs.meta


fileFormatVersion: 2
guid: 54ad01bd6d555e0438e364d8b0f17e06
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/Core/Volume/Editor/Drawers/ClampedFloatParameterDrawer.cs.meta → /ScriptableRenderPipeline/Core/Volume/Editor/Drawers/FloatParameterDrawer.cs.meta

/ScriptableRenderPipeline/Core/Volume/Editor/Drawers/ClampedIntParameterDrawer.cs.meta → /ScriptableRenderPipeline/Core/Volume/Editor/Drawers/IntParameterDrawer.cs.meta

正在加载...
取消
保存