Skip to content

Commit

Permalink
Merge pull request #104 from CyberAgentGameEntertainment/feature/kiyo…
Browse files Browse the repository at this point in the history
…hara/ui-particle-mask

uGUIのマスクに対応
  • Loading branch information
CA-Tatami authored Jan 21, 2025
2 parents aef4f1d + a6a8616 commit 5c545fa
Show file tree
Hide file tree
Showing 91 changed files with 14,611 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUber.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ CBUFFER_START(UnityPerMaterial)

CBUFFER_END

#ifdef UNITY_UI_CLIP_RECT
float4 _ClipRect;
float _UIMaskSoftnessX;
float _UIMaskSoftnessY;
#endif

// Returns the sampler state of the base map.
SamplerState GetBaseMapSamplerState()
{
Expand Down
20 changes: 20 additions & 0 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUberUnlit.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ struct Varyings
float4 flowTransitionSecondUVs : TEXCOORD11; // xy: FlowMap UV, zw: TransitionMap UV
float2 transitionEmissionProgressesSecond : TEXCOORD12; // x: TransitionMap Progress, y: EmissionMap Progress
#endif

#ifdef UNITY_UI_CLIP_RECT
float4 mask : TEXCOORD13;
#endif

UNITY_VERTEX_INPUT_INSTANCE_ID
};

Expand All @@ -75,6 +80,14 @@ inline void InitializeVertexOutput(in Attributes input, in out Varyings output,
tangentWS.w = input.tangentOS.w * GetOddNegativeScale();
output.viewDirTS = GetViewDirectionTangentSpace(tangentWS, output.normalWS, output.viewDirWS);
#endif

#ifdef UNITY_UI_CLIP_RECT
float2 pixelSize = output.positionHCS.w;
pixelSize /= float2(1, 1) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));

float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
output.mask = float4(input.positionOS.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_UIMaskSoftnessX, _UIMaskSoftnessY) + abs(pixelSize.xy)));
#endif
}

inline void InitializeFragmentInput(in out Varyings input)
Expand Down Expand Up @@ -355,8 +368,15 @@ half4 fragUnlit(in out Varyings input, uniform bool useEmission)
ApplyDepthFade(color, input.projectedPosition);
#endif


#ifdef UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw);
color.a *= m.x * m.y;
#endif

AlphaClip(color.a, _Cutoff);
color.rgb = ApplyAlpha(color.rgb, color.a);

return color;
}
#endif
20 changes: 20 additions & 0 deletions Assets/Nova/Runtime/Core/Shaders/UIParticlesUberLit.shader
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Shader "Nova/UIParticles/UberLit"
_SpecularHighlights("Specular Highlights", Float) = 0.0
_EnvironmentReflections("Environment Reflections", Float) = 1.0

_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255

_ColorMask ("Color Mask", Float) = 15

// Surface Maps
_NormalMap("Normal Map", 2D) = "" {}
_NormalMap2DArray("Normal Map 2D Array", 2DArray) = "" {}
Expand Down Expand Up @@ -202,6 +210,15 @@ Shader "Nova/UIParticles/UberLit"
"RenderPipeline" = "UniversalPipeline"
}

Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}

Pass
{
Tags
Expand Down Expand Up @@ -295,6 +312,9 @@ Shader "Nova/UIParticles/UberLit"
// Vertex Deformation
#pragma shader_feature_local_vertex _ _VERTEX_DEFORMATION_ENABLED

// Rect2D Clip
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT

#include "ParticlesUberLitForward.hlsl"
ENDHLSL
}
Expand Down
20 changes: 20 additions & 0 deletions Assets/Nova/Runtime/Core/Shaders/UIParticlesUberUnlit.shader
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Shader "Nova/UIParticles/UberUnlit"
_ZWriteOverride("ZWrite Override", Float) = -1.0
_ZTest("ZTest", Float) = 4.0

_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255

_ColorMask ("Color Mask", Float) = 15

// Base Map
_BaseMapMode("Base Map Mode", Float) = 0.0
[MainTexture] _BaseMap("Base Map", 2D) = "white" {}
Expand Down Expand Up @@ -177,6 +185,15 @@ Shader "Nova/UIParticles/UberUnlit"
"RenderPipeline" = "UniversalPipeline"
}

Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}

Pass
{
Tags
Expand Down Expand Up @@ -251,6 +268,9 @@ Shader "Nova/UIParticles/UberUnlit"
// Vertex Deformation
#pragma shader_feature_local_vertex _ _VERTEX_DEFORMATION_ENABLED

// Rect2D Clip
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT

#include "ParticlesUberUnlitForward.hlsl"
ENDHLSL
}
Expand Down
5 changes: 4 additions & 1 deletion Assets/Tests/Runtime/AverageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class AverageTest
{
[TestCase("Test_Unlit", ExpectedResult = null)]
[TestCase("Test_Lit", ExpectedResult = null)]
[TestCase("Test_UIParticleUnlit", ExpectedResult = null)]
[TestCase("Test_UIParticleLit", ExpectedResult = null)]
[TestCase("Test_UIParticleMask", ExpectedResult = null)]
[TestCase("Test_Distortion", ExpectedResult = null)]
[TestCase("Test_Vertex_Deformation", ExpectedResult = null)]
[GameViewResolution(1920, 1080, "Full HD")]
Expand All @@ -38,7 +41,7 @@ public IEnumerator Test(string scenePath)
// タイムスケールを0に指定しても、バインドポーズになるときもあれば、
// 0フレームのアニメーションが再生されてしまうことがあり、テストが不安定だった。
// そこでシーンに含まれているアニメーターを無効にしてアニメーションが再生されないようにする。
var animators = GameObject.FindObjectsOfType<Animator>();
var animators = Object.FindObjectsOfType<Animator>();
foreach (var animator in animators) animator.enabled = false;

// シーンのレンダリングが一回終わるまで待つ
Expand Down
8 changes: 8 additions & 0 deletions Assets/Tests/Scenes/Materials/UIParticle-Lit.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c545fa

Please sign in to comment.