Skip to content

Commit

Permalink
Fixed: UIEffectCapturedImage: When iteration count is even. the resul…
Browse files Browse the repository at this point in the history
…t image is flipped vertically (on Windows) #62
  • Loading branch information
Takashi Sakai committed May 10, 2018
1 parent bc87c42 commit 9d911eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
15 changes: 5 additions & 10 deletions Assets/UIEffect/UI-EffectCapture.shader
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ Shader "UI/Hidden/UI-EffectCapture"
fixed4 colorFactor : COLOR1;
#endif

#if defined (UI_TONE) || defined (UI_BLUR)
half4 effectFactor : TEXCOORD2;
#endif
};

sampler2D _MainTex;
Expand All @@ -51,16 +49,9 @@ Shader "UI/Hidden/UI-EffectCapture"
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(v.vertex);

#if UNITY_UV_STARTS_AT_TOP
OUT.texcoord = half2(v.texcoord.x, 1 - v.texcoord.y);
#else
OUT.texcoord = v.texcoord;
#endif

#if defined (UI_TONE) || defined (UI_BLUR)
OUT.texcoord = v.texcoord;
OUT.effectFactor = _EffectFactor;
#endif

#if UI_TONE_HUE
OUT.effectFactor.y = sin(OUT.effectFactor.x*3.14159265359*2);
Expand All @@ -73,6 +64,10 @@ Shader "UI/Hidden/UI-EffectCapture"
OUT.colorFactor = _ColorFactor;
#endif

#if UNITY_UV_STARTS_AT_TOP
OUT.texcoord.y = lerp(OUT.texcoord.y, 1 - OUT.texcoord.y, OUT.effectFactor.w);
#endif

return OUT;
}

Expand Down
3 changes: 2 additions & 1 deletion Assets/UIEffect/UIEffectCapturedImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void Capture()
_buffer.Blit(BuiltinRenderTextureType.CurrentActive, s_CopyId);

// Set properties.
_buffer.SetGlobalVector("_EffectFactor", new Vector4(toneLevel, 0, blur, 0));
_buffer.SetGlobalVector("_EffectFactor", new Vector4(toneLevel, 0, blur, 1));
_buffer.SetGlobalVector("_ColorFactor", new Vector4(effectColor.r, effectColor.g, effectColor.b, effectColor.a));

// Blit without effect.
Expand All @@ -261,6 +261,7 @@ public void Capture()
// Iterate the operation.
if(1 < m_Iterations)
{
_buffer.SetGlobalVector("_EffectFactor", new Vector4(toneLevel, 0, blur, 0));
_buffer.GetTemporaryRT(s_EffectId2, w, h, 0, m_FilterMode);
for (int i = 1; i < m_Iterations; i++)
{
Expand Down

0 comments on commit 9d911eb

Please sign in to comment.