一、代码内容
代码如下(示例):
// 颜色混合
Shader "Study/ImageShader1"
{
Properties
{
_MainTex ("Main Texture", 2D) = "white" {
}
_RampTex ("Ramp Texture",2D) = "black"{
}
_Offset("Ramp Offset",float) = 0
// _ValueW("Value W",fixed) = 0.1 //混合权重
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
// 开启透明度混合 color_out = color_src * a + color_bg * (1-a)
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
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;
}
sampler2D _MainTex;
sampler2D _RampTex;
float _Offset;
// fixed _ValueW;
// 片元着色器
fixed4 frag (v2f i) : SV_Target
{
// tex2D:通过UV采样纹理
fixed4 col = tex2D(_MainTex, i.uv);
// just invert the colors 负片效果
// col.rgb = 1 - col.rgb;
fixed4 ramp_col = tex2D(_RampTex,i.uv);
fixed w = 0.5;
col.rgb = col*w + ramp_col*(1 - w);
return col;
}
ENDCG
}
}
}