Created
February 8, 2017 13:58
-
-
Save thorikawa/960ca23071fc07a7323bd71b8b07f8a7 to your computer and use it in GitHub Desktop.
Shader script to gradual appearance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Shader "Custom/DynamicIllusionShader" { | |
| Properties{ | |
| _MainTex("Base (RGB)", 2D) = "white" {} | |
| } | |
| SubShader{ | |
| Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } | |
| Blend SrcAlpha OneMinusSrcAlpha | |
| Pass{ | |
| CGPROGRAM | |
| #pragma vertex vert | |
| #pragma fragment frag | |
| #include "UnityCG.cginc" | |
| uniform sampler2D _MainTex; | |
| struct vertOut | |
| { | |
| float4 position : SV_POSITION; | |
| float4 worldSpacePosition : TEXCOORD0; | |
| float4 modelSpacePosition : TEXCOORD1; | |
| half2 uv : TEXCOORD2; | |
| }; | |
| vertOut vert(appdata_full vertIn) | |
| { | |
| vertOut o; | |
| o.position = mul(UNITY_MATRIX_MVP, vertIn.vertex); | |
| o.worldSpacePosition = mul(unity_ObjectToWorld, vertIn.vertex); | |
| o.modelSpacePosition = vertIn.vertex; | |
| o.uv = vertIn.texcoord; | |
| return o; | |
| } | |
| float4 frag(vertOut fragIn) : COLOR | |
| { | |
| const float PI = 3.14159; | |
| // config | |
| // time to draw a layer | |
| float s = 0.1f; | |
| // number of layers in 1.0 unity unit. | |
| int nLayer = 40; | |
| float layerHeight = 1.0f / float(nLayer); | |
| float maxHeight = 2.4f; | |
| float t = _Time.y; | |
| float4 col = tex2D(_MainTex, fragIn.uv); | |
| float4 wpos = fragIn.worldSpacePosition; | |
| float4 mpos = fragIn.modelSpacePosition; | |
| int layerIndex = int(t / s); | |
| float drawnHeight = layerHeight * layerIndex; | |
| int thisLayer = int((maxHeight - wpos.y) / layerHeight); | |
| if (layerIndex == thisLayer) { | |
| // 0.0-1.0 | |
| float timeInLoop = (t - float(layerIndex) * s) / s; | |
| float poll = (PI + atan2(mpos.z, mpos.x)) / (PI * 2.0f); | |
| if (poll > timeInLoop) { | |
| col.a = 0.0f; | |
| } | |
| } | |
| else if (layerIndex < thisLayer) { | |
| col.a = 0.0f; | |
| } | |
| return col; | |
| } | |
| ENDCG | |
| } | |
| } | |
| Fallback "Unlit/Transparent" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment