Hi, I'm trying to make a very simple shader which has a single color and is not affected by lightning. Here is what I have so far. But it does not work. It's always full black whatever color I choose. Code (csharp): Shader "Unlit Single Color" { Properties { _Color ("Main Color", COLOR) = (1,1,1,1) } SubShader { Pass { Material { Diffuse [_Color] } Lighting Off } } } So, what's wrong with this shader? Thanks..
Code (csharp): Shader "Unlit Single Color" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} } Category { Lighting Off ZWrite On Cull Back SubShader { Pass { SetTexture [_MainTex] { constantColor [_Color] Combine texture * constant, texture * constant } } } } }
So, I guess we can't get rid of that MainTex property even though we don't have any texture to choose. Anyway, thanks. It works like a charm.
You don't need a texture, you just need to specify the color. Code (csharp): Shader "Unlit Color Only" { Properties { _Color ("Color", Color) = (1,1,1) } SubShader { Color [_Color] Pass {} } } --Eric
FYI, for some reason the shader provided by @Eric does not work properly on my iPod Touch 4th gen (it was only visible under a point light and invisible otherwise), so I had to use @twiesner's shader instead. Thanks.
What do you mean it was not visible? Did it turn black or the object was not rendered? I'm no expert in fixed function or shaderlab and don't know ipod specs, anyway you can try: 1. this one does a few things explicitly, but I guess does not differ much from Eric's one (both render OK on on my workstation) Code (csharp): Shader "Unlit Color Only" { Properties { _Color ("Color", Color) = (1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { Lighting Off ZWrite On Cull Back SetTexture[_] { constantColor [_Color] Combine constant } } } } 2. this one is made in pure CG and I expect it to work on enything with programmable shaders. Since GLES 2.0 devices don't have fixed function stuff it's probably better anyway. Code (csharp): Shader "Unlit Color Only CG" { Properties { _Color ("Color", Color) = (1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } LOD 200 Pass { Tags { "LightMode" = "Always" } Fog { Mode Off } ZWrite On ZTest LEqual Cull Back Lighting Off CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest fixed4 _Color; struct appdata { float4 vertex : POSITION; }; struct v2f { float4 vertex : POSITION; }; v2f vert (appdata v) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); return o; } fixed4 frag (v2f i) : COLOR { return _Color; } ENDCG } } } If nr.2 works and nr.1 doesn't then I'd combine them in one so it works on both programmable and fixed function (CG first, fixed/shaderlab one following as subshaders). Though I'd expect unity to compile shaderlab stuff to GLES, so the issue may be different.
Thanks @cician, your both shaders work without a problem in my iPod. I don't know the difference between these, so which one should I prefer? Will they have equal performance?