Add shader time scaling

Shaders' `TIME` will be affected by the new shader time scale, that is set via the also new `VisualServer::set_time_scale()`.
This commit is contained in:
Pedro J. Estébanez 2020-06-06 18:47:03 +02:00
parent 9f4a14ba97
commit 1ff7b0a0a9
12 changed files with 38 additions and 2 deletions

View file

@ -3453,6 +3453,16 @@
Sets the default clear color which is used when a specific clear color has not been selected.
</description>
</method>
<method name="set_shader_time_scale">
<return type="void">
</return>
<argument index="0" name="scale" type="float">
</argument>
<description>
Sets the scale to apply to the passage of time for the shaders' [code]TIME[/code] builtin.
The default value is [code]1.0[/code], which means [code]TIME[/code] will count the real time as it goes by, without narrowing or stretching it.
</description>
</method>
<method name="shader_create">
<return type="RID">
</return>

View file

@ -796,6 +796,7 @@ public:
RasterizerScene *get_scene() { return &scene; }
void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) {}
void set_shader_time_scale(float p_scale) {}
void initialize() {}
void begin_frame(double frame_step) {}

View file

@ -270,7 +270,7 @@ void RasterizerGLES2::initialize() {
}
void RasterizerGLES2::begin_frame(double frame_step) {
time_total += frame_step;
time_total += frame_step * time_scale;
if (frame_step == 0) {
//to avoid hiccups
@ -395,6 +395,11 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c
end_frame(true);
}
void RasterizerGLES2::set_shader_time_scale(float p_scale) {
time_scale = p_scale;
}
void RasterizerGLES2::blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen) {
ERR_FAIL_COND(storage->frame.current_rt);
@ -490,6 +495,7 @@ RasterizerGLES2::RasterizerGLES2() {
storage->scene = scene;
time_total = 0;
time_scale = 1;
}
RasterizerGLES2::~RasterizerGLES2() {

View file

@ -45,6 +45,7 @@ class RasterizerGLES2 : public Rasterizer {
RasterizerSceneGLES2 *scene;
double time_total;
float time_scale;
public:
virtual RasterizerStorage *get_storage();
@ -52,6 +53,7 @@ public:
virtual RasterizerScene *get_scene();
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true);
virtual void set_shader_time_scale(float p_scale);
virtual void initialize();
virtual void begin_frame(double frame_step);

View file

@ -194,7 +194,7 @@ void RasterizerGLES3::initialize() {
void RasterizerGLES3::begin_frame(double frame_step) {
time_total += frame_step;
time_total += frame_step * time_scale;
if (frame_step == 0) {
//to avoid hiccups
@ -331,6 +331,11 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c
end_frame(true);
}
void RasterizerGLES3::set_shader_time_scale(float p_scale) {
time_scale = p_scale;
}
void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen) {
ERR_FAIL_COND(storage->frame.current_rt);
@ -420,6 +425,7 @@ RasterizerGLES3::RasterizerGLES3() {
storage->scene = scene;
time_total = 0;
time_scale = 1;
}
RasterizerGLES3::~RasterizerGLES3() {

View file

@ -45,6 +45,7 @@ class RasterizerGLES3 : public Rasterizer {
RasterizerSceneGLES3 *scene;
double time_total;
float time_scale;
public:
virtual RasterizerStorage *get_storage();
@ -52,6 +53,7 @@ public:
virtual RasterizerScene *get_scene();
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true);
virtual void set_shader_time_scale(float p_scale);
virtual void initialize();
virtual void begin_frame(double frame_step);

View file

@ -1114,6 +1114,7 @@ public:
virtual RasterizerScene *get_scene() = 0;
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) = 0;
virtual void set_shader_time_scale(float p_scale) = 0;
virtual void initialize() = 0;
virtual void begin_frame(double frame_step) = 0;

View file

@ -174,6 +174,10 @@ void VisualServerRaster::set_default_clear_color(const Color &p_color) {
VSG::viewport->set_default_clear_color(p_color);
}
void VisualServerRaster::set_shader_time_scale(float p_scale) {
VSG::rasterizer->set_shader_time_scale(p_scale);
}
bool VisualServerRaster::has_feature(Features p_feature) const {
return false;

View file

@ -692,6 +692,7 @@ public:
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true);
virtual void set_default_clear_color(const Color &p_color);
virtual void set_shader_time_scale(float p_scale);
virtual bool has_feature(Features p_feature) const;

View file

@ -615,6 +615,7 @@ public:
FUNC4(set_boot_image, const Ref<Image> &, const Color &, bool, bool)
FUNC1(set_default_clear_color, const Color &)
FUNC1(set_shader_time_scale, float)
FUNC0R(RID, get_test_cube)

View file

@ -2044,6 +2044,7 @@ void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &VisualServer::set_boot_image, DEFVAL(true));
ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &VisualServer::set_default_clear_color);
ClassDB::bind_method(D_METHOD("set_shader_time_scale", "scale"), &VisualServer::set_shader_time_scale);
ClassDB::bind_method(D_METHOD("has_feature", "feature"), &VisualServer::has_feature);
ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &VisualServer::has_os_feature);

View file

@ -1046,6 +1046,7 @@ public:
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) = 0;
virtual void set_default_clear_color(const Color &p_color) = 0;
virtual void set_shader_time_scale(float p_scale) = 0;
enum Features {
FEATURE_SHADERS,