- Home /
Unlit greyscale shader
I want to make a shader that show a unlit transparent texture with greyscale effect over a mesh without normals.
I try with a code like this:
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = dot(c.rgb, float3(0.3, 0.59, 0.11));
o.Alpha = c.a;
}
ENDCG
}
But this approach use Lambert light model, and I need unlit result for mesh that haven't normals.
Any idea? Thanks!
Comment
Best Answer
Answer by Tim-Michels · Nov 06, 2012 at 07:35 AM
I've written another shader that has the same result. This should not give you the warning.
Shader "Unlit/GreyScale" {
Properties {
_MainTex ("Texture", 2D) = "white" { }
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D (_MainTex, i.uv);
texcol.rgb = dot(texcol.rgb, float3(0.3, 0.59, 0.11));
return texcol;
}
ENDCG
}
}
Fallback "VertexLit"
}
Cheers ;)
Please mark answer as correct, so other people can also see the solution. Thanks
Your answer
Follow this Question
Related Questions
Unlit shader with shadows. 0 Answers
How to make cheap terrain for ocean floor? 0 Answers
Problem with unlit additive shader 1 Answer
How to make the terrain unlit? 0 Answers
Particles/Standard unlit behaving differently in different scenes 0 Answers