1
0

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.

Unity2021.2.13f1でシンプルなPostEffectsとShaderGraphを試す

Posted at

SimplePostEffects

keijiro神の URP SimplePostEffectsをみて、新しいUnity2021でのShaderGraphとPosteffectについて勉強してみました。

本家のリポジトリにはREADMEがなかったので、以下は独自に分解してみた解説です。

環境

  • Unity2021.2.13f1 (Windows版で実験しています)

(まずはデモ)ShaderGraphを試してみる

とりあえず本家のプロジェクトが意図しているであろう Inverse という処理を Material と ShaderGraph の OneMinus で書いているので Remap に置き換えてみます!

もともとのレンダリング結果(Test.unity)

image

image

Asset/Posteffectの Invert を開く。左はマテリアルで、Shader Graphs/Invert を指定している。Surface Inputとして MainTex を指定して、これをShaderGraph内で操作するのね。

image

image

image

image

左上の"Save Asset"を押すのが必要なのに気づかなかった…が、わかればこれは楽しい…。

image

シーンを分解してみる

Camera

  • Post Processing
  • Dithering
  • Ocullusion Culling (check off)

Background colorSolid Color で黒などにしておくのは大事かもしれない。

image

カメラの下には Postprocess という名前のGameobject、VolumeGlobal Volume で作成できる。

Profile には Assets/Misc/Postprocess.asset がアタッチされており、これは Global Volume Processというオブジェクト。

  • Bloom
  • Tonemapping
  • Chromatic Aberration (色収差)
  • Shadows Midtones Highlights

が設定されている。

たとえば Bloom なら

  • Threshold : 0
  • Intensity : 0.4
  • Scatter : 0.9

という感じ。

image

ちなみにこのあたりのパラメータはエディタ上で(Runしなくても)リアルタイムで反映されるので楽しい。

Intensity を、ぐっと 9ぐらい まで上げてみています。

image

実行すると、こんな感じです。

image

ShaderGraph と スクリプト について

ShaderGraph についての詳細はまたの機会にしますが、冒頭に書いた通り、見よう見まねで作ることができました。

左上のボタン Save Asset で、保存をするのを忘れずに。これはリアルタイム反映されないのかな?

スクリプトとしては UniversalAdditionalCameraData.cs

PostEffectFeature.cs

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

namespace UrpTestbed {

sealed class PostEffectPass : ScriptableRenderPass
{
    public Material material;

    public override void Execute
      (ScriptableRenderContext context, ref RenderingData data)
    {
        if (material == null) return;
        var cmd = CommandBufferPool.Get("PostEffect");
        Blit(cmd, ref data, material, 0);
        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }
}

public sealed class PostEffectFeature : ScriptableRendererFeature
{
    public Material material;

    PostEffectPass _pass;

    public override void Create()
      => _pass = new PostEffectPass
           { material = material,
             renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing };

    public override void AddRenderPasses
      (ScriptableRenderer renderer, ref RenderingData data)
      => renderer.EnqueuePass(_pass);
}

} // namespace UrpTestbed

ちなみに UVChecker も ShaderGraph で作られている

かっけえ

image

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?