add day/night color tints
This commit is contained in:
@@ -55,6 +55,22 @@ static M4x4 inverse_view_matrix = inverse_view(V3_(0.0f, 0.0f, 0.0f), radians(45
|
||||
static M4x4 projection_matrix = projection (radians(45.0f), 16.0f / 9.0f, NEAR_PLANE);
|
||||
static M4x4 inverse_projection_matrix = inverse_projection(radians(45.0f), 16.0f / 9.0f, NEAR_PLANE);
|
||||
|
||||
static SDL_DateTime time_offset = {};
|
||||
|
||||
static int time_tints_times[4][3] = {
|
||||
{ 4, 0, 0 },
|
||||
{ 9, 0, 0 },
|
||||
{ 19, 0, 0 },
|
||||
{ 21, 0, 0 },
|
||||
};
|
||||
|
||||
static V3 time_tints[4] = {
|
||||
V3_(0.314f, 0.369f, 0.455f),
|
||||
V3_(1.0f, 0.891f, 0.868f),
|
||||
V3_(1.0f, 0.465f, 0.373f),
|
||||
V3_(0.314f, 0.369f, 0.455f),
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
V3 pos;
|
||||
};
|
||||
@@ -1050,6 +1066,24 @@ bool recreate_tile_textures() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int real_mod(int a, int b) {
|
||||
int result = a % b;
|
||||
return result >= 0 ? result : result + b;
|
||||
}
|
||||
|
||||
bool imgui_time_picker(const char *label, int time[3]) {
|
||||
bool result = ImGui::DragScalarN(label, ImGuiDataType_S32, time, 3);
|
||||
|
||||
time[1] += time[2] >= 0 ? time[2] / 60 : -1;
|
||||
time[0] += time[1] >= 0 ? time[1] / 60 : -1;
|
||||
|
||||
time[2] = real_mod(time[2], 60);
|
||||
time[1] = real_mod(time[1], 60);
|
||||
time[0] = real_mod(time[0], 24);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
setup_memory_functions();
|
||||
|
||||
@@ -1186,6 +1220,23 @@ int main(int argc, char **argv) {
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
SDL_Time time;
|
||||
SDL_GetCurrentTime(&time);
|
||||
|
||||
SDL_DateTime calendar_time;
|
||||
SDL_TimeToDateTime(time, &calendar_time, true);
|
||||
|
||||
calendar_time.second += time_offset.second;
|
||||
calendar_time.minute += time_offset.minute;
|
||||
calendar_time.hour += time_offset.hour;
|
||||
|
||||
calendar_time.minute += calendar_time.second / 60;
|
||||
calendar_time.hour += calendar_time.minute / 60;
|
||||
|
||||
calendar_time.second = real_mod(calendar_time.second, 60);
|
||||
calendar_time.minute = real_mod(calendar_time.minute, 60);
|
||||
calendar_time.hour = real_mod(calendar_time.hour, 24);
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(0, window_height), ImVec2(window_width, window_height));
|
||||
ImGui::SetNextWindowSize(ImVec2(0.2 * window_width, window_height), ImGuiCond_FirstUseEver);
|
||||
@@ -1253,6 +1304,21 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::DragScalarN("calendar_time", ImGuiDataType_S32, &calendar_time.hour, 3);
|
||||
imgui_time_picker("time_offset", &time_offset.hour);
|
||||
|
||||
ImGui::NewLine();
|
||||
imgui_time_picker("time0", time_tints_times[0]);
|
||||
imgui_time_picker("time1", time_tints_times[1]);
|
||||
imgui_time_picker("time2", time_tints_times[2]);
|
||||
imgui_time_picker("time3", time_tints_times[3]);
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::ColorEdit3("time0_color", time_tints[0].E);
|
||||
ImGui::ColorEdit3("time1_color", time_tints[1].E);
|
||||
ImGui::ColorEdit3("time2_color", time_tints[2].E);
|
||||
ImGui::ColorEdit3("time3_color", time_tints[3].E);
|
||||
|
||||
if (selected_tile != -1 && ImGui::IsWindowFocused() && ImGui::IsKeyPressed(ImGuiKey_R, false)) {
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
||||
selected_rotation = (selected_rotation - 1) & 3;
|
||||
@@ -1489,6 +1555,31 @@ int main(int argc, char **argv) {
|
||||
projection_matrix = projection (radians(per_frame.fovy_degrees), per_frame.aspect_ratio, NEAR_PLANE);
|
||||
inverse_projection_matrix = inverse_projection(radians(per_frame.fovy_degrees), per_frame.aspect_ratio, NEAR_PLANE);
|
||||
}
|
||||
|
||||
{
|
||||
ZoneScopedN("tint color");
|
||||
Sint64 tint_times_ns[5];
|
||||
for (int i = 0; i < 4; i++)
|
||||
tint_times_ns[i] = (time_tints_times[i][0] * 60 * 60 + time_tints_times[i][1] * 60 + time_tints_times[i][2]) * SDL_NS_PER_SECOND;
|
||||
tint_times_ns[4] = (24 * 60 * 60 + 60 * 60 + 60) * SDL_NS_PER_SECOND + tint_times_ns[0];
|
||||
|
||||
Sint64 calendar_time_ns = (calendar_time.hour * 60 * 60 + calendar_time.minute * 60 + calendar_time.second) * SDL_NS_PER_SECOND + (Sint64)calendar_time.nanosecond;
|
||||
|
||||
int last_time_index = 3;
|
||||
if (calendar_time_ns > tint_times_ns[0]) last_time_index = 0;
|
||||
if (calendar_time_ns > tint_times_ns[1]) last_time_index = 1;
|
||||
if (calendar_time_ns > tint_times_ns[2]) last_time_index = 2;
|
||||
if (calendar_time_ns > tint_times_ns[3]) last_time_index = 3;
|
||||
if (calendar_time_ns <= tint_times_ns[0]) calendar_time_ns += (24 * 60 * 60 + 60 * 60 + 60) * SDL_NS_PER_SECOND;
|
||||
|
||||
Sint64 v = calendar_time_ns - tint_times_ns[last_time_index];
|
||||
Sint64 time_between = tint_times_ns[last_time_index + 1] - tint_times_ns[last_time_index];
|
||||
|
||||
double t = v / (double)time_between;
|
||||
|
||||
V3 tint_color = lerp(time_tints[last_time_index], time_tints[(last_time_index + 1) % 4], t);
|
||||
SDL_PushGPUFragmentUniformData(command_buffer, 0, &tint_color, sizeof(tint_color));
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GPUColorTargetInfo color_target_info = {
|
||||
|
||||
Reference in New Issue
Block a user