hi)
i create shader for coloring static people. a lot. material with this shader must be bathing, cause all materials of my people has similar properties. but…
in Scene view all looks like great. in Game view all objects has one color =(
what’s my problem? what am I doing wrong?
i use Unity 2018.3.14f1
shader code:
Shader "Custom/MaskedColorPeopleView"
{
Properties
{
_Tex1 ("Albedo (RGB)", 2D) = "white" {}
_NoiseMap ("Albedo (RGB)", 2D) = "gray" {}
_SkinGrad ("Albedo (RGB)", 2D) = "white" {}
_ClothGrad ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "Queue" = "Transparent" "RenderType"="Opaque" "PreviewType"="plane"}
LOD 200
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _Tex1;
sampler2D _NoiseMap;
sampler2D _SkinGrad;
sampler2D _ClothGrad;
struct Input
{
float2 uv_MainTex;
float4 objPos;
};
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float4 worldPos : COLOR;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.worldPos = mul(unity_ObjectToWorld, float4(0,0,0,1));
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 pos = fmod(abs(i.worldPos / 10), fixed3(1,1,1));
fixed4 noiseMap = tex2D(_NoiseMap, float2(pos.r, pos.b));
fixed4 tex1 = tex2D(_Tex1, i.uv);
fixed4 skinColor = tex2D(_SkinGrad, float2(noiseMap.r, 0.5)) * tex1.r * tex1.g;
fixed4 shirtColor = tex2D(_ClothGrad, float2(noiseMap.g, 0.5)) * tex1.r * tex1.b;
fixed4 pantsColor = tex2D(_ClothGrad, float2(noiseMap.b, 0.5)) * tex1.r * tex1.a;
fixed4 col = skinColor + shirtColor + pantsColor;
col.a = 1;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
аssets in attachments.
PS: I hope I will not be banned … I just create spectators in my game…
4505620–416347–PeopleView.zip (1.55 MB)