From ab755b1d499b7393562dd708bf0e6a8e05340dec Mon Sep 17 00:00:00 2001 From: RSlysz Date: Wed, 21 Oct 2020 17:10:57 +0200 Subject: [PATCH 1/6] Update UV display --- .../Material/Decal/DecalProjectorEditor.cs | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs index 9baa9afe6b2..b7a554f9f93 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs @@ -284,7 +284,8 @@ static void DrawGizmosSelected(DecalProjector decalProjector, GizmoType gizmoTyp { handle.center = decalProjector.offset; handle.size = decalProjector.size; - handle.DrawHull(editMode == k_EditShapePreservingUV || editMode == k_EditShapeWithoutPreservingUV); + bool inEditMode = editMode == k_EditShapePreservingUV || editMode == k_EditShapeWithoutPreservingUV; + handle.DrawHull(inEditMode); Quaternion arrowRotation = Quaternion.LookRotation(Vector3.down, Vector3.right); float arrowSize = decalProjector.size.z * 0.25f; @@ -302,17 +303,34 @@ static void DrawGizmosSelected(DecalProjector decalProjector, GizmoType gizmoTyp //Handles.DrawLine(projectedPivot, projectedPivot + decalProjector.m_Size.y * 0.5f * Vector3.up); //Handles.DrawLine(projectedPivot, projectedPivot + decalProjector.m_Size.z * 0.5f * Vector3.forward); - //draw UV - Color face = Color.green; - face.a = 0.1f; - Vector2 size = new Vector2( - (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.x) * decalProjector.size.x, - (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.y) * decalProjector.size.y - ); - Vector2 start = (Vector2)projectedPivot - new Vector2(decalProjector.uvBias.x * size.x, decalProjector.uvBias.y * size.y); - using (new Handles.DrawingScope(face, Matrix4x4.TRS(decalProjector.transform.position - decalProjector.transform.rotation * (decalProjector.size * 0.5f + decalProjector.offset.z * Vector3.back), decalProjector.transform.rotation, Vector3.one))) + //draw UV and bolder edges + using (new Handles.DrawingScope(Matrix4x4.TRS(decalProjector.transform.position - decalProjector.transform.rotation * (decalProjector.size * 0.5f + decalProjector.offset.z * Vector3.back), decalProjector.transform.rotation, Vector3.one))) { - Handles.DrawSolidRectangleWithOutline(new Rect(start, size), face, Color.white); + if (inEditMode) + { + Vector2 size = new Vector2( + (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.x) * decalProjector.size.x, + (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.y) * decalProjector.size.y + ); + Vector2 start = (Vector2)projectedPivot - new Vector2(decalProjector.uvBias.x * size.x, decalProjector.uvBias.y * size.y); + Handles.DrawDottedLines( + new Vector3[] + { + start, start + new Vector2(size.x, 0), + start + new Vector2(size.x, 0), start + size, + start + size, start + new Vector2(0, size.y), + start + new Vector2(0, size.y), start + }, + 5f); + } + + Vector2 halfSize = decalProjector.size * .5f; + Vector2 halfSize2 = new Vector2(halfSize.x, -halfSize.y); + Vector2 center = (Vector2)projectedPivot + halfSize; + Handles.DrawLine(center - halfSize, center - halfSize2, 3f); + Handles.DrawLine(center - halfSize2, center + halfSize, 3f); + Handles.DrawLine(center + halfSize, center + halfSize2, 3f); + Handles.DrawLine(center + halfSize2, center - halfSize, 3f); } } } From c19d6d4681504ccc2206625ef18192656ff1e81f Mon Sep 17 00:00:00 2001 From: RSlysz Date: Wed, 21 Oct 2020 18:51:06 +0200 Subject: [PATCH 2/6] update edition of size in inspector --- .../Decal/DecalProjectorEditor.Skin.cs | 5 +++ .../Material/Decal/DecalProjectorEditor.cs | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs index a643a82a8b6..733e57ca04f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs @@ -9,6 +9,11 @@ partial class DecalProjectorEditor const string k_EditUVTooltip = "Modify the UV positions only"; static readonly GUIContent k_SizeContent = EditorGUIUtility.TrTextContent("Size", "Sets the size of the projector."); + static readonly GUIContent[] k_SizeSubContent = new[] { + EditorGUIUtility.TrTextContent("W", "Sets the width of the projector."), + EditorGUIUtility.TrTextContent("H", "Sets the height of the projector."), + EditorGUIUtility.TrTextContent("D", "Sets the projection depth of the projector.") + }; static readonly GUIContent k_MaterialContent = EditorGUIUtility.TrTextContent("Material", "Specifies the Material this component projects as a decal."); static readonly GUIContent k_DecalLayerMaskContent = EditorGUIUtility.TrTextContent("Decal Layer", "Specify the decal layer mask to use for this projector. RenderingLayerMask of Mesh matching this value will receive the decal. Enable Layers in Decal section of HDRP settings to access it."); static readonly GUIContent k_DistanceContent = EditorGUIUtility.TrTextContent("Draw Distance", "Sets the distance from the Camera at which HDRP stop rendering the decal."); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs index b7a554f9f93..4da7738d310 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs @@ -20,6 +20,8 @@ partial class DecalProjectorEditor : Editor SerializedProperty m_UVBiasProperty; SerializedProperty m_AffectsTransparencyProperty; SerializedProperty m_Size; + SerializedProperty[] m_SizeValues; + SerializedProperty m_OffsetZ; SerializedProperty m_FadeFactor; SerializedProperty m_DecalLayerMask; @@ -125,6 +127,13 @@ private void OnEnable() m_UVBiasProperty = serializedObject.FindProperty("m_UVBias"); m_AffectsTransparencyProperty = serializedObject.FindProperty("m_AffectsTransparency"); m_Size = serializedObject.FindProperty("m_Size"); + m_SizeValues = new[] + { + m_Size.FindPropertyRelative("x"), + m_Size.FindPropertyRelative("y"), + m_Size.FindPropertyRelative("z"), + }; + m_OffsetZ = serializedObject.FindProperty("m_Offset").FindPropertyRelative("z"); m_FadeFactor = serializedObject.FindProperty("m_FadeFactor"); m_DecalLayerMask = serializedObject.FindProperty("m_DecalLayerMask"); } @@ -365,8 +374,27 @@ public override void OnInspectorGUI() EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); - - EditorGUILayout.PropertyField(m_Size, k_SizeContent); + + Rect rect = EditorGUILayout.GetControlRect(); + EditorGUI.BeginProperty(rect, k_SizeSubContent[0], m_SizeValues[0]); + EditorGUI.BeginProperty(rect, k_SizeSubContent[1], m_SizeValues[1]); + EditorGUI.BeginProperty(rect, k_SizeSubContent[2], m_SizeValues[2]); + EditorGUI.BeginProperty(rect, k_SizeContent, m_OffsetZ); + float[] size = new float[3] { m_SizeValues[0].floatValue, m_SizeValues[1].floatValue, m_SizeValues[2].floatValue }; + EditorGUI.BeginChangeCheck(); + EditorGUI.MultiFloatField(rect, k_SizeContent, k_SizeSubContent, size); + if (EditorGUI.EndChangeCheck()) + { + m_SizeValues[0].floatValue = Mathf.Max(0, size[0]); + m_SizeValues[1].floatValue = Mathf.Max(0, size[1]); + m_SizeValues[2].floatValue = Mathf.Max(0, size[2]); + m_OffsetZ.floatValue = m_SizeValues[2].floatValue * 0.5f; + } + EditorGUI.EndProperty(); + EditorGUI.EndProperty(); + EditorGUI.EndProperty(); + EditorGUI.EndProperty(); + EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent); bool decalLayerEnabled = false; From 2481b0efb636f5ef9bb2423fa61f969c14eb0777 Mon Sep 17 00:00:00 2001 From: RSlysz Date: Thu, 22 Oct 2020 10:22:36 +0200 Subject: [PATCH 3/6] Separate Projection Depth on a new line --- .../Decal/DecalProjectorEditor.Skin.cs | 6 +++--- .../Material/Decal/DecalProjectorEditor.cs | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs index 733e57ca04f..afd5df1b830 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.Skin.cs @@ -10,10 +10,10 @@ partial class DecalProjectorEditor static readonly GUIContent k_SizeContent = EditorGUIUtility.TrTextContent("Size", "Sets the size of the projector."); static readonly GUIContent[] k_SizeSubContent = new[] { - EditorGUIUtility.TrTextContent("W", "Sets the width of the projector."), - EditorGUIUtility.TrTextContent("H", "Sets the height of the projector."), - EditorGUIUtility.TrTextContent("D", "Sets the projection depth of the projector.") + EditorGUIUtility.TrTextContent("Width", "Sets the width of the projection plan."), + EditorGUIUtility.TrTextContent("Height", "Sets the height of the projection plan.") }; + static readonly GUIContent k_ProjectionDepthContent = EditorGUIUtility.TrTextContent("Projection Depth", "Sets the projection depth of the projector."); static readonly GUIContent k_MaterialContent = EditorGUIUtility.TrTextContent("Material", "Specifies the Material this component projects as a decal."); static readonly GUIContent k_DecalLayerMaskContent = EditorGUIUtility.TrTextContent("Decal Layer", "Specify the decal layer mask to use for this projector. RenderingLayerMask of Mesh matching this value will receive the decal. Enable Layers in Decal section of HDRP settings to access it."); static readonly GUIContent k_DistanceContent = EditorGUIUtility.TrTextContent("Draw Distance", "Sets the distance from the Camera at which HDRP stop rendering the decal."); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs index 4da7738d310..25162368f5f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs @@ -378,23 +378,25 @@ public override void OnInspectorGUI() Rect rect = EditorGUILayout.GetControlRect(); EditorGUI.BeginProperty(rect, k_SizeSubContent[0], m_SizeValues[0]); EditorGUI.BeginProperty(rect, k_SizeSubContent[1], m_SizeValues[1]); - EditorGUI.BeginProperty(rect, k_SizeSubContent[2], m_SizeValues[2]); - EditorGUI.BeginProperty(rect, k_SizeContent, m_OffsetZ); - float[] size = new float[3] { m_SizeValues[0].floatValue, m_SizeValues[1].floatValue, m_SizeValues[2].floatValue }; + float[] size = new float[2] { m_SizeValues[0].floatValue, m_SizeValues[1].floatValue }; EditorGUI.BeginChangeCheck(); EditorGUI.MultiFloatField(rect, k_SizeContent, k_SizeSubContent, size); if (EditorGUI.EndChangeCheck()) { m_SizeValues[0].floatValue = Mathf.Max(0, size[0]); m_SizeValues[1].floatValue = Mathf.Max(0, size[1]); - m_SizeValues[2].floatValue = Mathf.Max(0, size[2]); - m_OffsetZ.floatValue = m_SizeValues[2].floatValue * 0.5f; } EditorGUI.EndProperty(); EditorGUI.EndProperty(); - EditorGUI.EndProperty(); - EditorGUI.EndProperty(); - + + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(m_SizeValues[2], k_ProjectionDepthContent); + if (EditorGUI.EndChangeCheck()) + { + m_SizeValues[2].floatValue = Mathf.Max(0, size[2]); + m_OffsetZ.floatValue = m_SizeValues[2].floatValue * 0.5f; + } + EditorGUILayout.PropertyField(m_MaterialProperty, k_MaterialContent); bool decalLayerEnabled = false; From 5f13f6bc9c5e1533a54d49114811549c6d9bae39 Mon Sep 17 00:00:00 2001 From: RSlysz Date: Thu, 22 Oct 2020 10:34:35 +0200 Subject: [PATCH 4/6] Update CHANGELOG.md --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index c3d62dddd05..4fef66c0c08 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -17,9 +17,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed the possibility to have a shader with a pre-refraction render queue and refraction enabled at the same time. - Fixed a migration issue with the rendering queue in ShaderGraph when upgrading to 10.x; - Fixed upside down XR occlusion mesh. +- Fixed issue where pivot of DecalProjector was not aligned anymore on Transform position when manipulating the size of the projector from the Inspector. ### Changed - Combined occlusion meshes into one to reduce draw calls and state changes with XR single-pass. +- Removed green coloration of the UV on the DecalProjector gizmo. ## [10.1.0] - 2020-10-12 From 0d07e3854e74f8537f532211c00ecbff10cf491c Mon Sep 17 00:00:00 2001 From: RSlysz Date: Fri, 23 Oct 2020 12:54:21 +0200 Subject: [PATCH 5/6] fix error on y UV --- .../Editor/Material/Decal/DecalProjectorEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs index 25162368f5f..8549b004e9e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs @@ -319,7 +319,7 @@ static void DrawGizmosSelected(DecalProjector decalProjector, GizmoType gizmoTyp { Vector2 size = new Vector2( (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.x) * decalProjector.size.x, - (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.y) * decalProjector.size.y + (decalProjector.uvScale.y > 100000 || decalProjector.uvScale.y < -100000 ? 0f : 1f / decalProjector.uvScale.y) * decalProjector.size.y ); Vector2 start = (Vector2)projectedPivot - new Vector2(decalProjector.uvBias.x * size.x, decalProjector.uvBias.y * size.y); Handles.DrawDottedLines( From 189da368283c0662613b7e28db7e6917c096da39 Mon Sep 17 00:00:00 2001 From: RSlysz Date: Fri, 23 Oct 2020 12:55:07 +0200 Subject: [PATCH 6/6] fix error when using shortchut where Decal is not selected --- .../Material/Decal/DecalProjectorEditor.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs index 8549b004e9e..2b9dd7f5acf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/DecalProjectorEditor.cs @@ -496,12 +496,24 @@ public override void OnInspectorGUI() } [Shortcut("HDRP/Decal: Handle changing size stretching UV", typeof(SceneView), KeyCode.Keypad1, ShortcutModifiers.Action)] - static void EnterEditModeWithoutPreservingUV(ShortcutArguments args) => + static void EnterEditModeWithoutPreservingUV(ShortcutArguments args) + { + //If editor is not there, then the selected GameObject does not contains a DecalProjector + if (s_Owner == null || s_Owner.Equals(null)) + return; + ChangeEditMode(k_EditShapeWithoutPreservingUV, (s_Owner as DecalProjectorEditor).GetBoundsGetter(), s_Owner); + } [Shortcut("HDRP/Decal: Handle changing size cropping UV", typeof(SceneView), KeyCode.Keypad2, ShortcutModifiers.Action)] - static void EnterEditModePreservingUV(ShortcutArguments args) => + static void EnterEditModePreservingUV(ShortcutArguments args) + { + //If editor is not there, then the selected GameObject does not contains a DecalProjector + if (s_Owner == null || s_Owner.Equals(null)) + return; + ChangeEditMode(k_EditShapePreservingUV, (s_Owner as DecalProjectorEditor).GetBoundsGetter(), s_Owner); + } //[TODO: add editable pivot. Uncomment this when ready] //[Shortcut("HDRP/Decal: Handle changing pivot position while preserving UV position", typeof(SceneView), KeyCode.Keypad3, ShortcutModifiers.Action)]