- Home /
Whole Screen Distortion in LWRP
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"
}
Answer by Irakuy17 · May 23, 2019 at 07:23 PM
hey,I'm not sure I can describe it all right, cuz Engish is really difficult for me. In the LWRP, some Unity Built-In traditional pass do not work any longer. You need to scritp the TargetPass in a C# script, in other words, you need control the pipeline by yourself. In the LWPR package, Unity has keeped some Interfaces, you can find it in your project. In your case, you need to realize the IAfterOpaquePass, then you need to create the gloable var grab texture. Then the texture you can use it in ShadrGraph or your custom shader. It is not ver有 difficult. Here is the video https://www.bilibili.com/video/av38056528, 74:40, in this Demo, he makes a blur effect by creat a new pass in LWRP to grab screen, and the demo you can get it in GitHub.
Your answer
Follow this Question
Related Questions
Render a sprite only when it's on the parent but not other sprites. 0 Answers
Rendering only outside the fog 1 Answer
How does Material's "SetShaderPassEnabled" work? 1 Answer
X-Ray shader / Cutting a hole through a mesh 1 Answer
Shader isn't displaying properly in editor view, but when built it displays properly. 0 Answers