[unity] Added Spine/SkeletonGraphic Grayscale shader.

This commit is contained in:
Harald Csaszar 2023-02-21 17:57:11 +01:00
parent 85a972922a
commit c191282f54
6 changed files with 162 additions and 56 deletions

View File

@ -30,6 +30,7 @@
* **Additions** * **Additions**
* `OnPostProcessVertices` callback parameter `MeshGeneratorBuffers` now provides access to `uv2Buffer` and `uv3Buffer` properties of `MeshGenerator`, automatically allocating buffers upon access if `tintBlack` is disabled. This allows for passing own vertex data to a shader on second and third uv channels. * `OnPostProcessVertices` callback parameter `MeshGeneratorBuffers` now provides access to `uv2Buffer` and `uv3Buffer` properties of `MeshGenerator`, automatically allocating buffers upon access if `tintBlack` is disabled. This allows for passing own vertex data to a shader on second and third uv channels.
* Added `Spine/SkeletonGraphic Grayscale` shader to provide a basic grayscale shader for SkeletonGraphic as well. SkeletonGraphic Material `SkeletonGraphicDefaultGrayscale` uses this shader and can be assigned at `SkeletonGraphic` components as usual.
* **Breaking changes** * **Breaking changes**

View File

@ -2,20 +2,25 @@
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000 --- !u!21 &2100000
Material: Material:
serializedVersion: 6 serializedVersion: 8
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: SkeletonGraphicDefaultGrayscale m_Name: SkeletonGraphicDefaultGrayscale
m_Shader: {fileID: 4800000, guid: fa95b0fb6983c0f40a152e6f9aa82bfb, type: 3} m_Shader: {fileID: 4800000, guid: 81eed00979b4e554cb3022dc0b83b517, type: 3}
m_ShaderKeywords: m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords:
- _USE8NEIGHBOURHOOD_ON
m_LightmapFlags: 5 m_LightmapFlags: 5
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: -1
stringTagMap: {} stringTagMap: {}
disabledShaderPasses: [] disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties: m_SavedProperties:
serializedVersion: 3 serializedVersion: 3
m_TexEnvs: m_TexEnvs:
@ -59,6 +64,7 @@ Material:
m_Texture: {fileID: 0} m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: m_Floats:
- PixelSnap: 0 - PixelSnap: 0
- _BumpScale: 1 - _BumpScale: 1
@ -69,10 +75,12 @@ Material:
- _DstBlend: 0 - _DstBlend: 0
- _EnableExternalAlpha: 0 - _EnableExternalAlpha: 0
- _Glossiness: 0.5 - _Glossiness: 0.5
- _GrayPhase: 1
- _Metallic: 0 - _Metallic: 0
- _Mode: 0 - _Mode: 0
- _OcclusionStrength: 1 - _OcclusionStrength: 1
- _OutlineMipLevel: 0 - _OutlineMipLevel: 0
- _OutlineOpaqueAlpha: 1
- _OutlineReferenceTexWidth: 1024 - _OutlineReferenceTexWidth: 1024
- _OutlineSmoothness: 1 - _OutlineSmoothness: 1
- _OutlineWidth: 3 - _OutlineWidth: 3

View File

@ -22,7 +22,9 @@ struct VertexOutput {
UNITY_VERTEX_OUTPUT_STEREO UNITY_VERTEX_OUTPUT_STEREO
}; };
#ifndef ENABLE_GRAYSCALE
fixed4 _Color; fixed4 _Color;
#endif
fixed4 _TextureSampleAdd; fixed4 _TextureSampleAdd;
float4 _ClipRect; float4 _ClipRect;
@ -30,6 +32,9 @@ float4 _ClipRect;
float4 _FillColor; float4 _FillColor;
float _FillPhase; float _FillPhase;
#endif #endif
#ifdef ENABLE_GRAYSCALE
float _GrayPhase;
#endif
VertexOutput vert (VertexInput IN) { VertexOutput vert (VertexInput IN) {
VertexOutput OUT; VertexOutput OUT;
@ -57,7 +62,11 @@ VertexOutput vert (VertexInput IN) {
// Saturated version used to prevent numerical issues of certain low-alpha values. // Saturated version used to prevent numerical issues of certain low-alpha values.
float4 vertexColor = PMAGammaToTargetSpaceSaturated(half4(TargetToGammaSpace(IN.color.rgb), IN.color.a)); float4 vertexColor = PMAGammaToTargetSpaceSaturated(half4(TargetToGammaSpace(IN.color.rgb), IN.color.a));
#endif #endif
OUT.color = vertexColor * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor. OUT.color = vertexColor;
#ifndef ENABLE_GRAYSCALE
OUT.color *= float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
#endif
return OUT; return OUT;
} }
@ -81,6 +90,9 @@ fixed4 frag (VertexOutput IN) : SV_Target
#ifdef ENABLE_FILL #ifdef ENABLE_FILL
color.rgb = lerp(color.rgb, (_FillColor.rgb * color.a), _FillPhase); // make sure to PMA _FillColor. color.rgb = lerp(color.rgb, (_FillColor.rgb * color.a), _FillPhase); // make sure to PMA _FillColor.
#endif #endif
#ifdef ENABLE_GRAYSCALE
color.rgb = lerp(color.rgb, dot(color.rgb, float3(0.3, 0.59, 0.11)), _GrayPhase);
#endif
return color; return color;
} }

View File

@ -19,60 +19,60 @@ Shader "Spine/SkeletonGraphic Fill"
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0 [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
// Outline properties are drawn via custom editor. // Outline properties are drawn via custom editor.
[HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0 [HideInInspector] _OutlineWidth("Outline Width", Range(0,8)) = 3.0
[HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1) [HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
[HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024 [HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
[HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25 [HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
[HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0 [HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
[HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1 [HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
[HideInInspector] _OutlineOpaqueAlpha("Opaque Alpha", Range(0,1)) = 1.0 [HideInInspector] _OutlineOpaqueAlpha("Opaque Alpha", Range(0,1)) = 1.0
[HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0 [HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
} }
SubShader SubShader
{
Tags
{ {
Tags "Queue" = "Transparent"
{ "IgnoreProjector" = "True"
"Queue" = "Transparent" "RenderType" = "Transparent"
"IgnoreProjector" = "True" "PreviewType" = "Plane"
"RenderType" = "Transparent" "CanUseSpriteAtlas" = "True"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Stencil
{
Ref[_Stencil]
Comp[_StencilComp]
Pass[_StencilOp]
ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest[unity_GUIZTestMode]
Fog { Mode Off }
Blend One OneMinusSrcAlpha
ColorMask[_ColorMask]
Pass
{
Name "Normal"
CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma shader_feature _ _CANVAS_GROUP_COMPATIBLE
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#define ENABLE_FILL
#include "CGIncludes/Spine-SkeletonGraphic-NormalPass.cginc"
ENDCG
}
} }
CustomEditor "SpineShaderWithOutlineGUI"
Stencil
{
Ref[_Stencil]
Comp[_StencilComp]
Pass[_StencilOp]
ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest[unity_GUIZTestMode]
Fog { Mode Off }
Blend One OneMinusSrcAlpha
ColorMask[_ColorMask]
Pass
{
Name "Normal"
CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma shader_feature _ _CANVAS_GROUP_COMPATIBLE
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#define ENABLE_FILL
#include "CGIncludes/Spine-SkeletonGraphic-NormalPass.cginc"
ENDCG
}
}
CustomEditor "SpineShaderWithOutlineGUI"
} }

View File

@ -0,0 +1,76 @@
Shader "Spine/SkeletonGraphic Grayscale"
{
Properties
{
_GrayPhase("Phase", Range(0, 1)) = 1
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
[Toggle(_CANVAS_GROUP_COMPATIBLE)] _CanvasGroupCompatible("CanvasGroup Compatible", Int) = 1
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8
[HideInInspector] _Stencil("Stencil ID", Float) = 0
[HideInInspector][Enum(UnityEngine.Rendering.StencilOp)] _StencilOp("Stencil Operation", Float) = 0
[HideInInspector] _StencilWriteMask("Stencil Write Mask", Float) = 255
[HideInInspector] _StencilReadMask("Stencil Read Mask", Float) = 255
[HideInInspector] _ColorMask("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
// 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] _OutlineOpaqueAlpha("Opaque Alpha", Range(0,1)) = 1.0
[HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Stencil
{
Ref[_Stencil]
Comp[_StencilComp]
Pass[_StencilOp]
ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest[unity_GUIZTestMode]
Fog { Mode Off }
Blend One OneMinusSrcAlpha
ColorMask[_ColorMask]
Pass
{
Name "Normal"
CGPROGRAM
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
#pragma shader_feature _ _CANVAS_GROUP_COMPATIBLE
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#define ENABLE_GRAYSCALE
#include "CGIncludes/Spine-SkeletonGraphic-NormalPass.cginc"
ENDCG
}
}
CustomEditor "SpineShaderWithOutlineGUI"
}

View File

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