mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[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:
parent
3bac3da543
commit
6df16d4fe1
@ -65,6 +65,7 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
|
|||||||
|
|
||||||
protected const string ShaderOutlineNamePrefix = "Spine/Outline/";
|
protected const string ShaderOutlineNamePrefix = "Spine/Outline/";
|
||||||
protected const string ShaderNormalNamePrefix = "Spine/";
|
protected const string ShaderNormalNamePrefix = "Spine/";
|
||||||
|
protected const string ShaderWithoutStandardVariantSuffix = "OutlineOnly";
|
||||||
|
|
||||||
#region ShaderGUI
|
#region ShaderGUI
|
||||||
|
|
||||||
@ -123,20 +124,30 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
|
|||||||
EditorGUIUtility.labelWidth = 0f;
|
EditorGUIUtility.labelWidth = 0f;
|
||||||
|
|
||||||
bool mixedValue;
|
bool mixedValue;
|
||||||
bool isOutlineEnabled = IsOutlineEnabled(_materialEditor, out mixedValue);
|
bool hasOutlineVariant = !IsShaderWithoutStandardVariantShader(_materialEditor, out mixedValue);
|
||||||
EditorGUI.showMixedValue = mixedValue;
|
bool isOutlineEnabled = true;
|
||||||
EditorGUI.BeginChangeCheck();
|
if (hasOutlineVariant) {
|
||||||
|
isOutlineEnabled = IsOutlineEnabled(_materialEditor, out mixedValue);
|
||||||
|
EditorGUI.showMixedValue = mixedValue;
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
|
||||||
var origFontStyle = EditorStyles.label.fontStyle;
|
var origFontStyle = EditorStyles.label.fontStyle;
|
||||||
EditorStyles.label.fontStyle = FontStyle.Bold;
|
EditorStyles.label.fontStyle = FontStyle.Bold;
|
||||||
isOutlineEnabled = EditorGUILayout.Toggle(_EnableOutlineText, isOutlineEnabled);
|
isOutlineEnabled = EditorGUILayout.Toggle(_EnableOutlineText, isOutlineEnabled);
|
||||||
EditorStyles.label.fontStyle = origFontStyle;
|
EditorStyles.label.fontStyle = origFontStyle;
|
||||||
EditorGUI.showMixedValue = false;
|
EditorGUI.showMixedValue = false;
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
foreach (Material material in _materialEditor.targets) {
|
foreach (Material material in _materialEditor.targets) {
|
||||||
SwitchShaderToOutlineSettings(material, isOutlineEnabled);
|
SwitchShaderToOutlineSettings(material, isOutlineEnabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var origFontStyle = EditorStyles.label.fontStyle;
|
||||||
|
EditorStyles.label.fontStyle = FontStyle.Bold;
|
||||||
|
EditorGUILayout.LabelField(_EnableOutlineText);
|
||||||
|
EditorStyles.label.fontStyle = origFontStyle;
|
||||||
|
}
|
||||||
|
|
||||||
if (isOutlineEnabled) {
|
if (isOutlineEnabled) {
|
||||||
_materialEditor.ShaderProperty(_OutlineWidth, _OutlineWidthText);
|
_materialEditor.ShaderProperty(_OutlineWidth, _OutlineWidthText);
|
||||||
@ -162,7 +173,7 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
|
|||||||
void SwitchShaderToOutlineSettings (Material material, bool enableOutline) {
|
void SwitchShaderToOutlineSettings (Material material, bool enableOutline) {
|
||||||
|
|
||||||
var shaderName = material.shader.name;
|
var shaderName = material.shader.name;
|
||||||
bool isSetToOutlineShader = shaderName.StartsWith(ShaderOutlineNamePrefix);
|
bool isSetToOutlineShader = shaderName.Contains(ShaderOutlineNamePrefix);
|
||||||
if (isSetToOutlineShader && !enableOutline) {
|
if (isSetToOutlineShader && !enableOutline) {
|
||||||
shaderName = shaderName.Replace(ShaderOutlineNamePrefix, ShaderNormalNamePrefix);
|
shaderName = shaderName.Replace(ShaderOutlineNamePrefix, ShaderNormalNamePrefix);
|
||||||
_materialEditor.SetShader(Shader.Find(shaderName), false);
|
_materialEditor.SetShader(Shader.Find(shaderName), false);
|
||||||
@ -179,7 +190,7 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
|
|||||||
mixedValue = false;
|
mixedValue = false;
|
||||||
bool isAnyEnabled = false;
|
bool isAnyEnabled = false;
|
||||||
foreach (Material material in editor.targets) {
|
foreach (Material material in editor.targets) {
|
||||||
if (material.shader.name.StartsWith(ShaderOutlineNamePrefix)) {
|
if (material.shader.name.Contains(ShaderOutlineNamePrefix)) {
|
||||||
isAnyEnabled = true;
|
isAnyEnabled = true;
|
||||||
}
|
}
|
||||||
else if (isAnyEnabled) {
|
else if (isAnyEnabled) {
|
||||||
@ -189,6 +200,20 @@ public class SpineShaderWithOutlineGUI : ShaderGUI {
|
|||||||
return isAnyEnabled;
|
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) {
|
static bool BoldToggleField (GUIContent label, bool value) {
|
||||||
FontStyle origFontStyle = EditorStyles.label.fontStyle;
|
FontStyle origFontStyle = EditorStyles.label.fontStyle;
|
||||||
EditorStyles.label.fontStyle = FontStyle.Bold;
|
EditorStyles.label.fontStyle = FontStyle.Bold;
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d122262772fd0ec47887efc848e8d285
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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"
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e07d39bf1c784604e9420722eb804edf
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 958b6dbd07d10374189a5c45cd641149
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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"
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0c26b8f3f8867ba41ac82baf19d8ff91
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user