From a5a749d4a8d759e22e668b7d071d13702bb0e2a5 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 25 Jul 2019 17:37:06 +0200 Subject: [PATCH 1/3] [unity] Spine/Sprite shaders: Renamed `Light Probes` parameter to `Light Probes & Ambient` so that users recognize its effect at first glance (visual name changed in inspector only). --- .../Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs index 30de38653..847e525a8 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs @@ -127,7 +127,7 @@ public class SpineSpriteShaderGUI : ShaderGUI { static GUIContent _fixedNormalText = new GUIContent("Fixed Normals", "If this is ticked instead of requiring mesh normals a Fixed Normal will be used instead (it's quicker and can result in better looking lighting effects on 2d objects)."); static GUIContent _fixedNormalDirectionText = new GUIContent("Fixed Normal Direction", "Should normally be (0,0,1) if in view-space or (0,0,-1) if in model-space."); static GUIContent _adjustBackfaceTangentText = new GUIContent("Adjust Back-face Tangents", "Tick only if you are going to rotate the sprite to face away from the camera, the tangents will be flipped when this is the case to make lighting correct."); - static GUIContent _sphericalHarmonicsText = new GUIContent("Spherical Harmonics", "Enable to use spherical harmonics to calculate ambient light / light probes. In vertex-lit mode this will be approximated from scenes ambient trilight settings."); + static GUIContent _sphericalHarmonicsText = new GUIContent("Light Probes & Ambient", "Enable to use spherical harmonics to aplpy ambient light and/or light probes. In vertex-lit mode this will be approximated from scenes ambient trilight settings."); static GUIContent _lightingModeText = new GUIContent("Lighting Mode", "Lighting Mode"); static GUIContent[] _lightingModeOptions = { new GUIContent("Vertex Lit"), From 44f2fa9c69ed8dd6a731f49025f9e0efd5b40338 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 25 Jul 2019 22:11:21 +0200 Subject: [PATCH 2/3] [unity] Added shader variant `Spine/Skeleton Lit ZWrite` and moved common functionality to cginc files. Cleanup of `Skeleton Lit` shader. --- .../Editor/Shaders/SpineSpriteShaderGUI.cs | 3 +- .../spine-unity/Shaders/CGIncludes.meta | 9 + .../Spine-Skeleton-Lit-Common-Shadow.cginc | 30 ++++ ...pine-Skeleton-Lit-Common-Shadow.cginc.meta | 9 + .../Spine-Skeleton-Lit-Common.cginc | 120 +++++++++++++ .../Spine-Skeleton-Lit-Common.cginc.meta | 9 + .../Shaders/Spine-Skeleton-Lit-ZWrite.shader | 67 ++++++++ .../Spine-Skeleton-Lit-ZWrite.shader.meta | 9 + .../Shaders/Spine-SkeletonLit.shader | 159 +----------------- 9 files changed, 264 insertions(+), 151 deletions(-) create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes.meta create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc.meta create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc.meta create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader.meta diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs index 847e525a8..f0d034080 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs @@ -183,7 +183,8 @@ public class SpineSpriteShaderGUI : ShaderGUI { base.AssignNewShaderToMaterial(material, oldShader, newShader); //If not originally a sprite shader set default keywords - if (oldShader.name != kShaderVertexLit && oldShader.name != kShaderPixelLit && oldShader.name != kShaderUnlit) { + if (oldShader.name != kShaderVertexLit && oldShader.name != kShaderPixelLit && oldShader.name != kShaderUnlit && + oldShader.name != kShaderLitLW) { SetDefaultSpriteKeywords(material, newShader); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes.meta new file mode 100644 index 000000000..c8804508f --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 511f90ee1fe01c146836d5ed23f2e70f +folderAsset: yes +timeCreated: 1564083752 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc new file mode 100644 index 000000000..f5150ab62 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc @@ -0,0 +1,30 @@ +#ifndef SKELETON_LIT_COMMON_SHADOW_INCLUDED +#define SKELETON_LIT_COMMON_SHADOW_INCLUDED + +#include "UnityCG.cginc" +struct v2f { + V2F_SHADOW_CASTER; + float4 uvAndAlpha : TEXCOORD1; +}; + +uniform float4 _MainTex_ST; + +v2f vertShadow(appdata_base v, float4 vertexColor : COLOR) { + v2f o; + TRANSFER_SHADOW_CASTER(o) + o.uvAndAlpha.xy = TRANSFORM_TEX(v.texcoord, _MainTex); + o.uvAndAlpha.z = 0; + o.uvAndAlpha.a = vertexColor.a; + return o; +} + +uniform sampler2D _MainTex; +uniform fixed SHADOW_CUTOFF; + +float4 fragShadow (v2f i) : SV_Target { + fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy); + clip(texcol.a * i.uvAndAlpha.a - SHADOW_CUTOFF); + SHADOW_CASTER_FRAGMENT(i) +} + +#endif diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc.meta new file mode 100644 index 000000000..b325e2369 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c7297b25c81d2494e8e73b742e3c7345 +timeCreated: 1564083752 +licenseType: Free +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc new file mode 100644 index 000000000..5bec05dc4 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc @@ -0,0 +1,120 @@ +#ifndef SKELETON_LIT_COMMON_INCLUDED +#define SKELETON_LIT_COMMON_INCLUDED + +#include "UnityCG.cginc" + +// ES2.0/WebGL/3DS can not do loops with non-constant-expression iteration counts :( +#if defined(SHADER_API_GLES) +#define LIGHT_LOOP_LIMIT 8 +#elif defined(SHADER_API_N3DS) +#define LIGHT_LOOP_LIMIT 4 +#else +#define LIGHT_LOOP_LIMIT unity_VertexLightParams.x +#endif + +#pragma multi_compile __ POINT SPOT + +//////////////////////////////////////// +// Alpha Clipping +// + +#if defined(_ALPHA_CLIP) + uniform fixed _Cutoff; + #define ALPHA_CLIP(pixel, color) clip((pixel.a * color.a) - _Cutoff); +#else + #define ALPHA_CLIP(pixel, color) +#endif + +half3 computeLighting (int idx, half3 dirToLight, half3 eyeNormal, half4 diffuseColor, half atten) { + half NdotL = max(dot(eyeNormal, dirToLight), 0.0); + // diffuse + half3 color = NdotL * diffuseColor.rgb * unity_LightColor[idx].rgb; + return color * atten; +} + +half3 computeOneLight (int idx, float3 eyePosition, half3 eyeNormal, half4 diffuseColor) { + float3 dirToLight = unity_LightPosition[idx].xyz; + half att = 1.0; + + #if defined(POINT) || defined(SPOT) + dirToLight -= eyePosition * unity_LightPosition[idx].w; + + // distance attenuation + float distSqr = dot(dirToLight, dirToLight); + att /= (1.0 + unity_LightAtten[idx].z * distSqr); + if (unity_LightPosition[idx].w != 0 && distSqr > unity_LightAtten[idx].w) att = 0.0; // set to 0 if outside of range + distSqr = max(distSqr, 0.000001); // don't produce NaNs if some vertex position overlaps with the light + dirToLight *= rsqrt(distSqr); + #if defined(SPOT) + + // spot angle attenuation + half rho = max(dot(dirToLight, unity_SpotDirection[idx].xyz), 0.0); + half spotAtt = (rho - unity_LightAtten[idx].x) * unity_LightAtten[idx].y; + att *= saturate(spotAtt); + #endif + #endif + + att *= 0.5; // passed in light colors are 2x brighter than what used to be in FFP + return min (computeLighting (idx, dirToLight, eyeNormal, diffuseColor, att), 1.0); +} + +int4 unity_VertexLightParams; // x: light count, y: zero, z: one (y/z needed by d3d9 vs loop instruction) + +struct appdata { + float3 pos : POSITION; + float3 normal : NORMAL; + half4 color : COLOR; + float2 uv0 : TEXCOORD0; + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct VertexOutput { + fixed4 color : COLOR0; + float2 uv0 : TEXCOORD0; + float4 pos : SV_POSITION; + UNITY_VERTEX_OUTPUT_STEREO +}; + +VertexOutput vert (appdata v) { + VertexOutput o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + + half4 color = v.color; + float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz; + half3 fixedNormal = half3(0,0,-1); + half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal)); + //half3 eyeNormal = half3(0,0,1); + + // Lights + half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb; + for (int il = 0; il < LIGHT_LOOP_LIMIT; ++il) { + lcolor += computeOneLight(il, eyePos, eyeNormal, color); + } + + color.rgb = lcolor.rgb; + o.color = saturate(color); + o.uv0 = v.uv0; + o.pos = UnityObjectToClipPos(v.pos); + return o; +} + +sampler2D _MainTex; + +fixed4 frag (VertexOutput i) : SV_Target { + fixed4 tex = tex2D(_MainTex, i.uv0); + ALPHA_CLIP(tex, i.color); + + fixed4 col; + #if defined(_STRAIGHT_ALPHA_INPUT) + col.rgb = tex * i.color * tex.a; + #else + col.rgb = tex * i.color; + #endif + + col *= 2; + col.a = tex.a * i.color.a; + return col; +} + +#endif diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc.meta new file mode 100644 index 000000000..ee3481036 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 70c77c02aabd5e44f94aab48dd0be7b2 +timeCreated: 1564083752 +licenseType: Free +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader new file mode 100644 index 000000000..8f112d5f0 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader @@ -0,0 +1,67 @@ +// - Vertex Lit + ShadowCaster +// - Premultiplied Alpha Blending (Optional straight alpha input) +// - Double-sided, ZWrite + +Shader "Spine/Skeleton Lit ZWrite" { + Properties { + _Cutoff ("Depth alpha cutoff", Range(0,1)) = 0.1 + _ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 + [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} + [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 + [HideInInspector] [HideInInspector, Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default + } + + SubShader { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + LOD 100 + + Stencil { + Ref[_StencilRef] + Comp[_StencilComp] + Pass Keep + } + + Pass { + Tags { "LightMode"="Vertex" "Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent" } + + ZWrite On + Cull Off + Blend One OneMinusSrcAlpha + + CGPROGRAM + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma vertex vert + #pragma fragment frag + #pragma target 2.0 + + #define _ALPHA_CLIP + #include "CGIncludes/Spine-Skeleton-Lit-Common.cginc" + ENDCG + + } + + Pass { + Name "Caster" + Tags { "LightMode"="ShadowCaster" } + Offset 1, 1 + + Fog { Mode Off } + ZWrite On + ZTest LEqual + Cull Off + Lighting Off + + CGPROGRAM + #pragma vertex vertShadow + #pragma fragment fragShadow + #pragma multi_compile_shadowcaster + #pragma fragmentoption ARB_precision_hint_fastest + + #define SHADOW_CUTOFF _ShadowAlphaCutoff + #include "CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc" + + ENDCG + } + } +} \ No newline at end of file diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader.meta new file mode 100644 index 000000000..28243a0f2 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: fde05abf1f7be4b4da1caf8c8de1823a +timeCreated: 1564082883 +licenseType: Free +ShaderImporter: + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader index 5b4536924..f9d976235 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader @@ -1,4 +1,4 @@ -// - Vertex Lit + ShadowCaster +// - Vertex Lit + ShadowCaster // - Premultiplied Alpha Blending (Optional straight alpha input) // - Double-sided, no depth @@ -8,39 +8,21 @@ Shader "Spine/Skeleton Lit" { [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 - [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default + [HideInInspector] [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } LOD 100 - Cull Off - ZWrite Off - Blend One OneMinusSrcAlpha - Stencil { Ref[_StencilRef] Comp[_StencilComp] Pass Keep } -// Pass { -// Tags { "LightMode"="Vertex" } -// ColorMaterial AmbientAndDiffuse -// Lighting On -// SetTexture [_MainTex] { -// Combine texture * primary DOUBLE, texture * primary -// } -// } - Pass { - Tags { - "LIGHTMODE"="Vertex" - "QUEUE"="Transparent" - "IGNOREPROJECTOR"="true" - "RenderType"="Transparent" - } + Tags { "LightMode"="Vertex" "Queue"="Transparent" "IgnoreProjector"="true" "RenderType"="Transparent" } ZWrite Off Cull Off @@ -51,110 +33,8 @@ Shader "Spine/Skeleton Lit" { #pragma vertex vert #pragma fragment frag #pragma target 2.0 - #include "UnityCG.cginc" - // ES2.0/WebGL/3DS can not do loops with non-constant-expression iteration counts :( - #if defined(SHADER_API_GLES) - #define LIGHT_LOOP_LIMIT 8 - #elif defined(SHADER_API_N3DS) - #define LIGHT_LOOP_LIMIT 4 - #else - #define LIGHT_LOOP_LIMIT unity_VertexLightParams.x - #endif - - #pragma multi_compile __ POINT SPOT - - half3 computeLighting (int idx, half3 dirToLight, half3 eyeNormal, half4 diffuseColor, half atten) { - half NdotL = max(dot(eyeNormal, dirToLight), 0.0); - // diffuse - half3 color = NdotL * diffuseColor.rgb * unity_LightColor[idx].rgb; - return color * atten; - } - - half3 computeOneLight (int idx, float3 eyePosition, half3 eyeNormal, half4 diffuseColor) { - float3 dirToLight = unity_LightPosition[idx].xyz; - half att = 1.0; - - #if defined(POINT) || defined(SPOT) - dirToLight -= eyePosition * unity_LightPosition[idx].w; - - // distance attenuation - float distSqr = dot(dirToLight, dirToLight); - att /= (1.0 + unity_LightAtten[idx].z * distSqr); - if (unity_LightPosition[idx].w != 0 && distSqr > unity_LightAtten[idx].w) att = 0.0; // set to 0 if outside of range - distSqr = max(distSqr, 0.000001); // don't produce NaNs if some vertex position overlaps with the light - dirToLight *= rsqrt(distSqr); - #if defined(SPOT) - - // spot angle attenuation - half rho = max(dot(dirToLight, unity_SpotDirection[idx].xyz), 0.0); - half spotAtt = (rho - unity_LightAtten[idx].x) * unity_LightAtten[idx].y; - att *= saturate(spotAtt); - #endif - #endif - - att *= 0.5; // passed in light colors are 2x brighter than what used to be in FFP - return min (computeLighting (idx, dirToLight, eyeNormal, diffuseColor, att), 1.0); - } - - int4 unity_VertexLightParams; // x: light count, y: zero, z: one (y/z needed by d3d9 vs loop instruction) - - struct appdata { - float3 pos : POSITION; - float3 normal : NORMAL; - half4 color : COLOR; - float2 uv0 : TEXCOORD0; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct VertexOutput { - fixed4 color : COLOR0; - float2 uv0 : TEXCOORD0; - float4 pos : SV_POSITION; - UNITY_VERTEX_OUTPUT_STEREO - }; - - VertexOutput vert (appdata v) { - VertexOutput o; - UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); - - half4 color = v.color; - float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz; - half3 fixedNormal = half3(0,0,-1); - half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal)); - //half3 eyeNormal = half3(0,0,1); - - // Lights - half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb; - for (int il = 0; il < LIGHT_LOOP_LIMIT; ++il) { - lcolor += computeOneLight(il, eyePos, eyeNormal, color); - } - - color.rgb = lcolor.rgb; - o.color = saturate(color); - o.uv0 = v.uv0; - o.pos = UnityObjectToClipPos(v.pos); - return o; - } - - sampler2D _MainTex; - - fixed4 frag (VertexOutput i) : SV_Target { - fixed4 tex = tex2D(_MainTex, i.uv0); - - fixed4 col; - - #if defined(_STRAIGHT_ALPHA_INPUT) - col.rgb = tex * i.color * tex.a; - #else - col.rgb = tex * i.color; - #endif - - col *= 2; - col.a = tex.a * i.color.a; - return col; - } + #include "CGIncludes/Spine-Skeleton-Lit-Common.cginc" ENDCG } @@ -171,35 +51,14 @@ Shader "Spine/Skeleton Lit" { Lighting Off CGPROGRAM - #pragma vertex vert - #pragma fragment frag + #pragma vertex vertShadow + #pragma fragment fragShadow #pragma multi_compile_shadowcaster #pragma fragmentoption ARB_precision_hint_fastest - #include "UnityCG.cginc" - struct v2f { - V2F_SHADOW_CASTER; - float4 uvAndAlpha : TEXCOORD1; - }; + + #define SHADOW_CUTOFF _Cutoff + #include "CGIncludes/Spine-Skeleton-Lit-Common-Shadow.cginc" - uniform float4 _MainTex_ST; - - v2f vert (appdata_base v, float4 vertexColor : COLOR) { - v2f o; - TRANSFER_SHADOW_CASTER(o) - o.uvAndAlpha.xy = TRANSFORM_TEX(v.texcoord, _MainTex); - o.uvAndAlpha.z = 0; - o.uvAndAlpha.a = vertexColor.a; - return o; - } - - uniform sampler2D _MainTex; - uniform fixed _Cutoff; - - float4 frag (v2f i) : SV_Target { - fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy); - clip(texcol.a * i.uvAndAlpha.a - _Cutoff); - SHADOW_CASTER_FRAGMENT(i) - } ENDCG } } From 9de0118f692a03af04e840735197e6bf56fe62ea Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 25 Jul 2019 22:17:43 +0200 Subject: [PATCH 3/3] [unity] Renamed shader file Spine-SkeletonLit.shader to Spine-Skeleton-Lit.shader. Adapted changelog to last two commits. --- CHANGELOG.md | 2 ++ .../{Spine-SkeletonLit.shader => Spine-Skeleton-Lit.shader} | 0 ...e-SkeletonLit.shader.meta => Spine-Skeleton-Lit.shader.meta} | 0 3 files changed, 2 insertions(+) rename spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/{Spine-SkeletonLit.shader => Spine-Skeleton-Lit.shader} (100%) rename spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/{Spine-SkeletonLit.shader.meta => Spine-Skeleton-Lit.shader.meta} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index de448ae80..d80fceada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,6 +164,7 @@ * `Lightweight Render Pipeline/Spine/Sprite`, as a lightweight variant of the `Spine/Sprite/Vertex Lit` and `Pixel Lit` shaders, which were not functioning in the lightweight render pipeline. The shaders can be assigned to materials as usual and will respect your settings of the assigned `LightweightRenderPipelineAsset` under `Project Settings - Graphics`. * **Restrictions** As all Spine shaders, the LWRP shaders **do not support `Premultiply alpha` (PMA) atlas textures in Linear color space**. Please export your atlas textures as `straight alpha` textures with disabled `Premultiply alpha` setting when using Linear color space. You can check the current color space via `Project Settings - Player - Other Settings - Color Space.`. * **Example:** You can find an example scene in the package under `com.esotericsoftware.spine.lwrp-shaders-3.8/Examples/LWRP Shaders.unity` that demonstrates usage of the LWRP shaders. + * Added `Spine/Skeleton Lit ZWrite` shader. This variant of the `Spine/Skeleton Lit` shader writes to the depth buffer with configurable depth alpha threshold. Apart from that it is identical to `Spine/Skeleton Lit`. * **Changes of default values** * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.SpineStyle` instead of `MixMode.MixAlways`. @@ -178,6 +179,7 @@ * Removed duplicates of `.cginc` files in `Modules/Shaders/Sprite` that were also present in the `Modules/Shaders/Sprite/CGIncludes` directory. * Moved shaders from `Modules/Shaders` to `Shaders` directory. * Moved shaders from `Modules/SkeletonGraphic/Shaders` to `Shaders/SkeletonGraphic`. + * Renamed shader `Shaders/Spine-SkeletonLit.shader` to `Shaders/Spine-Skeleton-Lit.shader`. * Moved components from `SkeletonGraphic` to `Components` and `Components/Following` except for `SkeletonGraphicMirror` which was moved to `Spine Examples/Scripts/Sample Components`. * Moved `BoneFollower`, `BoneFollowerGraphic` and `PointFollower` from `Components` directory to `Components/Following`. * Moved `BoundingBoxFollower` component from `Modules/BoundingBoxFollower` to `Components/Following`. diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader similarity index 100% rename from spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader rename to spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader.meta similarity index 100% rename from spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-SkeletonLit.shader.meta rename to spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader.meta