From d1458632e9a275dc6edbe4a364c1a545e76b6a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 3 Sep 2018 14:31:29 +0200 Subject: [PATCH] Add fog --- game.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/game.cpp b/game.cpp index 51d7851..efc58e5 100644 --- a/game.cpp +++ b/game.cpp @@ -110,6 +110,24 @@ inline uint8_t rgbToIndex(uint8_t r, uint8_t g, uint8_t b) return (r & 0b00000111) | ((g & 0b00000111) << 3) | ((b & 0b00000011) << 6); } +inline uint8_t darkenColor(uint8_t color, uint8_t intensity) +{ + uint8_t r = color & 0b00000111; + uint8_t g = (color & 0b00111000) >> 3; + uint8_t b = (color & 0b11000000) >> 6; + + r += intensity; + r = r > 7 ? 7 : r; + + g += intensity; + g = g > 7 ? 7 : g; + + b += intensity / 2; + b = b > 3 ? 3 : b; + + return rgbToIndex(r,g,b); +} + class Level { public: @@ -196,10 +214,10 @@ if (pixel.isWall) if (intensity < 0) intensity = 0; -} -if (pixel.isWall) c = sampleImage(image,pixel.hit.textureCoord,pixel.textureCoordY); + c = darkenColor(c,intensity); +} else c = rgbToIndex(intensity,intensity,intensity / 2);