So what’s happening here is that the brain is using its prior expectations built deeply into the circuits of the visual cortex that a cast shadow dims the appearance of a surface, so that we see B as lighter than it really is.
OK, so what’s going on here?
Now all this.
Have a look into this.