|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|