Version: 5.4
イメージエフェクト
アンチエイリアス

イメージエフェクト

イメージエフェクトは、Unity の画像に用いるポストプロセスの一種です。

OnRenderImage 関数を持つスクリプトならばすべて、ポストプロセス エフェクトとして機能します。カメラ オブジェクトにちょっと加えてみてください。スクリプト関数にしたがって全体のイメージエフェクト ロジックが働きます。

OnRenderImage 関数

This script function receives two arguments: source image as a RenderTexture and destination it should render into, as a render texture as well. Typically a postprocessing effect uses Shaders that read the source image, do some calculations on it, and render the result into the provided destination (e.g using Graphics.Blit). It is expected that the image effect will fully replace all pixels of the destination texture.

When multiple postprocessing effects are added on the camera, they are executed in the order they are shown in the inspector, topmost effect being rendered first. Result of one effect is passed as “source image” to the next one; and internally Unity creates one or more temporary render textures to keep these intermediate results in.

注意事項

  • 移動先のレンダーテクスチャは null、つまり「スクリーンにレンダリング」(バックバッファ) でも可能です。これは通常、カメラの最後の画像にポストプロセス エフェクトを加えるときに起こります。
  • OnRenderImage が終了すると、たいてい、移動先のレンダーテクスチャがアクティブなレンダーターゲットになっています。通常、移動先テクスチャへの Graphics.Blit か手動レンダリングが最終レンダリング操作となります。
  • 通常は、イメージエフェクト シェーダーでのデプスバッファの書き込みとテストをオフにすることを推奨します。そうしないと、Graphics.Blit を実行するときに、デプスバッファが意図しない値を移動先 Z のバッファに書き込んでしまうからです。ほぼすべてのイメージエフェクト シェーダー パスは Cull Off ZWrite Off ZTest Always ステートであるべきです。
  • オリジナルシーンのレンダリングからステンシルバッファやデプスバッファを使用したい場合は、デプスターゲットとしてオリジナルのシーンレンダリングから排他的にデプスバッファをバインドします。これは、 Graphics.SetRenderTarget を使って行うことができます。バインドするには、デプスバッファとして最初のソース画像のエフェクトのデプスバッファを引数に指定します。

不透明のイメージエフェクト後

By default, an image effect is executed after whole scene is rendered. In some cases however, it is desirable to render an effect after all opaque objects are done (but before skybox or transparencies are rendered). Often depth-based effects like Depth of Field use this.

Adding an ImageEffectOpaque attribute on the OnRenderImage function allows to achieve that.

異なるプラットフォーム上のテクスチャ調整

イメージエフェクトが一度に異なる画面関連のテクスチャをサンプリングすると、テクスチャ調整の仕方を考えるうえでプラットフォームの違いに気を付けなければならない場合があります。

一般的なシナリオでは、「ソース」テクスチャエフェクトとカメラのデプステクスチャには、アンチアイリアス設定によって異なる垂直方向の調整が必要です。詳細は プラットフォーム別のレンダリングの違い を参照してください。

スタンダードアセットの helper イメージエフェクト コードの使用

Effects package には独自のイメージエフェクトの基礎となるいくつかの base と helper クラスが含まれています。すべてのコードは UnityStandardAssets.ImageEffects 名前空間にあります。

関連事項

イメージエフェクト
アンチエイリアス
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961