diff --git a/demo2.cpp b/demo2.cpp index 90ac032..c2c93e7 100644 --- a/demo2.cpp +++ b/demo2.cpp @@ -493,6 +493,9 @@ Vector2D shotPosition; Vector2D shotDirection; bool shotFired = false; +uint8_t previousColumn = 255; ///< Helper for pixelIntensity. +int8_t pixelIntensity = 0; ///< Precomputed column intensity addition. + /** Function for drawing a single pixel (like fragment shader). */ @@ -506,7 +509,17 @@ inline void pixelFunc(PixelInfo pixel) if (pixel.isWall) { c = sampleImage(textures[pixel.hit.type],pixel.hit.textureCoord,pixel.textureCoordY); - c = addIntensity(c, 1 - pixel.depth / (UNITS_PER_SQUARE * 2) + (pixel.hit.direction % 2 == 0 ? 2 : 0)); + + if (previousColumn == pixel.position.x) + { + c = addIntensity(c,pixelIntensity); + } + else + { + // optimization: precompute intensity for the whole column + pixelIntensity = 1 - pixel.depth / (UNITS_PER_SQUARE * 2) + (pixel.hit.direction % 2 == 0 ? 2 : 0); + previousColumn = pixel.position.x; + } } else c = pixel.isFloor ? cFloor: cCeiling;