12
12

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 5 years have passed since last update.

Unityのshaderで動く雲っぽいやつ

Last updated at Posted at 2017-03-24

いつもどうやってつくるんだったっけってなるので記録を残しておく

5d745321c2e16bd68dc87c54c06386f6.gif

#コード

qiita.glsl

Shader "Unlit/KUMO"
{
    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;

            float Circle(float2 p){
				p*= 10.0;

				return ((p.x*p.x+p.y*p.y)-10);
			}
            
            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;
            }

            float rand(float3 co)
{
return frac(sin(dot(co.xyz, float3(12.9898, 78.233, 56.787))) * 43758.5453);
}

            float rings(float2 p){
				return sin(length(p)*100);
			}

			float noise(float3 pos)
{
float3 ip = floor(pos);
float3 fp = smoothstep(0, 1, frac(pos));
float4 a = float4(
rand(ip + float3(0, 0, 0)),
rand(ip + float3(1, 0, 0)),
rand(ip + float3(0, 1, 0)),
rand(ip + float3(1, 1, 0)));
float4 b = float4(
rand(ip + float3(0, 0, 1)),
rand(ip + float3(1, 0, 1)),
rand(ip + float3(0, 1, 1)),
rand(ip + float3(1, 1, 1)));
a = lerp(a, b, fp.z);
a.xy = lerp(a.xy, a.zw, fp.y);
return lerp(a.x, a.y, fp.x);
}

			float perlin(float3 pos,float time){
			return 
(noise(pos) +
noise(pos * 2 ) +
noise(pos * 4) +
noise(pos * 8) +
noise(pos * 16-time) +
noise(pos * 32+time) ) / 6;
}

            
            fixed4 frag (v2f i) : SV_Target
            {
           
               	float s = _Time*10;

		
              
               float2 m = i.uv+perlin (float3(_Music*10,_Music*10,0),s);
               float4 col = float4(0,0,1,1)+float4(perlin (float3(i.uv,0),s),perlin (float3(i.uv,0),s),perlin (float3(i.uv,0),s),1);
        
               return col;
                }

                 
            
            ENDCG
        }
    }
}

パーリンノイズでいい感じにしてあげてあとは動かす!

終わり

12
12
2

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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?