mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 23:34:53 +08:00
[unity] Added support for double-sided lighting at SkeletonLit shaders (including URP and LWRP packages). Closes #1730.
This commit is contained in:
parent
0e2ced5042
commit
3c94f52b52
@ -83,7 +83,13 @@ VertexOutput vert (appdata v) {
|
|||||||
float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz;
|
float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz;
|
||||||
half3 fixedNormal = half3(0,0,-1);
|
half3 fixedNormal = half3(0,0,-1);
|
||||||
half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal));
|
half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal));
|
||||||
//half3 eyeNormal = half3(0,0,1);
|
|
||||||
|
#ifdef _DOUBLE_SIDED_LIGHTING
|
||||||
|
// unfortunately we have to compute the sign here in the vertex shader
|
||||||
|
// instead of using VFACE in fragment shader stage.
|
||||||
|
half faceSign = sign(eyeNormal.z);
|
||||||
|
eyeNormal *= faceSign;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Lights
|
// Lights
|
||||||
half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb;
|
half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb;
|
||||||
|
|||||||
@ -5,6 +5,7 @@ Shader "Spine/Outline/Skeleton Lit" {
|
|||||||
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
||||||
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
||||||
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
||||||
|
[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
|
||||||
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
||||||
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ Shader "Spine/Outline/Skeleton Lit ZWrite" {
|
|||||||
_ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
_ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
||||||
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
||||||
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
||||||
|
[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
|
||||||
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
||||||
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ Shader "Spine/Skeleton Lit ZWrite" {
|
|||||||
_ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
_ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
||||||
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
||||||
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
||||||
|
[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
|
||||||
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
||||||
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ Shader "Spine/Skeleton Lit ZWrite" {
|
|||||||
|
|
||||||
CGPROGRAM
|
CGPROGRAM
|
||||||
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
||||||
|
#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
|
||||||
#pragma vertex vert
|
#pragma vertex vert
|
||||||
#pragma fragment frag
|
#pragma fragment frag
|
||||||
#pragma target 2.0
|
#pragma target 2.0
|
||||||
|
|||||||
@ -7,6 +7,7 @@ Shader "Spine/Skeleton Lit" {
|
|||||||
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
||||||
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
||||||
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
||||||
|
[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
|
||||||
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
||||||
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ Shader "Spine/Skeleton Lit" {
|
|||||||
|
|
||||||
CGPROGRAM
|
CGPROGRAM
|
||||||
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
||||||
|
#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
|
||||||
#pragma vertex vert
|
#pragma vertex vert
|
||||||
#pragma fragment frag
|
#pragma fragment frag
|
||||||
#pragma target 2.0
|
#pragma target 2.0
|
||||||
|
|||||||
@ -6,7 +6,7 @@ struct appdata {
|
|||||||
float3 normal : NORMAL;
|
float3 normal : NORMAL;
|
||||||
half4 color : COLOR;
|
half4 color : COLOR;
|
||||||
float2 uv0 : TEXCOORD0;
|
float2 uv0 : TEXCOORD0;
|
||||||
|
|
||||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,6 +44,15 @@ VertexOutput vert(appdata v) {
|
|||||||
float3 positionWS = TransformObjectToWorld(v.pos);
|
float3 positionWS = TransformObjectToWorld(v.pos);
|
||||||
half3 fixedNormal = half3(0, 0, -1);
|
half3 fixedNormal = half3(0, 0, -1);
|
||||||
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
|
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
|
||||||
|
|
||||||
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS);
|
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS);
|
||||||
|
|
||||||
// Note: ambient light is also handled via SH.
|
// Note: ambient light is also handled via SH.
|
||||||
|
|||||||
@ -7,6 +7,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" {
|
|||||||
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
||||||
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
||||||
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
||||||
|
[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
|
||||||
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
||||||
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
|
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
|
||||||
}
|
}
|
||||||
@ -19,7 +20,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" {
|
|||||||
Cull Off
|
Cull Off
|
||||||
ZWrite Off
|
ZWrite Off
|
||||||
Blend One OneMinusSrcAlpha
|
Blend One OneMinusSrcAlpha
|
||||||
|
|
||||||
Stencil {
|
Stencil {
|
||||||
Ref[_StencilRef]
|
Ref[_StencilRef]
|
||||||
Comp[_StencilComp]
|
Comp[_StencilComp]
|
||||||
@ -48,7 +49,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" {
|
|||||||
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
|
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
|
||||||
#pragma multi_compile _ _SHADOWS_SOFT
|
#pragma multi_compile _ _SHADOWS_SOFT
|
||||||
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
|
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
|
||||||
|
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
// Unity defined keywords
|
// Unity defined keywords
|
||||||
#pragma multi_compile_fog
|
#pragma multi_compile_fog
|
||||||
@ -60,6 +61,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" {
|
|||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
// Spine related keywords
|
// Spine related keywords
|
||||||
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
||||||
|
#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
|
||||||
#pragma vertex vert
|
#pragma vertex vert
|
||||||
#pragma fragment frag
|
#pragma fragment frag
|
||||||
#pragma target 2.0
|
#pragma target 2.0
|
||||||
|
|||||||
@ -44,6 +44,15 @@ VertexOutput vert(appdata v) {
|
|||||||
float3 positionWS = TransformObjectToWorld(v.pos);
|
float3 positionWS = TransformObjectToWorld(v.pos);
|
||||||
half3 fixedNormal = half3(0, 0, -1);
|
half3 fixedNormal = half3(0, 0, -1);
|
||||||
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
|
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
|
||||||
|
|
||||||
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS);
|
color.rgb = LightweightLightVertexSimplified(positionWS, normalWS);
|
||||||
|
|
||||||
// Note: ambient light is also handled via SH.
|
// Note: ambient light is also handled via SH.
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
|
||||||
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
|
||||||
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
[Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0
|
||||||
|
[Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0
|
||||||
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
||||||
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
|
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default
|
||||||
}
|
}
|
||||||
@ -55,6 +56,7 @@
|
|||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
// Spine related keywords
|
// Spine related keywords
|
||||||
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
#pragma shader_feature _ _STRAIGHT_ALPHA_INPUT
|
||||||
|
#pragma shader_feature _ _DOUBLE_SIDED_LIGHTING
|
||||||
#pragma vertex vert
|
#pragma vertex vert
|
||||||
#pragma fragment frag
|
#pragma fragment frag
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user