Skip to content

Commit

Permalink
Improved shadow rendering
Browse files Browse the repository at this point in the history
Doubled resolution of shadows
Added rectangle shadow rendering
Mobs that have a infinite height are now properly sorted in the draw queue
  • Loading branch information
Helodity committed Aug 18, 2024
1 parent e6e71d6 commit 4f8495c
Show file tree
Hide file tree
Showing 8 changed files with 327 additions and 25 deletions.
Binary file modified Game_data/Graphics/Shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_data/Graphics/Shadow_square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
296 changes: 287 additions & 9 deletions Source/documents/Vectorial graphics/Effects.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 27 additions & 11 deletions Source/source/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,19 +1076,24 @@ void draw_menu_button_icon(
/**
* @brief Draws a mob's shadow.
*
* @param center Center of the mob.
* @param diameter Diameter of the mob.
* @param m mob to draw the shadow for.
* @param delta_z The mob is these many units above the floor directly below it.
* @param shadow_stretch How much to stretch the shadow by
* (used to simulate sun shadow direction casting).
*/
void draw_mob_shadow(
const point &center, const float diameter,
const mob* m,
const float delta_z, const float shadow_stretch
) {

point shadow_size = point(m->radius * 2.2f, m->radius * 2.2f);
if(m->rectangular_dim.x != 0) {
shadow_size = m->rectangular_dim * 1.1f;
}

if(shadow_stretch <= 0) return;

float diameter = shadow_size.x;
float shadow_x = 0;
float shadow_w =
diameter + (diameter * shadow_stretch * MOB::SHADOW_STRETCH_MULT);
Expand All @@ -1102,14 +1107,25 @@ void draw_mob_shadow(
shadow_x = -(diameter * 0.5);
shadow_x += shadow_stretch * delta_z * MOB::SHADOW_Y_MULT;
}

draw_bitmap(
game.sys_assets.bmp_shadow,
point(center.x + shadow_x + shadow_w / 2, center.y),
point(shadow_w, diameter),
0,
map_alpha(255 * (1 - shadow_stretch))
);

if(m->rectangular_dim.x != 0) {
draw_bitmap(
game.sys_assets.bmp_shadow_square,
point(m->pos.x + shadow_x + shadow_w / 2, m->pos.y),
shadow_size,
m->angle,
map_alpha(255 * (1 - shadow_stretch))
);
}
else {
draw_bitmap(
game.sys_assets.bmp_shadow,
point(m->pos.x + shadow_x + shadow_w / 2, m->pos.y),
point(shadow_w, diameter),
0,
map_alpha(255 * (1 - shadow_stretch))
);
}
}


Expand Down
2 changes: 1 addition & 1 deletion Source/source/drawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void draw_sector_edge_offsets(
sector* s_ptr, ALLEGRO_BITMAP* buffer, const float opacity
);
void draw_mob_shadow(
const point &where, const float size,
const mob* m,
const float delta_z, const float shadow_stretch
);
void draw_scaled_text(
Expand Down
7 changes: 3 additions & 4 deletions Source/source/game_states/gameplay/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ void gameplay_state::draw_world_components(ALLEGRO_BITMAP* bmp_output) {
} else {
c.z = mob_ptr->ground_sector->z;
}
c.z += 0.01f;
c.z += mob_ptr->height == 0 ? FLT_MAX - 1: mob_ptr->height - 1;
components.push_back(c);
}

Expand Down Expand Up @@ -1994,7 +1994,7 @@ void gameplay_state::draw_world_components(ALLEGRO_BITMAP* bmp_output) {
if(mob_ptr->holder.m && mob_ptr->holder.above_holder) {
c.z = mob_ptr->holder.m->z + mob_ptr->holder.m->height + 0.01;
} else {
c.z = mob_ptr->z + mob_ptr->height;
c.z = mob_ptr->height == 0 ? FLT_MAX : mob_ptr->z + mob_ptr->height;
}
components.push_back(c);

Expand Down Expand Up @@ -2075,8 +2075,7 @@ void gameplay_state::draw_world_components(ALLEGRO_BITMAP* bmp_output) {
c_ptr->mob_shadow_ptr->ground_sector->z;
}
draw_mob_shadow(
c_ptr->mob_shadow_ptr->pos,
c_ptr->mob_shadow_ptr->radius * 2,
c_ptr->mob_shadow_ptr,
delta_z,
mob_shadow_stretch
);
Expand Down
3 changes: 3 additions & 0 deletions Source/source/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,8 @@ void load_misc_graphics() {
game.bitmaps.get(game.asset_file_names.bmp_rock);
game.sys_assets.bmp_shadow =
game.bitmaps.get(game.asset_file_names.bmp_shadow);
game.sys_assets.bmp_shadow_square =
game.bitmaps.get(game.asset_file_names.bmp_shadow_square);
game.sys_assets.bmp_smack =
game.bitmaps.get(game.asset_file_names.bmp_smack);
game.sys_assets.bmp_smoke =
Expand Down Expand Up @@ -1360,6 +1362,7 @@ void unload_misc_resources() {
game.bitmaps.free(game.sys_assets.bmp_random);
game.bitmaps.free(game.sys_assets.bmp_rock);
game.bitmaps.free(game.sys_assets.bmp_shadow);
game.bitmaps.free(game.sys_assets.bmp_shadow_square);
game.bitmaps.free(game.sys_assets.bmp_smack);
game.bitmaps.free(game.sys_assets.bmp_smoke);
game.bitmaps.free(game.sys_assets.bmp_sparkle);
Expand Down
6 changes: 6 additions & 0 deletions Source/source/misc_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ struct asset_file_names_t {

//Mob shadow.
string bmp_shadow = "Shadow.png";

//Rectangular mob shadow.
string bmp_shadow_square = "Shadow_square.png";

//Smack effect.
string bmp_smack = "Smack.png";
Expand Down Expand Up @@ -792,6 +795,9 @@ struct system_asset_list {

//Mob shadow.
ALLEGRO_BITMAP* bmp_shadow = nullptr;

//Rectangular mob shadow.
ALLEGRO_BITMAP* bmp_shadow_square = nullptr;

//Smack effect.
ALLEGRO_BITMAP* bmp_smack = nullptr;
Expand Down

0 comments on commit 4f8495c

Please sign in to comment.