This is really a very broad question; I will give you just a few pointers, but a full answer could fill a book.
Yes, any 1D/2D pattern (barcode) scanner is looking at spatial variations in the received intensity; and it typically looks for "brighter/darker" to decide how to do the binary decoding ('
1/0). Bar codes are constructed in such a way that they are roughly 50% black and 50% white regardless of the number represented, so this trick works fairly well.
How well it works, then, really depends on the contrast between the black and white signal. If you have limited contrast - say, the reflectivity of the white is 60% and the reflectivity of the black is 40$ - then the total signal is 20% (60%-40%), while the average signal is 50% ((40%+60%)/2). If you had excellent contrast, the values would be 0% for black, and 100% for white.
Now there are several things that degrade the quality of the scan. The first is the color (bright/dark-ness) of the object scanned, as described above; but there may be other factors degrading the contrast: reflection (shiny barcodes are hard) and scatter along the optical path (dirt on the lens, "fog" in the air) being the most important.
When you build a scanner, there is not much you can do to change the reflectivity (black/white ratio) of the object scanned: that is "external". So all you can do is minimize the effect of reflectivity and scatter.
Reflectivity is a function of angle: in principle, if you move your light source to different places and don't move the barcode, then different parts of the surface will cause specular reflection. The corollary is that a point source of light will sometimes cause a strong reflection at one place, and this might make that one place hard to decode. An extended light source prevents that. You may have seen how people using laser scanners sometimes have to move the bar code around to get a good scan: that's not only because of positioning, but also to get rid of a reflection. In principle, if you used a pair of scanning light sources that were offset by 30 or more degrees, and you scanned with each of them in quick succession, then reflection from one would not show up on the other, and you could create a "complete" image. But a "camera" shot of the bar code illuminated by an extended source will typically work better. Polarization can also help: laser light is typically linearly polarized, and speculation reflection maintains that polarization. By putting a cross polarizer in front of the detecting element you can greatly reduce the effect of specular reflection. Only light scattered by the "white" of the bar code, having lost its polarization, would be detected - in principle.
But there's this second thing - scatter. Most of the time, that does not matter for barcode scanners - just keep your optics clean. However, there are certain situations (not typically with bar code scanners - but stay with me, this is interesting) where you need to be able to "see through the fog". Quite literally. Examples are underwater search and rescue, and of course driving through fog. Now if you use a scanning beam of light that is slightly offset from your line of view, then that beam will strongly scatter off the fog; but if you are only interested in a point "at the end of the beam", then most of that scatter doesn't matter. By scanning the beam, and creating a composite image that is composed only of "the point at the end of the beam" (for a particular viewing distance and angle, you know where that point is in your field of view), you are actually able to reduce the effect of fog / suspended particles / scatter by orders of magnitude. Sometimes people use pulsed laser sources for this, and add a time gate for the detection of the reflected light - that removes even more of the scatter. The result is a "magical" device that can literally look through fog, and see things that are invisible to the unaided eye. Because of the scanning, they are a bit slow for using in driving conditions (I am not aware of cars equipped with this technology) but they work great in search and rescue. The general field is called "structured light imaging" and here is a nice paper summarizing some of the methods.