Jan
20
2012

Wipe transition (Shader)

Wipe shader test.. Modified unity version from the original glsl shader “postpro” by iq (2009)

Webplayer:
http://unitycoder.com/upload/demos/mWipeShader/

Source: (shader)

// Modified Unity version - WipeShader - mgear - http://unitycoder.com/blog/
// ORIGINAL GLSL SHADER "Postpro" WAS MADE BY: iq (2009)

Shader "mShaders/mWipe1"
{
Properties
{
_tex0 ("Texture1", 2D) = "white" {}
_tex1 ("Texture2", 2D) = "white" {}
}

SubShader
{
Tags {Queue = Geometry}
Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"

sampler2D _tex0;
sampler2D _tex1;

struct v2f {
float4 pos : POSITION;
float4 color : COLOR0;
float4 fragPos : COLOR1;
float2  uv : TEXCOORD0;
};

float4 _tex0_ST;

v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.fragPos = o.pos;
o.uv = TRANSFORM_TEX (v.texcoord, _tex0);
o.color = float4 (1.0, 1.0, 1.0, 1);
return o;
}

// I dont really have idea whats happening here..its a bit modified version from the original shader
half4 frag (v2f i) : COLOR
{
float animtime = _Time*10.0;
float2 q = i.uv.xy / float2(1,1);
float3 oricol = tex2D (_tex0,float2(q.x,q.y)).xyz;
float3 col = tex2D (_tex1,float2(i.uv.x,i.uv.y)).xyz;
float comp = smoothstep( 0.2, 0.7, sin(animtime) );
col = lerp(col,oricol,  clamp(-2.0+2.0*q.x+3.0*comp,0.0,1.0)); // ??
return float4(col,1);
}
ENDCG
}
}
FallBack "VertexLit"
}

4 Comments + Add Comment

  • cleaned up version with alpha support:
    http://stackoverflow.com/a/21968380

  • Hey, I’ve been learning Unity3D these days. And I’m very interested in your work. But I cannot understand your code here. Could you please send the unity3d source code to me about the wipe transition effect? I would very very appreciate you!! I hope to have more communications with you.

    My e-mail address is zhouxuanc@foxmail.com.

    THX a lot!!!

    • Hi,

      It’s a shader source code, so:
      First create new shader file from menu: Assets / Create / Shader
      Then copy paste that code there,
      Then create new material from menu: Assets / Create / Material
      Then assign that shader to the new material (using the Shader dropdown in inspector, when the material file is selected from Project panel)

      And google for: unity3d shader tutorial

      for example,
      https://cgcookie.com/unity/cgc-courses/introduction-to-surface-shaders-in-unity/

      then you can learn how to modify it etc.

      • I see! Thank you for your prompt reply!

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.