From 2ef2e702105bdd1d514fbe50aa96a5da6db39cf4 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 13 Aug 2019 19:02:15 +0200 Subject: [PATCH] [unity] Spine LWRP shaders package: Added LWRP version of "Spine/Skeleton" shader. The normal shader no longer worked in LWRP setting on Unity 2019.1.6+ on Android GLES 3.0 (due to instancing problems). Closes #1446. --- .../Spine-Skeleton-ForwardPass-LW.hlsl | 43 +++++ .../Spine-Skeleton-ForwardPass-LW.hlsl.meta | 9 + .../Shaders/Spine-Skeleton-LW.shader | 155 ++++++++++++++++++ .../Shaders/Spine-Skeleton-LW.shader.meta | 9 + 4 files changed, 216 insertions(+) create mode 100644 spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl create mode 100644 spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl.meta create mode 100644 spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader create mode 100644 spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader.meta diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl new file mode 100644 index 000000000..d9067d8cd --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl @@ -0,0 +1,43 @@ +#ifndef SKELETON_FORWARD_PASS_LW_INCLUDED +#define SKELETON_FORWARD_PASS_LW_INCLUDED + +struct appdata { + float3 pos : POSITION; + half4 color : COLOR; + float2 uv0 : TEXCOORD0; + + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct VertexOutput { + half4 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); + + float3 positionWS = TransformObjectToWorld(v.pos); + o.pos = TransformWorldToHClip(positionWS); + o.uv0 = v.uv0; + o.color = v.color; + return o; +} + +sampler2D _MainTex; + +half4 frag(VertexOutput i) : SV_Target{ + float4 texColor = tex2D(_MainTex, i.uv0); + + #if defined(_STRAIGHT_ALPHA_INPUT) + texColor.rgb *= texColor.a; + #endif + + return (texColor * i.color); +} + +#endif diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl.meta b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl.meta new file mode 100644 index 000000000..ad6bdf025 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 7b0e8ff465c74264ab0348b088f52d7e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader new file mode 100644 index 000000000..5772003b4 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader @@ -0,0 +1,155 @@ +Shader "Lightweight Render Pipeline/Spine/Skeleton" { + Properties { + _Cutoff("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 + [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default + } + + 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 + } + + Pass { + Name "Forward" + Tags{"LightMode" = "LightweightForward"} + + ZWrite Off + Cull Off + Blend One OneMinusSrcAlpha + + HLSLPROGRAM + // Required to compile gles 2.0 with standard srp library + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma target 2.0 + + // ------------------------------------- + // Lightweight Pipeline keywords + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE + #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile _ _SHADOWS_SOFT + + // ------------------------------------- + // Unity defined keywords + #pragma multi_compile_fog + + //-------------------------------------- + // GPU Instancing + #pragma multi_compile_instancing + + //-------------------------------------- + // Spine related keywords + #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma vertex vert + #pragma fragment frag + #pragma target 2.0 + + #undef LIGHTMAP_ON + + #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl" + + #define USE_LWRP + #define fixed4 half4 + #define fixed3 half3 + #define fixed half + #include "CGIncludes/Spine-Skeleton-ForwardPass-LW.hlsl" + ENDHLSL + } + + Pass + { + Name "ShadowCaster" + Tags{"LightMode" = "ShadowCaster"} + + ZWrite On + ZTest LEqual + Cull Off + + HLSLPROGRAM + // Required to compile gles 2.0 with standard srp library + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma target 2.0 + + // ------------------------------------- + // Material Keywords + #pragma shader_feature _ALPHATEST_ON + + //-------------------------------------- + // GPU Instancing + #pragma multi_compile_instancing + #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + + #pragma vertex ShadowPassVertexSkeletonLit + #pragma fragment ShadowPassFragmentSkeletonLit + + #include "Packages/com.unity.render-pipelines.lightweight/Shaders/LitInput.hlsl" + #include "Packages/com.unity.render-pipelines.lightweight/Shaders/ShadowCasterPass.hlsl" + + #define USE_LWRP + #define fixed4 half4 + #define fixed3 half3 + #define fixed half + #include "CGIncludes/Spine-Input-LW.hlsl" + #include "CGIncludes/Spine-SkeletonLit-ShadowCasterPass-LW.hlsl" + + ENDHLSL + } + + Pass + { + Name "DepthOnly" + Tags{"LightMode" = "DepthOnly"} + + ZWrite On + ColorMask 0 + Cull Off + + HLSLPROGRAM + // Required to compile gles 2.0 with standard srp library + #pragma prefer_hlslcc gles + #pragma exclude_renderers d3d11_9x + #pragma target 2.0 + + #pragma vertex DepthOnlyVertexSprite + #pragma fragment DepthOnlyFragmentSprite + + // ------------------------------------- + // Material Keywords + #pragma shader_feature _ALPHATEST_ON + #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + + //-------------------------------------- + // GPU Instancing + #pragma multi_compile_instancing + + #include "Packages/com.unity.render-pipelines.lightweight/Shaders/LitInput.hlsl" + #include "Packages/com.unity.render-pipelines.lightweight/Shaders/DepthOnlyPass.hlsl" + + #define USE_LWRP + #define fixed4 half4 + #define fixed3 half3 + #define fixed half + #include "CGIncludes/Spine-Input-LW.hlsl" + #include "CGIncludes/Spine-DepthOnlyPass-LW.hlsl" + ENDHLSL + } + } + + FallBack "Hidden/InternalErrorShader" +} diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader.meta b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader.meta new file mode 100644 index 000000000..a7740f135 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Skeleton-LW.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 65857b179c43d9c49ba05eeb3e483e87 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: