- Home /
Unlit Shader With Texture, Color, Overbrightness, and Alpha-based Transparency
Today I was working on making code that would flash my mesh a certain color, and then return to the standard color. I am planning on baking in my own shadows on characters like Mega Man Legends, so I would like to know that what I am coloring in an external program is what I get in Unity. For this purpose, Unlit textures seems to be the way to go.
Basically, I need an unlit texture that has a color property such that when the color property is {127,127,127,255} it looks the same as an unlit shader. At {255,255,255,255} the character is solid white (Overbrightness?). At {0,0,0,255} the character is solid black.
But I also want the alpha channel of the color to determine the transparency of my character. So that at {127,127,127,127} he is colored like the unlit shader, but halfway transparent. When alpha is zero, he is invisible etc.
I have found a couple shaders that bring me close on the color aspect but not on the transparency.
Shader "Custom" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
Category {
SubShader {
Tags { "Queue" = "Geometry" }
Pass {
SetTexture [_MainTex] {
constantColor [_Color]
Combine texture * constant DOUBLE
}
}
}
}
}
The above shader is good because it is normal at {127,127,127,255}, but it is not bright enough at white (Not solid). Transparency does not match alpha.
Shader "Vertex color unlit2" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
}
Category {
Tags { "Queue"="Geometry" }
Lighting Off
BindChannels {
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}
// ---- Dual texture cards
SubShader {
Pass {
SetTexture [_MainTex] {
//combine texture * primary
}
SetTexture [_MainTex] {
constantColor [_Color]
combine previous lerp (previous) constant DOUBLE
}
}
}
// ---- Single texture cards (does not do vertex colors)
SubShader {
Pass {
Blend SrcAlpha OneMinusSrcAlpha // Alpha blending
SetTexture [_MainTex] {
constantColor [_Color]
combine texture lerp(texture) constant DOUBLE
}
}
}
}
}
This second shader is good, but the "baseline" is Black and it is dark and the textures look burnt. When the color is white, the object is solid white which is desirable. This does not have the alpha based transparency that i want either.
I tried adding in the alpha, but nothing got the right look. I hope I made my desired effect clear, thank you in advance for any help.
https://www.dropbox.com/s/scrmqax06uxf12r/shader.png
^Here is a picture of the desired effect of the shader. From right to left: {127,127,127,255} {255,255,255,255} {127,127,255,127}
Your answer
![](https://koobas.hobune.stream/wayback/20220613071652im_/https://answers.unity.com/themes/thub/images/avi.jpg)