您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

62 行
1.3 KiB

Shader "Hidden/Noise Shader RGB" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_GrainTex ("Base (RGB)", 2D) = "gray" {}
_ScratchTex ("Base (RGB)", 2D) = "gray" {}
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uvg : TEXCOORD1; // grain
float2 uvs : TEXCOORD2; // scratch
};
uniform sampler2D _MainTex;
uniform sampler2D _GrainTex;
uniform sampler2D _ScratchTex;
uniform float4 _GrainOffsetScale;
uniform float4 _ScratchOffsetScale;
uniform fixed4 _Intensity; // x=grain, y=scratch
v2f vert (appdata_img v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
o.uvg = v.texcoord.xy * _GrainOffsetScale.zw + _GrainOffsetScale.xy;
o.uvs = v.texcoord.xy * _ScratchOffsetScale.zw + _ScratchOffsetScale.xy;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
// sample noise texture and do a signed add
fixed3 grain = tex2D(_GrainTex, i.uvg).rgb * 2 - 1;
col.rgb += grain * _Intensity.x;
// sample scratch texture and do a signed add
fixed3 scratch = tex2D(_ScratchTex, i.uvs).rgb * 2 - 1;
col.rgb += scratch * _Intensity.y;
return col;
}
ENDCG
}
}
Fallback off
}