forked from cgvr/DeltaVR
		
	
		
			
				
	
	
		
			156 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			156 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
Shader "DBV/Kristo/Enviorment/AdScrollShader"
 | 
						|
{
 | 
						|
    Properties
 | 
						|
    {
 | 
						|
        _TexArray ("Textures", 2DArray) = "" {}
 | 
						|
        _TextureCount ("Textures count", int) = 0
 | 
						|
        _Speed ("Speed", float) = 1
 | 
						|
 | 
						|
        _ScrollTime ("Scroll time", Range(0.3,10)) = 1
 | 
						|
        _ViewTime ("View time", Range(1,10)) = 1
 | 
						|
    }
 | 
						|
 | 
						|
    SubShader
 | 
						|
    {
 | 
						|
        Tags { "RenderType"="Opaque" }
 | 
						|
        LOD 100
 | 
						|
 | 
						|
        Pass
 | 
						|
        {
 | 
						|
 | 
						|
 | 
						|
            CGPROGRAM
 | 
						|
            #pragma vertex vert
 | 
						|
            #pragma fragment frag
 | 
						|
            // make fog work
 | 
						|
            #pragma multi_compile_fog
 | 
						|
            #include "UnityCG.cginc"
 | 
						|
 | 
						|
            Texture2DArray _TexArray : register(t0);
 | 
						|
            SamplerState sampler_linear_repeat;
 | 
						|
 | 
						|
            int _TextureCount;
 | 
						|
            float _Speed;
 | 
						|
 | 
						|
            float _ScrollTime, _ViewTime;
 | 
						|
 | 
						|
            struct appdata
 | 
						|
            {
 | 
						|
                float4 vertex : POSITION;
 | 
						|
                float2 uv : TEXCOORD0;
 | 
						|
            };
 | 
						|
 | 
						|
            struct v2f
 | 
						|
            {
 | 
						|
                float2 uv : TEXCOORD0;
 | 
						|
                UNITY_FOG_COORDS(1)
 | 
						|
                float4 vertex : SV_POSITION;
 | 
						|
            };
 | 
						|
 | 
						|
 | 
						|
            v2f vert (appdata v)
 | 
						|
            {
 | 
						|
                v2f o;
 | 
						|
                o.vertex = UnityObjectToClipPos(v.vertex);
 | 
						|
                o.uv = v.uv;
 | 
						|
                UNITY_TRANSFER_FOG(o,o.vertex);
 | 
						|
                return o;
 | 
						|
            }
 | 
						|
 | 
						|
            fixed4 frag (v2f i) : SV_Target
 | 
						|
            {       
 | 
						|
                fixed4 col;
 | 
						|
 | 
						|
                float stepTotal = _ScrollTime + _ViewTime;
 | 
						|
                float scrollPercent = _ScrollTime/stepTotal;
 | 
						|
                float viewPercent = _ViewTime/stepTotal;
 | 
						|
 | 
						|
                float cycleTotal = stepTotal * _TextureCount;
 | 
						|
 | 
						|
                float cycleTime = fmod(_Time.x * _Speed, cycleTotal);
 | 
						|
                float cycleIndex = (cycleTime/cycleTotal) * _TextureCount;
 | 
						|
                float stepTime = cycleIndex - floor(cycleIndex);
 | 
						|
 | 
						|
                if(stepTime < scrollPercent) {//Scroll
 | 
						|
                    float scrollAmount = stepTime/scrollPercent;
 | 
						|
                    int scrollBotIndex = cycleIndex;
 | 
						|
                    int scrollTopIndex = fmod(cycleIndex+1, _TextureCount);
 | 
						|
                    
 | 
						|
                    float y = i.uv.y + scrollAmount;
 | 
						|
 | 
						|
                    if(y > 1) col = _TexArray.Sample( sampler_linear_repeat, float3( i.uv.x, y - 1, scrollTopIndex ) );
 | 
						|
                    else col = _TexArray.Sample( sampler_linear_repeat, float3( i.uv.x, y, scrollBotIndex ) );
 | 
						|
 | 
						|
                    }
 | 
						|
                else {//Show picture
 | 
						|
                    col = _TexArray.Sample( sampler_linear_repeat, float3( i.uv, fmod(ceil(cycleIndex), _TextureCount) ) );
 | 
						|
                    }
 | 
						|
                /*
 | 
						|
                int totalIndex = fmod(_Time.x * _Speed, _TextureCount*2);
 | 
						|
                if(totalIndex % 2 == 0) {
 | 
						|
 | 
						|
                    float index = ;
 | 
						|
 | 
						|
                    int bottomIndex = floor(index);
 | 
						|
                    int topIndex = fmod(ceil(index), _TextureCount);
 | 
						|
 | 
						|
                    float dif = index - bottomIndex;
 | 
						|
 | 
						|
                    float y = i.uv.y + dif;
 | 
						|
 | 
						|
                    if(y > 1) col = _TexArray.Sample( sampler_linear_repeat, float3( i.uv.x, y - 1, topIndex ) );
 | 
						|
                    else col = _TexArray.Sample( sampler_linear_repeat, float3( i.uv.x, y, bottomIndex ) );
 | 
						|
 | 
						|
                    }
 | 
						|
                else {
 | 
						|
                    col = _TexArray.Sample( sampler_linear_repeat, float3( i.uv, _TextureCount - totalIndex/2 - 1 ) );//fixed4(0,0,0,0);//
 | 
						|
                    }
 | 
						|
                */
 | 
						|
 | 
						|
                // apply fog
 | 
						|
                UNITY_APPLY_FOG(i.fogCoord, col);
 | 
						|
                return col;
 | 
						|
            }
 | 
						|
            ENDCG
 | 
						|
        }
 | 
						|
 | 
						|
        Pass
 | 
						|
        {
 | 
						|
            Name "ShadowCaster"
 | 
						|
            Tags { "LightMode" = "ShadowCaster" }
 | 
						|
            LOD 80
 | 
						|
            Cull [_Culling]
 | 
						|
            Offset [_Offset], [_Offset]
 | 
						|
            ZWrite [_ZWrite]
 | 
						|
            ZTest [_ZTest]
 | 
						|
           
 | 
						|
            CGPROGRAM
 | 
						|
            #pragma vertex vertShadow
 | 
						|
            #pragma fragment fragShadow
 | 
						|
            #pragma target 2.0
 | 
						|
            #pragma multi_compile_shadowcaster
 | 
						|
 | 
						|
            struct v2fShadow {
 | 
						|
                V2F_SHADOW_CASTER;
 | 
						|
                UNITY_VERTEX_OUTPUT_STEREO
 | 
						|
            };
 | 
						|
         
 | 
						|
            v2fShadow vertShadow( appdata_base v )
 | 
						|
            {
 | 
						|
                v2fShadow o;
 | 
						|
                UNITY_SETUP_INSTANCE_ID(v);
 | 
						|
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
 | 
						|
                TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
 | 
						|
                return o;
 | 
						|
            }
 | 
						|
         
 | 
						|
            float4 fragShadow( v2fShadow i ) : SV_Target
 | 
						|
            {
 | 
						|
                SHADOW_CASTER_FRAGMENT(i)
 | 
						|
            }
 | 
						|
 | 
						|
            ENDCG
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |