Until recently, I was using the following shader on a UI image to apply a distortion effect to the whole screen. However, since then, I’ve switched to the lightweight render pipeline, which has completely broken the shader. I’ve tried recreating the effect using the shader graph, but nothing I’ve tried so far has worked at all. Is there any way to modify this shader to work with the LWRP or perhaps another way to recreate it that I’m not aware of?
Shader "Custom/NauseaEffect"
{
Properties
{
_IntensityFilter ("Intensity Filter", 2D) = "white" {}
_Intensity ("Intensity", float) = 0.25
_Frequency ("Frequency", float) = 1.0
_Speed ("Speed", float) = 1.0
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"DisableBatching" = "True"
}
// Grab the screen behind the object into _GrabTexture
GrabPass
{
"_GrabTexture"
}
Pass
{
//ZTest Always
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _GrabTexture;
sampler2D _IntensityFilter;
float _Intensity;
float _Frequency;
float _Speed;
struct vin_vct
{
float4 vertex : POSITION;
};
struct v2f_vct
{
float4 vertex : POSITION;
float4 uvgrab : TEXCOORD1;
};
// Vertex function
v2f_vct vert (vin_vct v)
{
v2f_vct o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uvgrab = ComputeGrabScreenPos(o.vertex);
return o;
}
// Fragment function
half4 frag (v2f_vct i) : COLOR
{
float filter = tex2Dlod(_IntensityFilter, float4(i.uvgrab)).rgb;
i.uvgrab.x += sin((_Time * _Speed + i.uvgrab.y) * _Frequency) * _Intensity * filter;
i.uvgrab.y += cos((_Time * _Speed + i.uvgrab.x) * _Frequency) * _Intensity * filter;
fixed4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
return col;
}
ENDCG
}
}
FallBack "VertexLit"
}