- Home /
Any shader simpler/faster than Vertex-Lit?
I'm working on a game where I will control the shading myself, by changing the baseColor of the textures. So I don't want a shader that does ANY lighting at all. I know I can get that effect by having no lights in the scene and turning up the ambient light on the render settings, but I still worry that the renderer will be working harder than it needs to.
According to the docs, Vertex-Lit is the simplest/fastest renderer, but even that computes light and applies it on a vertex basis. Is there any "None" shader that just draws flat textures exactly as they are, not affected by lighting at all?
Answer by Eric5h5 · Feb 01, 2011 at 04:55 AM
This shader on the wiki is about the simplest and fastest you can get:
Shader "Texture Only"{
Properties { _MainTex ("Texture", 2D) = "" }
SubShader { Pass {SetTexture[_MainTex]} }
}
Alpha transparency does not work with this one. Is there a version of this that respects transparency?
Answer by Peter G · Feb 01, 2011 at 04:41 AM
You can turn Lighting Off:
Shader "No Lighting" { Properties { _Color ("Main Color", COLOR) = (1,1,1,1) } SubShader { Pass { Material { Diffuse [_Color] Ambient [_Color] }
//---------------------------
Lighting Off
//---------------------------
}
}
}
And just set the texturing to take a mainColor into account with a texture.
Answer by Jessy · Feb 01, 2011 at 10:08 AM
I'm thinking that when you say "baseColor", you mean the a solid color that gets multiplied into the whole material. That's what happens with "ambient light", anyway.
I know I can get that effect by having no lights in the scene and turning up the ambient light on the render settings.
Or maybe you just mean that you're making the ambient setting white, and "baseColor" is something else entirely? Please let us know.
If you actually wanted to use the color in the render settings, you could use this (it won't display right in the material preview for some reason, but looks fine in the scene; I'm reporting a bug right now):
Shader "Ambient Lit Texture" {
Properties { _MainTex ("Texture", 2D) = "" }
SubShader { Lighting On Material {Ambient (2, 2, 2)} Pass{ SetTexture[_MainTex] {Combine texture * primary} } }
}
If you want to use Material.color, then these will yield the same result. The first one sets the vertex colors of the mesh to be a solid color, and the second one defines a constant in the texturing stage. I don't know which is faster, but I'd love for someone to tell me about that. ;-) (Daniel Brauer told me that grabbing vert lighting values can be faster than using constants, which seems counterintuitive to me, but I never designed a GPU.)
Shader "Tinted Texture" {
Properties { _Color ("Base Color", Color) = (1,1,1) _MainTex ("Texture", 2D) = "" }
SubShader { Color[_Color] Pass{ SetTexture[_MainTex] {Combine texture * primary} } }
}
.
Shader "Tinted Texture" {
Properties { _Color ("Base Color", Color) = (1,1,1) _MainTex ("Texture", 2D) = "" }
SubShader { Pass{ SetTexture[_MainTex] {Combine texture * constant ConstantColor[_Color]} } }
}
Answer by davedev · Mar 28, 2012 at 09:42 AM
Unlit shader should be the fastest and sounds like it does what you want.
http://unity3d.com/support/documentation/Components/shader-Performance.html
Your answer
Follow this Question
Related Questions
Help with adding a normalmap to a shader 1 Answer
Torchlight effect in 2D 3 Answers
World coordinates for texture on procedural mesh 0 Answers
If not lit, use different texture 2 Answers
Shader light fix? 1 Answer