- Home /
2D Greyscale shader with lighting and color.
I am very new to unity and shaders in general. I am currently trying to make a shader that when something is unlit it will be in greyscale but when it is lit it will be normal color. Any help on how to make this would be greatly appreciated!
Answer by Klarzahs · Oct 26, 2020 at 03:08 PM
Hi @tsirgamesalott ,
I think the easiest way to do this would be to check the attenuation level (i.e. shadow intensity) in your shader. You can find code examples here, you would have to write your own lighting calculation for a surface shader. Just check if the attenuation is below a threshold and grayscale the colour.
You can in theory use raycasts and an extra texture, which might be better for edge cases. See this question for more information, or this shader code for a lookup texture setup.
Generally said though, the less light (the more shadow) your object has, the grayer it is anyway :D
Your answer
Follow this Question
Related Questions
Unity 2D Shader Graph Sprite transparent when in shadow 0 Answers
Trying to create 2D pixel art lighting 1 Answer
Ambient Light not working with some objects 1 Answer
Making glowing lines and shapes 1 Answer
2d lighting effect 1 Answer