Unityで画像処理を行うためのライブラリ
A library for image processing in Unity
簡単な画像処理をComputeShaderを利用することで高速に行うことができます.
You can simple image processing rapidly by using ComputeShader.
メソッドチェーンのように記述することができ,直感的に書けるのが特徴です.
You can write like a method chain, so you can write intuitively.
Releaseのページから最新版をダウンロードし,利用するUnityプロジェクト内で展開してください
Please download the latest version from the Release page, and deploy it in your Unity project.
利用したいシーン内に ShaderSettings
のPrefabを置きます.
Put a Prefab called ShaderSettings
in the scene you want to use.
- 画像処理したいテクスチャをTexture2D等のフォーマットからRenderTexture(ComputeShaderで扱えるフォーマット)に変換します.
Converts a texture to RenderTexture (a format that can be handled by ComputeShader).
var renderTexture = tex2D.ToRenderTexture();
FilterLibrary.cs
を参考に,好きなフィルタ関数を選びRenderTextureに適用します.
Refer toFilterLibrary.cs
and choose your favorite filter function and apply it to RenderTexture.
// このようにメソッドチェーンのように連続して処理を行うことができます
// you can write a sequence of operations like a method chain
var editedTexture = renderTexture.GaussianFilter3x3().MedianFilter3x3();
- RenderTextureのままRawImageに貼りつけることで,画像を表示できます
You can view the image by pasting it to RawImage, even if it is still a RenderTexture.
this.GetComponent<RawImage>().texture = renderTexture;
- 画像をRenderTextureからTexture2Dに変更することもできます
You can also change the image from RenderTexture to Texture2D.
var texture2D = renderTexture().ToTexture2D();