diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index c9984de800a..2cc89661699 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -3951,7 +3951,12 @@ void RasterizerGLES2::begin_frame() { double time = (OS::get_singleton()->get_ticks_usec() / 1000); // get msec time /= 1000.0; // make secs - time_delta = time - last_time; + if (frame != 0) { + time_delta = time_scale * (time - last_time); + } else { + time_delta = 0.0f; + } + scaled_time += time_delta; last_time = time; frame++; @@ -4966,7 +4971,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry, const Material DEBUG_TEST_ERROR("Material arameters"); if (p_material->shader_cache->uses_time) { - material_shader.set_uniform(MaterialShaderGLES2::TIME, Math::fmod(last_time, shader_time_rollback)); + material_shader.set_uniform(MaterialShaderGLES2::TIME, Math::fmod(scaled_time, shader_time_rollback)); draw_next_frame = true; } //if uses TIME - draw_next_frame=true @@ -5009,7 +5014,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry, const Material material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_END, Vector3(col_end.r, col_end.g, col_end.b)); } - //material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(last_time,300.0)); + //material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(scaled_time,300.0)); //if uses TIME - draw_next_frame=true return rebind; @@ -8794,7 +8799,7 @@ void RasterizerGLES2::_canvas_item_setup_shader_uniforms(CanvasItemMaterial *mat } if (shader->uses_time) { - canvas_shader.set_uniform(CanvasShaderGLES2::TIME, Math::fmod(last_time, shader_time_rollback)); + canvas_shader.set_uniform(CanvasShaderGLES2::TIME, Math::fmod(scaled_time, shader_time_rollback)); draw_next_frame = true; } //if uses TIME - draw_next_frame=true @@ -9371,6 +9376,11 @@ bool RasterizerGLES2::is_canvas_light_occluder(const RID &p_rid) const { return false; } +void RasterizerGLES2::set_time_scale(float p_scale) { + + time_scale = p_scale; +} + void RasterizerGLES2::free(const RID &p_rid) { if (texture_owner.owns(p_rid)) { @@ -10405,6 +10415,7 @@ void RasterizerGLES2::init() { #endif shader_time_rollback = GLOBAL_DEF("rasterizer/shader_time_rollback", 300); + time_scale = 1.0f; using_canvas_bg = false; _update_framebuffer(); @@ -10737,6 +10748,7 @@ RasterizerGLES2::RasterizerGLES2(bool p_compress_arrays, bool p_keep_ram_copy, b base_framebuffer = 0; frame = 0; + scaled_time = 0.0; draw_next_frame = false; use_framebuffers = true; framebuffer.active = false; diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index 265d618703a..f3856f8765c 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -1251,6 +1251,7 @@ class RasterizerGLES2 : public Rasterizer { Size2 window_size; VS::ViewportRect viewport; double last_time; + double scaled_time; double time_delta; uint64_t frame; uint64_t scene_pass; @@ -1259,6 +1260,7 @@ class RasterizerGLES2 : public Rasterizer { VS::ScenarioDebugMode current_debug; RID overdraw_material; float shader_time_rollback; + float time_scale; mutable MaterialShaderGLES2 material_shader; mutable CanvasShaderGLES2 canvas_shader; @@ -1653,6 +1655,8 @@ public: virtual bool is_canvas_light_occluder(const RID &p_rid) const; + virtual void set_time_scale(float p_scale); + virtual void free(const RID &p_rid); virtual void init(); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 76702c93ba8..ca2740cb1c2 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -1047,6 +1047,8 @@ public: virtual bool is_canvas_light_occluder(const RID &p_rid) const = 0; + virtual void set_time_scale(float p_scale) = 0; + virtual void free(const RID &p_rid) = 0; virtual void init() = 0; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index c97bf19dd23..b0fe09b12bc 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -7017,6 +7017,11 @@ Color VisualServerRaster::get_default_clear_color() const { return clear_color; } +void VisualServerRaster::set_time_scale(float p_scale) { + + rasterizer->set_time_scale(p_scale); +} + void VisualServerRaster::set_boot_image(const Image &p_image, const Color &p_color, bool p_scale) { if (p_image.empty()) diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 950013c28fa..59917e7402f 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1258,6 +1258,8 @@ public: virtual void set_default_clear_color(const Color &p_color); virtual Color get_default_clear_color() const; + virtual void set_time_scale(float p_scale); + VisualServerRaster(Rasterizer *p_rasterizer); ~VisualServerRaster(); }; diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index c86d91c1184..f1bf1a3ec83 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -689,6 +689,7 @@ public: FUNC3(set_boot_image, const Image &, const Color &, bool); FUNC1(set_default_clear_color, const Color &); FUNC0RC(Color, get_default_clear_color); + FUNC1(set_time_scale, float); FUNC0R(RID, get_test_cube); diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index d6065612eb7..de16ac019a7 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -537,6 +537,8 @@ void VisualServer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_default_clear_color"), &VisualServer::set_default_clear_color); ObjectTypeDB::bind_method(_MD("get_default_clear_color"), &VisualServer::get_default_clear_color); + ObjectTypeDB::bind_method(_MD("set_time_scale"), &VisualServer::set_time_scale); + ObjectTypeDB::bind_method(_MD("get_render_info"), &VisualServer::get_render_info); BIND_CONSTANT(NO_INDEX_ARRAY); diff --git a/servers/visual_server.h b/servers/visual_server.h index 07eb5eb25ec..2989df46f30 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -1138,6 +1138,8 @@ public: virtual void set_default_clear_color(const Color &p_color) = 0; virtual Color get_default_clear_color() const = 0; + virtual void set_time_scale(float p_scale) = 0; + enum Features { FEATURE_SHADERS, FEATURE_MULTITHREADED,