前部分知识复习02
一、物体的屏幕UV坐标
float2 ScreenUV = i.pos.xy / _ScreenParams.xy;
二、抓取屏幕图像
GrabPass{" _A "} //_A为贴图图像名称
之后需在Pass中声明该贴图才能在Pass中引用此贴图
三、屏幕抓取并制作热效应代码
Shader"unity/HeatDistort 07"
{
Properties
{
_DistortTex("DistortTex",2D)="white"{}
_DistortUV_X("DistortUV_X",int)=0
_DistortUV_Y("DistortUV_Y",int)=0
_Distort("Distort",Range(0,1))=0
}
SubShader
{
Tags{"Queue"="Transparent"}
GrabPass{"_Texture"}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _Texture;
sampler2D _DistortTex;
float4 _DistortTex_ST;
float _DistortUV_X;
float _DistortUV_Y;
float _Distort;
struct appdate
{
float4 vertex : POSITION;
float2 uv : TEXCOORD;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD;
};
v2f vert(appdate v)
{
v2f o;
o.pos=UnityObjectToClipPos(v.vertex);
o.uv=TRANSFORM_TEX(v.uv,_DistortTex)+float2(_DistortUV_X,_DistortUV_Y)*_Time.y;
return o;
}
float4 frag(v2f i):SV_Target
{
float4 distort=tex2D(_DistortTex,i.uv);
float2 ScreenUV=i.pos.xy/_ScreenParams.xy;
float2 dis=lerp(ScreenUV,distort,_Distort);
float4 tex=tex2D(_Texture,dis);
return tex;
}
ENDCG
}
}
}