1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

Implement time scaling for the rasterizer

which affects 3D particles and the TIME uniform
This commit is contained in:
Pedro J. Estébanez
2017-03-20 19:58:22 +01:00
parent f8db8a3faa
commit b4119f4fe9
8 changed files with 34 additions and 4 deletions

View File

@@ -3950,7 +3950,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++;
@@ -4960,7 +4965,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
@@ -5003,7 +5008,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;
@@ -8784,7 +8789,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
@@ -9361,6 +9366,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)) {
@@ -10384,6 +10394,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();
@@ -10716,6 +10727,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;