├── Resources └── Demo-images │ ├── rocky.gif │ ├── simple.gif │ ├── megaman-blue.gif │ ├── simple_patten.png │ └── megaman-colored.gif ├── LICENSE ├── README.md └── TransitionShader_WithTexture.shader /Resources/Demo-images/rocky.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jimmar/Unity-Transition-Effect-Shader/HEAD/Resources/Demo-images/rocky.gif -------------------------------------------------------------------------------- /Resources/Demo-images/simple.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jimmar/Unity-Transition-Effect-Shader/HEAD/Resources/Demo-images/simple.gif -------------------------------------------------------------------------------- /Resources/Demo-images/megaman-blue.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jimmar/Unity-Transition-Effect-Shader/HEAD/Resources/Demo-images/megaman-blue.gif -------------------------------------------------------------------------------- /Resources/Demo-images/simple_patten.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jimmar/Unity-Transition-Effect-Shader/HEAD/Resources/Demo-images/simple_patten.png -------------------------------------------------------------------------------- /Resources/Demo-images/megaman-colored.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jimmar/Unity-Transition-Effect-Shader/HEAD/Resources/Demo-images/megaman-colored.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jafar Abdulrasoul 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Transition Effect Shader 2 | A shader to create cool transition effects in unity. 3 | 4 | I wrote this shader to mimic what [Dan](http://danjohnmoran.com) did in his [youtube video](https://www.youtube.com/watch?v=LnAoD7hgDxw). 5 | 6 | The shader was rewritten to add a way to use textures as a transition image instead of just a color while preserving the ability to use any transition color. 7 | 8 | # Demo 9 | You can make cool things like 10 | 11 | ![alt text](Resources/Demo-images/simple.gif) using ![alt text](Resources/Demo-images/simple_patten.png) 12 | 13 | or if you used a noisier texture, you can create 14 | 15 | ![alt text](Resources/Demo-images/rocky.gif) 16 | 17 | but why stop there ? you can use images like this the ones from [this pack](http://blo0p.deviantart.com/art/Bloop-s-New-Superhero-Wallpapers-304284941) and end up with something like 18 | 19 | ![alt text](Resources/Demo-images/megaman-blue.gif) 20 | 21 | (Color is modifiable too) 22 | 23 | and lastly you can use another texture (or the same one) for the transition image to create something like 24 | 25 | ![alt text](Resources/Demo-images/megaman-colored.gif) 26 | 27 | # Using the shader 28 | The shader is used by creating a material out of it [Right click on the shader in Unity and then create a new material] and using that material in a C# `MonoBehaviour`. 29 | 30 | The C# script should have a `Graphics.Blit` inside the `OnRenderImage()` 31 | ```c# 32 | public Material mat; 33 | 34 | void OnRenderImage (RenderTexture source, RenderTexture destination){ 35 | Graphics.Blit(source,destination,mat); 36 | } 37 | ``` 38 | Attach the script to the camera and go into play mode. 39 | You can get the effect by adjusting the slider in the material. 40 | 41 | To access the the slider from code you can call: 42 | ```c# 43 | mat.SetFloat("_Cutoff",newValue); 44 | ``` 45 | before `Graphics.Blit` 46 | 47 | # Author 48 | Jafar Abdulrasoul [@JimmarxD](https://twitter.com/jimmarxd) -------------------------------------------------------------------------------- /TransitionShader_WithTexture.shader: -------------------------------------------------------------------------------- 1 | // Created by Jafar Abdulrasoul 2 | 3 | // Special thanks to Dan http://danjohnmoran.com 4 | 5 | 6 | Shader "Effects/TransitionShaderWithTexture" 7 | { 8 | Properties 9 | { 10 | _MainTex ("Texture", 2D) = "white" {} //Main Texture, leave empty 11 | _TranTex ("Transition Texture", 2D) = "black" {} //Transition texture. Leave blank if using color 12 | _PatternTex ("Pattern Texture", 2d) = "white" {} //The pattern transition texture 13 | _Cutoff("Progress", Range (0, 1)) = 0 //Cut off slider 14 | _Color("Color", Color) = (0,0,0,0) //defaults to black 15 | [MaterialToggle] _UseColor("Use Color", Float) = 0 //color or texture toggle 16 | } 17 | SubShader 18 | { 19 | // No culling or depth 20 | Cull Off ZWrite Off ZTest Always 21 | 22 | Pass 23 | { 24 | CGPROGRAM 25 | #pragma vertex vert 26 | #pragma fragment frag 27 | 28 | #include "UnityCG.cginc" 29 | 30 | struct appdata 31 | { 32 | float4 vertex : POSITION; 33 | float2 uv : TEXCOORD0; 34 | }; 35 | 36 | struct v2f 37 | { 38 | float2 uv : TEXCOORD0; 39 | float2 uv1 : TEXCOORD1; 40 | float4 vertex : SV_POSITION; 41 | }; 42 | 43 | sampler2D _MainTex; 44 | sampler2D _TranTex; 45 | sampler2D _PatternTex; 46 | float _Cutoff; 47 | fixed4 _Color; 48 | float _UseColor; 49 | 50 | v2f vert (appdata v) 51 | { 52 | v2f o; 53 | o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); 54 | o.uv = v.uv; 55 | o.uv1 = v.uv; 56 | 57 | //because shaders are complicated, this adjusts coordinates 58 | #if UNITY_UV_STARTS_AT_TOP 59 | if (_MainTex_TexelSize.y < 0) 60 | o.uv1.y = 1 - o.uv1.y; 61 | #endif 62 | 63 | return o; 64 | } 65 | 66 | fixed4 frag(v2f i) : SV_Target 67 | { 68 | fixed4 transit = tex2D(_PatternTex, i.uv); 69 | //checks the blue attribute of the pattern and cuts off in respect to that 70 | if(transit.b < _Cutoff){ 71 | // if _UseColor is enabled, use color instead 72 | if(_UseColor > 0) 73 | return _Color; 74 | // _Use color is not enabled, use the _TranTex 75 | return tex2D(_TranTex, i.uv); 76 | } 77 | // return the original texture aka don't do anything 78 | return tex2D(_MainTex, i.uv); 79 | } 80 | ENDCG 81 | } 82 | } 83 | } 84 | --------------------------------------------------------------------------------