image.png
Shader "Unlit/lasttest"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_GrayTex("GrayTexture", 2D) = "white" {}
_Color255("Color255", Color) = (1, 1, 1)
_Color214("Color200", Color) = (1, 1, 1)
_Color137("Color111", Color) = (1, 1, 1)
_Color71("Color35", Color) = (1, 1, 1)
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float4 worldPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _GrayTex;
float4 _GrayTex_ST;
fixed3 _Color255;
fixed3 _Color214;
fixed3 _Color137;
fixed3 _Color71;
// RGB 转 HSV
//float3 RGB2HSV(float3 c)
//{
// float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
// float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
// float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
// float d = q.x - min(q.w, q.y);
// float e = 1.0e-10;
// return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
//}
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 sss = tex2D(_GrayTex, i.uv);
float realR = sss.r * 255;
if (realR <= 72)
{
col.xyz = _Color71;
}
else if (realR <= 138)
{
col.xyz = _Color137;
}
else if (realR <= 215)
{
col.xyz = _Color214;
}
else
{
col.xyz = _Color255;
}
//float
//fixed3 _Color255;
//fixed3 _Color214;
//fixed3 _Color137;
//fixed3 _Color71;
//else col.xyz *= _Color35;
return col;
}
ENDCG
}
}
}
网友评论