Implemented a dumb lighting system.
This commit is contained in:
parent
4d31a4daf2
commit
f88eca9cd9
1 changed files with 24 additions and 1 deletions
|
@ -1,9 +1,32 @@
|
||||||
#include "raycaster.hpp"
|
#include "raycaster.hpp"
|
||||||
#include "texture.hpp"
|
#include "texture.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
|
|
||||||
|
union ColorConv {
|
||||||
|
struct {
|
||||||
|
uint8_t r;
|
||||||
|
uint8_t g;
|
||||||
|
uint8_t b;
|
||||||
|
uint8_t a;
|
||||||
|
} as_color;
|
||||||
|
uint32_t as_int;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline uint32_t dumb_lighting(uint32_t pixel, double distance) {
|
||||||
|
if(distance < 0.9) return pixel;
|
||||||
|
|
||||||
|
ColorConv conv{.as_int=pixel};
|
||||||
|
conv.as_color.r /= distance;
|
||||||
|
conv.as_color.g /= distance;
|
||||||
|
conv.as_color.b /= distance;
|
||||||
|
|
||||||
|
return conv.as_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Raycaster::Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height) :
|
Raycaster::Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height) :
|
||||||
$width(width), $height(height),
|
$width(width), $height(height),
|
||||||
$window(window),
|
$window(window),
|
||||||
|
@ -226,7 +249,7 @@ void Raycaster::cast_rays() {
|
||||||
int texY = (int)texPos & (textures.TEXTURE_HEIGHT - 1);
|
int texY = (int)texPos & (textures.TEXTURE_HEIGHT - 1);
|
||||||
texPos += step;
|
texPos += step;
|
||||||
RGBA pixel = texture[textures.TEXTURE_HEIGHT * texY + texX];
|
RGBA pixel = texture[textures.TEXTURE_HEIGHT * texY + texX];
|
||||||
pixels[pixcoord(x, y)] = pixel;
|
pixels[pixcoord(x, y)] = dumb_lighting(pixel, perpWallDist);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SET THE ZBUFFER FOR THE SPRITE CASTING
|
// SET THE ZBUFFER FOR THE SPRITE CASTING
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue