From 7ecedb68194ddc99a873c4f405546bc9dc2fd4b5 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 2 Mar 2026 13:46:27 +0100 Subject: [PATCH] - [FIX] Calcul de la llum corregit. --- main.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index fbf97ea..1364a63 100644 --- a/main.cpp +++ b/main.cpp @@ -319,6 +319,7 @@ void loadMap(const char* name) } +float light_zoom = 1280; int actual_sector = -1; int last_sector = -1; void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, vec2 origin, vec2 infi) @@ -376,7 +377,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v float actual_dist = straight_dist / SDL_cosf(a_inc*DEG_TO_RAD); int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) - position.x)) % s.ceil_surf->w; int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) - position.y)) % s.ceil_surf->h; - float light_dist = 1.0f - (-actual_dist>512 ? 1.0f : -actual_dist/512); + float light_dist = 1.0f - (-actual_dist>light_zoom ? 1.0f : -actual_dist/light_zoom); float light = 1.0f - (light_dist*s.light); uint8_t pixcolor = s.ceil_surf->pixels[tx+ty*s.ceil_surf->w]; pixcolor = colormap[pixcolor + int(light*31)*256]; @@ -393,7 +394,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v if (surf) { for (int i=0; i=end) break; - float light_dist = 1.0f - (dist>512 ? 1.0f : dist/512); + float light_dist = 1.0f - (dist>light_zoom ? 1.0f : dist/light_zoom); float light = 1.0f - (light_dist*s.light); uint8_t pixcolor = surf->pixels[(int(v)%surf->w)+(int(cpix)%surf->h)*surf->w]; pixcolor = colormap[pixcolor + int(light*31)*256]; @@ -413,7 +414,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v if (w->upper_surf) for (int i=0; i=end) break; - float light_dist = 1.0f - (dist>512 ? 1.0f : dist/512); + float light_dist = 1.0f - (dist>light_zoom ? 1.0f : dist/light_zoom); float light = 1.0f - (light_dist*s.light); uint8_t pixcolor = w->upper_surf->pixels[(int(v)%w->upper_surf->w)+(int(cpix)%w->upper_surf->h)*w->upper_surf->w]; pixcolor = colormap[pixcolor + int(light*31)*256]; @@ -449,7 +450,7 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v if (w->lower_surf) for (int i=0; i=end) break; - float light_dist = 1.0f - (dist>512 ? 1.0f : dist/512); + float light_dist = 1.0f - (dist>light_zoom ? 1.0f : dist/light_zoom); float light = 1.0f - (light_dist*s.light); uint8_t pixcolor = w->lower_surf->pixels[(int(v)%w->lower_surf->w)+(int(cpix)%w->lower_surf->h)*w->lower_surf->w]; pixcolor = colormap[pixcolor + int(light*31)*256]; @@ -470,8 +471,8 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v int tx = SDL_abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) + position.x)) % s.floor_surf->w; int ty = SDL_abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) + position.y)) % s.floor_surf->h; - float light_dist = 1.0f - (actual_dist>512 ? 1.0f : actual_dist/512); - float light = 1.0f - (light_dist*s.light); + float light_dist = (actual_dist>light_zoom ? 1.0f : actual_dist/light_zoom); + float light = 1.0f - SDL_clamp(s.light-light_dist, 0.0f, 1.0f); uint8_t pixcolor = s.floor_surf->pixels[tx+ty*s.floor_surf->w]; pixcolor = colormap[pixcolor + int(light*31)*256]; draw::putpd(screen_column, y, pixcolor, straight_dist);