Factorize luminance computation.
Write a shader to convert CIE to RGB.
Add some code to average log luminance.
Plug in brightness adaptation