冯乐乐的《Unity Shader入门精要》附带项目,其中部分shader已经修改测试
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
1.0 KiB

Shader "Hidden/ImageDistort"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_DistortTex ("Distort Texture", 2D) = "white" {}
_DistortScale ("Distort Scale",Range(0,1)) = 1.0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Tags { }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _DistortTex;
float _DistortScale;
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
//i.uv = abs(0.5-i.uv);
fixed4 noise = tex2D(_DistortTex,i.uv);
i.uv = i.uv + (0.5-noise.r) * _DistortScale*0.1;
fixed4 col = tex2D(_MainTex, i.uv);
// just invert the colors
//col.rgb = 1 - col.rgb;
return col;
}
ENDCG
}
}
}