summaryrefslogtreecommitdiff
path: root/scene/resources/sky_material.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/sky_material.h')
-rw-r--r--scene/resources/sky_material.h54
1 files changed, 38 insertions, 16 deletions
diff --git a/scene/resources/sky_material.h b/scene/resources/sky_material.h
index 9bd9d7ec8b..63e730617b 100644
--- a/scene/resources/sky_material.h
+++ b/scene/resources/sky_material.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -28,14 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "core/rid.h"
+#include "core/templates/rid.h"
#include "scene/resources/material.h"
#ifndef SKY_MATERIAL_H
#define SKY_MATERIAL_H
class ProceduralSkyMaterial : public Material {
-
GDCLASS(ProceduralSkyMaterial, Material);
private:
@@ -52,11 +51,14 @@ private:
float sun_angle_max;
float sun_curve;
- RID shader;
+ static Mutex shader_mutex;
+ static RID shader;
+ static void _update_shader();
+ mutable bool shader_set = false;
protected:
static void _bind_methods();
- virtual bool _can_do_next_pass() const;
+ virtual bool _can_do_next_pass() const override;
public:
void set_sky_top_color(const Color &p_sky_top);
@@ -89,8 +91,11 @@ public:
void set_sun_curve(float p_curve);
float get_sun_curve() const;
- virtual Shader::Mode get_shader_mode() const;
- RID get_shader_rid() const;
+ virtual Shader::Mode get_shader_mode() const override;
+ virtual RID get_shader_rid() const override;
+ virtual RID get_rid() const override;
+
+ static void cleanup_shader();
ProceduralSkyMaterial();
~ProceduralSkyMaterial();
@@ -104,18 +109,25 @@ class PanoramaSkyMaterial : public Material {
private:
Ref<Texture2D> panorama;
- RID shader;
+
+ static Mutex shader_mutex;
+ static RID shader;
+ static void _update_shader();
+ mutable bool shader_set = false;
protected:
static void _bind_methods();
- virtual bool _can_do_next_pass() const;
+ virtual bool _can_do_next_pass() const override;
public:
void set_panorama(const Ref<Texture2D> &p_panorama);
Ref<Texture2D> get_panorama() const;
- virtual Shader::Mode get_shader_mode() const;
- RID get_shader_rid() const;
+ virtual Shader::Mode get_shader_mode() const override;
+ virtual RID get_shader_rid() const override;
+ virtual RID get_rid() const override;
+
+ static void cleanup_shader();
PanoramaSkyMaterial();
~PanoramaSkyMaterial();
@@ -128,7 +140,8 @@ class PhysicalSkyMaterial : public Material {
GDCLASS(PhysicalSkyMaterial, Material);
private:
- RID shader;
+ static Mutex shader_mutex;
+ static RID shader;
float rayleigh;
Color rayleigh_color;
@@ -140,10 +153,13 @@ private:
Color ground_color;
float exposure;
float dither_strength;
+ Ref<Texture2D> night_sky;
+ static void _update_shader();
+ mutable bool shader_set = false;
protected:
static void _bind_methods();
- virtual bool _can_do_next_pass() const;
+ virtual bool _can_do_next_pass() const override;
public:
void set_rayleigh_coefficient(float p_rayleigh);
@@ -176,8 +192,14 @@ public:
void set_dither_strength(float p_dither_strength);
float get_dither_strength() const;
- virtual Shader::Mode get_shader_mode() const;
- RID get_shader_rid() const;
+ void set_night_sky(const Ref<Texture2D> &p_night_sky);
+ Ref<Texture2D> get_night_sky() const;
+
+ virtual Shader::Mode get_shader_mode() const override;
+ virtual RID get_shader_rid() const override;
+
+ static void cleanup_shader();
+ virtual RID get_rid() const override;
PhysicalSkyMaterial();
~PhysicalSkyMaterial();