更新,spine和很多优化
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
#ifndef COMMON_SHADOW_CASTER_PASS_URP_INCLUDED
|
||||
#define COMMON_SHADOW_CASTER_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
float3 _LightDirection;
|
||||
|
||||
struct AttributesSpine
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float4 vertexColor : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VaryingsSpine
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 texcoordAndAlpha: TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 GetShadowPositionHClip(AttributesSpine input)
|
||||
{
|
||||
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
|
||||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
|
||||
|
||||
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
positionCS.z = min(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
|
||||
#else
|
||||
positionCS.z = max(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
|
||||
#endif
|
||||
|
||||
return positionCS;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53d9e6b22286c5640b000735f5a4f2ee
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
#ifndef SPINE_COMMON_URP_INCLUDED
|
||||
#define SPINE_COMMON_URP_INCLUDED
|
||||
|
||||
#if defined(USE_FORWARD_PLUS) || defined(USE_CLUSTER_LIGHT_LOOP)
|
||||
#define IS_URP_14_OR_NEWER 1
|
||||
#define IS_URP_12_OR_NEWER 1
|
||||
#else
|
||||
#define IS_URP_14_OR_NEWER 0
|
||||
#ifdef UNIVERSAL_REALTIME_LIGHTS_INCLUDED
|
||||
#define IS_URP_12_OR_NEWER 1
|
||||
#else
|
||||
#define IS_URP_12_OR_NEWER 0
|
||||
#endif
|
||||
#endif
|
||||
#if IS_URP_14_OR_NEWER && !defined(_USE_WEBGL1_LIGHTS)
|
||||
#define IS_URP_15_OR_NEWER 1
|
||||
#include "Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolume.hlsl"
|
||||
#if defined(_APVWorldOffset)
|
||||
#define IS_URP_17_OR_NEWER 1
|
||||
#else
|
||||
#define IS_URP_17_OR_NEWER 0
|
||||
#endif
|
||||
#else
|
||||
#define IS_URP_15_OR_NEWER 0
|
||||
#endif
|
||||
|
||||
#if defined(_WRITE_RENDERING_LAYERS) && IS_URP_14_OR_NEWER
|
||||
#define USE_WRITE_RENDERING_LAYERS
|
||||
#endif
|
||||
|
||||
#if defined(_LIGHT_LAYERS) && IS_URP_12_OR_NEWER
|
||||
#define USE_LIGHT_LAYERS
|
||||
#endif
|
||||
|
||||
#if defined(_LIGHT_COOKIES) && IS_URP_12_OR_NEWER
|
||||
#define USE_LIGHT_COOKIES
|
||||
#endif
|
||||
|
||||
#ifdef USE_LIGHT_LAYERS
|
||||
uint GetMeshRenderingLayerBackwardsCompatible()
|
||||
{
|
||||
#if IS_URP_14_OR_NEWER
|
||||
return GetMeshRenderingLayer();
|
||||
#elif IS_URP_12_OR_NEWER
|
||||
return GetMeshRenderingLightLayer();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
uint GetMeshRenderingLayerBackwardsCompatible()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if USE_FORWARD_PLUS
|
||||
// note: LIGHT_LOOP_BEGIN accesses inputData.normalizedScreenSpaceUV and inputData.positionWS.
|
||||
#define LIGHT_LOOP_BEGIN_SPINE LIGHT_LOOP_BEGIN
|
||||
#define LIGHT_LOOP_END_SPINE LIGHT_LOOP_END
|
||||
#elif !_USE_WEBGL1_LIGHTS
|
||||
#define LIGHT_LOOP_BEGIN_SPINE(lightCount) \
|
||||
for (uint lightIndex = 0u; lightIndex < lightCount; ++lightIndex) {
|
||||
|
||||
#define LIGHT_LOOP_END_SPINE }
|
||||
#else
|
||||
// WebGL 1 doesn't support variable for loop conditions
|
||||
#define LIGHT_LOOP_BEGIN_SPINE(lightCount) \
|
||||
for (int lightIndex = 0; lightIndex < _WEBGL1_MAX_LIGHTS; ++lightIndex) { \
|
||||
if (lightIndex >= (int)lightCount) break;
|
||||
|
||||
#define LIGHT_LOOP_END_SPINE }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c898d902be2aa254fac1da6de09f0a87
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#ifndef SPRITES_DEPTH_NORMALS_PASS_URP_INCLUDED
|
||||
#define SPRITES_DEPTH_NORMALS_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct AttributesSpine
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float4 vertexColor : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VaryingsSpine
|
||||
{
|
||||
float3 normalWS : NORMAL;
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 texcoordAndAlpha: TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VaryingsSpine DepthNormalsVertex(AttributesSpine input)
|
||||
{
|
||||
VaryingsSpine output = (VaryingsSpine)0;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
half3 fixedNormal = half3(0, 0, -1);
|
||||
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
|
||||
|
||||
#ifdef _DOUBLE_SIDED_LIGHTING
|
||||
// unfortunately we have to compute the sign here in the vertex shader
|
||||
// instead of using VFACE in fragment shader stage.
|
||||
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
|
||||
half faceSign = sign(dot(viewDirWS, normalWS));
|
||||
normalWS *= faceSign;
|
||||
#endif
|
||||
output.normalWS = normalWS;
|
||||
|
||||
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
|
||||
output.texcoordAndAlpha.a = input.vertexColor.a;
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
return output;
|
||||
}
|
||||
|
||||
void DepthNormalsFragment(VaryingsSpine input,
|
||||
out half4 outNormalWS : SV_Target0
|
||||
#ifdef _WRITE_RENDERING_LAYERS
|
||||
, out float4 outRenderingLayers : SV_Target1
|
||||
#endif
|
||||
)
|
||||
{
|
||||
fixed4 texureColor = tex2D(_MainTex, input.texcoordAndAlpha.xy);
|
||||
clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
|
||||
|
||||
float3 normalWS = input.normalWS;
|
||||
#if defined(_GBUFFER_NORMALS_OCT)
|
||||
float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms.
|
||||
float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
|
||||
half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
|
||||
outNormalWS = half4(packedNormalWS, 0.0);
|
||||
#else
|
||||
outNormalWS = half4(normalWS, 0.0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_WRITE_RENDERING_LAYERS
|
||||
uint renderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 803855a1999ecce4081f5e0fb18c6475
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#ifndef SPRITES_DEPTH_ONLY_PASS_URP_INCLUDED
|
||||
#define SPRITES_DEPTH_ONLY_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct AttributesSpine
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float4 vertexColor : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VaryingsSpine
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 texcoordAndAlpha: TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VaryingsSpine DepthOnlyVertex(AttributesSpine input)
|
||||
{
|
||||
VaryingsSpine output = (VaryingsSpine)0;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
|
||||
output.texcoordAndAlpha.a = input.vertexColor.a;
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 DepthOnlyFragment(VaryingsSpine input) : SV_TARGET
|
||||
{
|
||||
fixed4 texureColor = tex2D(_MainTex, input.texcoordAndAlpha.xy);
|
||||
clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
|
||||
return input.positionCS.z;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 692e50ad8dd7bb44cb6f6f7473b62ac8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#ifndef URP_INPUT_OUTLINE_INCLUDED
|
||||
#define URP_INPUT_OUTLINE_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
|
||||
////////////////////////////////////////
|
||||
// Defines
|
||||
//
|
||||
#undef LIGHTMAP_ON
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _MainTex_ST;
|
||||
#ifndef NO_CUTOFF_PARAM
|
||||
half _Cutoff;
|
||||
#endif
|
||||
float _OutlineWidth;
|
||||
float4 _OutlineColor;
|
||||
float4 _MainTex_TexelSize;
|
||||
float _ThresholdEnd;
|
||||
float _OutlineSmoothness;
|
||||
float _OutlineOpaqueAlpha;
|
||||
float _OutlineMipLevel;
|
||||
int _OutlineReferenceTexWidth;
|
||||
CBUFFER_END
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
#endif // URP_INPUT_OUTLINE_INCLUDED
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbcfa8e1a739e2b4d9307f6c0980c50f
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#ifndef URP_INPUT_SPRITE_INCLUDED
|
||||
#define URP_INPUT_SPRITE_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
|
||||
float4 _MainTex_ST;
|
||||
half4 _Color;
|
||||
half4 _Black;
|
||||
half _Cutoff;
|
||||
half _ShadowAlphaCutoff;
|
||||
|
||||
#ifndef SPRITE_SHADER_2D
|
||||
half _Metallic;
|
||||
half _Glossiness;
|
||||
half _GlossMapScale;
|
||||
#endif
|
||||
|
||||
half _BumpScale;
|
||||
|
||||
float _BlendAmount;
|
||||
|
||||
float _Hue;
|
||||
float _Saturation;
|
||||
float _Brightness;
|
||||
half4 _OverlayColor;
|
||||
|
||||
half4 _EmissionColor;
|
||||
float _EmissionPower;
|
||||
|
||||
float4 _FixedNormal;
|
||||
|
||||
float _RimPower;
|
||||
half4 _RimColor;
|
||||
|
||||
CBUFFER_END
|
||||
|
||||
#endif // URP_INPUT_SPRITE_INCLUDED
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cb02894258b6c249ad73b7869086876
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
#ifndef URP_LIT_INPUT_INCLUDED
|
||||
#define URP_LIT_INPUT_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
|
||||
////////////////////////////////////////
|
||||
// Defines
|
||||
//
|
||||
#undef LIGHTMAP_ON
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
|
||||
float4 _MainTex_ST;
|
||||
half _Cutoff;
|
||||
half4 _Color;
|
||||
half4 _Black;
|
||||
|
||||
CBUFFER_END
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
#endif // URP_LIT_INPUT_INCLUDED
|
||||
Packages/com.esotericsoftware.spine.urp-shaders-4.3-2019.1/Shaders/Include/Spine-Input-URP.hlsl.meta
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04433ebe597dd6d48ad3306ae3eeca2e
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#ifndef SPINE_OUTLINE_PASS_URP_INCLUDED
|
||||
#define SPINE_OUTLINE_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Outline-Common.cginc"
|
||||
|
||||
struct VertexInput {
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertexColor : COLOR;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float vertexColorAlpha : COLOR;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VertexOutput vertOutline(VertexInput v) {
|
||||
VertexOutput o;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
o.pos = TransformObjectToHClip(v.positionOS.xyz);
|
||||
o.uv = v.uv;
|
||||
o.vertexColorAlpha = v.vertexColor.a;
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 fragOutline(VertexOutput i) : SV_Target {
|
||||
|
||||
float4 texColor = computeOutlinePixel(_MainTex, _MainTex_TexelSize.xy, i.uv, i.vertexColorAlpha,
|
||||
_OutlineWidth, _OutlineReferenceTexWidth, _OutlineMipLevel,
|
||||
_OutlineSmoothness, _ThresholdEnd, _OutlineOpaqueAlpha, _OutlineColor);
|
||||
return texColor;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6702be883c5f0ef439d7d9ad87d0b84b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#ifndef SKELETON_FORWARD_PASS_URP_INCLUDED
|
||||
#define SKELETON_FORWARD_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Common.cginc"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Skeleton-Tint-Common.cginc"
|
||||
|
||||
struct appdata {
|
||||
float3 pos : POSITION;
|
||||
half4 color : COLOR;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
float2 tintBlackRG : TEXCOORD1;
|
||||
float2 tintBlackB : TEXCOORD2;
|
||||
#endif
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
half4 color : COLOR0;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float4 pos : SV_POSITION;
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
float3 darkColor : TEXCOORD1;
|
||||
#endif
|
||||
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 = PMAGammaToTargetSpace(v.color);
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
o.color *= _Color;
|
||||
o.darkColor = GammaToTargetSpace(
|
||||
half3(v.tintBlackRG.r, v.tintBlackRG.g, v.tintBlackB.r)) + (_Black.rgb * v.color.a);
|
||||
#elif defined (APPLY_MATERIAL_TINT_COLOR)
|
||||
o.color *= _Color;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(VertexOutput i) : SV_Target{
|
||||
float4 texColor = tex2D(_MainTex, i.uv0);
|
||||
#if defined(_ZWRITE)
|
||||
clip(texColor.a * i.color.a - _Cutoff);
|
||||
#endif
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
return fragTintedColor(texColor, i.darkColor, i.color, _Color.a, _Black.a);
|
||||
#else
|
||||
#if defined(_STRAIGHT_ALPHA_INPUT)
|
||||
texColor.rgb *= texColor.a;
|
||||
#endif
|
||||
return (texColor * i.color);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66d99756a2edf0e4d8761712cb85e9f1
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
#ifndef SKELETONLIT_FORWARD_PASS_URP_INCLUDED
|
||||
#define SKELETONLIT_FORWARD_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Common.cginc"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Skeleton-Tint-Common.cginc"
|
||||
|
||||
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
#define SKELETONLIT_RECEIVE_SHADOWS
|
||||
#endif
|
||||
|
||||
#if !defined(DYNAMICLIGHTMAP_ON) && !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && defined(__PROBEVOLUME_HLSL__)
|
||||
#define USE_ADAPTIVE_PROBE_VOLUMES
|
||||
#endif
|
||||
|
||||
#if !(defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
|
||||
#undef _FOG
|
||||
#endif
|
||||
|
||||
struct appdata {
|
||||
float3 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
half4 color : COLOR;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
float2 tintBlackRG : TEXCOORD1;
|
||||
float2 tintBlackB : TEXCOORD2;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
half4 color : COLOR0;
|
||||
#if defined(_FOG)
|
||||
float3 uv0AndFog : TEXCOORD0;
|
||||
#else
|
||||
float2 uv0 : TEXCOORD0;
|
||||
#endif
|
||||
float4 pos : SV_POSITION;
|
||||
|
||||
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
||||
float4 shadowCoord : TEXCOORD1;
|
||||
half3 shadowedColor : TEXCOORD2;
|
||||
#endif
|
||||
#if defined(_ADDITIONAL_LIGHTS) && USE_FORWARD_PLUS
|
||||
float3 positionWS : TEXCOORD3;
|
||||
half3 normalWS : TEXCOORD4;
|
||||
#endif
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
float3 darkColor : TEXCOORD5;
|
||||
#endif
|
||||
#if defined(USE_ADAPTIVE_PROBE_VOLUMES) && defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)
|
||||
float3 positionCS : TEXCOORD6;
|
||||
#endif
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
#if defined(_FOG)
|
||||
#define PackedUV0(i) i.uv0AndFog.xy
|
||||
#define PackedFog(i) i.uv0AndFog.z
|
||||
#else
|
||||
#define PackedUV0(i) i.uv0.xy
|
||||
#endif
|
||||
|
||||
half3 ProcessLight(float3 positionWS, half3 normalWS, uint meshRenderingLayers, int lightIndex)
|
||||
{
|
||||
Light light = GetAdditionalLight(lightIndex, positionWS);
|
||||
#ifdef USE_LIGHT_LAYERS
|
||||
if (!IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
return half3(0, 0, 0);
|
||||
#endif
|
||||
|
||||
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
return LightingLambert(attenuatedLightColor, light.direction, normalWS);
|
||||
}
|
||||
|
||||
half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS, out half3 shadowedColor) {
|
||||
Light mainLight = GetMainLight();
|
||||
half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
|
||||
half3 mainLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
|
||||
|
||||
half3 additionalLightColor = half3(0, 0, 0);
|
||||
// Note: we don't add any lighting in the fragment shader, thus we include both variants below
|
||||
#if defined(_ADDITIONAL_LIGHTS) || defined(_ADDITIONAL_LIGHTS_VERTEX)
|
||||
uint meshRenderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
#if USE_FORWARD_PLUS
|
||||
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
additionalLightColor += ProcessLight(positionWS, normalWS, meshRenderingLayers, lightIndex);
|
||||
}
|
||||
#else // !USE_FORWARD_PLUS
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
LIGHT_LOOP_BEGIN_SPINE(pixelLightCount)
|
||||
additionalLightColor += ProcessLight(positionWS, normalWS, meshRenderingLayers, lightIndex);
|
||||
LIGHT_LOOP_END_SPINE
|
||||
#endif // USE_FORWARD_PLUS
|
||||
#endif
|
||||
|
||||
shadowedColor = additionalLightColor;
|
||||
return mainLightColor + additionalLightColor;
|
||||
}
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS) && USE_FORWARD_PLUS
|
||||
half3 LightweightLightFragmentSimplified(float3 positionWS, float2 positionCS, half3 normalWS, out half3 shadowedColor) {
|
||||
half3 additionalLightColor = half3(0, 0, 0);
|
||||
shadowedColor = half3(0, 0, 0);
|
||||
|
||||
InputData inputData; // LIGHT_LOOP_BEGIN macro requires InputData struct in USE_FORWARD_PLUS branch
|
||||
inputData.positionWS = positionWS;
|
||||
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(positionCS);
|
||||
|
||||
uint meshRenderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
LIGHT_LOOP_BEGIN_SPINE(pixelLightCount)
|
||||
additionalLightColor += ProcessLight(positionWS, normalWS, meshRenderingLayers, lightIndex);
|
||||
LIGHT_LOOP_END_SPINE
|
||||
return additionalLightColor;
|
||||
}
|
||||
#endif
|
||||
|
||||
VertexOutput vert(appdata v) {
|
||||
VertexOutput o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
half4 color = PMAGammaToTargetSpace(v.color);
|
||||
float3 positionWS = TransformObjectToWorld(v.pos);
|
||||
half3 fixedNormal = half3(0, 0, -1);
|
||||
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
|
||||
|
||||
o.pos = TransformWorldToHClip(positionWS);
|
||||
#if defined(_FOG)
|
||||
half fogFactor = ComputeFogFactor(o.pos.z);
|
||||
PackedFog(o) = fogFactor;
|
||||
#endif
|
||||
PackedUV0(o) = v.uv0;
|
||||
|
||||
#ifdef _DOUBLE_SIDED_LIGHTING
|
||||
// unfortunately we have to compute the sign here in the vertex shader
|
||||
// instead of using VFACE in fragment shader stage.
|
||||
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
|
||||
half faceSign = sign(dot(viewDirWS, normalWS));
|
||||
normalWS *= faceSign;
|
||||
#endif
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS) && USE_FORWARD_PLUS
|
||||
o.positionWS = positionWS;
|
||||
o.normalWS = normalWS;
|
||||
#endif
|
||||
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
color *= _Color;
|
||||
o.darkColor = GammaToTargetSpace(
|
||||
half3(v.tintBlackRG.r, v.tintBlackRG.g, v.tintBlackB.r)) + (_Black.rgb * v.color.a);
|
||||
#endif
|
||||
|
||||
half3 shadowedColor;
|
||||
#if !defined(_LIGHT_AFFECTS_ADDITIVE)
|
||||
if (color.a == 0) {
|
||||
o.color = color;
|
||||
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
||||
o.shadowedColor = color.rgb;
|
||||
o.shadowCoord = float4(0, 0, 0, 0);
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
#endif // !defined(_LIGHT_AFFECTS_ADDITIVE)
|
||||
|
||||
color.rgb *= LightweightLightVertexSimplified(positionWS, normalWS, shadowedColor);
|
||||
|
||||
// Note: ambient light is also handled via SH.
|
||||
half3 vertexSH;
|
||||
float4 ignoredProbeOcclusion;
|
||||
#if IS_URP_15_OR_NEWER
|
||||
#ifdef OUTPUT_SH4
|
||||
#if IS_URP_17_OR_NEWER
|
||||
OUTPUT_SH4(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), vertexSH, ignoredProbeOcclusion);
|
||||
#else // 15 or newer
|
||||
OUTPUT_SH4(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), vertexSH);
|
||||
#endif
|
||||
#else
|
||||
OUTPUT_SH(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), vertexSH);
|
||||
#endif
|
||||
#else
|
||||
OUTPUT_SH(normalWS.xyz, vertexSH);
|
||||
#endif
|
||||
|
||||
#if defined(USE_ADAPTIVE_PROBE_VOLUMES)
|
||||
#if !defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)
|
||||
half4 shadowMask = 1.0;
|
||||
half3 bakedGI = SAMPLE_GI(vertexSH,
|
||||
GetAbsolutePositionWS(positionWS),
|
||||
normalWS.xyz,
|
||||
GetWorldSpaceNormalizeViewDir(positionWS),
|
||||
o.pos.xy,
|
||||
ignoredProbeOcclusion,
|
||||
shadowMask) * v.color.a;
|
||||
#else // _ADAPTIVE_PROBE_VOLUMES_PER_PIXEL
|
||||
half3 bakedGI = half3(0.0, 0.0, 0.0);
|
||||
o.positionCS = o.pos;
|
||||
#endif
|
||||
#else
|
||||
half3 bakedGI = SAMPLE_GI(v.lightmapUV, vertexSH, normalWS) * v.color.a;
|
||||
#endif
|
||||
color.rgb += bakedGI;
|
||||
o.color = color;
|
||||
|
||||
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
||||
shadowedColor += bakedGI;
|
||||
o.shadowedColor = shadowedColor;
|
||||
|
||||
VertexPositionInputs vertexInput;
|
||||
vertexInput.positionWS = positionWS;
|
||||
vertexInput.positionCS = o.pos;
|
||||
o.shadowCoord = GetShadowCoord(vertexInput);
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(VertexOutput i
|
||||
#ifdef USE_WRITE_RENDERING_LAYERS
|
||||
, out float4 outRenderingLayers : SV_Target1
|
||||
#endif
|
||||
) : SV_Target0
|
||||
{
|
||||
half4 tex = tex2D(_MainTex, PackedUV0(i));
|
||||
#if !defined(_TINT_BLACK_ON) && defined(_STRAIGHT_ALPHA_INPUT)
|
||||
tex.rgb *= tex.a;
|
||||
#endif
|
||||
|
||||
#if defined(USE_ADAPTIVE_PROBE_VOLUMES) && defined(_ADAPTIVE_PROBE_VOLUMES_PER_PIXEL)
|
||||
half3 vertexSH;
|
||||
float4 ignoredProbeOcclusion;
|
||||
OUTPUT_SH4(i.positionWS, i.normalWS.xyz, GetWorldSpaceNormalizeViewDir(i.positionWS), vertexSH, ignoredProbeOcclusion);
|
||||
half4 shadowMask = 1.0;
|
||||
half3 bakedGI = SAMPLE_GI(vertexSH,
|
||||
GetAbsolutePositionWS(i.positionWS),
|
||||
i.normalWS.xyz,
|
||||
GetWorldSpaceNormalizeViewDir(i.positionWS),
|
||||
i.positionCS.xy,
|
||||
ignoredProbeOcclusion,
|
||||
shadowMask) * i.color.a;
|
||||
i.color.rgb += bakedGI;
|
||||
#endif
|
||||
|
||||
if (i.color.a == 0) {
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
return fragTintedColor(tex, i.darkColor, i.color, _Color.a, _Black.a);
|
||||
#else
|
||||
return tex * i.color;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS) && USE_FORWARD_PLUS
|
||||
// USE_FORWARD_PLUS lights need to be processed in fragment shader,
|
||||
// otherwise light culling by vertex will create a very bad lighting result.
|
||||
half3 shadowedColor;
|
||||
i.color.rgb += LightweightLightFragmentSimplified(i.positionWS, i.pos.xy, i.normalWS, shadowedColor);
|
||||
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
||||
i.shadowedColor += shadowedColor;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
||||
half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
|
||||
i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
|
||||
#endif
|
||||
|
||||
#ifdef USE_WRITE_RENDERING_LAYERS
|
||||
uint renderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
|
||||
#endif
|
||||
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
half4 pixel = fragTintedColor(tex, i.darkColor, i.color, _Color.a, _Black.a);
|
||||
#else
|
||||
half4 pixel = tex * i.color;
|
||||
#endif
|
||||
|
||||
#if defined(_FOG)
|
||||
pixel.rgb = MixFogColor(pixel.rgb, unity_FogColor.rgb * pixel.a, PackedFog(i));
|
||||
#endif
|
||||
return pixel;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 259a1da3d69e3904e92a582735352359
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#ifndef SKELETONLIT_SHADOW_CASTER_PASS_URP_INCLUDED
|
||||
#define SKELETONLIT_SHADOW_CASTER_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
|
||||
float3 _LightDirection;
|
||||
|
||||
struct AttributesSpine
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float4 vertexColor : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VaryingsSpine
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 texcoordAndAlpha: TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
|
||||
{
|
||||
float3 positionWS = TransformObjectToWorld(positionOS);
|
||||
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
positionCS.z = min(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
|
||||
#else
|
||||
positionCS.z = max(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
|
||||
#endif
|
||||
|
||||
return positionCS;
|
||||
}
|
||||
|
||||
VaryingsSpine ShadowPassVertexSkeletonLit(AttributesSpine input)
|
||||
{
|
||||
VaryingsSpine output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
|
||||
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
|
||||
|
||||
half3 fixedNormalOS = half3(0, 0, -1);
|
||||
half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
|
||||
#ifdef _DOUBLE_SIDED_LIGHTING
|
||||
// flip normal for shadow bias if necessary
|
||||
// unfortunately we have to compute the sign here in the vertex shader
|
||||
// instead of using VFACE in fragment shader stage.
|
||||
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
|
||||
half faceSign = sign(dot(viewDirWS, normalWS));
|
||||
normalWS *= faceSign;
|
||||
#endif
|
||||
|
||||
output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
|
||||
output.texcoordAndAlpha.a = input.vertexColor.a;
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 ShadowPassFragmentSkeletonLit(VaryingsSpine input) : SV_TARGET
|
||||
{
|
||||
fixed4 texureColor = tex2D(_MainTex, input.texcoordAndAlpha.xy);
|
||||
clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80e9a34d66b713544a0a47bcf9ec53fe
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#ifndef URP_SPRITE_COMMON_INCLUDED
|
||||
#define URP_SPRITE_COMMON_INCLUDED
|
||||
|
||||
#undef LIGHTMAP_ON
|
||||
|
||||
#if defined(_SPECULAR) || defined(_SPECULAR_GLOSSMAP)
|
||||
#define SPECULAR
|
||||
#endif
|
||||
|
||||
//Have to process lighting per pixel if using normal maps or a diffuse ramp or rim lighting or specular
|
||||
#if defined(_NORMALMAP) || defined(_DIFFUSE_RAMP) || defined(_RIM_LIGHTING) || defined(SPECULAR)
|
||||
#define PER_PIXEL_LIGHTING
|
||||
#endif
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/ShaderShared.cginc"
|
||||
|
||||
#if defined(SPECULAR)
|
||||
|
||||
sampler2D _MetallicGlossMap;
|
||||
|
||||
inline half2 getMetallicGloss(float2 uv)
|
||||
{
|
||||
half2 mg;
|
||||
|
||||
#ifdef _SPECULAR_GLOSSMAP
|
||||
mg = tex2D(_MetallicGlossMap, uv).ra;
|
||||
mg.g *= _GlossMapScale;
|
||||
#else
|
||||
mg.r = _Metallic;
|
||||
mg.g = _Glossiness;
|
||||
#endif
|
||||
|
||||
return mg;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // URP_SPRITE_COMMON_INCLUDED
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46ef6e1b09e1bc04885eb905a8f2822d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#ifndef SPRITES_DEPTH_NORMALS_PASS_URP_INCLUDED
|
||||
#define SPRITES_DEPTH_NORMALS_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-Common-URP.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/SpriteLighting.cginc"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Common.cginc"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl"
|
||||
|
||||
struct VaryingsSprite
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
fixed4 vertexColor : COLOR;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
|
||||
#if defined(_NORMALMAP)
|
||||
half4 normalWorld : TEXCOORD4;
|
||||
half4 tangentWorld : TEXCOORD5;
|
||||
half4 binormalWorld : TEXCOORD6;
|
||||
#else
|
||||
half3 normalWorld : TEXCOORD4;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VaryingsSprite DepthNormalsVertexSprite(VertexInput input)
|
||||
{
|
||||
VaryingsSprite output = (VaryingsSprite)0;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.pos = calculateLocalPos(input.vertex);
|
||||
output.vertexColor = calculateVertexColor(input.color);
|
||||
output.texcoord = float3(calculateTextureCoord(input.texcoord), 0);
|
||||
|
||||
float backFaceSign = 1;
|
||||
#if defined(FIXED_NORMALS_BACKFACE_RENDERING)
|
||||
float3 positionWS = TransformObjectToWorld(input.vertex.xyz);
|
||||
backFaceSign = calculateBackfacingSign(positionWS.xyz);
|
||||
#endif
|
||||
|
||||
half3 normalWS = calculateSpriteWorldNormal(input, -backFaceSign);
|
||||
output.normalWorld.xyz = normalWS;
|
||||
#if defined(_NORMALMAP)
|
||||
output.tangentWorld.xyz = calculateWorldTangent(input.tangent);
|
||||
output.binormalWorld.xyz = calculateSpriteWorldBinormal(input, output.normalWorld.xyz, output.tangentWorld.xyz, backFaceSign);
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void DepthNormalsFragmentSprite(VaryingsSprite input,
|
||||
out half4 outNormalWS : SV_Target0
|
||||
#ifdef _WRITE_RENDERING_LAYERS
|
||||
, out float4 outRenderingLayers : SV_Target1
|
||||
#endif
|
||||
)
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
|
||||
ALPHA_CLIP(texureColor, input.vertexColor)
|
||||
|
||||
#if defined(PER_PIXEL_LIGHTING) && defined(_NORMALMAP)
|
||||
half3 normalWS = calculateNormalFromBumpMap(input.texcoord.xy, input.tangentWorld.xyz, input.binormalWorld.xyz, input.normalWorld.xyz);
|
||||
#else
|
||||
half3 normalWS = input.normalWorld.xyz;
|
||||
#endif
|
||||
|
||||
#if defined(_GBUFFER_NORMALS_OCT)
|
||||
float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms.
|
||||
float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
|
||||
half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
|
||||
outNormalWS = half4(packedNormalWS, 0.0);
|
||||
#else
|
||||
outNormalWS = half4(normalWS, 0.0);
|
||||
#endif
|
||||
|
||||
#ifdef USE_WRITE_RENDERING_LAYERS
|
||||
uint renderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5070c54df4a943a438cfe0a199b55657
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#ifndef SPRITES_DEPTH_ONLY_PASS_URP_INCLUDED
|
||||
#define SPRITES_DEPTH_ONLY_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-Common-URP.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct AttributesSprite
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float4 vertexColor : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VaryingsSprite
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 texcoordAndAlpha: TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
VaryingsSprite DepthOnlyVertexSprite(AttributesSprite input)
|
||||
{
|
||||
VaryingsSprite output = (VaryingsSprite)0;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
|
||||
output.texcoordAndAlpha.a = input.vertexColor.a * _Color.a;
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 DepthOnlyFragmentSprite(VaryingsSprite input) : SV_TARGET
|
||||
{
|
||||
fixed4 texureColor = calculateTexturePixel(input.texcoordAndAlpha.xy);
|
||||
clip(texureColor.a * input.texcoordAndAlpha.a - _Cutoff);
|
||||
return input.positionCS.z;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e6e6f2288b792e4aa0db167249e73bd
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+435
@@ -0,0 +1,435 @@
|
||||
#ifndef VERTEX_LIT_FORWARD_PASS_URP_INCLUDED
|
||||
#define VERTEX_LIT_FORWARD_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-Common-URP.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/SpriteLighting.cginc"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Common.cginc"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Common-URP.hlsl"
|
||||
|
||||
#if defined(_ALPHAPREMULTIPLY_ON)
|
||||
#undef _STRAIGHT_ALPHA_INPUT
|
||||
#elif !defined(_STRAIGHT_ALPHA_INPUT)
|
||||
#define _STRAIGHT_ALPHA_INPUT
|
||||
#endif
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Skeleton-Tint-Common.cginc"
|
||||
|
||||
#if !defined(DYNAMICLIGHTMAP_ON) && !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)) && defined(__PROBEVOLUME_HLSL__)
|
||||
#define USE_ADAPTIVE_PROBE_VOLUMES
|
||||
#endif
|
||||
|
||||
#if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS) || defined(USE_LIGHT_COOKIES) || defined(USE_ADAPTIVE_PROBE_VOLUMES)
|
||||
#define NEEDS_POSITION_WS
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
// Vertex output struct
|
||||
//
|
||||
struct VertexOutputLWRP
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
fixed4 vertexColor : COLOR;
|
||||
float3 texcoord : TEXCOORD0;
|
||||
|
||||
half4 fogFactorAndVertexLight : TEXCOORD1;
|
||||
half3 viewDirectionWS : TEXCOORD2;
|
||||
|
||||
DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 3);
|
||||
|
||||
#if defined(_NORMALMAP)
|
||||
half4 normalWorld : TEXCOORD4;
|
||||
half4 tangentWorld : TEXCOORD5;
|
||||
half4 binormalWorld : TEXCOORD6;
|
||||
#else
|
||||
half3 normalWorld : TEXCOORD4;
|
||||
#endif
|
||||
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
float4 shadowCoord : TEXCOORD7;
|
||||
#endif
|
||||
#if defined(NEEDS_POSITION_WS)
|
||||
float4 positionWS : TEXCOORD8;
|
||||
#endif
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
float3 darkColor : TEXCOORD9;
|
||||
#endif
|
||||
#if defined(USE_ADAPTIVE_PROBE_VOLUMES)
|
||||
float3 positionCS : TEXCOORD10;
|
||||
#endif
|
||||
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Vertex and Fragment functions //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
half4 CalculateShadowMaskBackwardsCompatible(InputData inputData)
|
||||
{
|
||||
// To ensure backward compatibility we have to avoid using shadowMask input, as it is not present in older shaders
|
||||
#if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON)
|
||||
half4 shadowMask = inputData.shadowMask;
|
||||
#elif !defined (LIGHTMAP_ON)
|
||||
half4 shadowMask = unity_ProbesOcclusion;
|
||||
#else
|
||||
half4 shadowMask = half4(1, 1, 1, 1);
|
||||
#endif
|
||||
|
||||
return shadowMask;
|
||||
}
|
||||
#endif
|
||||
|
||||
half3 LightweightLightVertexSimplified(float3 positionWS, half3 normalWS) {
|
||||
#ifdef _MAIN_LIGHT_VERTEX
|
||||
Light mainLight = GetMainLight();
|
||||
half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
|
||||
half3 diffuseLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
|
||||
#else
|
||||
half3 diffuseLightColor = half3(0, 0, 0);
|
||||
#endif
|
||||
|
||||
#ifdef _ADDITIONAL_LIGHTS_VERTEX
|
||||
int pixelLightCount = GetAdditionalLightsCount();
|
||||
for (int i = 0; i < pixelLightCount; ++i)
|
||||
{
|
||||
Light light = GetAdditionalLight(i, positionWS);
|
||||
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
diffuseLightColor += LightingLambert(attenuatedLightColor, light.direction, normalWS);
|
||||
}
|
||||
#endif // _ADDITIONAL_LIGHTS_VERTEX
|
||||
return diffuseLightColor;
|
||||
}
|
||||
|
||||
#ifdef _DIFFUSE_RAMP
|
||||
half3 LightingLambertRamped(half3 lightColor, float attenuation, half3 lightDir, half3 normal)
|
||||
{
|
||||
half angleDot = max(0, dot(lightDir, normal));
|
||||
return calculateRampedDiffuse(lightColor, attenuation, angleDot);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SPECULAR)
|
||||
|
||||
half3 ProcessLightPBRSimplified(InputData inputData, BRDFData brdfData, half4 shadowMask, uint meshRenderingLayers, int lightIndex)
|
||||
{
|
||||
#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask);
|
||||
#else
|
||||
Light light = GetAdditionalLight(lightIndex, inputData.positionWS);
|
||||
#endif
|
||||
#ifdef USE_LIGHT_LAYERS
|
||||
if (!IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
return half3(0, 0, 0);
|
||||
#endif
|
||||
return LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS);
|
||||
}
|
||||
|
||||
half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha, half metallic, half3 specular,
|
||||
half smoothness, half3 emission, half4 vertexColor)
|
||||
{
|
||||
#if !defined(_TINT_BLACK_ON)
|
||||
half4 albedo = texAlbedoAlpha * vertexColor;
|
||||
#else
|
||||
half4 albedo = texAlbedoAlpha;
|
||||
#endif
|
||||
|
||||
BRDFData brdfData;
|
||||
half ignoredAlpha = 1; // ignore alpha, otherwise
|
||||
InitializeBRDFData(albedo.rgb, metallic, specular, smoothness, ignoredAlpha, brdfData);
|
||||
brdfData.specular *= albedo.a;
|
||||
|
||||
#ifndef _MAIN_LIGHT_VERTEX
|
||||
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
Light mainLight = GetMainLight(inputData.shadowCoord);
|
||||
#else
|
||||
Light mainLight = GetMainLight();
|
||||
#endif
|
||||
#if defined(USE_LIGHT_COOKIES)
|
||||
half3 cookieColor = SampleMainLightCookie(inputData.positionWS);
|
||||
mainLight.color *= cookieColor;
|
||||
#endif
|
||||
|
||||
half3 finalColor = inputData.bakedGI * albedo.rgb;
|
||||
finalColor += LightingPhysicallyBased(brdfData, mainLight, inputData.normalWS, inputData.viewDirectionWS);
|
||||
#else // _MAIN_LIGHT_VERTEX
|
||||
half3 finalColor = inputData.bakedGI * albedo.rgb;
|
||||
#endif // _MAIN_LIGHT_VERTEX
|
||||
|
||||
#ifdef _ADDITIONAL_LIGHTS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
half4 shadowMask = CalculateShadowMaskBackwardsCompatible(inputData);
|
||||
#else
|
||||
half4 shadowMask = half4(1, 1, 1, 1);
|
||||
#endif
|
||||
|
||||
#if USE_FORWARD_PLUS
|
||||
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
finalColor += ProcessLightPBRSimplified(inputData, brdfData, shadowMask, meshRenderingLayers, lightIndex);
|
||||
}
|
||||
#endif
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
LIGHT_LOOP_BEGIN_SPINE(pixelLightCount)
|
||||
finalColor += ProcessLightPBRSimplified(inputData, brdfData, shadowMask, meshRenderingLayers, lightIndex);
|
||||
LIGHT_LOOP_END_SPINE
|
||||
|
||||
#endif // _ADDITIONAL_LIGHTS
|
||||
|
||||
#ifdef _ADDITIONAL_LIGHTS_VERTEX
|
||||
finalColor += inputData.vertexLighting * brdfData.diffuse;
|
||||
#endif
|
||||
finalColor += emission;
|
||||
return prepareLitPixelForOutput(half4(finalColor, albedo.a), texAlbedoAlpha.a, vertexColor.a);
|
||||
}
|
||||
|
||||
#else // !SPECULAR
|
||||
|
||||
half3 ProcessLightLambert(InputData inputData, half4 shadowMask, uint meshRenderingLayers, int lightIndex)
|
||||
{
|
||||
#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask);
|
||||
#else
|
||||
Light light = GetAdditionalLight(lightIndex, inputData.positionWS);
|
||||
#endif
|
||||
|
||||
#ifdef USE_LIGHT_LAYERS
|
||||
if (!IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
return half3(0, 0, 0);
|
||||
#endif
|
||||
|
||||
half3 attenuation = (light.distanceAttenuation * light.shadowAttenuation);
|
||||
half3 attenuatedLightColor = light.color * attenuation;
|
||||
#ifndef _DIFFUSE_RAMP
|
||||
return LightingLambert(attenuatedLightColor, light.direction, inputData.normalWS);
|
||||
#else
|
||||
return LightingLambertRamped(light.color, attenuation, light.direction, inputData.normalWS);
|
||||
#endif
|
||||
}
|
||||
|
||||
half4 LightweightFragmentBlinnPhongSimplified(InputData inputData, half4 texDiffuseAlpha, half3 emission, half4 vertexColor)
|
||||
{
|
||||
#if !defined(_TINT_BLACK_ON)
|
||||
half4 diffuse = texDiffuseAlpha * vertexColor;
|
||||
#else
|
||||
half4 diffuse = texDiffuseAlpha;
|
||||
#endif
|
||||
|
||||
#ifndef _MAIN_LIGHT_VERTEX
|
||||
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
Light mainLight = GetMainLight(inputData.shadowCoord);
|
||||
#else
|
||||
Light mainLight = GetMainLight();
|
||||
#endif
|
||||
#if defined(USE_LIGHT_COOKIES)
|
||||
half3 cookieColor = SampleMainLightCookie(inputData.positionWS);
|
||||
mainLight.color *= cookieColor;
|
||||
#endif
|
||||
|
||||
half3 diffuseLighting = inputData.bakedGI;
|
||||
|
||||
half3 attenuation = mainLight.distanceAttenuation* mainLight.shadowAttenuation;
|
||||
half3 attenuatedLightColor = mainLight.color * attenuation;
|
||||
#ifndef _DIFFUSE_RAMP
|
||||
diffuseLighting += LightingLambert(attenuatedLightColor, mainLight.direction, inputData.normalWS);
|
||||
#else
|
||||
diffuseLighting += LightingLambertRamped(mainLight.color, attenuation, mainLight.direction, inputData.normalWS);
|
||||
#endif
|
||||
#else // _MAIN_LIGHT_VERTEX
|
||||
half3 diffuseLighting = inputData.bakedGI;
|
||||
#endif // _MAIN_LIGHT_VERTEX
|
||||
|
||||
#ifdef _ADDITIONAL_LIGHTS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
half4 shadowMask = CalculateShadowMaskBackwardsCompatible(inputData);
|
||||
#else
|
||||
half4 shadowMask = half4(1, 1, 1, 1);
|
||||
#endif
|
||||
#if USE_FORWARD_PLUS
|
||||
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
diffuseLighting += ProcessLightLambert(inputData, shadowMask, meshRenderingLayers, lightIndex);
|
||||
}
|
||||
#endif
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
LIGHT_LOOP_BEGIN_SPINE(pixelLightCount)
|
||||
diffuseLighting += ProcessLightLambert(inputData, shadowMask, meshRenderingLayers, lightIndex);
|
||||
LIGHT_LOOP_END_SPINE
|
||||
|
||||
#endif
|
||||
#ifdef _ADDITIONAL_LIGHTS_VERTEX
|
||||
diffuseLighting += inputData.vertexLighting;
|
||||
#endif
|
||||
diffuseLighting += emission;
|
||||
//half3 finalColor = diffuseLighting * diffuse + emission;
|
||||
half3 finalColor = diffuseLighting * diffuse.rgb;
|
||||
return prepareLitPixelForOutput(half4(finalColor, diffuse.a), texDiffuseAlpha.a, vertexColor.a);
|
||||
}
|
||||
#endif // SPECULAR
|
||||
|
||||
VertexOutputLWRP ForwardPassVertexSprite(VertexInput input)
|
||||
{
|
||||
VertexOutputLWRP output = (VertexOutputLWRP)0;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.pos = calculateLocalPos(input.vertex);
|
||||
output.vertexColor = calculateVertexColor(input.color);
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
output.darkColor = GammaToTargetSpace(
|
||||
half3(input.tintBlackRG.r, input.tintBlackRG.g, input.tintBlackB.r)) + (_Black.rgb * input.color.a);
|
||||
#endif
|
||||
output.texcoord = float3(calculateTextureCoord(input.texcoord), 0);
|
||||
|
||||
float3 positionWS = TransformObjectToWorld(input.vertex.xyz);
|
||||
|
||||
float backFaceSign = 1;
|
||||
#if defined(FIXED_NORMALS_BACKFACE_RENDERING)
|
||||
backFaceSign = calculateBackfacingSign(positionWS.xyz);
|
||||
#endif
|
||||
output.viewDirectionWS = GetCameraPositionWS() - positionWS;
|
||||
#if defined(NEEDS_POSITION_WS)
|
||||
output.positionWS = float4(positionWS, 1);
|
||||
#endif
|
||||
|
||||
half3 normalWS = calculateSpriteWorldNormal(input, -backFaceSign);
|
||||
output.normalWorld.xyz = normalWS;
|
||||
#if defined(_NORMALMAP)
|
||||
output.tangentWorld.xyz = calculateWorldTangent(input.tangent);
|
||||
output.binormalWorld.xyz = calculateSpriteWorldBinormal(input, output.normalWorld.xyz, output.tangentWorld.xyz, backFaceSign);
|
||||
#endif
|
||||
|
||||
output.fogFactorAndVertexLight.yzw = LightweightLightVertexSimplified(positionWS, normalWS);
|
||||
|
||||
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
|
||||
VertexPositionInputs vertexInput;
|
||||
vertexInput.positionWS = positionWS;
|
||||
vertexInput.positionCS = output.pos;
|
||||
output.shadowCoord = GetShadowCoord(vertexInput);
|
||||
#endif
|
||||
|
||||
#if defined(_FOG)
|
||||
half fogFactor = ComputeFogFactor(output.pos.z);
|
||||
output.fogFactorAndVertexLight.x = fogFactor;
|
||||
#endif
|
||||
|
||||
#if IS_URP_15_OR_NEWER
|
||||
#ifdef OUTPUT_SH4
|
||||
#if IS_URP_17_OR_NEWER
|
||||
float4 ignoredProbeOcclusion;
|
||||
OUTPUT_SH4(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), output.vertexSH, ignoredProbeOcclusion);
|
||||
#else // 15 or newer
|
||||
OUTPUT_SH4(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), output.vertexSH);
|
||||
#endif
|
||||
#else
|
||||
OUTPUT_SH(positionWS, normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), output.vertexSH);
|
||||
#endif
|
||||
#else
|
||||
OUTPUT_SH(normalWS.xyz, output.vertexSH);
|
||||
#endif
|
||||
#if defined(USE_ADAPTIVE_PROBE_VOLUMES)
|
||||
output.positionCS = output.pos;
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 ForwardPassFragmentSprite(VertexOutputLWRP input
|
||||
#ifdef USE_WRITE_RENDERING_LAYERS
|
||||
, out float4 outRenderingLayers : SV_Target1
|
||||
#endif
|
||||
) : SV_Target0
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
fixed4 texureColor = calculateTexturePixel(input.texcoord.xy);
|
||||
|
||||
RETURN_UNLIT_IF_ADDITIVE_SLOT_TINT(texureColor, input.vertexColor, input.darkColor, _Color.a, _Black.a) // shall be called before ALPHA_CLIP
|
||||
|
||||
ALPHA_CLIP(texureColor, input.vertexColor)
|
||||
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
texureColor = fragTintedColor(texureColor, input.darkColor, input.vertexColor, _Color.a, _Black.a);
|
||||
#endif
|
||||
|
||||
// fill out InputData struct
|
||||
InputData inputData;
|
||||
#if !defined(_RECEIVE_SHADOWS_OFF)
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
||||
inputData.shadowCoord = input.shadowCoord;
|
||||
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
|
||||
inputData.shadowCoord = TransformWorldToShadowCoord(input.positionWS.xyz);
|
||||
#elif defined(_MAIN_LIGHT_SHADOWS)
|
||||
inputData.shadowCoord = input.shadowCoord;
|
||||
#else
|
||||
inputData.shadowCoord = float4(0, 0, 0, 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inputData.viewDirectionWS = input.viewDirectionWS;
|
||||
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
|
||||
|
||||
#if defined(PER_PIXEL_LIGHTING) && defined(_NORMALMAP)
|
||||
half3 normalWS = calculateNormalFromBumpMap(input.texcoord.xy, input.tangentWorld.xyz, input.binormalWorld.xyz, input.normalWorld.xyz);
|
||||
#else
|
||||
half3 normalWS = input.normalWorld.xyz;
|
||||
#endif
|
||||
|
||||
inputData.normalWS = normalWS;
|
||||
#if defined(USE_ADAPTIVE_PROBE_VOLUMES)
|
||||
half4 shadowMask = 1.0;
|
||||
float4 ignoredProbeOcclusion;
|
||||
inputData.bakedGI = SAMPLE_GI(input.vertexSH,
|
||||
GetAbsolutePositionWS(input.positionWS),
|
||||
inputData.normalWS.xyz,
|
||||
GetWorldSpaceNormalizeViewDir(input.positionWS),
|
||||
input.positionCS.xy,
|
||||
ignoredProbeOcclusion,
|
||||
shadowMask);
|
||||
#else // USE_ADAPTIVE_PROBE_VOLUMES
|
||||
inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
|
||||
#endif
|
||||
|
||||
#if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) || defined(USE_LIGHT_COOKIES)
|
||||
inputData.positionWS = input.positionWS.rgb;
|
||||
#endif
|
||||
#if defined(_ADDITIONAL_LIGHTS) && USE_FORWARD_PLUS
|
||||
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.pos);
|
||||
// note: don't assign normalizedScreenSpaceUV otherwise since old URP versions are missing this member variable
|
||||
#endif
|
||||
|
||||
#if defined(SPECULAR)
|
||||
half2 metallicGloss = getMetallicGloss(input.texcoord.xy);
|
||||
half metallic = metallicGloss.x;
|
||||
half smoothness = metallicGloss.y; // this is 1 minus the square root of real roughness m.
|
||||
|
||||
half3 specular = half3(0, 0, 0);
|
||||
half4 emission = half4(0, 0, 0, 1);
|
||||
APPLY_EMISSION_SPECULAR(emission, input.texcoord.xy)
|
||||
half4 pixel = LightweightFragmentPBRSimplified(inputData, texureColor, metallic, specular, smoothness, emission.rgb, input.vertexColor);
|
||||
#else
|
||||
half3 emission = half3(0, 0, 0);
|
||||
APPLY_EMISSION(emission, input.texcoord.xy)
|
||||
half4 pixel = LightweightFragmentBlinnPhongSimplified(inputData, texureColor, emission, input.vertexColor);
|
||||
#endif
|
||||
|
||||
#if defined(_RIM_LIGHTING)
|
||||
pixel.rgb = applyRimLighting(input.positionWS.xyz, normalWS, pixel);
|
||||
#endif
|
||||
|
||||
COLORISE(pixel)
|
||||
APPLY_FOG_LWRP(pixel, input.fogFactorAndVertexLight.x)
|
||||
|
||||
#ifdef USE_WRITE_RENDERING_LAYERS
|
||||
uint renderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
||||
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
|
||||
#endif
|
||||
|
||||
return pixel;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf623d0aff5fa5a46a8ab141746282e8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#ifndef SPRITES_SHADOW_CASTER_PASS_URP_INCLUDED
|
||||
#define SPRITES_SHADOW_CASTER_PASS_URP_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
|
||||
float3 _LightDirection;
|
||||
|
||||
struct AttributesSpine
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
float4 vertexColor : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct VaryingsSpine
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 texcoordAndAlpha: TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 GetShadowPositionHClip(float3 positionOS, half3 normalWS)
|
||||
{
|
||||
float3 positionWS = TransformObjectToWorld(positionOS);
|
||||
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
positionCS.z = min(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
|
||||
#else
|
||||
positionCS.z = max(positionCS.z, positionCS.w * UNITY_NEAR_CLIP_VALUE);
|
||||
#endif
|
||||
|
||||
return positionCS;
|
||||
}
|
||||
|
||||
VaryingsSpine ShadowPassVertexSprite(AttributesSpine input)
|
||||
{
|
||||
VaryingsSpine output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
|
||||
output.texcoordAndAlpha.xyz = float3(TRANSFORM_TEX(input.texcoord, _MainTex).xy, 0);
|
||||
|
||||
half3 fixedNormalOS = half3(0, 0, -1);
|
||||
half3 normalWS = normalize(TransformObjectToWorldNormal(fixedNormalOS));
|
||||
// flip normal for shadow bias if necessary
|
||||
// unfortunately we have to compute the sign here in the vertex shader
|
||||
// instead of using VFACE in fragment shader stage.
|
||||
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
|
||||
half faceSign = sign(dot(viewDirWS, normalWS));
|
||||
normalWS *= faceSign;
|
||||
|
||||
output.positionCS = GetShadowPositionHClip(input.positionOS.xyz, normalWS);
|
||||
output.texcoordAndAlpha.a = input.vertexColor.a * _Color.a;
|
||||
return output;
|
||||
}
|
||||
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/ShaderShared.cginc"
|
||||
|
||||
half4 ShadowPassFragmentSprite(VaryingsSpine input) : SV_TARGET
|
||||
{
|
||||
fixed4 texureColor = calculateTexturePixel(input.texcoordAndAlpha.xy);
|
||||
clip(texureColor.a * input.texcoordAndAlpha.a - _ShadowAlphaCutoff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb352cfad402b384bb31649b44fa2cf3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 543e1e9f1b6cdaf40a010bc06130716c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+472
@@ -0,0 +1,472 @@
|
||||
// Upgrade NOTE: upgraded instancing buffer 'PerDrawSprite' to new syntax.
|
||||
|
||||
#ifndef SHADER_SHARED_INCLUDED
|
||||
#define SHADER_SHARED_INCLUDED
|
||||
|
||||
#if defined(USE_LWRP)
|
||||
#include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/SpineCoreShaders/Spine-Common.cginc"
|
||||
#elif defined(USE_URP)
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/SpineCoreShaders/Spine-Common.cginc"
|
||||
#else
|
||||
#include "UnityCG.cginc"
|
||||
#include "../../CGIncludes/Spine-Common.cginc"
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
// Space functions
|
||||
//
|
||||
|
||||
inline float4 calculateWorldPos(float4 vertex)
|
||||
{
|
||||
return mul(unity_ObjectToWorld, vertex);
|
||||
}
|
||||
|
||||
#if defined(USE_LWRP) || defined(USE_URP)
|
||||
// snaps post-transformed position to screen pixels
|
||||
inline float4 UnityPixelSnap(float4 pos)
|
||||
{
|
||||
float2 hpc = _ScreenParams.xy * 0.5f;
|
||||
#if SHADER_API_PSSL
|
||||
// sdk 4.5 splits round into v_floor_f32(x+0.5) ... sdk 5.0 uses v_rndne_f32, for compatabilty we use the 4.5 version
|
||||
float2 temp = ((pos.xy / pos.w) * hpc) + float2(0.5f, 0.5f);
|
||||
float2 pixelPos = float2(__v_floor_f32(temp.x), __v_floor_f32(temp.y));
|
||||
#else
|
||||
float2 pixelPos = round((pos.xy / pos.w) * hpc);
|
||||
#endif
|
||||
pos.xy = pixelPos / hpc * pos.w;
|
||||
return pos;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline float4 calculateLocalPos(float4 vertex)
|
||||
{
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
#ifdef UNITY_INSTANCING_ENABLED
|
||||
vertex.xy *= _Flip.xy;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LWRP) || defined(USE_URP)
|
||||
float4 pos = TransformObjectToHClip(vertex.xyz);
|
||||
#else
|
||||
float4 pos = UnityObjectToClipPos(vertex);
|
||||
#endif
|
||||
|
||||
#ifdef PIXELSNAP_ON
|
||||
pos = UnityPixelSnap(pos);
|
||||
#endif
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
inline half3 calculateWorldNormal(float3 normal)
|
||||
{
|
||||
#if defined(USE_LWRP) || defined(USE_URP)
|
||||
return TransformObjectToWorldNormal(normal);
|
||||
#else
|
||||
return UnityObjectToWorldNormal(normal);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Normal map functions
|
||||
//
|
||||
|
||||
#if defined(_NORMALMAP)
|
||||
|
||||
uniform sampler2D _BumpMap;
|
||||
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform half _BumpScale;
|
||||
#endif
|
||||
|
||||
half3 UnpackScaleNormal(half4 packednormal, half bumpScale)
|
||||
{
|
||||
#if defined(UNITY_NO_DXT5nm)
|
||||
return packednormal.xyz * 2 - 1;
|
||||
#else
|
||||
half3 normal;
|
||||
normal.xy = (packednormal.wy * 2 - 1);
|
||||
// Note: we allow scaled normals in LWRP since we might be using fewer instructions.
|
||||
#if (SHADER_TARGET >= 30) || defined(USE_LWRP) || defined(USE_URP)
|
||||
// SM2.0: instruction count limitation
|
||||
// SM2.0: normal scaler is not supported
|
||||
normal.xy *= bumpScale;
|
||||
#endif
|
||||
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
|
||||
return normal;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline half3 calculateWorldTangent(float4 tangent)
|
||||
{
|
||||
#if defined(USE_LWRP) || defined(USE_URP)
|
||||
return TransformObjectToWorldDir(tangent.xyz);
|
||||
#else
|
||||
return UnityObjectToWorldDir(tangent);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline half3 calculateWorldBinormal(half3 normalWorld, half3 tangentWorld, float tangentSign)
|
||||
{
|
||||
//When calculating the binormal we have to flip it when the mesh is scaled negatively.
|
||||
//Normally this would just be unity_WorldTransformParams.w but this isn't set correctly by Unity for its SpriteRenderer meshes so get from objectToWorld matrix scale instead.
|
||||
half worldTransformSign = sign(unity_ObjectToWorld[0][0] * unity_ObjectToWorld[1][1] * unity_ObjectToWorld[2][2]);
|
||||
half sign = tangentSign * worldTransformSign;
|
||||
return cross(normalWorld, tangentWorld) * sign;
|
||||
}
|
||||
|
||||
inline half3 calculateNormalFromBumpMap(float2 texUV, half3 tangentWorld, half3 binormalWorld, half3 normalWorld)
|
||||
{
|
||||
half3 localNormal = UnpackScaleNormal(tex2D(_BumpMap, texUV), _BumpScale);
|
||||
half3x3 rotation = half3x3(tangentWorld, binormalWorld, normalWorld);
|
||||
half3 normal = normalize(mul(localNormal, rotation));
|
||||
return normal;
|
||||
}
|
||||
|
||||
#endif // _NORMALMAP
|
||||
|
||||
////////////////////////////////////////
|
||||
// Blending functions
|
||||
//
|
||||
inline fixed4 prepareLitPixelForOutput(fixed4 finalPixel, fixed textureAlpha, fixed colorAlpha) : SV_Target
|
||||
{
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
const bool applyPMA = false;
|
||||
#else
|
||||
const bool applyPMA = true;
|
||||
#endif
|
||||
|
||||
#if defined(_ALPHABLEND_ON)
|
||||
//Normal Alpha
|
||||
if (applyPMA) finalPixel.rgb *= finalPixel.a;
|
||||
#elif defined(_ALPHAPREMULTIPLY_VERTEX_ONLY)
|
||||
//PMA vertex, straight texture
|
||||
if (applyPMA) finalPixel.rgb *= textureAlpha;
|
||||
#elif defined(_ALPHAPREMULTIPLY_ON)
|
||||
//Pre multiplied alpha, both vertex and texture
|
||||
// texture and vertex colors are premultiplied already
|
||||
#elif defined(_MULTIPLYBLEND)
|
||||
//Multiply
|
||||
finalPixel = lerp(fixed4(1,1,1,1), finalPixel, finalPixel.a);
|
||||
#elif defined(_MULTIPLYBLEND_X2)
|
||||
//Multiply x2
|
||||
finalPixel.rgb *= 2.0f;
|
||||
finalPixel = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), finalPixel, finalPixel.a);
|
||||
#elif defined(_ADDITIVEBLEND)
|
||||
//Additive
|
||||
finalPixel *= 2.0f;
|
||||
if (applyPMA) finalPixel.rgb *= colorAlpha;
|
||||
#elif defined(_ADDITIVEBLEND_SOFT)
|
||||
//Additive soft
|
||||
if (applyPMA) finalPixel.rgb *= finalPixel.a;
|
||||
#else
|
||||
//Opaque
|
||||
finalPixel.a = 1;
|
||||
#endif
|
||||
return finalPixel;
|
||||
}
|
||||
|
||||
inline fixed4 calculateLitPixel(fixed4 texureColor, fixed4 color, fixed3 lighting) : SV_Target
|
||||
{
|
||||
#if !defined(_TINT_BLACK_ON)
|
||||
fixed4 finalPixel = texureColor * color * fixed4(lighting, 1);
|
||||
#else
|
||||
fixed4 finalPixel = texureColor * fixed4(lighting, 1);
|
||||
#endif
|
||||
finalPixel = prepareLitPixelForOutput(finalPixel, texureColor.a, color.a);
|
||||
return finalPixel;
|
||||
}
|
||||
|
||||
inline fixed4 calculateLitPixel(fixed4 texureColor, fixed3 lighting) : SV_Target
|
||||
{
|
||||
// note: we let the optimizer work, removed duplicate code.
|
||||
return calculateLitPixel(texureColor, fixed4(1, 1, 1, 1), lighting);
|
||||
}
|
||||
|
||||
inline fixed4 calculateAdditiveLitPixel(fixed4 texureColor, fixed4 color, fixed3 lighting) : SV_Target
|
||||
{
|
||||
fixed4 finalPixel;
|
||||
|
||||
#if defined(_ALPHABLEND_ON) || defined(_MULTIPLYBLEND) || defined(_MULTIPLYBLEND_X2) || defined(_ADDITIVEBLEND) || defined(_ADDITIVEBLEND_SOFT)
|
||||
//Normal Alpha, Additive and Multiply modes
|
||||
finalPixel.rgb = (texureColor.rgb * lighting * color.rgb) * (texureColor.a * color.a);
|
||||
finalPixel.a = 1.0;
|
||||
#elif defined(_ALPHAPREMULTIPLY_VERTEX_ONLY)
|
||||
//PMA vertex, straight texture
|
||||
finalPixel.rgb = texureColor.rgb * lighting * color.rgb * texureColor.a;
|
||||
finalPixel.a = 1.0;
|
||||
#elif defined(_ALPHAPREMULTIPLY_ON)
|
||||
//Pre multiplied alpha, both vertex and texture
|
||||
finalPixel.rgb = texureColor.rgb * lighting * color.rgb;
|
||||
finalPixel.a = 1.0;
|
||||
#else
|
||||
//Opaque
|
||||
finalPixel.rgb = texureColor.rgb * lighting * color.rgb;
|
||||
finalPixel.a = 1.0;
|
||||
#endif
|
||||
|
||||
return finalPixel;
|
||||
}
|
||||
|
||||
inline fixed4 calculateAdditiveLitPixel(fixed4 texureColor, fixed3 lighting) : SV_Target
|
||||
{
|
||||
fixed4 finalPixel;
|
||||
|
||||
#if defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_VERTEX_ONLY) || defined(_MULTIPLYBLEND) || defined(_MULTIPLYBLEND_X2) || defined(_ADDITIVEBLEND) || defined(_ADDITIVEBLEND_SOFT)
|
||||
//Normal Alpha, Additive and Multiply modes
|
||||
finalPixel.rgb = (texureColor.rgb * lighting) * texureColor.a;
|
||||
finalPixel.a = 1.0;
|
||||
#else
|
||||
//Pre multiplied alpha and Opaque
|
||||
finalPixel.rgb = texureColor.rgb * lighting;
|
||||
finalPixel.a = 1.0;
|
||||
#endif
|
||||
|
||||
return finalPixel;
|
||||
}
|
||||
|
||||
inline fixed4 calculatePixel(fixed4 texureColor, fixed4 color) : SV_Target
|
||||
{
|
||||
// note: we let the optimizer work, removed duplicate code.
|
||||
return calculateLitPixel(texureColor, color, fixed3(1, 1, 1));
|
||||
}
|
||||
|
||||
inline fixed4 calculatePixel(fixed4 texureColor) : SV_Target
|
||||
{
|
||||
// note: we let the optimizer work, removed duplicate code.
|
||||
return calculateLitPixel(texureColor, fixed4(1, 1, 1, 1), fixed3(1, 1, 1));
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Alpha Clipping
|
||||
//
|
||||
|
||||
#if defined(_ALPHA_CLIP)
|
||||
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform fixed _Cutoff;
|
||||
#endif
|
||||
|
||||
#define ALPHA_CLIP(pixel, color) clip((pixel.a * color.a) - _Cutoff);
|
||||
|
||||
#else
|
||||
|
||||
#define ALPHA_CLIP(pixel, color)
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
// Additive Slot blend mode
|
||||
// return unlit textureColor, alpha clip textureColor.a only
|
||||
//
|
||||
// [Deprecated] RETURN_UNLIT_IF_ADDITIVE_SLOT macro will be removed in future versions.
|
||||
// Use RETURN_UNLIT_IF_ADDITIVE_SLOT_TINT instead.
|
||||
#if defined(_ALPHAPREMULTIPLY_ON) && !defined(_LIGHT_AFFECTS_ADDITIVE)
|
||||
#define RETURN_UNLIT_IF_ADDITIVE_SLOT(textureColor, vertexColor) \
|
||||
if (vertexColor.a == 0 && (vertexColor.r || vertexColor.g || vertexColor.b)) {\
|
||||
ALPHA_CLIP(texureColor, fixed4(1, 1, 1, 1))\
|
||||
return texureColor * vertexColor;\
|
||||
}
|
||||
#elif defined(_ALPHAPREMULTIPLY_VERTEX_ONLY) && !defined(_LIGHT_AFFECTS_ADDITIVE)
|
||||
#define RETURN_UNLIT_IF_ADDITIVE_SLOT(textureColor, vertexColor) \
|
||||
if (vertexColor.a == 0 && (vertexColor.r || vertexColor.g || vertexColor.b)) {\
|
||||
ALPHA_CLIP(texureColor, fixed4(1, 1, 1, 1))\
|
||||
return texureColor * texureColor.a * vertexColor;\
|
||||
}
|
||||
#else
|
||||
#define RETURN_UNLIT_IF_ADDITIVE_SLOT(textureColor, vertexColor)
|
||||
#endif
|
||||
|
||||
// Replacement for deprecated RETURN_UNLIT_IF_ADDITIVE_SLOT macro.
|
||||
#if (defined(_ALPHAPREMULTIPLY_ON) || defined(_ALPHAPREMULTIPLY_VERTEX_ONLY)) && !defined(_LIGHT_AFFECTS_ADDITIVE)
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
#define TINTED_RESULT_PIXEL(textureColor, vertexColor, darkVertexColor, lightColorA, darkColorA) fragTintedColor(texureColor, darkVertexColor, vertexColor, lightColorA, darkColorA)
|
||||
#elif defined(_ALPHAPREMULTIPLY_VERTEX_ONLY)
|
||||
#define TINTED_RESULT_PIXEL(textureColor, vertexColor, darkVertexColor, lightColorA, darkColorA) (texureColor * texureColor.a * vertexColor)
|
||||
#else
|
||||
#define TINTED_RESULT_PIXEL(textureColor, vertexColor, darkVertexColor, lightColorA, darkColorA) (texureColor * vertexColor)
|
||||
#endif
|
||||
|
||||
#define RETURN_UNLIT_IF_ADDITIVE_SLOT_TINT(textureColor, vertexColor, darkVertexColor, lightColorA, darkColorA) \
|
||||
if (vertexColor.a == 0 && (vertexColor.r || vertexColor.g || vertexColor.b)) {\
|
||||
ALPHA_CLIP(texureColor, fixed4(1, 1, 1, 1))\
|
||||
return TINTED_RESULT_PIXEL(textureColor, vertexColor, darkVertexColor, lightColorA, darkColorA);\
|
||||
}
|
||||
#else
|
||||
#define RETURN_UNLIT_IF_ADDITIVE_SLOT_TINT(textureColor, vertexColor, darkVertexColor, lightColorA, darkColorA)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
// Color functions
|
||||
//
|
||||
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform fixed4 _Color;
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
uniform fixed4 _Black;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline fixed4 calculateVertexColor(fixed4 color)
|
||||
{
|
||||
#if defined(_ALPHAPREMULTIPLY_ON) || _ALPHAPREMULTIPLY_VERTEX_ONLY
|
||||
return PMAGammaToTargetSpace(color) * _Color;
|
||||
#elif !defined (UNITY_COLORSPACE_GAMMA)
|
||||
return fixed4(GammaToLinearSpace(color.rgb), color.a) * _Color;
|
||||
#else
|
||||
return color * _Color;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_COLOR_ADJUST)
|
||||
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform float _Hue;
|
||||
uniform float _Saturation;
|
||||
uniform float _Brightness;
|
||||
uniform fixed4 _OverlayColor;
|
||||
#endif
|
||||
|
||||
float3 rgb2hsv(float3 c)
|
||||
{
|
||||
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
|
||||
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
|
||||
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
float3 hsv2rgb(float3 c)
|
||||
{
|
||||
c = float3(c.x, clamp(c.yz, 0.0, 1.0));
|
||||
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
inline fixed4 adjustColor(fixed4 color)
|
||||
{
|
||||
float3 hsv = rgb2hsv(color.rgb);
|
||||
|
||||
hsv.x += _Hue;
|
||||
hsv.y *= _Saturation;
|
||||
hsv.z *= _Brightness;
|
||||
|
||||
color.rgb = hsv2rgb(hsv);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#define COLORISE(pixel) pixel.rgb = lerp(pixel.rgb, _OverlayColor.rgb, _OverlayColor.a * pixel.a);
|
||||
#define COLORISE_ADDITIVE(pixel) pixel.rgb = ((1.0-_OverlayColor.a) * pixel.rgb);
|
||||
|
||||
#else // !_COLOR_ADJUST
|
||||
|
||||
#define COLORISE(pixel)
|
||||
#define COLORISE_ADDITIVE(pixel)
|
||||
|
||||
#endif // !_COLOR_ADJUST
|
||||
|
||||
////////////////////////////////////////
|
||||
// Fog
|
||||
//
|
||||
|
||||
#if defined(_FOG) && (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
|
||||
|
||||
inline fixed4 applyFog(fixed4 pixel, float fogCoordOrFactorAtLWRP)
|
||||
{
|
||||
#if defined(_ADDITIVEBLEND) || defined(_ADDITIVEBLEND_SOFT)
|
||||
//In additive mode blend from clear to black based on luminance
|
||||
float luminance = pixel.r * 0.3 + pixel.g * 0.59 + pixel.b * 0.11;
|
||||
fixed4 fogColor = lerp(fixed4(0,0,0,0), fixed4(0,0,0,1), luminance);
|
||||
#elif defined(_MULTIPLYBLEND)
|
||||
//In multiplied mode fade to white based on inverse luminance
|
||||
float luminance = pixel.r * 0.3 + pixel.g * 0.59 + pixel.b * 0.11;
|
||||
fixed4 fogColor = lerp(fixed4(1,1,1,1), fixed4(0,0,0,0), luminance);
|
||||
#elif defined(_MULTIPLYBLEND_X2)
|
||||
//In multipliedx2 mode fade to grey based on inverse luminance
|
||||
float luminance = pixel.r * 0.3 + pixel.g * 0.59 + pixel.b * 0.11;
|
||||
fixed4 fogColor = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), fixed4(0,0,0,0), luminance);
|
||||
#elif defined(_ALPHABLEND_ON) || defined(_ALPHAPREMULTIPLY_VERTEX_ONLY) || defined(_ALPHAPREMULTIPLY_ON)
|
||||
//In alpha blended modes blend to fog color based on pixel alpha
|
||||
fixed4 fogColor = lerp(fixed4(0,0,0,0), unity_FogColor, pixel.a);
|
||||
#else
|
||||
//In opaque mode just return fog color;
|
||||
fixed4 fogColor = unity_FogColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LWRP) || defined(USE_URP)
|
||||
pixel.rgb = MixFogColor(pixel.rgb, fogColor.rgb, fogCoordOrFactorAtLWRP);
|
||||
#else
|
||||
UNITY_APPLY_FOG_COLOR(fogCoordOrFactorAtLWRP, pixel, fogColor);
|
||||
#endif
|
||||
|
||||
return pixel;
|
||||
}
|
||||
|
||||
#define APPLY_FOG(pixel, input) pixel = applyFog(pixel, input.fogCoord);
|
||||
#define APPLY_FOG_LWRP(pixel, fogFactor) pixel = applyFog(pixel, fogFactor);
|
||||
|
||||
#define APPLY_FOG_ADDITIVE(pixel, input) \
|
||||
UNITY_APPLY_FOG_COLOR(input.fogCoord, pixel.rgb, fixed4(0,0,0,0)); // fog towards black in additive pass
|
||||
|
||||
#else
|
||||
|
||||
#define APPLY_FOG(pixel, input)
|
||||
#define APPLY_FOG_LWRP(pixel, fogFactor)
|
||||
#define APPLY_FOG_ADDITIVE(pixel, input)
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
// Texture functions
|
||||
//
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
|
||||
#if _TEXTURE_BLEND
|
||||
uniform sampler2D _BlendTex;
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform float _BlendAmount;
|
||||
#endif
|
||||
|
||||
inline fixed4 calculateBlendedTexturePixel(float2 texcoord)
|
||||
{
|
||||
return (1.0-_BlendAmount) * tex2D(_MainTex, texcoord) + _BlendAmount * tex2D(_BlendTex, texcoord);
|
||||
}
|
||||
#endif // _TEXTURE_BLEND
|
||||
|
||||
inline fixed4 calculateTexturePixel(float2 texcoord)
|
||||
{
|
||||
fixed4 pixel;
|
||||
|
||||
#if _TEXTURE_BLEND
|
||||
pixel = calculateBlendedTexturePixel(texcoord);
|
||||
#else
|
||||
pixel = tex2D(_MainTex, texcoord);
|
||||
#endif // !_TEXTURE_BLEND
|
||||
|
||||
#if defined(_COLOR_ADJUST)
|
||||
pixel = adjustColor(pixel);
|
||||
#endif // _COLOR_ADJUST
|
||||
|
||||
return pixel;
|
||||
}
|
||||
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform fixed4 _MainTex_ST;
|
||||
#endif
|
||||
|
||||
inline float2 calculateTextureCoord(float4 texcoord)
|
||||
{
|
||||
return TRANSFORM_TEX(texcoord, _MainTex);
|
||||
}
|
||||
|
||||
|
||||
#endif // SHADER_SHARED_INCLUDED
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c831ab76c424d9429cdff3bc8fbb856
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#ifndef SPINE_COMMON_INCLUDED
|
||||
#define SPINE_COMMON_INCLUDED
|
||||
|
||||
#if defined(USE_LWRP)
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
#define GammaToLinearSpace SRGBToLinear
|
||||
#define LinearToGammaSpace LinearToSRGB
|
||||
#elif defined(USE_URP)
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
#define GammaToLinearSpace SRGBToLinear
|
||||
#define LinearToGammaSpace LinearToSRGB
|
||||
#else
|
||||
#include "UnityCG.cginc"
|
||||
#endif
|
||||
|
||||
inline half3 GammaToTargetSpace(half3 gammaColor) {
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
return gammaColor;
|
||||
#else
|
||||
return GammaToLinearSpace(gammaColor);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline half3 TargetToGammaSpace(half3 targetColor) {
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
return targetColor;
|
||||
#else
|
||||
return LinearToGammaSpace(targetColor);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline half4 PMAGammaToTargetSpace(half4 gammaPMAColor) {
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
return gammaPMAColor;
|
||||
#else
|
||||
return gammaPMAColor.a == 0 ?
|
||||
half4(GammaToLinearSpace(gammaPMAColor.rgb), gammaPMAColor.a) :
|
||||
half4(GammaToLinearSpace(gammaPMAColor.rgb / gammaPMAColor.a) * gammaPMAColor.a, gammaPMAColor.a);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Saturated version to prevent numerical issues that occur at CanvasRenderer
|
||||
// shader during linear-space PMA vertex color correction (countering automatic Unity conversion).
|
||||
// Note: Only use this method when the original color.rgb values lie within [0,1] range and
|
||||
// it's not an HDR color. This method is usually suitable for vertex color.
|
||||
inline half4 PMAGammaToTargetSpaceSaturated(half4 gammaPMAColor) {
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
return gammaPMAColor;
|
||||
#else
|
||||
return gammaPMAColor.a == 0 ?
|
||||
half4(GammaToLinearSpace(gammaPMAColor.rgb), gammaPMAColor.a) :
|
||||
half4(saturate(GammaToLinearSpace(gammaPMAColor.rgb / gammaPMAColor.a)) * gammaPMAColor.a, gammaPMAColor.a);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e0db06e1bfb2c544ba6d1b209ad1911
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#ifndef SPINE_OUTLINE_COMMON_INCLUDED
|
||||
#define SPINE_OUTLINE_COMMON_INCLUDED
|
||||
|
||||
float4 computeOutlinePixel(sampler2D mainTexture, float2 mainTextureTexelSize,
|
||||
float2 uv, float vertexColorAlpha,
|
||||
float OutlineWidth, float OutlineReferenceTexWidth, float OutlineMipLevel,
|
||||
float OutlineSmoothness, float ThresholdEnd, float OutlineOpaqueAlpha, float4 OutlineColor) {
|
||||
|
||||
float4 texColor = fixed4(0, 0, 0, 0);
|
||||
|
||||
#if !_USE_SCREENSPACE_OUTLINE_WIDTH
|
||||
// constant width in texture space
|
||||
float outlineWidthCompensated = OutlineWidth / (OutlineReferenceTexWidth * mainTextureTexelSize.x);
|
||||
float xOffset = mainTextureTexelSize.x * outlineWidthCompensated;
|
||||
float yOffset = mainTextureTexelSize.y * outlineWidthCompensated;
|
||||
#else
|
||||
float2 ddxUV = ddx(uv);
|
||||
float2 ddyUV = ddy(uv);
|
||||
float2 ddu = float2(ddxUV.x, ddyUV.x);
|
||||
float2 ddv = float2(ddxUV.y, ddyUV.y);
|
||||
float widthScale = OutlineWidth * _ScreenParams.x / OutlineReferenceTexWidth;
|
||||
float xOffset = length(ddu) * widthScale;
|
||||
float yOffset = length(ddv) * widthScale;
|
||||
#endif
|
||||
float xOffsetDiagonal = xOffset * 0.7;
|
||||
float yOffsetDiagonal = yOffset * 0.7;
|
||||
|
||||
float pixelCenter = tex2D(mainTexture, uv).a;
|
||||
|
||||
float4 uvCenterWithLod = float4(uv, 0, OutlineMipLevel);
|
||||
float pixelTop = tex2Dlod(mainTexture, uvCenterWithLod + float4(0, yOffset, 0, 0)).a;
|
||||
float pixelBottom = tex2Dlod(mainTexture, uvCenterWithLod + float4(0, -yOffset, 0, 0)).a;
|
||||
float pixelLeft = tex2Dlod(mainTexture, uvCenterWithLod + float4(-xOffset, 0, 0, 0)).a;
|
||||
float pixelRight = tex2Dlod(mainTexture, uvCenterWithLod + float4(xOffset, 0, 0, 0)).a;
|
||||
#if _USE8NEIGHBOURHOOD_ON
|
||||
float numSamples = 8;
|
||||
float pixelTopLeft = tex2Dlod(mainTexture, uvCenterWithLod + float4(-xOffsetDiagonal, yOffsetDiagonal, 0, 0)).a;
|
||||
float pixelTopRight = tex2Dlod(mainTexture, uvCenterWithLod + float4(xOffsetDiagonal, yOffsetDiagonal, 0, 0)).a;
|
||||
float pixelBottomLeft = tex2Dlod(mainTexture, uvCenterWithLod + float4(-xOffsetDiagonal, -yOffsetDiagonal, 0, 0)).a;
|
||||
float pixelBottomRight = tex2Dlod(mainTexture, uvCenterWithLod + float4(xOffsetDiagonal, -yOffsetDiagonal, 0, 0)).a;
|
||||
float average = (pixelTop + pixelBottom + pixelLeft + pixelRight +
|
||||
pixelTopLeft + pixelTopRight + pixelBottomLeft + pixelBottomRight)
|
||||
* vertexColorAlpha / numSamples;
|
||||
#else // 4 neighbourhood
|
||||
float numSamples = 4;
|
||||
float average = (pixelTop + pixelBottom + pixelLeft + pixelRight) * vertexColorAlpha / numSamples;
|
||||
#endif
|
||||
float thresholdStart = ThresholdEnd * (1.0 - OutlineSmoothness);
|
||||
float outlineAlpha = saturate((average - thresholdStart) / (ThresholdEnd - thresholdStart));
|
||||
#if !_OUTLINE_FILL_INSIDE
|
||||
outlineAlpha = saturate(outlineAlpha - pixelCenter);
|
||||
outlineAlpha = pixelCenter > OutlineOpaqueAlpha ? 0.0 : outlineAlpha;
|
||||
#else
|
||||
outlineAlpha = pixelCenter > OutlineOpaqueAlpha ? 1.0 : outlineAlpha;
|
||||
#endif
|
||||
return lerp(texColor, OutlineColor, outlineAlpha);
|
||||
}
|
||||
|
||||
float4 computeOutlinePixel(sampler2D mainTexture, float2 mainTextureTexelSize,
|
||||
float2 uv, float vertexColorAlpha,
|
||||
float OutlineWidth, float OutlineReferenceTexWidth, float OutlineMipLevel,
|
||||
float OutlineSmoothness, float ThresholdEnd, float4 OutlineColor) {
|
||||
|
||||
return computeOutlinePixel(mainTexture, mainTextureTexelSize,
|
||||
uv, vertexColorAlpha, OutlineWidth, OutlineReferenceTexWidth, OutlineMipLevel,
|
||||
OutlineSmoothness, ThresholdEnd, 1.0, OutlineColor);
|
||||
}
|
||||
|
||||
#endif
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13cee1d5ffe7f304a9f5ff15ef07c3bc
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#ifndef SKELETON_TINT_COMMON_INCLUDED
|
||||
#define SKELETON_TINT_COMMON_INCLUDED
|
||||
|
||||
float4 fragTintedColor(float4 texColor, float3 darkTintColor, float4 lightTintColorPMA, float lightColorAlpha, float darkColorAlpha) {
|
||||
|
||||
float a = texColor.a * lightTintColorPMA.a;
|
||||
|
||||
#if !defined(_STRAIGHT_ALPHA_INPUT)
|
||||
float3 texDarkColor = texColor.a - texColor.rgb;
|
||||
#else
|
||||
float3 texDarkColor = (1 - texColor.rgb);
|
||||
#endif
|
||||
float3 darkColor = texDarkColor * darkTintColor.rgb * lightColorAlpha;
|
||||
float3 lightColor = texColor.rgb * lightTintColorPMA.rgb;
|
||||
|
||||
float4 fragColor = float4(darkColor + lightColor, a);
|
||||
#if defined(_STRAIGHT_ALPHA_INPUT)
|
||||
fragColor.rgb *= texColor.a;
|
||||
#endif
|
||||
|
||||
#if defined(_DARK_COLOR_ALPHA_ADDITIVE)
|
||||
fragColor.a = a * (1 - darkColorAlpha);
|
||||
#endif
|
||||
return fragColor;
|
||||
}
|
||||
|
||||
#endif
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17717bcd66ca5ee4388ec779392904c3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
#ifndef SPRITE_LIGHTING_INCLUDED
|
||||
#define SPRITE_LIGHTING_INCLUDED
|
||||
|
||||
//Check for using mesh normals
|
||||
#if !defined(_FIXED_NORMALS_VIEWSPACE) && !defined(_FIXED_NORMALS_VIEWSPACE_BACKFACE) && !defined(_FIXED_NORMALS_MODELSPACE) && !defined(_FIXED_NORMALS_MODELSPACE_BACKFACE) && !defined(_FIXED_NORMALS_WORLDSPACE)
|
||||
#define MESH_NORMALS
|
||||
#endif
|
||||
|
||||
//Check for fixing backfacing tangents
|
||||
#if defined(_FIXED_NORMALS_VIEWSPACE_BACKFACE) || defined(_FIXED_NORMALS_MODELSPACE_BACKFACE)
|
||||
#define FIXED_NORMALS_BACKFACE_RENDERING
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
// Vertex structs
|
||||
//
|
||||
|
||||
struct VertexInput
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 texcoord : TEXCOORD0;
|
||||
float4 color : COLOR;
|
||||
#if defined(MESH_NORMALS)
|
||||
float3 normal : NORMAL;
|
||||
#endif // _FIXED_NORMALS
|
||||
#if defined(_NORMALMAP)
|
||||
float4 tangent : TANGENT;
|
||||
#endif // _NORMALMAP
|
||||
#if defined(_TINT_BLACK_ON)
|
||||
float2 tintBlackRG : TEXCOORD1;
|
||||
float2 tintBlackB : TEXCOORD2;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
// Normal functions
|
||||
//
|
||||
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform float4 _FixedNormal = float4(0, 0, 1, 1);
|
||||
#endif
|
||||
|
||||
inline float3 getFixedNormal()
|
||||
{
|
||||
return _FixedNormal.xyz;
|
||||
}
|
||||
|
||||
inline float calculateBackfacingSign(float3 worldPos)
|
||||
{
|
||||
//If we're using fixed normals and mesh is facing away from camera, flip tangentSign
|
||||
//Unity uses a left handed coordinate system so camera always looks down the negative z axis
|
||||
float3 cameraForward = float3(0,0,-1);
|
||||
float3 meshWorldForward = mul((float3x3)unity_ObjectToWorld, cameraForward);
|
||||
float3 toCamera = _WorldSpaceCameraPos - worldPos;
|
||||
return sign(dot(toCamera, meshWorldForward));
|
||||
}
|
||||
|
||||
inline half3 calculateSpriteWorldNormal(VertexInput vertex, float backFaceSign)
|
||||
{
|
||||
#if defined(MESH_NORMALS)
|
||||
|
||||
return calculateWorldNormal(vertex.normal);
|
||||
|
||||
#else // !MESH_NORMALS
|
||||
|
||||
float3 normal = getFixedNormal();
|
||||
|
||||
#if defined(_FIXED_NORMALS_VIEWSPACE) || defined(_FIXED_NORMALS_VIEWSPACE_BACKFACE)
|
||||
//View space fixed normal
|
||||
//Rotate fixed normal by inverse view matrix to convert the fixed normal into world space
|
||||
float3x3 invView = transpose((float3x3)UNITY_MATRIX_V);
|
||||
return normalize(mul(invView, normal));
|
||||
#elif defined (_FIXED_NORMALS_WORLDSPACE)
|
||||
//World space fixed normal
|
||||
return normal;
|
||||
#else
|
||||
//Model space fixed normal.
|
||||
#if defined(FIXED_NORMALS_BACKFACE_RENDERING)
|
||||
//If back face rendering is enabled and the sprite is facing away from the camera (ie we're rendering the backface) then need to flip the normal
|
||||
normal *= backFaceSign;
|
||||
#endif
|
||||
return calculateWorldNormal(normal);
|
||||
#endif
|
||||
|
||||
#endif // !MESH_NORMALS
|
||||
}
|
||||
|
||||
inline half3 calculateSpriteViewNormal(VertexInput vertex, float backFaceSign)
|
||||
{
|
||||
#if defined(MESH_NORMALS)
|
||||
|
||||
return normalize(mul((float3x3)UNITY_MATRIX_IT_MV, vertex.normal));
|
||||
|
||||
#else // !MESH_NORMALS
|
||||
|
||||
float3 normal = getFixedNormal();
|
||||
|
||||
#if defined(_FIXED_NORMALS_VIEWSPACE) || defined(_FIXED_NORMALS_VIEWSPACE_BACKFACE)
|
||||
//View space fixed normal
|
||||
return normal;
|
||||
#elif defined (_FIXED_NORMALS_WORLDSPACE)
|
||||
//World space fixed normal
|
||||
return normalize(mul((float3x3)UNITY_MATRIX_V, normal));
|
||||
#else
|
||||
//Model space fixed normal
|
||||
#if defined(FIXED_NORMALS_BACKFACE_RENDERING)
|
||||
//If back face rendering is enabled and the sprite is facing away from the camera (ie we're rendering the backface) then need to flip the normal
|
||||
normal *= backFaceSign;
|
||||
#endif
|
||||
return normalize(mul((float3x3)UNITY_MATRIX_IT_MV, normal));
|
||||
#endif
|
||||
|
||||
#endif // !MESH_NORMALS
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Normal map functions
|
||||
//
|
||||
|
||||
#if defined(_NORMALMAP)
|
||||
|
||||
inline half3 calculateSpriteWorldBinormal(VertexInput vertex, half3 normalWorld, half3 tangentWorld, float backFaceSign)
|
||||
{
|
||||
float tangentSign = vertex.tangent.w;
|
||||
|
||||
#if defined(FIXED_NORMALS_BACKFACE_RENDERING)
|
||||
tangentSign *= backFaceSign;
|
||||
#endif
|
||||
|
||||
return calculateWorldBinormal(normalWorld, tangentWorld, tangentSign);
|
||||
}
|
||||
|
||||
#endif // _NORMALMAP
|
||||
|
||||
#if defined(_DIFFUSE_RAMP)
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// Diffuse ramp functions
|
||||
//
|
||||
|
||||
uniform sampler2D _DiffuseRamp;
|
||||
|
||||
inline fixed3 calculateDiffuseRamp(float ramp)
|
||||
{
|
||||
return tex2D(_DiffuseRamp, float2(ramp, ramp)).rgb;
|
||||
}
|
||||
|
||||
inline fixed3 calculateRampedDiffuse(fixed3 lightColor, float attenuation, float angleDot)
|
||||
{
|
||||
#if defined(_FULLRANGE_HARD_RAMP)
|
||||
float d = angleDot;
|
||||
half3 ramp = calculateDiffuseRamp(d);
|
||||
return lightColor * ramp * attenuation;
|
||||
#elif defined(_FULLRANGE_SOFT_RAMP)
|
||||
float d = angleDot;
|
||||
half3 ramp = calculateDiffuseRamp(d * attenuation);
|
||||
return lightColor * ramp;
|
||||
#elif defined(_OLD_SOFT_RAMP)
|
||||
// for unmodified behaviour with existing projects when
|
||||
// the HARD_DIFFUSE_RAMP define was disabled in this file.
|
||||
// uses only the right half of the ramp texture, as
|
||||
// negative angleDot is clamped to [0,1] before.
|
||||
float d = angleDot * 0.5 + 0.5;
|
||||
half3 ramp = calculateDiffuseRamp(d);
|
||||
return lightColor * ramp * (attenuation * 2);
|
||||
#else // _OLD_HARD_RAMP
|
||||
// old default, for unmodified behaviour with existing projects,
|
||||
// uses only the right half of the ramp texture, as
|
||||
// negative angleDot is clamped to [0,1] before.
|
||||
float d = angleDot * 0.5 + 0.5;
|
||||
half3 ramp = calculateDiffuseRamp(d * attenuation * 2);
|
||||
return lightColor * ramp;
|
||||
#endif
|
||||
}
|
||||
#endif // _DIFFUSE_RAMP
|
||||
|
||||
////////////////////////////////////////
|
||||
// Rim Lighting functions
|
||||
//
|
||||
|
||||
#ifdef _RIM_LIGHTING
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform float _RimPower;
|
||||
uniform fixed4 _RimColor;
|
||||
#endif
|
||||
|
||||
inline fixed3 applyRimLighting(fixed3 posWorld, fixed3 normalWorld, fixed4 pixel) : SV_Target
|
||||
{
|
||||
fixed3 viewDir = normalize(_WorldSpaceCameraPos - posWorld);
|
||||
float invDot = 1.0 - saturate(dot(normalWorld, viewDir));
|
||||
float rimPower = pow(invDot, _RimPower);
|
||||
float rim = saturate(rimPower * _RimColor.a);
|
||||
|
||||
#if defined(_DIFFUSE_RAMP)
|
||||
rim = calculateDiffuseRamp(rim).r;
|
||||
#endif
|
||||
|
||||
return lerp(pixel.rgb, _RimColor.xyz * pixel.a, rim);
|
||||
}
|
||||
|
||||
#endif //_RIM_LIGHTING
|
||||
|
||||
////////////////////////////////////////
|
||||
// Emission functions
|
||||
//
|
||||
|
||||
#ifdef _EMISSION
|
||||
|
||||
uniform sampler2D _EmissionMap;
|
||||
|
||||
#if !defined(USE_LWRP) && !defined(USE_URP)
|
||||
uniform fixed4 _EmissionColor;
|
||||
uniform float _EmissionPower;
|
||||
#endif
|
||||
|
||||
|
||||
#define APPLY_EMISSION(diffuse, uv) diffuse += tex2D(_EmissionMap, uv).rgb * _EmissionColor.rgb * _EmissionPower;
|
||||
#define APPLY_EMISSION_SPECULAR(pixel, uv) pixel.rgb += (tex2D(_EmissionMap, uv).rgb * _EmissionColor.rgb * _EmissionPower) * pixel.a;
|
||||
|
||||
#else //!_EMISSION
|
||||
|
||||
#define APPLY_EMISSION(diffuse, uv)
|
||||
#define APPLY_EMISSION_SPECULAR(pixel, uv)
|
||||
|
||||
#endif //!_EMISSION
|
||||
|
||||
#endif // SPRITE_LIGHTING_INCLUDED
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63fe0a6c5f377d9448f7ee7ad96e6a8f
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user