Skip to content

Commit

Permalink
Merge branch 'release/0.8.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvtesh committed Nov 18, 2021
2 parents b4d88ac + e585221 commit f415a97
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 51 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/).

## [0.8.5] - 2021.11.18

Bugfixes and improvements.

### Added
- Added support for HDR color pickers ([#42](https://github.com/Arvtesh/UnityFx.Outline/issues/42)).

### Fixed
- Fixed URP depth testing with MSAA enabled when using `OutlineLayerCollection`, thanks @AGM-GR for the help ([#39](https://github.com/Arvtesh/UnityFx.Outline/issues/39)).
- Added loop unroll statement to make shaders compatible with some platforms (WebGL 1.0) ([#45](https://github.com/Arvtesh/UnityFx.Outline/issues/45)).
- Removed `BeginSample`/`EndSample` profiler calls when rendering outlines to get rid of the editor errors ([#44](https://github.com/Arvtesh/UnityFx.Outline/issues/44)).

## [0.8.4] - 2021.08.17

Misc improvements.

### Added
Expand Down
10 changes: 10 additions & 0 deletions Outline.Core/Packages/UnityFx.Outline/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/).

## [0.8.5] - 2021.11.18

Bugfixes and improvements.

### Added
- Added support for HDR color pickers ([#42](https://github.com/Arvtesh/UnityFx.Outline/issues/42)).

### Fixed
- Added loop unroll statement to make shaders compatible with some platforms (WebGL 1.0) ([#45](https://github.com/Arvtesh/UnityFx.Outline/issues/45)).

## [0.8.4] - 2021.08.17
Misc improvements.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ namespace UnityFx.Outline
{
public static class OutlineEditorUtility
{
public static readonly GUIContent FilterSettingsContent = new GUIContent("Outline Filter Settings", "");
public static readonly GUIContent LayerMaskContent = new GUIContent("Layer Mask", OutlineResources.OutlineLayerMaskTooltip);
public static readonly GUIContent RenderingLayerMaskContent = new GUIContent("Rendering Layer Mask", OutlineResources.OutlineRenderingLayerMaskTooltip);
public static readonly GUIContent ColorContent = new GUIContent("Color", "Outline color.");
public static readonly GUIContent WidthContent = new GUIContent("Width", "Outline width in pixels.");
public static readonly GUIContent RenderFlagsContent = new GUIContent("Render Flags", "Outline render flags. Multiple values can be selected at the same time.");
public static readonly GUIContent BlurIntensityContent = new GUIContent("Blur Intensity", "Outline intensity value. It is only usable for blurred outlines.");
public static readonly GUIContent AlphaCutoffContent = new GUIContent("Alpha Cutoff", "Outline alpha cutoff value. It is only usable when alpha testing is enabled and the material doesn't have _Cutoff property.");

public static void RenderPreview(OutlineLayer layer, int layerIndex, bool showObjects)
{
if (layer != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ private void OnDrawLayer(Rect rect, int index, bool isActive, bool isFocused)
{
EditorGUI.BeginDisabledGroup(obj != null);

color = EditorGUI.ColorField(new Rect(rect.x, y, rect.width, lineHeight), "Color", color);
color = EditorGUI.ColorField(new Rect(rect.x, y, rect.width, lineHeight), OutlineEditorUtility.ColorContent, color, true, true, true);
y += lineOffset;

width = EditorGUI.IntSlider(new Rect(rect.x, y, rect.width, lineHeight), "Width", width, OutlineResources.MinWidth, OutlineResources.MaxWidth);
width = EditorGUI.IntSlider(new Rect(rect.x, y, rect.width, lineHeight), OutlineEditorUtility.WidthContent, width, OutlineResources.MinWidth, OutlineResources.MaxWidth);
y += lineOffset;

renderMode = (OutlineRenderFlags)EditorGUI.EnumFlagsField(new Rect(rect.x, y, rect.width, lineHeight), "Render Flags", renderMode);
renderMode = (OutlineRenderFlags)EditorGUI.EnumFlagsField(new Rect(rect.x, y, rect.width, lineHeight), OutlineEditorUtility.RenderFlagsContent, renderMode);
y += lineOffset;

if ((renderMode & OutlineRenderFlags.Blurred) != 0)
{
blurIntensity = EditorGUI.Slider(new Rect(rect.x, y, rect.width, lineHeight), "Blur Intensity", blurIntensity, OutlineResources.MinIntensity, OutlineResources.MaxIntensity);
blurIntensity = EditorGUI.Slider(new Rect(rect.x, y, rect.width, lineHeight), OutlineEditorUtility.BlurIntensityContent, blurIntensity, OutlineResources.MinIntensity, OutlineResources.MaxIntensity);
y += lineOffset;
}

if ((renderMode & OutlineRenderFlags.EnableAlphaTesting) != 0)
{
alphaCutoff = EditorGUI.Slider(new Rect(rect.x, y, rect.width, lineHeight), "Alpha Cutoff", alphaCutoff, OutlineResources.MinAlphaCutoff, OutlineResources.MaxAlphaCutoff);
alphaCutoff = EditorGUI.Slider(new Rect(rect.x, y, rect.width, lineHeight), OutlineEditorUtility.AlphaCutoffContent, alphaCutoff, OutlineResources.MinAlphaCutoff, OutlineResources.MaxAlphaCutoff);
}

EditorGUI.EndDisabledGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ public class OutlineSettingsEditor : Editor
private const string _cutoffPropName = "_outlineAlphaCutoff";
private const string _renderModePropName = "_outlineMode";

private static readonly GUIContent _filterModeContent = new GUIContent("Outline Filter Settings", "");
private static readonly GUIContent _layerMaskContent = new GUIContent("Layer Mask", OutlineResources.OutlineLayerMaskTooltip);
private static readonly GUIContent _renderingLayerMaskContent = new GUIContent("Rendering Layer Mask", OutlineResources.OutlineRenderingLayerMaskTooltip);
private static readonly GUIContent _colorContent = new GUIContent("Color", "Outline color.");
private static readonly GUIContent _widthContent = new GUIContent("Width", "Outline width in pixels.");
private static readonly GUIContent _renderModeContent = new GUIContent("Render Flags", "Outline render flags. Multiple values can be selected at the same time.");
private static readonly GUIContent _intensityContent = new GUIContent("Blur Intensity", "Outline intensity value. It is only usable for blurred outlines.");
private static readonly GUIContent _cutoffContent = new GUIContent("Alpha Cutoff", "Outline alpha cutoff value. It is only usable when alpha testing is enabled and the material doesn't have _Cutoff property.");

public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Expand All @@ -42,20 +33,22 @@ public override void OnInspectorGUI()
var renderModeProp = serializedObject.FindProperty(_renderModePropName);
var renderMode = (OutlineRenderFlags)renderModeProp.intValue;

EditorGUILayout.PropertyField(colorProp, _colorContent);
EditorGUILayout.PropertyField(widthProp, _widthContent);
//EditorGUILayout.PropertyField(colorProp, _colorContent);
colorProp.colorValue = EditorGUILayout.ColorField(OutlineEditorUtility.ColorContent, colorProp.colorValue, true, true, true);

EditorGUILayout.PropertyField(widthProp, OutlineEditorUtility.WidthContent);

//EditorGUILayout.PropertyField(renderModeProp, _renderModeContent);
renderModeProp.intValue = (int)(OutlineRenderFlags)EditorGUILayout.EnumFlagsField(_renderModeContent, renderMode);
renderModeProp.intValue = (int)(OutlineRenderFlags)EditorGUILayout.EnumFlagsField(OutlineEditorUtility.RenderFlagsContent, renderMode);

if ((renderMode & OutlineRenderFlags.Blurred) != 0)
{
EditorGUILayout.PropertyField(intensityProp, _intensityContent);
EditorGUILayout.PropertyField(intensityProp, OutlineEditorUtility.BlurIntensityContent);
}

if ((renderMode & OutlineRenderFlags.EnableAlphaTesting) != 0)
{
EditorGUILayout.PropertyField(cutoffProp, _cutoffContent);
EditorGUILayout.PropertyField(cutoffProp, OutlineEditorUtility.AlphaCutoffContent);
}

serializedObject.ApplyModifiedProperties();
Expand Down Expand Up @@ -159,14 +152,14 @@ internal static void DrawSettingsWithMask(Rect rc, SerializedProperty property)
var lineCy = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
var filterModeProp = property.FindPropertyRelative(_filterModePropName);

EditorGUI.PropertyField(new Rect(rc.x, rc.y, rc.width, EditorGUIUtility.singleLineHeight), filterModeProp, _filterModeContent);
EditorGUI.PropertyField(new Rect(rc.x, rc.y, rc.width, EditorGUIUtility.singleLineHeight), filterModeProp, OutlineEditorUtility.FilterSettingsContent);

if (filterModeProp.intValue == (int)OutlineFilterMode.UseLayerMask)
{
var layerMaskProp = property.FindPropertyRelative(_layerMaskPropName);

EditorGUI.indentLevel += 1;
EditorGUI.PropertyField(new Rect(rc.x, rc.y + lineCy, rc.width, EditorGUIUtility.singleLineHeight), layerMaskProp, _layerMaskContent);
EditorGUI.PropertyField(new Rect(rc.x, rc.y + lineCy, rc.width, EditorGUIUtility.singleLineHeight), layerMaskProp, OutlineEditorUtility.LayerMaskContent);
EditorGUI.indentLevel -= 1;

DrawSettingsInstance(new Rect(rc.x, rc.y + lineCy * 2, rc.width, rc.height - lineCy), property);
Expand All @@ -176,10 +169,10 @@ internal static void DrawSettingsWithMask(Rect rc, SerializedProperty property)
var renderingLayerMaskProp = property.FindPropertyRelative(_renderingLayerMaskPropName);

EditorGUI.indentLevel += 1;
EditorGUI.PropertyField(new Rect(rc.x, rc.y + lineCy, rc.width, EditorGUIUtility.singleLineHeight), renderingLayerMaskProp, _renderingLayerMaskContent);
EditorGUI.PropertyField(new Rect(rc.x, rc.y + lineCy, rc.width, EditorGUIUtility.singleLineHeight), renderingLayerMaskProp, OutlineEditorUtility.RenderingLayerMaskContent);
EditorGUI.indentLevel -= 1;

DrawSettingsInstance(new Rect(rc.x, rc.y + lineCy * 2, rc.width, rc.height - lineCy), property);
DrawSettingsInstance(new Rect(rc.x, rc.y + lineCy * 2, rc.width, rc.height - lineCy), property);
}
}

Expand All @@ -189,20 +182,22 @@ private static void DrawSettingsInternal(Rect rc, SerializedProperty colorProp,
var lineCy = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
var n = 4;

EditorGUI.PropertyField(new Rect(rc.x, rc.y + 1 * lineCy, rc.width, EditorGUIUtility.singleLineHeight), colorProp, _colorContent);
EditorGUI.PropertyField(new Rect(rc.x, rc.y + 2 * lineCy, rc.width, EditorGUIUtility.singleLineHeight), widthProp, _widthContent);
//EditorGUI.PropertyField(new Rect(rc.x, rc.y + 1 * lineCy, rc.width, EditorGUIUtility.singleLineHeight), colorProp, _colorContent);
colorProp.colorValue = EditorGUI.ColorField(new Rect(rc.x, rc.y + 1 * lineCy, rc.width, EditorGUIUtility.singleLineHeight), OutlineEditorUtility.ColorContent, colorProp.colorValue, true, true, true);

EditorGUI.PropertyField(new Rect(rc.x, rc.y + 2 * lineCy, rc.width, EditorGUIUtility.singleLineHeight), widthProp, OutlineEditorUtility.WidthContent);

// NOTE: EditorGUI.PropertyField doesn't allow multi-selection, have to use EnumFlagsField explixitly.
renderModeProp.intValue = (int)(OutlineRenderFlags)EditorGUI.EnumFlagsField(new Rect(rc.x, rc.y + 3 * lineCy, rc.width, EditorGUIUtility.singleLineHeight), _renderModeContent, renderMode);
renderModeProp.intValue = (int)(OutlineRenderFlags)EditorGUI.EnumFlagsField(new Rect(rc.x, rc.y + 3 * lineCy, rc.width, EditorGUIUtility.singleLineHeight), OutlineEditorUtility.RenderFlagsContent, renderMode);

if ((renderMode & OutlineRenderFlags.Blurred) != 0)
{
EditorGUI.PropertyField(new Rect(rc.x, rc.y + n++ * lineCy, rc.width, EditorGUIUtility.singleLineHeight), intensityProp, _intensityContent);
EditorGUI.PropertyField(new Rect(rc.x, rc.y + n++ * lineCy, rc.width, EditorGUIUtility.singleLineHeight), intensityProp, OutlineEditorUtility.BlurIntensityContent);
}

if ((renderMode & OutlineRenderFlags.EnableAlphaTesting) != 0)
{
EditorGUI.PropertyField(new Rect(rc.x, rc.y + n * lineCy, rc.width, EditorGUIUtility.singleLineHeight), cutoffProp, _cutoffContent);
EditorGUI.PropertyField(new Rect(rc.x, rc.y + n * lineCy, rc.width, EditorGUIUtility.singleLineHeight), cutoffProp, OutlineEditorUtility.AlphaCutoffContent);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public sealed class OutlineResources : ScriptableObject
/// <summary>
/// Maximum value of outline width parameter.
/// </summary>
/// <remarks>
/// If the value is changed here, it should be adjusted in Outline.shader as well.
/// </remarks>
/// <seealso cref="MinWidth"/>
public const int MaxWidth = 32;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,13 @@ public void Render(IReadOnlyList<Renderer> renderers, IOutlineSettings settings,

if (renderers.Count > 0)
{
if (string.IsNullOrEmpty(sampleName))
{
sampleName = renderers[0].name;
}
// NOTE: Remove BeginSample/EndSample for now (https://github.com/Arvtesh/UnityFx.Outline/issues/44).
//if (string.IsNullOrEmpty(sampleName))
//{
// sampleName = renderers[0].name;
//}

_commandBuffer.BeginSample(sampleName);
//_commandBuffer.BeginSample(sampleName);
{
RenderObjectClear(settings.OutlineRenderMode);

Expand All @@ -279,7 +280,7 @@ public void Render(IReadOnlyList<Renderer> renderers, IOutlineSettings settings,

RenderOutline(settings);
}
_commandBuffer.EndSample(sampleName);
//_commandBuffer.EndSample(sampleName);
}
}

Expand All @@ -303,18 +304,20 @@ public void Render(Renderer renderer, IOutlineSettings settings, string sampleNa
throw new ArgumentNullException(nameof(settings));
}

if (string.IsNullOrEmpty(sampleName))
{
sampleName = renderer.name;
}
// NOTE: Remove BeginSample/EndSample for now (https://github.com/Arvtesh/UnityFx.Outline/issues/44).
//if (string.IsNullOrEmpty(sampleName))
//{
// sampleName = renderer.name;
//}

_commandBuffer.BeginSample(sampleName);
// NOTE: Remove this for now (https://github.com/Arvtesh/UnityFx.Outline/issues/44).
//_commandBuffer.BeginSample(sampleName);
{
RenderObjectClear(settings.OutlineRenderMode);
DrawRenderer(renderer, settings);
RenderOutline(settings);
}
_commandBuffer.EndSample(sampleName);
//_commandBuffer.EndSample(sampleName);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,34 @@ Shader "Hidden/UnityFx/Outline"

#endif

float CalcIntensityN0(float2 uv, float2 offset, int k)
{
return UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, uv + k * offset).r * _GaussSamples[k];
}

float CalcIntensityN1(float2 uv, float2 offset, int k)
{
return UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, uv - k * offset).r * _GaussSamples[k];
}

float CalcIntensity(float2 uv, float2 offset)
{
float intensity = 0;

// Accumulates horizontal or vertical blur intensity for the specified texture position.
// Set offset = (tx, 0) for horizontal sampling and offset = (0, ty) for vertical.
for (int k = -_Width; k <= _Width; ++k)
//
// NOTE: Unroll directive is needed to make the method function on platforms like WebGL 1.0 where loops are not supported.
// If maximum outline width is changed here, it should be changed in OutlineResources.MaxWidth as well.
//
[unroll(32)]
for (int k = 1; k <= _Width; ++k)
{
intensity += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, uv + k * offset).r * _GaussSamples[abs(k)];
intensity += CalcIntensityN0(uv, offset, k);
intensity += CalcIntensityN1(uv, offset, k);
}

intensity += CalcIntensityN0(uv, offset, 0);
return intensity;
}

Expand Down
2 changes: 1 addition & 1 deletion Outline.Core/Packages/UnityFx.Outline/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.unityfx.outline",
"version": "0.8.4",
"version": "0.8.5",
"displayName": "Outline toolkit",
"description": "This package contains configurable per-object and per-camera outline effect implementation for built-in render pipeline. Both solid and blurred outline modes are supported (Gauss blur), as well as depth testing. Reusable and extensible API.",
"unity": "2018.4",
Expand Down
12 changes: 12 additions & 0 deletions Outline.URP/Packages/UnityFx.Outline.URP/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/).

## [0.5.0] - 2021.11.18

Bugfixes and improvements.

### Added
- Added support for HDR color pickers ([#42](https://github.com/Arvtesh/UnityFx.Outline/issues/42)).

### Fixed
- Fixed URP depth testing with MSAA enabled when using `OutlineLayerCollection`, thanks @AGM-GR for the help ([#39](https://github.com/Arvtesh/UnityFx.Outline/issues/39)).
- Added loop unroll statement to make shaders compatible with some platforms (WebGL 1.0) ([#45](https://github.com/Arvtesh/UnityFx.Outline/issues/45)).
- Removed `BeginSample`/`EndSample` profiler calls when rendering outlines to get rid of the editor errors ([#44](https://github.com/Arvtesh/UnityFx.Outline/issues/44)).

## [0.4.0] - 2021.08.17
Misc improvements.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
if (_feature.OutlineLayers)
{
var cmd = CommandBufferPool.Get(OutlineResources.EffectName);
var depthTexture = new RenderTargetIdentifier("_CameraDepthTexture");

using (var renderer = new OutlineRenderer(cmd, outlineResources, _renderer.cameraColorTarget, _renderer.cameraDepth, camData.cameraTargetDescriptor))
using (var renderer = new OutlineRenderer(cmd, outlineResources, _renderer.cameraColorTarget, depthTexture /*_renderer.cameraDepth*/, camData.cameraTargetDescriptor))
{
_renderObjects.Clear();
_feature.OutlineLayers.GetRenderObjects(_renderObjects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,34 @@ Shader "Hidden/UnityFx/Outline.URP"

#endif

float CalcIntensityN0(float2 uv, float2 offset, int k)
{
return SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, uv + k * offset).r * _GaussSamples[k];
}

float CalcIntensityN1(float2 uv, float2 offset, int k)
{
return SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, uv - k * offset).r * _GaussSamples[k];
}

float CalcIntensity(float2 uv, float2 offset)
{
float intensity = 0;

// Accumulates horizontal or vertical blur intensity for the specified texture position.
// Set offset = (tx, 0) for horizontal sampling and offset = (0, ty) for vertical.
for (int k = -_Width; k <= _Width; ++k)
//
// NOTE: Unroll directive is needed to make the method function on platforms like WebGL 1.0 where loops are not supported.
// If maximum outline width is changed here, it should be changed in OutlineResources.MaxWidth as well.
//
[unroll(32)]
for (int k = 1; k <= _Width; ++k)
{
intensity += SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, uv + k * offset).r * _GaussSamples[abs(k)];
intensity += CalcIntensityN0(uv, offset, k);
intensity += CalcIntensityN1(uv, offset, k);
}

intensity += CalcIntensityN0(uv, offset, 0);
return intensity;
}

Expand Down
4 changes: 2 additions & 2 deletions Outline.URP/Packages/UnityFx.Outline.URP/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "com.unityfx.outline.urp",
"version": "0.4.0",
"version": "0.5.0",
"displayName": "Outline toolkit (URP)",
"description": "This package contains configurable outline implementation for Universal Render Pipeline.",
"unity": "2019.4",
"dependencies": {
"com.unityfx.outline": "0.8.4",
"com.unityfx.outline": "0.8.5",
"com.unity.render-pipelines.universal": "7.0.0"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion Outline.URP/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"depth": 0,
"source": "embedded",
"dependencies": {
"com.unityfx.outline": "0.8.3",
"com.unityfx.outline": "0.8.5",
"com.unity.render-pipelines.universal": "7.0.0"
}
},
Expand Down
Loading

0 comments on commit f415a97

Please sign in to comment.