24
18

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.

頂点アニメーションとリムライトを組み合わせたらいい感じだった

Last updated at Posted at 2018-02-27

#はじめに
思いつき次第でいろいろ遊べそうな表現だったのでシァエします
安心と信頼のMade With Unity

#シェーダ
タイトル通り簡単な頂点アニメーションとリムライトを加算合成しちゃうシェーダです
CameraのClearFlagsをSkyboxにすると映らなくなっちゃう(何かがおかしい)のでSolidColorにしてあげてください

AlbedoとかAlphaに何も入れてないからなのか...?

Yurayura.shader
Shader "Custom/Yurayura"
{
    Properties
	{
        _MainTex("Texture", 2D) = "white" {}
        _Color("Color", Color) = (1, 1, 1, 1)
        _Amplitude("Amplitude", float) = 1.0
        _RimPower("RimPower", Range(0.1, 10.0)) = 3.0
    }

    SubShader
	{
        Tags{ "RenderType"="Transparent" "Queue"="Transparent" }
        Blend One One
        Cull Back
        ZWrite Off

        CGPROGRAM
        #pragma surface surf Lambert vertex:vert
        #pragma target 3.0      
        #include "Noise.cginc"

        sampler2D _MainTex;
        float _Amplitude;
        float4 _Color;
        half _RimPower;

        struct Input
		{
            float2 uv_MainTex;
            float3 viewDir;
        };

        void vert(inout appdata_full v)
		{
            v.vertex.xyz += v.normal * _Amplitude * perlin(v.vertex.xyz * _Time.y);
        }

        void surf(Input IN, inout SurfaceOutput o)
		{
            float rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
            float3 rimColor = pow(rim, _RimPower);
            o.Emission = tex2D(_MainTex, IN.uv_MainTex).rgb * rimColor * _Color;
        }

        ENDCG
    }
    Fallback "Diffuse"
}
Noise.cginc
float rand(float2 co) 
{
    return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453);
}

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

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) {
    return  (noise(pos) * 32 +
            noise(pos * 2 ) * 16 +
            noise(pos * 4) * 8 +
            noise(pos * 8) * 4 +
            noise(pos * 16) * 2 +
            noise(pos * 32) ) / 63;
}

Noiseみたいな関数群はcgincにまとめちゃうと便利ですね

とりあえずSphereにペタるとこんな感じになる

動くも◯っとボールみたいになりましたが、ちょっと味気ないので少し調整してあげます

スクリーンショット 2018-02-27 15.18.51.png Materialをこうすると 随分と可愛くなりました

#こんなん出来るよ集
##炎の輪っぽいの
スクリーンショット 2018-02-27 15.49.32.png

Sphereを3つ重ねて、それぞれRotationだけズラしてあげるとこんな感じになる

##結晶みたいなの
スクリーンショット 2018-02-27 16.02.36.png

Amplitudeを負の値にするとこんな感じになります

##適当にテクスチャ入れてみる
スクリーンショット 2018-02-27 16.12.18.png

Sphere2つ重ね。カラフルなテクスチャを入れると賑やかですね

#信じられるか?これ全部Sphereなんだぜ...

PostProcessingStackアセットをぶち込んでBloomとか入れてあげると、もっと綺麗になりそうですね

24
18
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
24
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?