Skip to content

Commit 90def6c

Browse files
committed
Enhance cloud shadow calculations, disable UI dimming and improve mesh resolution
1 parent b30ad1b commit 90def6c

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

src/main.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,17 @@ const char *fs3D = "#version 330\n"
6666
" float b = 2.0 * dot(fragPos, sunDir);\n"
6767
" float c = earthRadius * earthRadius - cloudR * cloudR;\n"
6868
" float t = (-b + sqrt(b * b - 4.0 * c)) * 0.5;\n"
69+
" float cloudH = max(cloudR - earthRadius, 1e-5);\n"
70+
" float minSunSin = 0.14;\n"
71+
" float maxShadowLen = cloudH / minSunSin;\n"
72+
" t = min(t, maxShadowLen);\n"
6973
" vec3 cn = normalize(fragPos + t * sunDir);\n"
7074
" vec2 cUV = vec2(atan(-cn.z, cn.x) / 6.28318530718 + 0.5, cn.y);\n"
7175
" cUV.y = acos(clamp(cUV.y, -1.0, 1.0)) / 3.14159265359;\n"
7276
" cUV.x = fract(cUV.x + cloudUVOffset);\n"
7377
" float cAlpha = texture(texture2, cUV).a;\n"
74-
" cShadow = mix(1.0, 0.1, cAlpha * smoothstep(-0.1, 0.2, intensity));\n"
78+
" float termFade = smoothstep(0.00, 0.25, intensity);\n"
79+
" cShadow = mix(1.0, 0.1, cAlpha * termFade);\n"
7580
" }\n"
7681
" \n"
7782
" scatteredDay = (scatteredDay * cShadow) + specular;\n"
@@ -599,20 +604,20 @@ int main(void)
599604

600605
DrawLoadingScreen(0.6f, "Generating Meshes...", logoTex);
601606
float draw_earth_radius = EARTH_RADIUS_KM / DRAW_SCALE;
602-
Mesh sphereMesh = GenEarthMesh(draw_earth_radius, 64, 64);
607+
Mesh sphereMesh = GenEarthMesh(draw_earth_radius, 80, 80);
603608
earthModel = LoadModelFromMesh(sphereMesh);
604609
earthModel.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = earthTexture;
605610
earthModel.materials[0].maps[MATERIAL_MAP_EMISSION].texture = earthNightTexture;
606611
Shader defaultEarthShader = earthModel.materials[0].shader;
607612

608613
DrawLoadingScreen(0.8f, "Loading Celestial Bodies...", logoTex);
609614

610-
Mesh skyboxMesh = GenEarthMesh(-500.0f, 32, 32); /* negative radius flips normals inward */
615+
Mesh skyboxMesh = GenEarthMesh(-500.0f, 40, 40); /* negative radius flips normals inward */
611616
skyboxModel = LoadModelFromMesh(skyboxMesh);
612617
skyboxModel.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = skyboxTexture;
613618

614619
float draw_cloud_radius = (EARTH_RADIUS_KM + 25.0f) / DRAW_SCALE;
615-
Mesh cloudMesh = GenEarthMesh(draw_cloud_radius, 64, 64);
620+
Mesh cloudMesh = GenEarthMesh(draw_cloud_radius, 80, 80);
616621
cloudModel = LoadModelFromMesh(cloudMesh);
617622
cloudTexture = LoadTexture(GetAssetPath(cfg.theme, "clouds.png"));
618623
SetTextureFilter(cloudTexture, TEXTURE_FILTER_BILINEAR);
@@ -621,13 +626,13 @@ int main(void)
621626
Shader defaultCloudShader = cloudModel.materials[0].shader;
622627

623628
float draw_atmosphere_radius = (EARTH_RADIUS_KM + 80.0f) / DRAW_SCALE;
624-
Mesh atmosphereMesh = GenEarthMesh(draw_atmosphere_radius, 64, 64);
629+
Mesh atmosphereMesh = GenEarthMesh(draw_atmosphere_radius, 80, 80);
625630
atmosphereModel = LoadModelFromMesh(atmosphereMesh);
626631
atmosphereModel.materials[0].shader = shaderAtmosphere;
627632
SetShaderValue(shaderAtmosphere, GetShaderLocation(shaderAtmosphere, "atmRadius"), &draw_atmosphere_radius, SHADER_UNIFORM_FLOAT);
628633

629634
float draw_moon_radius = MOON_RADIUS_KM / DRAW_SCALE;
630-
Mesh moonMesh = GenEarthMesh(draw_moon_radius, 32, 32);
635+
Mesh moonMesh = GenEarthMesh(draw_moon_radius, 48, 48);
631636
moonModel = LoadModelFromMesh(moonMesh);
632637
moonTexture = LoadTexture(GetAssetPath(cfg.theme, "moon.png"));
633638
SetTextureFilter(moonTexture, TEXTURE_FILTER_BILINEAR);

src/ui.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static TLESource_t RETLECTOR_SOURCES[] = {
9797
{"25", "CubeSats", "https://retlector.eu/tle/cubesat"}
9898
};
9999
#define NUM_RETLECTOR_SOURCES 25
100+
#define HELP_WINDOW_W 420.0f
101+
#define HELP_WINDOW_H 500.0f
100102

101103
/* window z-ordering management */
102104
typedef enum
@@ -789,7 +791,7 @@ static void FindSmartWindowPosition(float w, float h, AppConfig *cfg, float *out
789791
Rectangle active[10];
790792
int count = 0;
791793
if (show_help)
792-
active[count++] = (Rectangle){hw_x, hw_y, 420 * cfg->ui_scale, 480 * cfg->ui_scale};
794+
active[count++] = (Rectangle){hw_x, hw_y, HELP_WINDOW_W * cfg->ui_scale, HELP_WINDOW_H * cfg->ui_scale};
793795
if (show_settings)
794796
active[count++] = (Rectangle){sw_x, sw_y, 250 * cfg->ui_scale, 520 * cfg->ui_scale};
795797
if (show_time_dialog)
@@ -884,7 +886,7 @@ bool IsMouseOverUI(AppConfig *cfg)
884886
bool over_window = false;
885887
float pass_w = 357 * cfg->ui_scale, pass_h = 380 * cfg->ui_scale;
886888

887-
if (show_help && CheckCollisionPointRec(GetMousePosition(), (Rectangle){hw_x, hw_y, 420 * cfg->ui_scale, 480 * cfg->ui_scale}))
889+
if (show_help && CheckCollisionPointRec(GetMousePosition(), (Rectangle){hw_x, hw_y, HELP_WINDOW_W * cfg->ui_scale, HELP_WINDOW_H * cfg->ui_scale}))
888890
over_window = true;
889891
if (show_settings && CheckCollisionPointRec(GetMousePosition(), (Rectangle){sw_x, sw_y, 250 * cfg->ui_scale, 520 * cfg->ui_scale}))
890892
over_window = true;
@@ -1231,7 +1233,7 @@ void DrawGUI(UIContext *ctx, AppConfig *cfg, Font customFont)
12311233
}
12321234

12331235
/* calculate interactive window rects */
1234-
Rectangle helpWindow = {hw_x, hw_y, 420 * cfg->ui_scale, 480 * cfg->ui_scale};
1236+
Rectangle helpWindow = {hw_x, hw_y, HELP_WINDOW_W * cfg->ui_scale, HELP_WINDOW_H * cfg->ui_scale};
12351237
Rectangle settingsWindow = {sw_x, sw_y, 250 * cfg->ui_scale, 520 * cfg->ui_scale};
12361238
Rectangle timeWindow = {td_x, td_y, 252 * cfg->ui_scale, 320 * cfg->ui_scale};
12371239
Rectangle tleWindow = {(GetScreenWidth() - 300 * cfg->ui_scale) / 2.0f, (GetScreenHeight() - 130 * cfg->ui_scale) / 2.0f, 300 * cfg->ui_scale, 130 * cfg->ui_scale};
@@ -1554,11 +1556,14 @@ void DrawGUI(UIContext *ctx, AppConfig *cfg, Font customFont)
15541556
Rectangle btnClock = {btn_start_x + 140 * cfg->ui_scale, GetScreenHeight() - 40 * cfg->ui_scale, 30 * cfg->ui_scale, 30 * cfg->ui_scale};
15551557

15561558
/* main toolbar rendering */
1557-
if (top_hovered_wnd != -1)
1559+
bool toolbar_blocked_by_window = (top_hovered_wnd != -1);
1560+
int old_toolbar_disabled_text = GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED);
1561+
GuiSetStyle(DEFAULT, TEXT_COLOR_DISABLED, GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL));
1562+
if (toolbar_blocked_by_window)
15581563
GuiDisable();
15591564

15601565
int normal_text = ColorToInt(cfg->text_main);
1561-
int disabled_text = ColorToInt(cfg->text_secondary);
1566+
int disabled_text = toolbar_blocked_by_window ? normal_text : ColorToInt(cfg->text_secondary);
15621567

15631568
#define HIGHLIGHT_START(cond) \
15641569
if (cond) \
@@ -1590,7 +1595,7 @@ void DrawGUI(UIContext *ctx, AppConfig *cfg, Font customFont)
15901595
{
15911596
if (!show_help)
15921597
{
1593-
FindSmartWindowPosition(420 * cfg->ui_scale, 480 * cfg->ui_scale, cfg, &hw_x, &hw_y);
1598+
FindSmartWindowPosition(HELP_WINDOW_W * cfg->ui_scale, HELP_WINDOW_H * cfg->ui_scale, cfg, &hw_x, &hw_y);
15941599
}
15951600
show_help = !show_help;
15961601
BringToFront(WND_HELP);
@@ -1763,16 +1768,23 @@ void DrawGUI(UIContext *ctx, AppConfig *cfg, Font customFont)
17631768
#undef HIGHLIGHT_START
17641769
#undef HIGHLIGHT_END
17651770

1766-
GuiEnable();
1771+
if (toolbar_blocked_by_window)
1772+
GuiEnable();
1773+
GuiSetStyle(DEFAULT, TEXT_COLOR_DISABLED, old_toolbar_disabled_text);
17671774

17681775
/* Render dialogs respecting Z-Order to enforce click consumption logically */
17691776
for (int win_idx = 0; win_idx < WND_MAX; win_idx++)
17701777
{
17711778
WindowID current_id = z_order[win_idx];
17721779
bool is_topmost = (top_hovered_wnd == -1) || (top_hovered_wnd == current_id);
1773-
1774-
if (!is_topmost)
1780+
bool window_blocked = !is_topmost;
1781+
int old_window_disabled_text = 0;
1782+
if (window_blocked)
1783+
{
1784+
old_window_disabled_text = GuiGetStyle(DEFAULT, TEXT_COLOR_DISABLED);
1785+
GuiSetStyle(DEFAULT, TEXT_COLOR_DISABLED, GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL));
17751786
GuiDisable();
1787+
}
17761788

17771789
switch (current_id)
17781790
{
@@ -2157,7 +2169,7 @@ void DrawGUI(UIContext *ctx, AppConfig *cfg, Font customFont)
21572169
if (DrawMaterialWindow(helpWindow, "#193# Help & Controls", cfg, customFont, true))
21582170
show_help = false;
21592171

2160-
Rectangle contentRec = {0, 0, helpWindow.width - 32 * cfg->ui_scale, 620 * cfg->ui_scale};
2172+
Rectangle contentRec = {0, 0, helpWindow.width - 32 * cfg->ui_scale, 660 * cfg->ui_scale};
21612173
Rectangle viewRec = {0};
21622174

21632175
int oldFocusD = GuiGetStyle(DEFAULT, BORDER_COLOR_FOCUSED);
@@ -3472,8 +3484,11 @@ case WND_SCOPE:
34723484
break;
34733485
}
34743486

3475-
if (!is_topmost)
3487+
if (window_blocked)
3488+
{
34763489
GuiEnable();
3490+
GuiSetStyle(DEFAULT, TEXT_COLOR_DISABLED, old_window_disabled_text);
3491+
}
34773492
}
34783493

34793494
if (show_tle_warning)
@@ -3550,7 +3565,7 @@ case WND_SCOPE:
35503565
else SetTargetFPS(0);
35513566
SaveAppConfig("settings.json", cfg);
35523567
if (!show_help) {
3553-
FindSmartWindowPosition(420 * cfg->ui_scale, 480 * cfg->ui_scale, cfg, &hw_x, &hw_y);
3568+
FindSmartWindowPosition(HELP_WINDOW_W * cfg->ui_scale, HELP_WINDOW_H * cfg->ui_scale, cfg, &hw_x, &hw_y);
35543569
show_help = true;
35553570
BringToFront(WND_HELP);
35563571
}
@@ -3575,7 +3590,7 @@ case WND_SCOPE:
35753590
else SetTargetFPS(0);
35763591
SaveAppConfig("settings.json", cfg);
35773592
if (!show_help) {
3578-
FindSmartWindowPosition(420 * cfg->ui_scale, 480 * cfg->ui_scale, cfg, &hw_x, &hw_y);
3593+
FindSmartWindowPosition(HELP_WINDOW_W * cfg->ui_scale, HELP_WINDOW_H * cfg->ui_scale, cfg, &hw_x, &hw_y);
35793594
show_help = true;
35803595
BringToFront(WND_HELP);
35813596
}

0 commit comments

Comments
 (0)