Browse Source

[unity] Added ontline-only single pass shaders to LWRP and URP packages. This allows for separate outline child GameObjects that reference the existing Mesh of their parent, and re-draw the mesh using this outline shader.
The component to ease replacing materials of the parent will be added in separate upcoming commit.

Harald Csaszar 5 years ago
parent
commit
6df16d4fe1

+ 39 - 14
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineShaderWithOutlineGUI.cs

@@ -65,6 +65,7 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
 
 	protected const string ShaderOutlineNamePrefix = "Spine/Outline/";
 	protected const string ShaderNormalNamePrefix = "Spine/";
+	protected const string ShaderWithoutStandardVariantSuffix = "OutlineOnly";
 
 	#region ShaderGUI
 
@@ -123,20 +124,30 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
 		EditorGUIUtility.labelWidth = 0f;
 
 		bool mixedValue;
-		bool isOutlineEnabled = IsOutlineEnabled(_materialEditor, out mixedValue);
-		EditorGUI.showMixedValue = mixedValue;
-		EditorGUI.BeginChangeCheck();
-
-		var origFontStyle = EditorStyles.label.fontStyle;
-		EditorStyles.label.fontStyle = FontStyle.Bold;
-		isOutlineEnabled = EditorGUILayout.Toggle(_EnableOutlineText, isOutlineEnabled);
-		EditorStyles.label.fontStyle = origFontStyle;
-		EditorGUI.showMixedValue = false;
-		if (EditorGUI.EndChangeCheck()) {
-			foreach (Material material in _materialEditor.targets) {
-				SwitchShaderToOutlineSettings(material, isOutlineEnabled);
+		bool hasOutlineVariant = !IsShaderWithoutStandardVariantShader(_materialEditor, out mixedValue);
+		bool isOutlineEnabled = true;
+		if (hasOutlineVariant) {
+			isOutlineEnabled = IsOutlineEnabled(_materialEditor, out mixedValue);
+			EditorGUI.showMixedValue = mixedValue;
+			EditorGUI.BeginChangeCheck();
+
+			var origFontStyle = EditorStyles.label.fontStyle;
+			EditorStyles.label.fontStyle = FontStyle.Bold;
+			isOutlineEnabled = EditorGUILayout.Toggle(_EnableOutlineText, isOutlineEnabled);
+			EditorStyles.label.fontStyle = origFontStyle;
+			EditorGUI.showMixedValue = false;
+			if (EditorGUI.EndChangeCheck()) {
+				foreach (Material material in _materialEditor.targets) {
+					SwitchShaderToOutlineSettings(material, isOutlineEnabled);
+				}
 			}
 		}
+		else {
+			var origFontStyle = EditorStyles.label.fontStyle;
+			EditorStyles.label.fontStyle = FontStyle.Bold;
+			EditorGUILayout.LabelField(_EnableOutlineText);
+			EditorStyles.label.fontStyle = origFontStyle;
+		}
 
 		if (isOutlineEnabled) {
 			_materialEditor.ShaderProperty(_OutlineWidth, _OutlineWidthText);
@@ -162,7 +173,7 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
 	void SwitchShaderToOutlineSettings (Material material, bool enableOutline) {
 
 		var shaderName = material.shader.name;
-		bool isSetToOutlineShader = shaderName.StartsWith(ShaderOutlineNamePrefix);
+		bool isSetToOutlineShader = shaderName.Contains(ShaderOutlineNamePrefix);
 		if (isSetToOutlineShader && !enableOutline) {
 			shaderName = shaderName.Replace(ShaderOutlineNamePrefix, ShaderNormalNamePrefix);
 			_materialEditor.SetShader(Shader.Find(shaderName), false);
@@ -179,7 +190,7 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
 		mixedValue = false;
 		bool isAnyEnabled = false;
 		foreach (Material material in editor.targets) {
-			if (material.shader.name.StartsWith(ShaderOutlineNamePrefix)) {
+			if (material.shader.name.Contains(ShaderOutlineNamePrefix)) {
 				isAnyEnabled = true;
 			}
 			else if (isAnyEnabled) {
@@ -189,6 +200,20 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
 		return isAnyEnabled;
 	}
 
+	static bool IsShaderWithoutStandardVariantShader (MaterialEditor editor, out bool mixedValue) {
+		mixedValue = false;
+		bool isAnyShaderWithoutVariant = false;
+		foreach (Material material in editor.targets) {
+			if (material.shader.name.Contains(ShaderWithoutStandardVariantSuffix)) {
+				isAnyShaderWithoutVariant = true;
+			}
+			else if (isAnyShaderWithoutVariant) {
+				mixedValue = true;
+			}
+		}
+		return isAnyShaderWithoutVariant;
+	}
+
 	static bool BoldToggleField (GUIContent label, bool value) {
 		FontStyle origFontStyle = EditorStyles.label.fontStyle;
 		EditorStyles.label.fontStyle = FontStyle.Bold;

+ 8 - 0
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Outline.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: d122262772fd0ec47887efc848e8d285
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 37 - 0
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Outline/Spine-Skeleton-OutlineOnly-LWRP.shader

@@ -0,0 +1,37 @@
+Shader "Lightweight Render Pipeline/Spine/Outline/Skeleton-OutlineOnly" {
+	Properties {
+		[NoScaleOffset] _MainTex("Main Texture", 2D) = "black" {}
+		[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
+		[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
+
+		// Outline properties are drawn via custom editor.
+		[HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
+		[HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
+		[HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
+		[HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
+		[HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
+		[HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
+		[HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
+	}
+
+	SubShader {
+		// Lightweight Pipeline tag is required. If Lightweight render pipeline is not set in the graphics settings
+		// this Subshader will fail.
+		Tags { "RenderPipeline" = "LightweightPipeline" "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
+		LOD 100
+		Cull Off
+		ZWrite Off
+		Blend One OneMinusSrcAlpha
+
+		Stencil {
+			Ref[_StencilRef]
+			Comp[_StencilComp]
+			Pass Keep
+		}
+
+		UsePass "Spine/Outline/Skeleton/OUTLINE"
+	}
+
+	FallBack "Hidden/InternalErrorShader"
+	CustomEditor "SpineShaderWithOutlineGUI"
+}

+ 9 - 0
spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Outline/Spine-Skeleton-OutlineOnly-LWRP.shader.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: e07d39bf1c784604e9420722eb804edf
+ShaderImporter:
+  externalObjects: {}
+  defaultTextures: []
+  nonModifiableTextures: []
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Outline.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 958b6dbd07d10374189a5c45cd641149
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 37 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Outline/Spine-Skeleton-OutlineOnly-URP.shader

@@ -0,0 +1,37 @@
+Shader "Universal Render Pipeline/Spine/Outline/Skeleton-OutlineOnly" {
+	Properties {
+		[NoScaleOffset] _MainTex("Main Texture", 2D) = "black" {}
+		[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
+		[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
+
+		// Outline properties are drawn via custom editor.
+		[HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
+		[HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
+		[HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
+		[HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
+		[HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
+		[HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
+		[HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
+	}
+
+	SubShader {
+		// Universal Pipeline tag is required. If Universal render pipeline is not set in the graphics settings
+		// this Subshader will fail.
+		Tags { "RenderPipeline" = "UniversalPipeline" "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
+		LOD 100
+		Cull Off
+		ZWrite Off
+		Blend One OneMinusSrcAlpha
+
+		Stencil {
+			Ref[_StencilRef]
+			Comp[_StencilComp]
+			Pass Keep
+		}
+
+		UsePass "Spine/Outline/Skeleton/OUTLINE"
+	}
+
+	FallBack "Hidden/InternalErrorShader"
+	CustomEditor "SpineShaderWithOutlineGUI"
+}

+ 9 - 0
spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Outline/Spine-Skeleton-OutlineOnly-URP.shader.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 0c26b8f3f8867ba41ac82baf19d8ff91
+ShaderImporter:
+  externalObjects: {}
+  defaultTextures: []
+  nonModifiableTextures: []
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: