- Home /
Shader wants texture coordinates...
Hi folks,
I'm trying to create a shader that does a couple of things:
1) Uses vertex lights
2) Uses the vertex colours
3) Modifies these by another colour/vector (don't mind which)
4) DOES NOT USE TEXTURES
As such, I've managed to fumble my way through the various guides and things and come up with:
Shader "Custom/MobileVertexLitVertexColouredAndBaseColoured"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader
{
Pass
{
Material
{
}
ColorMaterial AmbientAndDiffuse
Lighting On
SetTexture [_MainColor]
{
Combine primary, primary
}
SetTexture [_MainColor]
{
constantColor [_Color]
Combine previous * constant DOUBLE, previous * constant
}
}
}
}
Now, of course, I've got two lovely 'SetTexture' commands in there that I don't really want - I don't want textures! But, of course, those segments of the shader are also what allows that 'constantColor' to be used.
The shader works, but - understandably - complains about the fact that I have no UVs. Is there an alternative way to do what I require in some other (presumably poorly documented) pass, that doesn't require a UV set? I'd rather not kluge my way around the issue by creating a texture and a bunch of useless UVs.
Many thanks for any hints. I appreciate your time, and hope I've specified the question well and clearly enough to be useful.
Thanks for that. I'm trying to stay well away from all pixel-shaders for mobile performance reasons.
Answer by FuzzyLogic · Aug 02, 2013 at 06:32 PM
You can do it with a surface shader.
Tested code...
Shader "Custom/MobileVertexLitVertexColouredAndBaseColoured" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Tags {
"RenderType" = "Opaque"
}
CGPROGRAM
// the noforwardadd option makes it use vertex lights only + 1 directional per-pixel light
#pragma surface surf BlinnPhong noforwardadd
float4 _Color;
struct Input {
float4 color: Color; // Vertex color
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = _Color.rgb + IN.color.rgb; // additive blend
}
ENDCG
}
// FallBack "Diffuse" // disable during development
}
The above shader does use one per-pixel light but if you really don't want it, you will need to do custom lighting.
Here's some surface shader examples from the unity reference.