- Home /
Aditive Greyscale Shader (Turns any texture a solid color)
I've been looking through all the docs all day and have found nothing. I'm trying to create an additive shader that will color any texture applied one solid color regardless of the texture's color. It would be a like a greyscale but I want the color to affect the entire color of the texture on the material and be adjustable. I don't want to edit all the textures in the project and make them colorless with photoshop. Making a shader is a much better approach.
Is this even possible? If someone could help me out that would be great.
Answer by cluh · Nov 30, 2012 at 08:53 AM
Should be pretty simple. Any affine sum of the r, g, and b components will result in a different type of grayscale. The following fragment shader should work, though I haven't tested it.
` float4 frag (v2f i) : COLOR
{
float4 tex = tex2D(_MainTex, i.texcoord);
return _Color * float4(float3((tex.r + tex.g + tex.b) / 3.0), tex.a);
}
`
Just checking, you left in `_Color *` in case someone wants a non-grey grey-scale shader?
For uneven weighting, I like to abuse dot-product: `col.rgb=dot(col.rgb, float3(0.4, 0.35, 0.25));`
Yes, _Color is in there because BHS wanted it to be monochromatic but with adjustable color. I do like the use of dot product there, it makes the code a bit cleaner, and shouldn't slow it down.
Your answer
Follow this Question
Related Questions
Fade A Whole Scene From Black & White to Colour 1 Answer
Greyscale shading 0 Answers
How to achieve a Black & White effect. 0 Answers
White contour around black texts 0 Answers
Giving MatCap_TextureAdd a black outline 0 Answers