7
3

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 1 year has passed since last update.

【Unity】URPのDecalを使い、床との距離でサイズと透明度が変わる影を作った

Last updated at Posted at 2022-10-12

概要

URPのDecalを使い、床との距離でサイズと透明度が変わる影を作りました。
床との距離はSphereCastで測っています。

gif.gif

コード

インスペクタ解説

image.png

変数 説明
Decal 影に使用している URP Decal Projector
同じ GameObject にコンポーネントがあれば自動で追加される
Ray Radius 床からの距離を測る SphereCast の半径
0を指定すると RayCast になる
Ray Margin Ray のゆとり
小さいと着地時に一瞬影が消える。大きいとRayが天井にぶつかる
Ray Direction 影を落とす方向
Ray Mask Sphere Cast で利用する LayerMask
Always Look Ray Dicrection 常に Decal の Transform を Ray Dicrection に向かせる
Base Size Rate 最低影サイズ
Add Size Rate 影との距離に比例して大きくなる割合
Min Opacity
Max Opacity
最低透明度
最大透明度
Add Opacity Rate 影との距離に比例して薄くなる割合

Decal のバグについて

影を Decal で描画する手法は、処理負荷を軽減するために採用される事が多いかと思います。
同じく処理負荷軽減で Render Scale を下げる事も多いかとも思います。

image.png

しかし、現状 2021.3 等のバージョンで両方を採用すると、下図のように Decal の表示がおかしくなります。

image.png

このバグは UnityForum で報告されており、URP 14.0.3 以降では修正されているようです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?