The function FELighting::inlineSetPixel() is called to apply the lighting on a single pixel one at a time. Things to be noticed here about this function -- The same calculation is carried out for the same values when calling this function from a loop. As an example consider these lines from FELighting::inlineSetPixel(): normalVector.setX(factorX * static_cast<float>(normal2DVector.x()) * data.surfaceScale); normalVector.setY(factorY * static_cast<float>(normal2DVector.y()) * data.surfaceScale); and consider the case when it is called from any loop in FELighting::drawLighting(). All loops call FELighting::inlineSetPixel() with the same values for factorX, factorY, normal2DVector and data.surfaceScale. So the above multiplications should be carried out only once for every loop and reused for all pixels processed in this loop. -- The calculation of FELighting::inlineSetPixel() is not reused for adjacent pixels if they should be the same. Caching the resulting color or the light strength of the last pixel should accelerate the lighting calculation for adjacent pixels.
<rdar://problem/19521229>
(In reply to Said Abou-Hallawa from comment #0) > The function FELighting::inlineSetPixel() is called to apply the lighting on > a single pixel one at a time. Things to be noticed here about this function > > -- The same calculation is carried out for the same values when calling this > function from a loop. As an example consider these lines from > FELighting::inlineSetPixel(): > > normalVector.setX(factorX * static_cast<float>(normal2DVector.x()) * > data.surfaceScale); > normalVector.setY(factorY * static_cast<float>(normal2DVector.y()) * > data.surfaceScale); > > and consider the case when it is called from any loop in > FELighting::drawLighting(). All loops call FELighting::inlineSetPixel() with > the same values for factorX, factorY, normal2DVector and data.surfaceScale. > So the above multiplications should be carried out only once for every loop > and reused for all pixels processed in this loop. The normal vector is not constant here; it's the surface normal, computed by the Sobel filter that compares the alpha values of neighboring pixels. > -- The calculation of FELighting::inlineSetPixel() is not reused for > adjacent pixels if they should be the same. Caching the resulting color or > the light strength of the last pixel should accelerate the lighting > calculation for adjacent pixels. That's possibly true.