[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.
This commit is contained in:
Harald Csaszar 2020-03-27 16:56:33 +01:00
parent 3bac3da543
commit 6df16d4fe1
7 changed files with 146 additions and 13 deletions

View File

@ -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,7 +124,10 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
EditorGUIUtility.labelWidth = 0f;
bool mixedValue;
bool isOutlineEnabled = IsOutlineEnabled(_materialEditor, out mixedValue);
bool hasOutlineVariant = !IsShaderWithoutStandardVariantShader(_materialEditor, out mixedValue);
bool isOutlineEnabled = true;
if (hasOutlineVariant) {
isOutlineEnabled = IsOutlineEnabled(_materialEditor, out mixedValue);
EditorGUI.showMixedValue = mixedValue;
EditorGUI.BeginChangeCheck();
@ -137,6 +141,13 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
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;

View File

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

View File

@ -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"
}

View File

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

View File

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

View File

@ -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"
}

View File

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