Optimize demo2

This commit is contained in:
Miloslav Číž 2018-09-10 07:41:39 +02:00
parent 1e7c302f5c
commit a625079d61

View file

@ -493,6 +493,9 @@ Vector2D shotPosition;
Vector2D shotDirection; Vector2D shotDirection;
bool shotFired = false; 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). Function for drawing a single pixel (like fragment shader).
*/ */
@ -506,7 +509,17 @@ inline void pixelFunc(PixelInfo pixel)
if (pixel.isWall) if (pixel.isWall)
{ {
c = sampleImage(textures[pixel.hit.type],pixel.hit.textureCoord,pixel.textureCoordY); 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 else
c = pixel.isFloor ? cFloor: cCeiling; c = pixel.isFloor ? cFloor: cCeiling;