Optimize demo2
This commit is contained in:
parent
1e7c302f5c
commit
a625079d61
1 changed files with 14 additions and 1 deletions
15
demo2.cpp
15
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;
|
||||
|
|
Loading…
Reference in a new issue