5
6

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.

URPで歪みシェーダーの実装

Last updated at Posted at 2021-08-22

前書き

URPで背景のバッファの取得とその使用方法をまとめました。

サンプルはGitHubに上げています。
https://github.com/eorfeorf/DistortionShaderInURP

環境

Unity2020.3.14f1
Universal RP 10.5.1 (ForwardRenderer)
Shader Graph 10.5.1

実装方法

描画されたバッファを取得する

Universal Render Pipeline AssetOpaque Textureにチェックを入れます。

ShaderGraphではSceneColorノードでOpaqueTextureを取得できます。
入力はUV、出力はColorです。

歪ませる

歪みはテクスチャをサンプリングする際のUVをずらすことで表現できます。
サンプルではGradient Noiseノードを使用してUVをずらしています。

出力結果

おまけ:ノイズテクスチャをUVに適用する

ノイズテクスチャをスクロール

タイリングやオフセットは専用のTiling And Offsetノードがあり、OffsetTimeノードのTimeを入れると時間経過でスクロールします。

ノイズをUVに加算する

ノイズテクスチャは白黒で表現されており、値としては0~1になっています。
このまま使っても良いのですが、UVが全体的にずれることになり、実物と見える位置が大きく異なります。
そこで使うのがRemapノードです。
このノードは与えられた数値を指定した数値範囲にマッピングしてくれる優れものです。
今回では0~1-0.01~0.01の範囲にリマッピングしています。

あとは出力された値をScreenPositionと足し合わせることでUVがずれ、歪みとして表現されます。

最後に

URPではGUIでチェックを入れ、ShaderGraphでテクスチャが取得ができるので非常に簡単でした。

参考文献

転載元

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?