Raycaster now leaves colors that are above a threshold to have a 'glow' effect.
This commit is contained in:
parent
c0d668fb0b
commit
96a585220b
3 changed files with 20 additions and 33 deletions
|
@ -100,12 +100,12 @@
|
|||
"frame_width": 256,
|
||||
"frame_height": 256
|
||||
},
|
||||
"floor":
|
||||
"lava_floor":
|
||||
{"path": "assets/floor_tile_test-256.png",
|
||||
"frame_width": 256,
|
||||
"frame_height": 256
|
||||
},
|
||||
"lava_floor":
|
||||
"floor":
|
||||
{"path": "assets/lava_floor-256.png",
|
||||
"frame_width": 256,
|
||||
"frame_height": 256
|
||||
|
|
|
@ -12,6 +12,8 @@ constexpr const int SCREEN_WIDTH=1280;
|
|||
constexpr const int SCREEN_HEIGHT=720;
|
||||
constexpr const int RAY_VIEW_X=(SCREEN_WIDTH - RAY_VIEW_WIDTH);
|
||||
constexpr const int RAY_VIEW_Y=0;
|
||||
constexpr const int GLOW_LIMIT=220;
|
||||
constexpr const int LIGHT_MULTIPLIER=2.5;
|
||||
|
||||
constexpr const int BOSS_VIEW_WIDTH=1080;
|
||||
constexpr const int BOSS_VIEW_HEIGHT=SCREEN_HEIGHT;
|
||||
|
|
|
@ -35,44 +35,29 @@ union ColorConv {
|
|||
//
|
||||
// Intensity = Object Intensity/Distance * Multiplier
|
||||
//
|
||||
inline uint32_t new_new_lighting(uint32_t pixel, float dist, int level) {
|
||||
ColorConv conv{.as_int=pixel};
|
||||
float intensity = (float(level) * PERCENT) / (dist + 1) * 2.5;
|
||||
|
||||
conv.as_color.r *= intensity;
|
||||
conv.as_color.g *= intensity;
|
||||
conv.as_color.b *= intensity;
|
||||
|
||||
return conv.as_int;
|
||||
}
|
||||
|
||||
inline uint32_t old_lighting(uint32_t pixel, float dist, int level) {
|
||||
(void)level;
|
||||
ColorConv conv{.as_int=pixel};
|
||||
conv.as_color.r /= dist;
|
||||
conv.as_color.g /= dist;
|
||||
conv.as_color.b /= dist;
|
||||
|
||||
return conv.as_int;
|
||||
}
|
||||
|
||||
/* It's hard to believe, but this is faster than any bitfiddling
|
||||
* I could devise. Just use a union with a struct, do the math
|
||||
* and I guess the compiler can handle it better than shifting
|
||||
* bits around.
|
||||
*/
|
||||
inline uint32_t new_lighting(uint32_t pixel, float dist, int level) {
|
||||
// Intensity = Object Intensity/Distance * Multiplier
|
||||
(void)dist; // ignore for now until I can do more research
|
||||
float factor = float(level) * PERCENT;
|
||||
inline uint32_t lighting_calc(uint32_t pixel, float dist, int level) {
|
||||
ColorConv conv{.as_int=pixel};
|
||||
conv.as_color.r *= factor;
|
||||
conv.as_color.g *= factor;
|
||||
conv.as_color.b *= factor;
|
||||
|
||||
if(conv.as_color.b < GLOW_LIMIT
|
||||
&& conv.as_color.r < GLOW_LIMIT
|
||||
&& conv.as_color.g < GLOW_LIMIT)
|
||||
{
|
||||
float intensity = (float(level) * PERCENT) / (dist + 1) * LIGHT_MULTIPLIER;
|
||||
|
||||
conv.as_color.r *= intensity;
|
||||
conv.as_color.g *= intensity;
|
||||
conv.as_color.b *= intensity;
|
||||
}
|
||||
|
||||
return conv.as_int;
|
||||
}
|
||||
|
||||
|
||||
Raycaster::Raycaster(int width, int height) :
|
||||
$view_texture(sf::Vector2u{(unsigned int)width, (unsigned int)height}),
|
||||
$view_sprite($view_texture),
|
||||
|
@ -332,7 +317,7 @@ void Raycaster::cast_rays() {
|
|||
tex_pos += step;
|
||||
RGBA pixel = texture[texture_height * tex_y + tex_x];
|
||||
int light_level = lights[map_y][map_x];
|
||||
$pixels[pixcoord(x, y)] = new_new_lighting(pixel, perp_wall_dist, light_level);
|
||||
$pixels[pixcoord(x, y)] = lighting_calc(pixel, perp_wall_dist, light_level);
|
||||
}
|
||||
|
||||
// SET THE ZBUFFER FOR THE SPRITE CASTING
|
||||
|
@ -400,11 +385,11 @@ void Raycaster::draw_ceiling_floor() {
|
|||
|
||||
// FLOOR
|
||||
color = $floor_texture[texture_width * ty + tx];
|
||||
$pixels[pixcoord(x, y)] = new_new_lighting(color, row_distance, light_level);
|
||||
$pixels[pixcoord(x, y)] = lighting_calc(color, row_distance, light_level);
|
||||
|
||||
// CEILING
|
||||
color = $ceiling_texture[texture_width * ty + tx];
|
||||
$pixels[pixcoord(x, $height - y - 1)] = new_new_lighting(color, row_distance, light_level);
|
||||
$pixels[pixcoord(x, $height - y - 1)] = lighting_calc(color, row_distance, light_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue