Advertisement
Guest User

Untitled

a guest
Aug 10th, 2021
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Universal Render Pipeline/2D/Spine/Skeleton Lit Depth Write" {
  2.     Properties {
  3.         [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
  4.         [NoScaleOffset] _MaskTex("Mask", 2D) = "white" {}
  5.         [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
  6.         [MaterialToggle(_LIGHT_AFFECTS_ADDITIVE)] _LightAffectsAdditive("Light Affects Additive", Float) = 0
  7.         [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
  8.         [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0
  9.         _ZWrite ("Depth Write", Float) = 1.0
  10.         // Disabled stencil test by default
  11.     }
  12.  
  13.     HLSLINCLUDE
  14.     #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  15.     ENDHLSL
  16.  
  17.     SubShader {
  18.         // UniversalPipeline tag is required. If Universal render pipeline is not set in the graphics settings
  19.         // this Subshader will fail.
  20.         Tags {"Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
  21.         Cull Off
  22.         ZWrite [_ZWrite]
  23.  
  24.         Stencil {
  25.             Ref[_StencilRef]
  26.             Comp[_StencilComp]
  27.             Pass Keep
  28.         }
  29.  
  30.         Pass {
  31.             Tags { "LightMode" = "Universal2D" }
  32.  
  33.             ZWrite [_ZWrite]
  34.             Cull Off
  35.             Blend One OneMinusSrcAlpha
  36.  
  37.             HLSLPROGRAM
  38.             // Required to compile gles 2.0 with standard srp library
  39.             #pragma prefer_hlslcc gles
  40.             #pragma exclude_renderers d3d11_9x
  41.             #pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __
  42.             #pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __
  43.             #pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __
  44.             #pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __
  45.             #pragma multi_compile _ _LIGHT_AFFECTS_ADDITIVE
  46.  
  47.             struct Attributes {
  48.                 float3 positionOS : POSITION;
  49.                 half4 color : COLOR;
  50.                 float2 uv : TEXCOORD0;
  51.             };
  52.  
  53.             struct Varyings {
  54.                 float4 positionCS : SV_POSITION;
  55.                 half4 color : COLOR0;
  56.                 float2 uv : TEXCOORD0;
  57.                 float2 lightingUV : TEXCOORD1;
  58.             };
  59.  
  60.             // Spine related keywords
  61.             #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
  62.             #pragma vertex CombinedShapeLightVertex
  63.             #pragma fragment CombinedShapeLightFragment
  64.  
  65.             #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
  66.             #define USE_URP
  67.             #include "../Include/SpineCoreShaders/Spine-Common.cginc"
  68.  
  69.             TEXTURE2D(_MainTex);
  70.             SAMPLER(sampler_MainTex);
  71.             TEXTURE2D(_MaskTex);
  72.             SAMPLER(sampler_MaskTex);
  73.  
  74.             #if USE_SHAPE_LIGHT_TYPE_0
  75.             SHAPE_LIGHT(0)
  76.             #endif
  77.  
  78.             #if USE_SHAPE_LIGHT_TYPE_1
  79.             SHAPE_LIGHT(1)
  80.             #endif
  81.  
  82.             #if USE_SHAPE_LIGHT_TYPE_2
  83.             SHAPE_LIGHT(2)
  84.             #endif
  85.  
  86.             #if USE_SHAPE_LIGHT_TYPE_3
  87.             SHAPE_LIGHT(3)
  88.             #endif
  89.  
  90.             Varyings CombinedShapeLightVertex(Attributes v)
  91.             {
  92.                 Varyings o = (Varyings)0;
  93.  
  94.                 o.positionCS = TransformObjectToHClip(v.positionOS);
  95.                 o.uv = v.uv;
  96.                 float4 clipVertex = o.positionCS / o.positionCS.w;
  97.                 o.lightingUV = ComputeScreenPos(clipVertex).xy;
  98.                 o.color = PMAGammaToTargetSpace(v.color);
  99.                 return o;
  100.             }
  101.  
  102.             #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"
  103.  
  104.             half4 CombinedShapeLightFragment(Varyings i) : SV_Target
  105.             {
  106.                 half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
  107.                 #if defined(_STRAIGHT_ALPHA_INPUT)
  108.                 tex.rgb *= tex.a;
  109.                 #endif
  110.  
  111.                 half4 main = tex * i.color;
  112.             #if !defined(_LIGHT_AFFECTS_ADDITIVE)
  113.                 if (i.color.a == 0)
  114.                     return main;
  115.             #endif
  116.                 half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
  117.                 return half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, i.lightingUV).rgb, main.a);
  118.             }
  119.  
  120.             ENDHLSL
  121.         }
  122.  
  123.         Pass
  124.         {
  125.             Tags { "LightMode" = "NormalsRendering"}
  126.  
  127.             Blend SrcAlpha OneMinusSrcAlpha
  128.             ZWrite [_ZWrite]
  129.  
  130.             HLSLPROGRAM
  131.             #pragma prefer_hlslcc gles
  132.             #pragma vertex NormalsRenderingVertex
  133.             #pragma fragment NormalsRenderingFragment
  134.  
  135.             struct Attributes
  136.             {
  137.                 float3 positionOS   : POSITION;
  138.                 float4 color        : COLOR;
  139.                 float2 uv           : TEXCOORD0;
  140.             };
  141.  
  142.             struct Varyings
  143.             {
  144.                 float4  positionCS      : SV_POSITION;
  145.                 float4  color           : COLOR;
  146.                 float2  uv              : TEXCOORD0;
  147.                 float3  normalVS        : TEXCOORD1;
  148.             };
  149.  
  150.             TEXTURE2D(_MainTex);
  151.             SAMPLER(sampler_MainTex);
  152.  
  153.             Varyings NormalsRenderingVertex(Attributes attributes)
  154.             {
  155.                 Varyings o = (Varyings)0;
  156.  
  157.                 o.positionCS = TransformObjectToHClip(attributes.positionOS);
  158.                 o.uv = attributes.uv;
  159.                 o.color = attributes.color;
  160.                 float3 normalWS = TransformObjectToWorldDir(float3(0, 0, -1));
  161.                 o.normalVS = TransformWorldToViewDir(normalWS);
  162.                 return o;
  163.             }
  164.  
  165.             #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/NormalsRenderingShared.hlsl"
  166.  
  167.             float4 NormalsRenderingFragment(Varyings i) : SV_Target
  168.             {
  169.                 float4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
  170.  
  171.                 float4 normalColor;
  172.                 normalColor.rgb = 0.5 * ((i.normalVS)+1);
  173.                 normalColor.a = mainTex.a;
  174.                 return normalColor;
  175.             }
  176.             ENDHLSL
  177.         }
  178.  
  179.         Pass
  180.         {
  181.             Name "Unlit"
  182.             Tags { "LightMode" = "UniversalForward" "Queue"="Transparent" "RenderType"="Transparent"}
  183.  
  184.             ZWrite [_ZWrite]
  185.             Cull Off
  186.             Blend One OneMinusSrcAlpha
  187.  
  188.             HLSLPROGRAM
  189.             #pragma prefer_hlslcc gles
  190.             #pragma vertex UnlitVertex
  191.             #pragma fragment UnlitFragment
  192.  
  193.             struct Attributes
  194.             {
  195.                 float3 positionOS   : POSITION;
  196.                 float4 color        : COLOR;
  197.                 float2 uv           : TEXCOORD0;
  198.             };
  199.  
  200.             struct Varyings
  201.             {
  202.                 float4  positionCS      : SV_POSITION;
  203.                 float4  color           : COLOR;
  204.                 float2  uv              : TEXCOORD0;
  205.             };
  206.  
  207.             TEXTURE2D(_MainTex);
  208.             SAMPLER(sampler_MainTex);
  209.             float4 _MainTex_ST;
  210.  
  211.             Varyings UnlitVertex(Attributes attributes)
  212.             {
  213.                 Varyings o = (Varyings)0;
  214.  
  215.                 o.positionCS = TransformObjectToHClip(attributes.positionOS);
  216.                 o.uv = TRANSFORM_TEX(attributes.uv, _MainTex);
  217.                 o.uv = attributes.uv;
  218.                 o.color = attributes.color;
  219.                 return o;
  220.             }
  221.  
  222.             float4 UnlitFragment(Varyings i) : SV_Target
  223.             {
  224.                 half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
  225.                 half4 main;
  226.                 #if defined(_STRAIGHT_ALPHA_INPUT)
  227.                 main.rgb = tex.rgb * i.color.rgb * tex.a;
  228.                 #else
  229.                 main.rgb = tex.rgb * i.color.rgb;
  230.                 #endif
  231.                 main.a = tex.a * i.color.a;
  232.  
  233.                 return main;
  234.             }
  235.             ENDHLSL
  236.         }
  237.     }
  238.     FallBack "Universal Render Pipeline/2D/Sprite-Lit-Default"
  239. }
  240.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement