Skip to content

Commit d440e11

Browse files
dbastiendbastien
authored andcommitted
address cr feedback
1 parent 0c1388d commit d440e11

File tree

6 files changed

+581
-560
lines changed

6 files changed

+581
-560
lines changed

Assets/HoloToolkit/Utilities/Scripts/NearPlaneFade.cs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,55 @@
33

44
using UnityEngine;
55

6-
/// <summary>
7-
/// Sets global shader variables relating to near plane fade
8-
/// </summary>
9-
[ExecuteInEditMode]
10-
public class NearPlaneFade : MonoBehaviour
6+
namespace HoloToolkit.Unity
117
{
12-
public float FadeDistanceStart = 0.85f;
13-
public float FadeDistanceEnd = 0.5f;
14-
15-
public bool NearPlaneFadeOn = true;
16-
17-
private const string FadeKeywordOn = "_NEAR_PLANE_FADE_ON";
18-
19-
private int fadeDistancePropertyID;
20-
21-
void Awake()
8+
/// <summary>
9+
/// Sets global shader variables relating to near plane fade
10+
/// </summary>
11+
[ExecuteInEditMode]
12+
public class NearPlaneFade : MonoBehaviour
2213
{
23-
fadeDistancePropertyID = Shader.PropertyToID("_NearPlaneFadeDistance");
24-
UpdateShaderParams();
25-
}
14+
public float FadeDistanceStart = 0.85f;
15+
public float FadeDistanceEnd = 0.5f;
2616

27-
private void OnValidate()
28-
{
29-
UpdateShaderParams();
30-
}
17+
public bool NearPlaneFadeOn = true;
3118

32-
private void UpdateShaderParams()
33-
{
34-
FadeDistanceStart = Mathf.Max(FadeDistanceStart, 0);
35-
FadeDistanceEnd = Mathf.Max(FadeDistanceEnd, 0);
36-
FadeDistanceStart = Mathf.Max(FadeDistanceStart, FadeDistanceEnd);
19+
private const string FadeKeywordOn = "_NEAR_PLANE_FADE_ON";
3720

38-
if (FadeDistanceStart != FadeDistanceEnd)
21+
private int fadeDistancePropertyID;
22+
23+
void Awake()
3924
{
40-
float rangeInverse = 1.0f / (FadeDistanceStart - FadeDistanceEnd);
41-
var fadeDist = new Vector4(-FadeDistanceEnd * rangeInverse, rangeInverse, 0, 0);
42-
Shader.SetGlobalVector(fadeDistancePropertyID, fadeDist);
25+
fadeDistancePropertyID = Shader.PropertyToID("_NearPlaneFadeDistance");
26+
UpdateShaderParams();
4327
}
4428

45-
if (NearPlaneFadeOn)
29+
void OnValidate()
4630
{
47-
Shader.EnableKeyword(FadeKeywordOn);
31+
UpdateShaderParams();
4832
}
49-
else
33+
34+
private void UpdateShaderParams()
5035
{
51-
Shader.DisableKeyword(FadeKeywordOn);
36+
FadeDistanceStart = Mathf.Max(FadeDistanceStart, 0);
37+
FadeDistanceEnd = Mathf.Max(FadeDistanceEnd, 0);
38+
FadeDistanceStart = Mathf.Max(FadeDistanceStart, FadeDistanceEnd);
39+
40+
if (FadeDistanceStart != FadeDistanceEnd)
41+
{
42+
float rangeInverse = 1.0f / (FadeDistanceStart - FadeDistanceEnd);
43+
var fadeDist = new Vector4(-FadeDistanceEnd * rangeInverse, rangeInverse, 0, 0);
44+
Shader.SetGlobalVector(fadeDistancePropertyID, fadeDist);
45+
}
46+
47+
if (NearPlaneFadeOn)
48+
{
49+
Shader.EnableKeyword(FadeKeywordOn);
50+
}
51+
else
52+
{
53+
Shader.DisableKeyword(FadeKeywordOn);
54+
}
5255
}
5356
}
54-
}
57+
}

Assets/HoloToolkit/Utilities/Shaders/FastConfigurable/Editor/CustomMaterialEditor.cs

Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,127 +4,130 @@
44
using UnityEditor;
55
using UnityEngine;
66

7-
/// <summary>
8-
/// Helper class for custom material editors
9-
/// </summary>
10-
public static class CustomMaterialEditor
7+
namespace HoloToolkit.Unity
118
{
12-
public static Rect TextureWithToggleableColorSingleLine
9+
/// <summary>
10+
/// Helper class for custom material editors
11+
/// </summary>
12+
public static class CustomMaterialEditor
13+
{
14+
public static Rect TextureWithToggleableColorSingleLine
1315
(
1416
MaterialEditor matEditor,
1517
GUIContent label,
1618
MaterialProperty textureProp,
1719
MaterialProperty colorToggleProp,
1820
MaterialProperty colorProp
1921
)
20-
{
21-
var lineRect = GetControlRectForSingleLine();
22-
var controlRect = lineRect;
22+
{
23+
var lineRect = GetControlRectForSingleLine();
24+
var controlRect = lineRect;
2325

24-
//TexturePropertyMiniThumbnail handles begin and end animation checks
25-
matEditor.TexturePropertyMiniThumbnail(lineRect, textureProp, label.text, label.tooltip);
26+
//TexturePropertyMiniThumbnail handles begin and end animation checks
27+
matEditor.TexturePropertyMiniThumbnail(lineRect, textureProp, label.text, label.tooltip);
2628

27-
controlRect.x += EditorGUIUtility.labelWidth;
28-
controlRect.width = EditorGUIUtility.fieldWidth;
29+
controlRect.x += EditorGUIUtility.labelWidth;
30+
controlRect.width = EditorGUIUtility.fieldWidth;
2931

30-
GUIContent toggleTooltip = new GUIContent();
31-
toggleTooltip.text = string.Empty;
32-
toggleTooltip.tooltip = "Enable/Disable color";
32+
GUIContent toggleTooltip = new GUIContent();
33+
toggleTooltip.text = string.Empty;
34+
toggleTooltip.tooltip = "Enable/Disable color";
3335

34-
//label indent of -1 is the secret sauce to make it aligned with right aligned toggles that come after labels
35-
//ShaderProperty handles begin and end animation checks
36-
matEditor.ShaderProperty(controlRect, colorToggleProp, toggleTooltip, -1);
36+
//label indent of -1 is the secret sauce to make it aligned with right aligned toggles that come after labels
37+
//ShaderProperty handles begin and end animation checks
38+
matEditor.ShaderProperty(controlRect, colorToggleProp, toggleTooltip, -1);
3739

38-
if (colorToggleProp.floatValue != 0.0f)
39-
{
40-
controlRect.x += EditorStyles.toggle.fixedWidth;
41-
controlRect.x += EditorStyles.toggle.padding.right;
40+
if (colorToggleProp.floatValue != 0.0f)
41+
{
42+
controlRect.x += EditorStyles.toggle.fixedWidth;
43+
controlRect.x += EditorStyles.toggle.padding.right;
4244

43-
//size it to take up the remainder of the space
44-
controlRect.width = lineRect.width - controlRect.x;
45+
//size it to take up the remainder of the space
46+
controlRect.width = lineRect.width - controlRect.x;
4547

46-
GUIContent tooltipOnly = new GUIContent();
47-
tooltipOnly.text = string.Empty;
48-
tooltipOnly.tooltip = label.tooltip;
49-
EditorGUI.BeginChangeCheck();
48+
GUIContent tooltipOnly = new GUIContent();
49+
tooltipOnly.text = string.Empty;
50+
tooltipOnly.tooltip = label.tooltip;
51+
EditorGUI.BeginChangeCheck();
5052

51-
var color = EditorGUI.ColorField(controlRect, tooltipOnly, colorProp.colorValue);
53+
var color = EditorGUI.ColorField(controlRect, tooltipOnly, colorProp.colorValue);
5254

53-
if (EditorGUI.EndChangeCheck())
54-
{
55-
colorProp.colorValue = color;
55+
if (EditorGUI.EndChangeCheck())
56+
{
57+
colorProp.colorValue = color;
58+
}
5659
}
57-
}
5860

59-
return lineRect;
60-
}
61+
return lineRect;
62+
}
6163

62-
public static void SetScaleOffsetKeywords
64+
public static void SetScaleOffsetKeywords
6365
(
6466
MaterialEditor matEditor,
6567
MaterialProperty textureProp,
6668
MaterialProperty scaleOffsetProp
6769
)
68-
{
69-
var texScaleOffset = scaleOffsetProp.vectorValue;
70-
bool usesScale = texScaleOffset.x != 1.0f || texScaleOffset.y != 1.0f;
71-
bool usesOffset = texScaleOffset.z != 0.0f || texScaleOffset.w != 0.0f;
70+
{
71+
var texScaleOffset = scaleOffsetProp.vectorValue;
72+
bool usesScale = texScaleOffset.x != 1.0f || texScaleOffset.y != 1.0f;
73+
bool usesOffset = texScaleOffset.z != 0.0f || texScaleOffset.w != 0.0f;
7274

73-
var mat = matEditor.target as Material;
75+
var mat = matEditor.target as Material;
7476

75-
var scaleKeyword = textureProp.name + "_SCALE_ON";
76-
var offsetKeyword = textureProp.name + "_OFFSET_ON";
77+
var scaleKeyword = textureProp.name + "_SCALE_ON";
78+
var offsetKeyword = textureProp.name + "_OFFSET_ON";
7779

78-
ShaderGUIUtils.SetKeyword(mat, scaleKeyword, usesScale);
79-
ShaderGUIUtils.SetKeyword(mat, offsetKeyword, usesOffset);
80-
}
80+
ShaderGUIUtils.SetKeyword(mat, scaleKeyword, usesScale);
81+
ShaderGUIUtils.SetKeyword(mat, offsetKeyword, usesOffset);
82+
}
8183

82-
public static Rect TextureWithToggleableColorAutoScaleOffsetSingleLine
84+
public static Rect TextureWithToggleableColorAutoScaleOffsetSingleLine
8385
(
8486
MaterialEditor matEditor,
8587
GUIContent label,
8688
MaterialProperty textureProp,
8789
MaterialProperty colorToggleProp, MaterialProperty colorProp,
8890
MaterialProperty scaleOffsetProp
8991
)
90-
{
91-
var rect = CustomMaterialEditor.TextureWithToggleableColorSingleLine(matEditor, label, textureProp, colorToggleProp, colorProp);
92+
{
93+
var rect = CustomMaterialEditor.TextureWithToggleableColorSingleLine(matEditor, label, textureProp, colorToggleProp, colorProp);
9294

93-
CustomMaterialEditor.SetScaleOffsetKeywords(matEditor, textureProp, scaleOffsetProp);
95+
CustomMaterialEditor.SetScaleOffsetKeywords(matEditor, textureProp, scaleOffsetProp);
9496

95-
return rect;
96-
}
97+
return rect;
98+
}
9799

98-
public static void TextureScaleOffsetVector4Property(MaterialEditor matEditor, GUIContent label, MaterialProperty scaleOffsetProp)
99-
{
100-
matEditor.BeginAnimatedCheck(scaleOffsetProp);
100+
public static void TextureScaleOffsetVector4Property(MaterialEditor matEditor, GUIContent label, MaterialProperty scaleOffsetProp)
101+
{
102+
matEditor.BeginAnimatedCheck(scaleOffsetProp);
101103

102-
EditorGUI.BeginChangeCheck();
104+
EditorGUI.BeginChangeCheck();
103105

104-
Vector4 scaleOffsetVector = scaleOffsetProp.vectorValue;
106+
Vector4 scaleOffsetVector = scaleOffsetProp.vectorValue;
105107

106-
Vector2 textureScale = new Vector2(scaleOffsetVector.x, scaleOffsetVector.y);
107-
textureScale = EditorGUILayout.Vector2Field(Styles.scale, textureScale, new GUILayoutOption[0]);
108+
Vector2 textureScale = new Vector2(scaleOffsetVector.x, scaleOffsetVector.y);
109+
textureScale = EditorGUILayout.Vector2Field(Styles.scale, textureScale, new GUILayoutOption[0]);
108110

109-
Vector2 textureOffset = new Vector2(scaleOffsetVector.z, scaleOffsetVector.w);
110-
textureOffset = EditorGUILayout.Vector2Field(Styles.offset, textureOffset, new GUILayoutOption[0]);
111+
Vector2 textureOffset = new Vector2(scaleOffsetVector.z, scaleOffsetVector.w);
112+
textureOffset = EditorGUILayout.Vector2Field(Styles.offset, textureOffset, new GUILayoutOption[0]);
111113

112-
if (EditorGUI.EndChangeCheck())
113-
{
114-
scaleOffsetProp.vectorValue = new Vector4(textureScale.x, textureScale.y, textureOffset.x, textureOffset.y);
115-
}
114+
if (EditorGUI.EndChangeCheck())
115+
{
116+
scaleOffsetProp.vectorValue = new Vector4(textureScale.x, textureScale.y, textureOffset.x, textureOffset.y);
117+
}
116118

117-
matEditor.EndAnimatedCheck();
118-
}
119+
matEditor.EndAnimatedCheck();
120+
}
119121

120-
public static Rect GetControlRectForSingleLine()
121-
{
122-
return EditorGUILayout.GetControlRect(true, 18f, EditorStyles.layerMaskField, new GUILayoutOption[0]);
123-
}
122+
public static Rect GetControlRectForSingleLine()
123+
{
124+
return EditorGUILayout.GetControlRect(true, 18f, EditorStyles.layerMaskField, new GUILayoutOption[0]);
125+
}
124126

125-
private static class Styles
126-
{
127-
public static GUIContent scale = new GUIContent("Tiling", "Scale of texture - multiplied by texture coordinates from vertices");
128-
public static GUIContent offset = new GUIContent("Offset", "Offset of texture - added to texture coordinates from vertices");
127+
private static class Styles
128+
{
129+
public static GUIContent scale = new GUIContent("Tiling", "Scale of texture - multiplied by texture coordinates from vertices");
130+
public static GUIContent offset = new GUIContent("Offset", "Offset of texture - added to texture coordinates from vertices");
131+
}
129132
}
130133
}

Assets/HoloToolkit/Utilities/Shaders/FastConfigurable/Editor/FastConfigurable2SidedGUI.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,30 @@
33

44
using UnityEditor;
55

6-
/// <summary>
7-
/// Editor for FastConfigurable2Sided shader
8-
/// </summary>
9-
public class FastConfigurable2SidedGUI : FastConfigurableGUI
6+
namespace HoloToolkit.Unity
107
{
11-
protected override void ShowOutputConfigurationGUI(MaterialEditor matEditor)
8+
/// <summary>
9+
/// Editor for FastConfigurable2Sided shader
10+
/// </summary>
11+
public class FastConfigurable2SidedGUI : FastConfigurableGUI
1212
{
13-
ShaderGUIUtils.BeginHeader("Output Configuration");
13+
protected override void ShowOutputConfigurationGUI(MaterialEditor matEditor)
1414
{
15-
matEditor.ShaderProperty(zTest, Styles.zTest);
16-
matEditor.ShaderProperty(zWrite, Styles.zWrite);
17-
matEditor.ShaderProperty(colorWriteMask, Styles.colorWriteMask);
18-
matEditor.RenderQueueField();
15+
ShaderGUIUtils.BeginHeader("Output Configuration");
16+
{
17+
matEditor.ShaderProperty(zTest, Styles.zTest);
18+
matEditor.ShaderProperty(zWrite, Styles.zWrite);
19+
matEditor.ShaderProperty(colorWriteMask, Styles.colorWriteMask);
20+
matEditor.RenderQueueField();
21+
}
22+
ShaderGUIUtils.EndHeader();
1923
}
20-
ShaderGUIUtils.EndHeader();
21-
}
2224

23-
protected override void CacheOutputConfigurationProperties(MaterialProperty[] props)
24-
{
25-
zTest = FindProperty("_ZTest", props);
26-
zWrite = FindProperty("_ZWrite", props);
27-
colorWriteMask = FindProperty("_ColorWriteMask", props);
25+
protected override void CacheOutputConfigurationProperties(MaterialProperty[] props)
26+
{
27+
zTest = FindProperty("_ZTest", props);
28+
zWrite = FindProperty("_ZWrite", props);
29+
colorWriteMask = FindProperty("_ColorWriteMask", props);
30+
}
2831
}
29-
}
32+
}

0 commit comments

Comments
 (0)