Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 944b2f2

Browse files
committed
Merge remote-tracking branch 'refs/remotes/Unity-Technologies/master'
2 parents b426406 + 457db7c commit 944b2f2

File tree

7 files changed

+174
-225
lines changed

7 files changed

+174
-225
lines changed

PostProcessing/Editor/Utils/CurveEditor.cs

Lines changed: 113 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ public Selection(SerializedProperty curve, int keyframeIndex, Keyframe? keyframe
9494
this.keyframe = keyframe;
9595
}
9696
}
97+
98+
internal struct MenuAction
99+
{
100+
internal SerializedProperty curve;
101+
internal int index;
102+
internal Vector3 position;
103+
104+
internal MenuAction(SerializedProperty curve)
105+
{
106+
this.curve = curve;
107+
this.index = -1;
108+
this.position = Vector3.zero;
109+
}
110+
111+
internal MenuAction(SerializedProperty curve, int index)
112+
{
113+
this.curve = curve;
114+
this.index = index;
115+
this.position = Vector3.zero;
116+
}
117+
118+
internal MenuAction(SerializedProperty curve, Vector3 position)
119+
{
120+
this.curve = curve;
121+
this.index = -1;
122+
this.position = position;
123+
}
124+
}
97125
#endregion
98126

99127
#region Fields & properties
@@ -201,7 +229,8 @@ public void SetKeyframe(SerializedProperty curve, int keyframeIndex, Keyframe ke
201229

202230
public bool OnGUI(Rect rect)
203231
{
204-
m_Dirty = false;
232+
if (Event.current.type == EventType.Repaint)
233+
m_Dirty = false;
205234

206235
GUI.BeginClip(rect);
207236
{
@@ -392,14 +421,34 @@ void OnCurveGUI(Rect rect, SerializedProperty curve, CurveState state)
392421
EditMoveTangent(animCurve, keys, k, m_TangentEditMode, e.shift || !(alreadyBroken || e.control));
393422
}
394423

395-
// Keyframe selection
424+
// Keyframe selection & context menu
396425
if (e.type == EventType.mouseDown && rect.Contains(e.mousePosition))
397426
{
398427
if (hitRect.Contains(e.mousePosition))
399428
{
400-
SelectKeyframe(curve, k);
401-
m_EditMode = EditMode.Moving;
402-
e.Use();
429+
if (e.button == 0)
430+
{
431+
SelectKeyframe(curve, k);
432+
m_EditMode = EditMode.Moving;
433+
e.Use();
434+
}
435+
else if (e.button == 1)
436+
{
437+
// Keyframe context menu
438+
var menu = new GenericMenu();
439+
menu.AddItem(new GUIContent("Delete Key"), false, (x) =>
440+
{
441+
var action = (MenuAction)x;
442+
var curveValue = action.curve.animationCurveValue;
443+
action.curve.serializedObject.Update();
444+
RemoveKeyframe(curveValue, action.index);
445+
m_SelectedKeyframeIndex = -1;
446+
SaveCurve(action.curve, curveValue);
447+
action.curve.serializedObject.ApplyModifiedProperties();
448+
}, new MenuAction(curve, k));
449+
menu.ShowAsContext();
450+
e.Use();
451+
}
403452
}
404453
}
405454

@@ -455,6 +504,7 @@ void OnGeneralUI(Rect rect)
455504
GUI.FocusControl(null);
456505
m_SelectedCurve = null;
457506
m_SelectedKeyframeIndex = -1;
507+
bool used = false;
458508

459509
var hit = CanvasToCurve(e.mousePosition);
460510
float curvePickValue = CurveToCanvas(hit).y;
@@ -478,18 +528,35 @@ void OnGeneralUI(Rect rect)
478528
{
479529
m_SelectedCurve = prop;
480530

481-
// Create a keyframe on double-click on this curve
482-
if (e.clickCount == 2)
531+
if (e.clickCount == 2 && e.button == 0)
483532
{
533+
// Create a keyframe on double-click on this curve
484534
EditCreateKeyframe(animCurve, hit, true, state.zeroKeyConstantValue);
485535
SaveCurve(prop, animCurve);
486536
}
537+
else if (e.button == 1)
538+
{
539+
// Curve context menu
540+
var menu = new GenericMenu();
541+
menu.AddItem(new GUIContent("Add Key"), false, (x) =>
542+
{
543+
var action = (MenuAction)x;
544+
var curveValue = action.curve.animationCurveValue;
545+
action.curve.serializedObject.Update();
546+
EditCreateKeyframe(curveValue, hit, true, 0f);
547+
SaveCurve(action.curve, curveValue);
548+
action.curve.serializedObject.ApplyModifiedProperties();
549+
}, new MenuAction(prop, hit));
550+
menu.ShowAsContext();
551+
e.Use();
552+
used = true;
553+
}
487554
}
488555
}
489556

490-
// Create a keyframe on every curve on double-click
491-
if (e.clickCount == 2 && m_SelectedCurve == null)
557+
if (e.clickCount == 2 && e.button == 0 && m_SelectedCurve == null)
492558
{
559+
// Create a keyframe on every curve on double-click
493560
foreach (var curve in m_Curves)
494561
{
495562
if (!curve.Value.editable || !curve.Value.visible)
@@ -502,6 +569,14 @@ void OnGeneralUI(Rect rect)
502569
SaveCurve(prop, animCurve);
503570
}
504571
}
572+
else if (!used && e.button == 1)
573+
{
574+
// Global context menu
575+
var menu = new GenericMenu();
576+
menu.AddItem(new GUIContent("Add Key At Position"), false, () => ContextMenuAddKey(hit, false));
577+
menu.AddItem(new GUIContent("Add Key On Curves"), false, () => ContextMenuAddKey(hit, true));
578+
menu.ShowAsContext();
579+
}
505580

506581
e.Use();
507582
}
@@ -547,6 +622,35 @@ void SelectKeyframe(SerializedProperty curve, int keyframeIndex)
547622
Invalidate();
548623
}
549624

625+
void ContextMenuAddKey(Vector3 hit, bool createOnCurve)
626+
{
627+
SerializedObject serializedObject = null;
628+
629+
foreach (var curve in m_Curves)
630+
{
631+
if (!curve.Value.editable || !curve.Value.visible)
632+
continue;
633+
634+
var prop = curve.Key;
635+
var state = curve.Value;
636+
637+
if (serializedObject == null)
638+
{
639+
serializedObject = prop.serializedObject;
640+
serializedObject.Update();
641+
}
642+
643+
var animCurve = prop.animationCurveValue;
644+
EditCreateKeyframe(animCurve, hit, createOnCurve, state.zeroKeyConstantValue);
645+
SaveCurve(prop, animCurve);
646+
}
647+
648+
if (serializedObject != null)
649+
serializedObject.ApplyModifiedProperties();
650+
651+
Invalidate();
652+
}
653+
550654
void EditCreateKeyframe(AnimationCurve curve, Vector3 position, bool createOnCurve, float zeroKeyConstantValue)
551655
{
552656
float tangent = EvaluateTangent(curve, position.x);

PostProcessing/Resources/Shaders/ACES.cginc

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -505,52 +505,13 @@ half segmented_spline_c5_fwd(half x)
505505
return pow(10.0, logy);
506506
}
507507

508-
half segmented_spline_c5_fwd_opt(half x)
509-
{
510-
const float xmin = log10(0.18 * exp2(-15.0));
511-
const float xmid = log10(0.18);
512-
const float xmax = log10(0.18 * exp2(18.0));
513-
514-
// Clamp input
515-
x = min(47185.91999999996, max(5.493164062500005e-6, x));
516-
517-
float logx = log10(x);
518-
float logy;
519-
520-
if ((logx > xmin) && (logx < xmid))
521-
{
522-
const float coefs[6] = { -4.0000000000, -4.0000000000, -3.1573765773, -0.4852499958, 1.8477324706, 1.8477324706 }; // coefs for B-spline between minPoint and midPoint (units of log luminance)
523-
const float2 maxPoint = float2(0.18 * exp2(18.0), 10000.0); // {luminance, luminance} linear extension above this
524-
float knot_coord = 3.0 * (logx - xmin) / (xmid - xmin);
525-
int j = knot_coord;
526-
float t = knot_coord - j;
527-
528-
float3 cf = float3(coefs[j], coefs[j + 1], coefs[j + 2]);
529-
float3 monomials = float3(t * t, t, 1.0);
530-
logy = dot(monomials, mul(M, cf));
531-
}
532-
else
533-
{
534-
const float coefs[6] = { -0.7185482425, 2.0810307172, 3.6681241237, 4.0000000000, 4.0000000000, 4.0000000000 }; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
535-
float knot_coord = 3 * (logx - xmid) / (xmax - xmid);
536-
int j = knot_coord;
537-
float t = knot_coord - j;
538-
539-
float3 cf = float3(coefs[j], coefs[j + 1], coefs[j + 2]);
540-
float3 monomials = float3(t * t, t, 1.0);
541-
logy = dot(monomials, mul(M, cf));
542-
}
543-
544-
return pow(10.0, logy);
545-
}
546-
547508
half segmented_spline_c9_fwd(half x)
548509
{
549510
const half coefsLow[10] = { -1.6989700043, -1.6989700043, -1.4779000000, -1.2291000000, -0.8648000000, -0.4480000000, 0.0051800000, 0.4511080334, 0.9113744414, 0.9113744414 }; // coefs for B-spline between minPoint and midPoint (units of log luminance)
550511
const half coefsHigh[10] = { 0.5154386965, 0.8470437783, 1.1358000000, 1.3802000000, 1.5197000000, 1.5985000000, 1.6467000000, 1.6746091357, 1.6878733390, 1.6878733390 }; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
551-
const half2 minPoint = half2(segmented_spline_c5_fwd_opt(0.18 * exp2(-6.5)), 0.02); // {luminance, luminance} linear extension below this
552-
const half2 midPoint = half2(segmented_spline_c5_fwd_opt(0.18), 4.8); // {luminance, luminance}
553-
const half2 maxPoint = half2(segmented_spline_c5_fwd_opt(0.18 * exp2(6.5)), 48.0); // {luminance, luminance} linear extension above this
512+
const half2 minPoint = half2(segmented_spline_c5_fwd(0.18 * exp2(-6.5)), 0.02); // {luminance, luminance} linear extension below this
513+
const half2 midPoint = half2(segmented_spline_c5_fwd(0.18), 4.8); // {luminance, luminance}
514+
const half2 maxPoint = half2(segmented_spline_c5_fwd(0.18 * exp2(6.5)), 48.0); // {luminance, luminance} linear extension above this
554515
const half slopeLow = 0.0; // log-log slope of low linear extension
555516
const half slopeHigh = 0.04; // log-log slope of high linear extension
556517

@@ -639,9 +600,9 @@ half3 RRT(half3 aces)
639600

640601
// --- Apply the tonescale independently in rendering-space RGB --- //
641602
half3 rgbPost;
642-
rgbPost.x = segmented_spline_c5_fwd_opt(rgbPre.x);
643-
rgbPost.y = segmented_spline_c5_fwd_opt(rgbPre.y);
644-
rgbPost.z = segmented_spline_c5_fwd_opt(rgbPre.z);
603+
rgbPost.x = segmented_spline_c5_fwd(rgbPre.x);
604+
rgbPost.y = segmented_spline_c5_fwd(rgbPre.y);
605+
rgbPost.z = segmented_spline_c5_fwd(rgbPre.z);
645606

646607
// --- RGB rendering space to OCES --- //
647608
half3 rgbOces = mul(AP1_2_AP0_MAT, rgbPost);

PostProcessing/Resources/Shaders/Uber.shader

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,5 @@ Shader "Hidden/Post FX/Uber Shader"
319319

320320
ENDCG
321321
}
322-
323-
// (1) Dejittered depth debug
324-
Pass
325-
{
326-
CGPROGRAM
327-
328-
#pragma vertex VertDefault
329-
#pragma fragment Frag
330-
331-
float4 Frag(VaryingsDefault i) : SV_Target0
332-
{
333-
return float4(tex2D(_MainTex, i.uv).xxx, 1.0);
334-
}
335-
336-
ENDCG
337-
}
338322
}
339323
}

PostProcessing/Textures/Spectral LUTs/SpectralLut_BlueRed.tga.meta

Lines changed: 14 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)