Change Scence's Texture Using Ray-Tracing

(Is this question in the right section of this forum ?)

NOTICE, I’m not talking about ray-tracing for good looking rendering.
I’m talking about the case, for example, that in a “Shooter game”, you shoot the gun at the wall, and afterwards you can see the “bullet trace” on the wall, the texture of the wall changed.

So what I’m trying to do, set the camera at some location in the scene, and paint ALL (and only) the surfaces that each pixel in the image shows.

For example, if you are in a completely white room, and the camera is looking somewhere, than all the surfaces the camera’s pixels see, will be painted blue, and stay blue afterwards.

How can this be done ?