Skip to content

Commit

Permalink
Fixed a problem in Alpha Transition where Flip-Book Progress in Flip …
Browse files Browse the repository at this point in the history
…Book was not reflected correctly.
  • Loading branch information
CA-Tatami committed Sep 12, 2024
1 parent 9b7ed5a commit 19db254
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUber.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,10 @@ half GetTransitionAlphaImpl(half4 map, uint channel, half transitionProgress, fl
}

#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
half GetTransitionAlpha(half2 transitionMapUv, half transitionMapProgress, half transitionProgress, half2 transitionMapSecondUv, half transitionProgressSecond)
half GetTransitionAlpha(half2 transitionMapUv, half transitionMapProgress, half transitionProgress, half2 transitionMapSecondUv, half transitionMapProgressSecond, half transitionProgressSecond)
{
half4 mainTexMap = SAMPLE_ALPHA_TRANSITION_MAP(transitionMapUv, transitionMapProgress);
half4 secondTexMap = SAMPLE_ALPHA_TRANSITION_MAP_SECOND(transitionMapSecondUv, transitionMapProgress);
half4 secondTexMap = SAMPLE_ALPHA_TRANSITION_MAP_SECOND(transitionMapSecondUv, transitionMapProgressSecond);
half mainTexAlpha = GetTransitionAlphaImpl(mainTexMap, (uint)_AlphaTransitionMapChannelsX, transitionProgress, _DissolveSharpness);
half secondTexAlpha = GetTransitionAlphaImpl(secondTexMap, (uint)_AlphaTransitionMapSecondTextureChannelsX, transitionProgressSecond, _DissolveSharpnessSecondTexture);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct VaryingsDrawDepth

#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float4 flowTransitionSecondUVs : TEXCOORD8; // xy: FlowMap UV, zw: TransitionMap UV
float2 transitionEmissionProgressesSecond : TEXCOORD9; // x: TransitionMap Progress, y: EmissionMap Progress
#endif

UNITY_VERTEX_INPUT_INSTANCE_ID
Expand Down Expand Up @@ -232,20 +233,24 @@ VaryingsDrawDepth vert(AttributesDrawDepth input)
#endif

// Transition Map Progress
#if defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY) || defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY)
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float transitionMapProgress = _AlphaTransitionMapSecondTextureProgress + GET_CUSTOM_COORD(_AlphaTransitionMapSecondTextureProgressCoord);
float sliceCount = _AlphaTransitionMapSecondTextureSliceCount;
#else
#if defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY) || defined(_ALPHA_TRANSITION_MAP_MODE_3D)
float transitionMapProgress = _AlphaTransitionMapProgress + GET_CUSTOM_COORD(_AlphaTransitionMapProgressCoord);
float sliceCount = _AlphaTransitionMapSliceCount;
#endif

#ifdef _ALPHA_TRANSITION_MAP_MODE_2D_ARRAY
output.transitionEmissionProgresses.x = FlipBookProgress(transitionMapProgress, sliceCount);
#elif _ALPHA_TRANSITION_MAP_MODE_3D
output.transitionEmissionProgresses.x = FlipBookBlendingProgress(transitionMapProgress, sliceCount);
#endif

#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float transitionMapProgressSecond = _AlphaTransitionMapSecondTextureProgress + GET_CUSTOM_COORD(_AlphaTransitionMapSecondTextureProgressCoord);
float sliceCountSecond = _AlphaTransitionMapSecondTextureSliceCount;
#ifdef _ALPHA_TRANSITION_MAP_MODE_2D_ARRAY
output.transitionEmissionProgressesSecond.x = FlipBookProgress(transitionMapProgressSecond, sliceCountSecond);
#elif _ALPHA_TRANSITION_MAP_MODE_3D
output.transitionEmissionProgressesSecond.x = FlipBookBlendingProgress(transitionMapProgressSecond, sliceCountSecond);
#endif
#endif
#endif

// Emission Map UV
Expand Down Expand Up @@ -337,7 +342,7 @@ half4 frag(VaryingsDrawDepth input) : SV_Target
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
half alphaTransitionProgressSecondTexture = _AlphaTransitionProgressSecondTexture + GET_CUSTOM_COORD(_AlphaTransitionProgressCoordSecondTexture);
ModulateAlphaTransitionProgress(alphaTransitionProgressSecondTexture, input.color.a);
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionEmissionProgresses.x, alphaTransitionProgress, input.flowTransitionSecondUVs.zw, alphaTransitionProgressSecondTexture);
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionEmissionProgresses.x, alphaTransitionProgress, input.flowTransitionSecondUVs.zw, input.transitionEmissionProgressesSecond.x, alphaTransitionProgressSecondTexture);
#else
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionEmissionProgresses.x, alphaTransitionProgress);
#endif
Expand Down
22 changes: 13 additions & 9 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUberShadowCaster.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct Varyings
float transitionProgress : TEXCOORD5;
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float4 flowTransitionSecondUVs : TEXCOORD6; // xy: FlowMap UV, zw: TransitionMap UV
float transitionProgressSecond : TEXCOORD7;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Expand Down Expand Up @@ -149,23 +150,26 @@ Varyings ShadowPassVertex(Attributes input)
#endif

// Transition Map Progress
#if defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY) || defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY)
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float transitionMapProgress = _AlphaTransitionMapSecondTextureProgress + GET_CUSTOM_COORD(_AlphaTransitionMapSecondTextureProgressCoord);
float sliceCount = _AlphaTransitionMapSecondTextureSliceCount;
#else
#if defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY) || defined(_ALPHA_TRANSITION_MAP_MODE_3D)
float transitionMapProgress = _AlphaTransitionMapProgress + GET_CUSTOM_COORD(_AlphaTransitionMapProgressCoord);
float sliceCount = _AlphaTransitionMapSliceCount;
#endif

#ifdef _ALPHA_TRANSITION_MAP_MODE_2D_ARRAY
output.transitionProgress = FlipBookProgress(transitionMapProgress, sliceCount);
#elif _ALPHA_TRANSITION_MAP_MODE_3D
output.transitionProgress = FlipBookBlendingProgress(transitionMapProgress, sliceCount);
#endif

#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float transitionMapProgressSecond = _AlphaTransitionMapSecondTextureProgress + GET_CUSTOM_COORD(_AlphaTransitionMapSecondTextureProgressCoord);
float sliceCountSecond = _AlphaTransitionMapSecondTextureSliceCount;
#ifdef _ALPHA_TRANSITION_MAP_MODE_2D_ARRAY
output.transitionProgressSecond = FlipBookProgress(transitionMapProgressSecond, sliceCountSecond);
#elif _ALPHA_TRANSITION_MAP_MODE_3D
output.transitionProgressSecond = FlipBookBlendingProgress(transitionMapProgressSecond, sliceCountSecond);
#endif
#endif
#endif
#endif

return output;
}

Expand Down Expand Up @@ -226,7 +230,7 @@ half4 ShadowPassFragment(Varyings input) : SV_TARGET
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
half alphaTransitionProgressSecondTexture = _AlphaTransitionProgressSecondTexture + GET_CUSTOM_COORD(_AlphaTransitionProgressCoordSecondTexture);
ModulateAlphaTransitionProgress(alphaTransitionProgressSecondTexture, input.color.a);
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionProgress, alphaTransitionProgress, input.flowTransitionSecondUVs.xy, alphaTransitionProgressSecondTexture);
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionProgress, alphaTransitionProgress, input.flowTransitionSecondUVs.zw, input.transitionProgressSecond, alphaTransitionProgressSecondTexture);
#else
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionProgress, alphaTransitionProgress);
#endif
Expand Down
21 changes: 13 additions & 8 deletions Assets/Nova/Runtime/Core/Shaders/ParticlesUberUnlit.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct Varyings
#endif
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float4 flowTransitionSecondUVs : TEXCOORD11; // xy: FlowMap UV, zw: TransitionMap UV
float2 transitionEmissionProgressesSecond : TEXCOORD12; // x: TransitionMap Progress, y: EmissionMap Progress
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Expand Down Expand Up @@ -177,20 +178,24 @@ Varyings vertUnlit(Attributes input, out float3 positionWS, uniform bool useEmis
#endif

// Transition Map Progress
#if defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY) || defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY)
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float transitionMapProgress = _AlphaTransitionMapSecondTextureProgress + GET_CUSTOM_COORD(_AlphaTransitionMapSecondTextureProgressCoord);
float sliceCount = _AlphaTransitionMapSecondTextureSliceCount;
#else
#if defined(_ALPHA_TRANSITION_MAP_MODE_2D_ARRAY) || defined(_ALPHA_TRANSITION_MAP_MODE_3D)
float transitionMapProgress = _AlphaTransitionMapProgress + GET_CUSTOM_COORD(_AlphaTransitionMapProgressCoord);
float sliceCount = _AlphaTransitionMapSliceCount;
#endif

#ifdef _ALPHA_TRANSITION_MAP_MODE_2D_ARRAY
output.transitionEmissionProgresses.x = FlipBookProgress(transitionMapProgress, sliceCount);
#elif _ALPHA_TRANSITION_MAP_MODE_3D
output.transitionEmissionProgresses.x = FlipBookBlendingProgress(transitionMapProgress, sliceCount);
#endif

#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
float transitionMapProgressSecond = _AlphaTransitionMapSecondTextureProgress + GET_CUSTOM_COORD(_AlphaTransitionMapSecondTextureProgressCoord);
float sliceCountSecond = _AlphaTransitionMapSecondTextureSliceCount;
#ifdef _ALPHA_TRANSITION_MAP_MODE_2D_ARRAY
output.transitionEmissionProgressesSecond.x = FlipBookProgress(transitionMapProgressSecond, sliceCountSecond);
#elif _ALPHA_TRANSITION_MAP_MODE_3D
output.transitionEmissionProgressesSecond.x = FlipBookBlendingProgress(transitionMapProgressSecond, sliceCountSecond);
#endif
#endif
#endif

if (useEmission)
Expand Down Expand Up @@ -303,7 +308,7 @@ half4 fragUnlit(in out Varyings input, uniform bool useEmission)
#if defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_AVERAGE) || defined(_ALPHA_TRANSITION_BLEND_SECOND_TEX_MULTIPLY)
half alphaTransitionProgressSecondTexture = _AlphaTransitionProgressSecondTexture + GET_CUSTOM_COORD(_AlphaTransitionProgressCoordSecondTexture);
ModulateAlphaTransitionProgress(alphaTransitionProgressSecondTexture, input.color.a);
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionEmissionProgresses.x, alphaTransitionProgress, input.flowTransitionSecondUVs.zw, alphaTransitionProgressSecondTexture);
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionEmissionProgresses.x, alphaTransitionProgress, input.flowTransitionSecondUVs.zw, input.transitionEmissionProgressesSecond.x, alphaTransitionProgressSecondTexture);
#else
color.a *= GetTransitionAlpha(input.flowTransitionUVs.zw, input.transitionEmissionProgresses.x, alphaTransitionProgress);
#endif
Expand Down

0 comments on commit 19db254

Please sign in to comment.