diff --git a/CHANGELOG.md b/CHANGELOG.md index d56a2af94..53db38f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -249,6 +249,7 @@ * `GetRemappedClone()` now provides an additional parameter `pivotShiftsMeshUVCoords` for `MeshAttachment` to prevent uv shifts at a non-central Sprite pivot. This parameter defaults to `true` to maintain previous behaviour. * `SkeletonRenderer` components now provide an additional update mode `Only Event Timelines` at the `Update When Invisible` property. This mode saves additional timeline updates compared to update mode `Everything Except Mesh`. * Now all URP (Universal Render Pipeline) and LWRP (Lightweight Render Pipeline) shaders support SRP (Scriptable Render Pipeline) batching. See [Unity SRPBatcher documentation pages](https://docs.unity3d.com/Manual/SRPBatcher.html) for additional information. + * Sprite shaders now provide four `Diffuse Ramp` modes as an Inspector Material parameter: `Hard`, `Soft`, `Old Hard` and `Old Soft`. In spine-unity 3.8 it defaults to `Old Hard` to keep the behaviour of existing projects unchanged. Note that `Old Hard` and `Old Soft` ramp versions were using only the right half of the ramp texture, and additionally multiplying the light intensity by 2, both leading to brighter lighting than without a ramp texture active. The new ramp modes `Hard` and `Soft` use the full ramp texture and do not modify light intensity, being consistent with lighting without a ramp texture active. * **Changes of default values** * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`. diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs index 29839722a..d28da4582 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Shaders/SpineSpriteShaderGUI.cs @@ -81,6 +81,16 @@ public class SpineSpriteShaderGUI : SpineShaderWithOutlineGUI { FixedNormalsWorldSpace = 2 }; + private enum eDiffuseRampMode { + NoRampSpecified = -1, + FullRangeHard = 0, + FullRangeSoft = 1, + OldHard = 2, + OldSoft = 3, + + DefaultRampMode = OldHard + }; + MaterialProperty _mainTexture = null; MaterialProperty _color = null; MaterialProperty _maskTexture = null; @@ -177,6 +187,7 @@ public class SpineSpriteShaderGUI : SpineShaderWithOutlineGUI { static GUIContent _meshRequiresTangentsText = new GUIContent("Note: Material requires a mesh with tangents."); static GUIContent _meshRequiresNormalsText = new GUIContent("Note: Material requires a mesh with normals."); static GUIContent _meshRequiresNormalsAndTangentsText = new GUIContent("Note: Material requires a mesh with Normals and Tangents."); + static GUIContent[] _fixedDiffuseRampModeOptions = { new GUIContent("Hard"), new GUIContent("Soft"), new GUIContent("Old Hard"), new GUIContent("Old Soft") }; const string _primaryMapsText = "Main Maps"; const string _depthLabelText = "Depth"; @@ -447,8 +458,7 @@ public class SpineSpriteShaderGUI : SpineShaderWithOutlineGUI { if (_maskTexture != null) _materialEditor.TexturePropertySingleLine(_maskText, _maskTexture); - if (_diffuseRamp != null) - _materialEditor.TexturePropertySingleLine(_diffuseRampText, _diffuseRamp); + dataChanged |= RenderDiffuseRampProperties(); dataChanged |= EditorGUI.EndChangeCheck(); @@ -612,6 +622,52 @@ public class SpineSpriteShaderGUI : SpineShaderWithOutlineGUI { return dataChanged; } + protected virtual bool RenderDiffuseRampProperties () { + bool dataChanged = false; + + eDiffuseRampMode rampMode = GetMaterialDiffuseRampMode((Material)_materialEditor.target); + bool mixedRampMode = false; + foreach (Material material in _materialEditor.targets) { + if (rampMode != GetMaterialDiffuseRampMode(material)) { + mixedRampMode = true; + break; + } + } + + EditorGUI.BeginChangeCheck(); + EditorGUI.showMixedValue = mixedRampMode; + EditorGUILayout.BeginHorizontal(); + + if (_diffuseRamp != null) + _materialEditor.TexturePropertySingleLine(_diffuseRampText, _diffuseRamp); + + if (EditorGUI.EndChangeCheck()) { + if (rampMode == eDiffuseRampMode.NoRampSpecified) + rampMode = eDiffuseRampMode.DefaultRampMode; + + SetDiffuseRampMode(_materialEditor, rampMode); + mixedRampMode = false; + dataChanged = true; + } + + if (_diffuseRamp.textureValue != null) { + //Show drop down for ramp mode + EditorGUI.BeginChangeCheck(); + EditorGUI.showMixedValue = mixedRampMode; + rampMode = (eDiffuseRampMode)EditorGUILayout.Popup((int)rampMode, _fixedDiffuseRampModeOptions); + if (EditorGUI.EndChangeCheck()) { + SetDiffuseRampMode(_materialEditor, rampMode); + mixedRampMode = false; + dataChanged = true; + } + } + EditorGUILayout.EndHorizontal(); + + EditorGUI.showMixedValue = false; + + return dataChanged; + } + protected virtual bool RenderShadowsProperties () { bool dataChanged = false; @@ -844,6 +900,7 @@ public class SpineSpriteShaderGUI : SpineShaderWithOutlineGUI { SetKeyword(material, "_EMISSION", false); //Start with preMultiply alpha by default SetBlendMode(material, eBlendMode.PreMultipliedAlpha); + SetDiffuseRampMode(material, eDiffuseRampMode.DefaultRampMode); //Start with mesh normals by default SetNormalsMode(material, eNormalsMode.MeshNormals, false); if (_fixedNormal != null) @@ -1093,9 +1150,8 @@ public class SpineSpriteShaderGUI : SpineShaderWithOutlineGUI { return eNormalsMode.MeshNormals; } - static void SetNormalsMode (MaterialEditor materialEditor, eNormalsMode normalsMode, bool allowBackFaceRendering) { - SetNormalsMode((Material)materialEditor.target, normalsMode, allowBackFaceRendering); + static void SetNormalsMode (MaterialEditor materialEditor, eNormalsMode normalsMode, bool allowBackFaceRendering) { foreach (Material material in materialEditor.targets) { SetNormalsMode(material, normalsMode, allowBackFaceRendering); } @@ -1113,6 +1169,32 @@ public class SpineSpriteShaderGUI : SpineShaderWithOutlineGUI { return material.IsKeywordEnabled("_FIXED_NORMALS_VIEWSPACE_BACKFACE") || material.IsKeywordEnabled("_FIXED_NORMALS_MODELSPACE_BACKFACE"); } + static eDiffuseRampMode GetMaterialDiffuseRampMode (Material material) { + if (material.IsKeywordEnabled("_FULLRANGE_HARD_RAMP")) + return eDiffuseRampMode.FullRangeHard; + if (material.IsKeywordEnabled("_FULLRANGE_SOFT_RAMP")) + return eDiffuseRampMode.FullRangeSoft; + if (material.IsKeywordEnabled("_OLD_HARD_RAMP")) + return eDiffuseRampMode.OldHard; + if (material.IsKeywordEnabled("_OLD_SOFT_RAMP")) + return eDiffuseRampMode.OldSoft; + + return eDiffuseRampMode.NoRampSpecified; + } + + static void SetDiffuseRampMode (MaterialEditor materialEditor, eDiffuseRampMode rampMode) { + foreach (Material material in materialEditor.targets) { + SetDiffuseRampMode(material, rampMode); + } + } + + static void SetDiffuseRampMode (Material material, eDiffuseRampMode rampMode) { + SetKeyword(material, "_FULLRANGE_HARD_RAMP", rampMode == eDiffuseRampMode.FullRangeHard); + SetKeyword(material, "_FULLRANGE_SOFT_RAMP", rampMode == eDiffuseRampMode.FullRangeSoft); + SetKeyword(material, "_OLD_HARD_RAMP", rampMode == eDiffuseRampMode.OldHard); + SetKeyword(material, "_OLD_SOFT_RAMP", rampMode == eDiffuseRampMode.OldSoft); + } + static bool HasZWriteEnabled (Material material) { if (material.HasProperty("_ZWrite")) { return material.GetFloat("_ZWrite") > 0.0f; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/SpriteLighting.cginc b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/SpriteLighting.cginc index 36005cd50..292f48fc6 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/SpriteLighting.cginc +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/SpriteLighting.cginc @@ -136,9 +136,6 @@ inline half3 calculateSpriteWorldBinormal(VertexInput vertex, half3 normalWorld, // Diffuse ramp functions // -//Disable for softer, more traditional diffuse ramping -#define HARD_DIFFUSE_RAMP - uniform sampler2D _DiffuseRamp; inline fixed3 calculateDiffuseRamp(float ramp) @@ -148,13 +145,29 @@ inline fixed3 calculateDiffuseRamp(float ramp) inline fixed3 calculateRampedDiffuse(fixed3 lightColor, float attenuation, float angleDot) { - float d = angleDot * 0.5 + 0.5; -#if defined(HARD_DIFFUSE_RAMP) - half3 ramp = calculateDiffuseRamp(d * attenuation * 2); +#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; -#else +#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 @@ -164,9 +177,10 @@ inline fixed3 calculateRampedDiffuse(fixed3 lightColor, float attenuation, float // #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 { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesPixelLit.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesPixelLit.shader index 7bdd1ab02..30b67655e 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesPixelLit.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesPixelLit.shader @@ -86,6 +86,7 @@ Shader "Spine/Sprite/Pixel Lit" #pragma shader_feature _EMISSION #pragma shader_feature _RIM_LIGHTING #pragma shader_feature _DIFFUSE_RAMP + #pragma shader_feature _ _FULLRANGE_HARD_RAMP _FULLRANGE_SOFT_RAMP _OLD_HARD_RAMP _OLD_SOFT_RAMP #pragma shader_feature _COLOR_ADJUST #pragma shader_feature _TEXTURE_BLEND #pragma shader_feature _SPHERICAL_HARMONICS @@ -121,6 +122,7 @@ Shader "Spine/Sprite/Pixel Lit" #pragma shader_feature _NORMALMAP #pragma shader_feature _ALPHA_CLIP #pragma shader_feature _DIFFUSE_RAMP + #pragma shader_feature _ _FULLRANGE_HARD_RAMP _FULLRANGE_SOFT_RAMP _OLD_HARD_RAMP _OLD_SOFT_RAMP #pragma shader_feature _COLOR_ADJUST #pragma shader_feature _TEXTURE_BLEND #pragma shader_feature _FOG diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesVertexLit.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesVertexLit.shader index 366e75aef..d1fd2dd99 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesVertexLit.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Sprite/SpritesVertexLit.shader @@ -86,6 +86,7 @@ Shader "Spine/Sprite/Vertex Lit" #pragma shader_feature _ALPHA_CLIP #pragma shader_feature _EMISSION #pragma shader_feature _DIFFUSE_RAMP + #pragma shader_feature _ _FULLRANGE_HARD_RAMP _FULLRANGE_SOFT_RAMP _OLD_HARD_RAMP _OLD_SOFT_RAMP #pragma shader_feature _COLOR_ADJUST #pragma shader_feature _RIM_LIGHTING #pragma shader_feature _TEXTURE_BLEND diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Input-Sprite-LW.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Input-Sprite-LW.hlsl index d73db894d..e1b4a4c2e 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Input-Sprite-LW.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Input-Sprite-LW.hlsl @@ -28,6 +28,9 @@ float _EmissionPower; float4 _FixedNormal; +float _RimPower; +half4 _RimColor; + CBUFFER_END #endif // LIGHTWEIGHT_INPUT_SPRITE_INCLUDED diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Sprite-LW.shader b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Sprite-LW.shader index 94168970a..66e4ba246 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Sprite-LW.shader +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-Sprite-LW.shader @@ -87,6 +87,7 @@ Shader "Lightweight Render Pipeline/Spine/Sprite" #pragma shader_feature _ALPHA_CLIP #pragma shader_feature _EMISSION #pragma shader_feature _DIFFUSE_RAMP + #pragma shader_feature _ _FULLRANGE_HARD_RAMP _FULLRANGE_SOFT_RAMP _OLD_HARD_RAMP _OLD_SOFT_RAMP #pragma shader_feature _COLOR_ADJUST #pragma shader_feature _RIM_LIGHTING #pragma shader_feature _TEXTURE_BLEND diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Input-Sprite-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Input-Sprite-URP.hlsl index 3ab408a57..65d6959d9 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Input-Sprite-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Input-Sprite-URP.hlsl @@ -28,6 +28,9 @@ float _EmissionPower; float4 _FixedNormal; +float _RimPower; +half4 _RimColor; + CBUFFER_END #endif // URP_INPUT_SPRITE_INCLUDED diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl index 05448fa59..cb578cba9 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl @@ -142,8 +142,13 @@ half4 LightweightFragmentBlinnPhongSimplified(InputData inputData, half4 texDiff for (int i = 0; i < pixelLightCount; ++i) { Light light = GetAdditionalLight(i, inputData.positionWS); - half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation); + half3 attenuation = (light.distanceAttenuation * light.shadowAttenuation); + half3 attenuatedLightColor = light.color * attenuation; +#ifndef _DIFFUSE_RAMP diffuseLighting += LightingLambert(attenuatedLightColor, light.direction, inputData.normalWS); +#else + diffuseLighting += LightingLambertRamped(light.color, attenuation, light.direction, inputData.normalWS); +#endif } #endif #ifdef _ADDITIONAL_LIGHTS_VERTEX diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader index ba688f14f..d12f91343 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader @@ -86,6 +86,7 @@ Shader "Universal Render Pipeline/Spine/Sprite" #pragma shader_feature _ALPHA_CLIP #pragma shader_feature _EMISSION #pragma shader_feature _DIFFUSE_RAMP + #pragma shader_feature _ _FULLRANGE_HARD_RAMP _FULLRANGE_SOFT_RAMP _OLD_HARD_RAMP _OLD_SOFT_RAMP #pragma shader_feature _COLOR_ADJUST #pragma shader_feature _RIM_LIGHTING #pragma shader_feature _TEXTURE_BLEND