Hesham
December 30, 2013, 12:37pm
1
I’m nit a shader programmer, but would appreciate if someone can point in the right direction. I want a shader that does an RGB Split like in the video posted below.
I wouldn’t mind to buy it off the asset store but I checked most of the packages and none seem to have it.
My “aubergines postprocess effects” pack has this effect. Its the _Lightwave shader in the package.
You need unity pro for it.
I have my email in the readme file, let me know when you need customization or extra features as its pretty generic out of the box.
Hesham
December 30, 2013, 5:11pm
5
Thank for the quick response. Got my customized shader in minutes.
This is the link to the asset on the store
For those who want to know the basis for how its done, heres a free example below
Reference : Jahfer's Blog
Shader "Custom/ChromaticAberration" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float _AberrationOffset;
float4 frag(v2f_img i) : COLOR
{
float2 coords = i.uv.xy;
_AberrationOffset /= 300.0f;
//Red Channel
float4 red = tex2D(_MainTex , coords.xy - _AberrationOffset);
//Green Channel
float4 green = tex2D(_MainTex, coords.xy );
//Blue Channel
float4 blue = tex2D(_MainTex, coords.xy + _AberrationOffset);
float4 finalColor = float4(red.r, green.g, blue.b, 1.0f);
return finalColor;
}
ENDCG
}
}
}
C# code, gets attached to the camera
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class ChromaticAberration : MonoBehaviour {
#region Variables
public Shader curShader;
public float ChromaticAbberation = 1.0f;
private Material curMaterial;
#endregion
#region Properties
Material material
{
get
{
if(curMaterial == null)
{
curMaterial = new Material(curShader);
curMaterial.hideFlags = HideFlags.HideAndDontSave;
}
return curMaterial;
}
}
#endregion
// Use this for initialization
void Start ()
{
if(!SystemInfo.supportsImageEffects)
{
enabled = false;
return;
}
}
void OnRenderImage (RenderTexture sourceTexture, RenderTexture destTexture)
{
if(curShader != null)
{
material.SetFloat("_AberrationOffset", ChromaticAbberation);
Graphics.Blit(sourceTexture, destTexture, material);
}
else
{
Graphics.Blit(sourceTexture, destTexture);
}
}
// Update is called once per frame
void Update ()
{
}
void OnDisable ()
{
if(curMaterial)
{
DestroyImmediate(curMaterial);
}
}
}
1 Like
bfowle
January 27, 2014, 10:57pm
7
This looks quite awesome! I was wondering if there was a possible solution for Unity Free to achieve something similar to the referenced post: http://blog.jahfer.com/2012/04/02/experimenting-shaders-openframeworks/ ? Cheers~
You are better of using Echologin’s Post FX here: https://www.assetstore.unity3d.com/#/content/13919
You can do that effect and so much more.
bfowle
January 28, 2014, 2:18am
9
Thanks for the heads up! Much appreciated.