Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/eb052a2f952a25db14004f2728ac0371 to your computer and use it in GitHub Desktop.
Save baobao/eb052a2f952a25db14004f2728ac0371 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// このコンポーネントをCameraコンポーネントがアタッチされているGameObjectにくっつけます
public class VerticalScroll : MonoBehaviour
{
[SerializeField] Shader m_shader;
[SerializeField] float m_speed = 0.005f;
Material m_mat;
// イメージエフェクトはOnRenderImage関数内で処理を書きます
void OnRenderImage (RenderTexture src, RenderTexture dest)
{
if (m_mat == null)
{
m_mat = new Material(m_shader);
// Materialが再生が終了したら破棄されるようにHideFlagsを設定する
m_mat.hideFlags = HideFlags.DontSave;
}
// Shaderの_ScrollValue変数に値を渡す
m_mat.SetFloat("_ScrollValue", (float)Time.frameCount * m_speed);
Graphics.Blit(src, dest, m_mat);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment