Skip to content

Commit d650c56

Browse files
committed
fix(ui): fix time scale
1 parent e3c3858 commit d650c56

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

shadertoy/OpenGL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ uniform vec4 iMouse; // mouse pixel coords. xy: current (if
6666
uniform vec4 iDate; // Year, month, day, time in seconds in .xyzw
6767
uniform vec3 iChannelResolution[4];
6868
69+
#define char char_
6970
)";
7071

7172
static const char* const shaderPixelFooter = R"(

shadertoy/ShaderToyContext.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ void ShaderToyContext::tick() {
4141
++mFrameCount;
4242
mFrameRate = ImGui::GetIO().Framerate;
4343

44-
const auto current = SystemClock::to_time_t(now);
44+
const auto offsetNow = mStartTime +
45+
std::chrono::duration_cast<SystemClock::duration>(
46+
std::chrono::nanoseconds{ static_cast<std::chrono::nanoseconds::rep>(mTime * 1e9) });
47+
const auto current = SystemClock::to_time_t(offsetNow);
4548
const auto tm = std::localtime(&current); // NOLINT(concurrency-mt-unsafe)
4649
mDate = { static_cast<float>(tm->tm_year + 1900 - 1), static_cast<float>(tm->tm_mon), static_cast<float>(tm->tm_mday),
4750
static_cast<float>(tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec) +
48-
static_cast<float>(now.time_since_epoch().count() % SystemClock::period::den) /
51+
static_cast<float>(offsetNow.time_since_epoch().count() % SystemClock::period::den) /
4952
static_cast<float>(SystemClock::period::den) };
5053
}
5154
void ShaderToyContext::pause() {

0 commit comments

Comments
 (0)