# How to write a custom shader in Unity 3D that lights up a specific pixel or group of pixel?

I'm making a FPS game in Unity, and I want the environment to light up as the player is shooting on his environment. The map would be entirely put in darkness at the beginning, but as the player shoots the environment, it would be rendered with its "real texture". So say I have a tree. First it is entirely black or greyish, but if I shoot somewhere, I would see some green. To accomplish this, I'm using a raycast to get the impact point and so I can access any renderer of the point that the player is shooting on. I guess the next step would be to write a custom shader to light the exact pixel that is shot. Do you have any idea how I could write this shader or another way of doing this effect?

Regards

• What is the effect you are looking for? A lighter point where the shot hit? You could just spawn a light at that point. – PatrickSharbaugh Nov 3 '15 at 15:36
• I want the map to be entirely put in darkness at the beginning, but as the player shoots the environment, it would be rendered with its "real texture". So say I have a tree. First it is entirely black or greyish, but if I shoot somewhere, I would see some green. – David Nov 3 '15 at 15:40

• It may be preferable to use a smaller, non-alpha, format as a stencil. Texture2D<bool> would be perfect but doesn't exist. If you write 1's wherever clicked, then the shader becomes Color * Stencil (Color or 0). – Jon Mar 20 '16 at 7:29