How to Run GLSL Program Based on System Time

102 Views Asked by At

I am trying to run different iterations of a shader program based on system time. I am hoping to set up an if else code to run one iteration of the program during the day and another at night. At the moment, I can't find how to bring system time into the glsl file. Any thoughts? Thanks!

1

There are 1 best solutions below

0
kshahar On

Two options:

  1. Pass the time in a uniform from your application (e.g. number of seconds since midnight)
  2. If it's really just an if/else for day/night you can run a different shader program depending on the time. One way to do this would be to add conditional preprocessor directives (#if defined(DAY)) instead of if/else, and modify the shader code dynamically before loading the program (add/remove #define day with basic string manipulation).