After initially being puzzled about this question, because it felt natural that objects don't change their brightness depending on the distance to the eye (or camera), but only depending on the distance to the light source, I did a quick google search and found this great article. It is about this exact topic in photography and explains why the distance between the object and the camera is not relevant.
To summarize it: Yes, the arriving energy decreases proportional to
1/r². But consider this: As the distance increases the object also appears smaller, as well proportional to
1/r². While having less arriving energy, it also covers a smaller area of your field of view. Those two effects cancel each other out. Thus the object-camera distance does not influence the perceived brightness.
That's a question solved by looking at physical units.
The irradiance (watt per square metre) on the whole object determines it's illumination, this unit varies with distance between object and light because the "subtended surface" diminishes by
1/r² with the distance.
(The radiant flux (W) of the light being constant)
For simplicity let's imagine a case where the light is at the camera position and we are looking at a white disc. The radiance of the disk is the emitted light by its surface considering our vision angle : in watt per steradian per square metre.
The radiance is necessarily less than its irradiance if the material is diffuse. Why is that ? because the camera only subtends a tiny angle of the total re-emission directions; while the disc re-emits its energy at
2π steradian (hemisphere).
So the radiance seen by the camera is
irradiance / 2π. As you can see it does not depend on the distance between the object and the camera. Now, radiance is a unit per square meter, which means it defines "light intensity" per area, so when discretized, it means that it is the pixel value :)
I hope I'm right, this is always confusing.