0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Clusterで使えるShaderめーも

Last updated at Posted at 2021-11-23

開発環境

  • Unity 2019.4.22f1
  • Cluster Creator Kit 1.13

Color

image.png

Shader "Unlit/ColorUnlitShader"
{
    Properties
    {
        _Color ("Main Color", Color) = (1,1,1,1)
    }

    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            
            fixed4 _Color;

            float4 vert (float4 vertex : POSITION) : SV_POSITION
            {
                return UnityObjectToClipPos(vertex);
            }

            fixed4 frag () : SV_Target
            {
                return _Color;
            }
            ENDCG
        }
    }
}

Normal

Shader "Unlit/NormalUnlitShader"
{
    Properties
    {

    }

    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct v2f {
                half3 worldNormal : TEXCOORD0;
                float4 pos : SV_POSITION;
            };

            v2f vert (float4 vertex : POSITION, float3 normal : NORMAL)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(vertex);
                o.worldNormal = UnityObjectToWorldNormal(normal);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 c = 0;
                c.rgb = i.worldNormal*0.5 + 0.5;
                return c;
            }
            ENDCG
        }
    }
}

シマシマ

Shader "Unlit/ShimaShimaUnlitShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

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

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            void Unity_Multiply_float (float A, float B, out float Out)
            {
                Out = A * B;
            }

            void Unity_Add_float (float A, float B, out float Out)
            {
                Out = A + B;
            }

            void Unity_Fraction_float (float In, out float Out)
            {
                Out = frac(In);
            }

            void Unity_Step_float (float Edge, float In, out float Out)
            {
                Out = step(Edge, In);
            }
            
            fixed4 frag (v2f i) : SV_Target
            {
                float2 _UV_Out = i.uv;
                float _Split_R = _UV_Out[0];
                float _Split_G = _UV_Out[1];
                
                float _Multiply_Out;
                Unity_Multiply_float(_Split_R, 3, _Multiply_Out);
                
                float _Add_Out;
                Unity_Add_float(_Multiply_Out, _Time.y, _Add_Out);
                
                float _Fraction_Out;
                Unity_Fraction_float(_Add_Out, _Fraction_Out);
                
                float _Step_Out;
                Unity_Step_float(_Fraction_Out, 0.5, _Step_Out);
                
                return _Step_Out;
            }
            ENDCG
        }
    }
}

実験

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?