srylain
September 19, 2017, 12:43am
1
The shader I have I believe is just a basic shader that has vertex color capabilities, and I’d like to turn it into an unlit shader so I can remove the light from my scene (everything else is unlit 2D stuff, this is the only thing that requires light).
Shader "Custom/CubeShader" {
Properties{
_MainTex("Base (RGB)", 2D) = "white" {}
}
SubShader{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
//Tags { "RenderType" = "Opaque" }
LOD 300
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float4 color: Color; // Vertex color
};
void surf(Input IN, inout SurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb * IN.color.rgb; // vertex RGB
o.Alpha = c.a * IN.color.a; // vertex Alpha
}
ENDCG
}
FallBack "Diffuse"
}
I know next to nothing about shaders, so any help would be greatly appreciated!
Can’t test it right now. Let me know if any compilation error.
Update 0920: modified from built-in Unlit/Normal (Texture) shader.
Shader "Custom/CubeShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
Lighting Off
ZWrite On//Off for transparent
Cull Back//Off if you want to show Front and Back sides.
LOD 100
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
o.color = v.color;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
return col;
}
ENDCG
}
}
}