baobao
7/20/2016 - 4:08 PM

logshader.glsl

Shader "Unlit/LogShader"
{
	Properties
	{
	}
	SubShader
	{
		Tags { "RenderType"="Transparent" "Queue"="Transparent" }
		LOD 100
        
		Pass
		{
            blend SrcAlpha OneMinusSrcAlpha
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};
			
			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				o.uv = v.uv;
				return o;
			}

            fixed4 Num (float num, float uv, float index)
            {
                if (num == 2)
                {
//                    Two(uv, index);
                }
            }
            
            fixed4 Two(float2 uv, float index)
            {
                fixed4 col = fixed4(1,0,0,1);
                // 0~1
                // 5*5マスの数字を表示する
                float size = 5;
                float resolution = 130;
                float ratio = 1/resolution;
                float offsetPos = -ratio * index*size;
                // 1行目

                float x = uv.x + offsetPos;
                float y = uv.y;

                if (x >= ratio * 2 && x < ratio * 5 && y >= ratio*5 && y < ratio*6)
                {
                    col = fixed4(1,1,1,1);
                    col.a = 1;
                }

                // 2行目
                if (x >= ratio * 4 && x < ratio * 5 && y >= ratio * 4 && y < ratio*5)
                {
                    col = fixed4(1,1,1,1);
                    col.a = 1;
                }

                // 3行目
                if (x >= ratio * 2 && x < ratio * 5 && y >= ratio*3 && y < ratio*4)
                {
                    col = fixed4(1,1,1,1);
                    col.a = 1;
                }

                // 4行目
                if (x >= ratio * 2 && x < ratio * 3 && y >= ratio*2 && y < ratio*3)
                {
                    col = fixed4(1,1,1,1);
                    col.a = 1;
                }

                // 5行目
                if (x >= ratio * 2 && x < ratio * 5 && y >= ratio && y < ratio*2)
                {
                    col = fixed4(1,1,1,1);
                    col.a = 1;
                }

                return col;
            }

			fixed4 frag (v2f i) : SV_Target
			{
                // 白文字
                fixed4 col;
                col = Two(i.uv, 0);
                col += Two(i.uv, 1);
				return col;
			}
   


			ENDCG
		}
	}
}