0
2

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.

UnityでShaderを書き始めるミニマムな手順

Posted at

UnityでShaderを書いて動かすためのミニマムな手順をまとめる。

具体的には、以下のように紫のグラデーションをシェーダーで描画させる。

スクリーンショット 2022-01-31 1.53.56.png

確認環境

  • MacBook Pro (16-inch 2019)
  • macOS Monterey 12.0.1

1. プロジェクトを作成する

ここではUnity 2020.3.18f1、URPで作成する(BRPでも同様の手順でOK)

スクリーンショット 2022-01-31 1.49.54.png

2. アセットウインドウで右クリックして [Create] -> [Shader] -> [Unlit Shader]

スクリーンショット 2022-01-31 1.51.30.png

名前は"NewUnlitShader"のままでよい。

3. アセットウインドウで右クリックして [Create] -> [Material]

スクリーンショット 2022-01-31 1.51.53.png

名前は"New Material"のままでよい。

4. マテリアルのインスペクタのShaderに"NewUnlitShader"を選ぶ。[Unlit] -> [NewUnlitShader]

スクリーンショット 2022-01-31 1.52.24.png

スクリーンショット 2022-01-31 1.52.29.png

5. ヒエラルキービューで右クリックして[3D Object] -> [Plane]

スクリーンショット 2022-01-31 1.51.09.png

スクリーンショット 2022-01-31 1.52.10.png

6. Planeのインスペクタを開き、作ったマテリアル("New Material")をドラッグ&ドロップする。

スクリーンショット 2022-01-31 1.52.58.png

7. 作ったシェーダー(NewUnlitShader)を開き、frag関数を以下のコードに書き換える。

fixed4 frag (v2f i) : SV_Target
{
    float4 col = float4(i.uv, 1.0, 1.0);
    return col;
}

以下のように紫のグラデーションがシェーダーによって描画される。

スクリーンショット 2022-01-31 1.53.56.png

以上

参考:

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?