2019-09-15 17:58:38 +08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* sky_material.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
2020-03-28 20:29:29 +08:00
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
2019-09-15 17:58:38 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SKY_MATERIAL_H
|
|
|
|
#define SKY_MATERIAL_H
|
|
|
|
|
2022-09-26 19:03:44 +08:00
|
|
|
#include "core/templates/rid.h"
|
|
|
|
#include "scene/resources/material.h"
|
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
class ProceduralSkyMaterial : public Material {
|
|
|
|
GDCLASS(ProceduralSkyMaterial, Material);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Color sky_top_color;
|
|
|
|
Color sky_horizon_color;
|
2022-05-02 22:28:25 +08:00
|
|
|
float sky_curve = 0.0f;
|
2022-08-01 07:20:24 +08:00
|
|
|
float sky_energy_multiplier = 0.0f;
|
2022-02-13 01:38:05 +08:00
|
|
|
Ref<Texture2D> sky_cover;
|
|
|
|
Color sky_cover_modulate;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
Color ground_bottom_color;
|
|
|
|
Color ground_horizon_color;
|
2022-05-02 22:28:25 +08:00
|
|
|
float ground_curve = 0.0f;
|
2022-08-01 07:20:24 +08:00
|
|
|
float ground_energy_multiplier = 0.0f;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2022-05-02 22:28:25 +08:00
|
|
|
float sun_angle_max = 0.0f;
|
|
|
|
float sun_curve = 0.0f;
|
2022-04-30 03:46:29 +08:00
|
|
|
bool use_debanding = true;
|
2023-10-25 20:12:22 +08:00
|
|
|
float global_energy_multiplier = 1.0f;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2021-07-21 19:47:49 +08:00
|
|
|
static Mutex shader_mutex;
|
2022-09-14 01:39:04 +08:00
|
|
|
static RID shader_cache[2];
|
2021-07-21 19:47:49 +08:00
|
|
|
static void _update_shader();
|
|
|
|
mutable bool shader_set = false;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-08-01 07:20:24 +08:00
|
|
|
void _validate_property(PropertyInfo &property) const;
|
2019-09-15 17:58:38 +08:00
|
|
|
|
|
|
|
public:
|
2020-03-20 08:32:19 +08:00
|
|
|
void set_sky_top_color(const Color &p_sky_top);
|
|
|
|
Color get_sky_top_color() const;
|
|
|
|
|
|
|
|
void set_sky_horizon_color(const Color &p_sky_horizon);
|
|
|
|
Color get_sky_horizon_color() const;
|
|
|
|
|
|
|
|
void set_sky_curve(float p_curve);
|
|
|
|
float get_sky_curve() const;
|
|
|
|
|
2022-08-01 07:20:24 +08:00
|
|
|
void set_sky_energy_multiplier(float p_multiplier);
|
|
|
|
float get_sky_energy_multiplier() const;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2022-02-13 01:38:05 +08:00
|
|
|
void set_sky_cover(const Ref<Texture2D> &p_sky_cover);
|
|
|
|
Ref<Texture2D> get_sky_cover() const;
|
|
|
|
|
|
|
|
void set_sky_cover_modulate(const Color &p_sky_cover_modulate);
|
|
|
|
Color get_sky_cover_modulate() const;
|
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
void set_ground_bottom_color(const Color &p_ground_bottom);
|
|
|
|
Color get_ground_bottom_color() const;
|
|
|
|
|
|
|
|
void set_ground_horizon_color(const Color &p_ground_horizon);
|
|
|
|
Color get_ground_horizon_color() const;
|
|
|
|
|
|
|
|
void set_ground_curve(float p_curve);
|
|
|
|
float get_ground_curve() const;
|
|
|
|
|
2022-08-01 07:20:24 +08:00
|
|
|
void set_ground_energy_multiplier(float p_energy);
|
|
|
|
float get_ground_energy_multiplier() const;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
void set_sun_angle_max(float p_angle);
|
|
|
|
float get_sun_angle_max() const;
|
|
|
|
|
|
|
|
void set_sun_curve(float p_curve);
|
|
|
|
float get_sun_curve() const;
|
|
|
|
|
2022-04-30 03:46:29 +08:00
|
|
|
void set_use_debanding(bool p_use_debanding);
|
|
|
|
bool get_use_debanding() const;
|
2022-04-10 00:23:20 +08:00
|
|
|
|
2023-10-25 20:12:22 +08:00
|
|
|
void set_energy_multiplier(float p_multiplier);
|
|
|
|
float get_energy_multiplier() const;
|
|
|
|
|
2020-07-10 18:34:39 +08:00
|
|
|
virtual Shader::Mode get_shader_mode() const override;
|
2021-01-06 07:01:50 +08:00
|
|
|
virtual RID get_shader_rid() const override;
|
2021-07-21 19:47:49 +08:00
|
|
|
virtual RID get_rid() const override;
|
|
|
|
|
|
|
|
static void cleanup_shader();
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
ProceduralSkyMaterial();
|
|
|
|
~ProceduralSkyMaterial();
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
/* PanoramaSkyMaterial */
|
|
|
|
|
|
|
|
class PanoramaSkyMaterial : public Material {
|
|
|
|
GDCLASS(PanoramaSkyMaterial, Material);
|
2019-09-15 17:58:38 +08:00
|
|
|
|
|
|
|
private:
|
2020-03-20 08:32:19 +08:00
|
|
|
Ref<Texture2D> panorama;
|
2023-10-25 20:12:22 +08:00
|
|
|
float energy_multiplier = 1.0f;
|
2021-07-21 19:47:49 +08:00
|
|
|
|
|
|
|
static Mutex shader_mutex;
|
2022-01-15 09:42:25 +08:00
|
|
|
static RID shader_cache[2];
|
2021-07-21 19:47:49 +08:00
|
|
|
static void _update_shader();
|
|
|
|
mutable bool shader_set = false;
|
2019-09-15 17:58:38 +08:00
|
|
|
|
2022-01-15 09:42:25 +08:00
|
|
|
bool filter = true;
|
|
|
|
|
2019-09-15 17:58:38 +08:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2020-03-20 08:32:19 +08:00
|
|
|
void set_panorama(const Ref<Texture2D> &p_panorama);
|
|
|
|
Ref<Texture2D> get_panorama() const;
|
2019-09-15 17:58:38 +08:00
|
|
|
|
2022-01-15 09:42:25 +08:00
|
|
|
void set_filtering_enabled(bool p_enabled);
|
|
|
|
bool is_filtering_enabled() const;
|
|
|
|
|
2022-08-01 07:20:24 +08:00
|
|
|
void set_energy_multiplier(float p_multiplier);
|
|
|
|
float get_energy_multiplier() const;
|
|
|
|
|
2020-07-10 18:34:39 +08:00
|
|
|
virtual Shader::Mode get_shader_mode() const override;
|
2021-01-06 07:01:50 +08:00
|
|
|
virtual RID get_shader_rid() const override;
|
2021-07-21 19:47:49 +08:00
|
|
|
virtual RID get_rid() const override;
|
|
|
|
|
|
|
|
static void cleanup_shader();
|
2019-09-15 17:58:38 +08:00
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
PanoramaSkyMaterial();
|
|
|
|
~PanoramaSkyMaterial();
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
/* PanoramaSkyMaterial */
|
|
|
|
|
|
|
|
class PhysicalSkyMaterial : public Material {
|
|
|
|
GDCLASS(PhysicalSkyMaterial, Material);
|
|
|
|
|
|
|
|
private:
|
2021-07-21 19:47:49 +08:00
|
|
|
static Mutex shader_mutex;
|
2022-09-14 01:39:04 +08:00
|
|
|
static RID shader_cache[2];
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2022-05-02 22:28:25 +08:00
|
|
|
float rayleigh = 0.0f;
|
2020-03-20 08:32:19 +08:00
|
|
|
Color rayleigh_color;
|
2022-05-02 22:28:25 +08:00
|
|
|
float mie = 0.0f;
|
|
|
|
float mie_eccentricity = 0.0f;
|
2020-03-20 08:32:19 +08:00
|
|
|
Color mie_color;
|
2022-05-02 22:28:25 +08:00
|
|
|
float turbidity = 0.0f;
|
|
|
|
float sun_disk_scale = 0.0f;
|
2020-03-20 08:32:19 +08:00
|
|
|
Color ground_color;
|
2022-08-01 07:20:24 +08:00
|
|
|
float energy_multiplier = 1.0f;
|
2022-04-30 03:46:29 +08:00
|
|
|
bool use_debanding = true;
|
2020-05-17 03:55:25 +08:00
|
|
|
Ref<Texture2D> night_sky;
|
2021-07-21 19:47:49 +08:00
|
|
|
static void _update_shader();
|
|
|
|
mutable bool shader_set = false;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-08-01 07:20:24 +08:00
|
|
|
void _validate_property(PropertyInfo &property) const;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
void set_rayleigh_coefficient(float p_rayleigh);
|
|
|
|
float get_rayleigh_coefficient() const;
|
|
|
|
|
|
|
|
void set_rayleigh_color(Color p_rayleigh_color);
|
|
|
|
Color get_rayleigh_color() const;
|
|
|
|
|
|
|
|
void set_turbidity(float p_turbidity);
|
|
|
|
float get_turbidity() const;
|
|
|
|
|
|
|
|
void set_mie_coefficient(float p_mie);
|
|
|
|
float get_mie_coefficient() const;
|
|
|
|
|
|
|
|
void set_mie_eccentricity(float p_eccentricity);
|
|
|
|
float get_mie_eccentricity() const;
|
|
|
|
|
|
|
|
void set_mie_color(Color p_mie_color);
|
|
|
|
Color get_mie_color() const;
|
|
|
|
|
|
|
|
void set_sun_disk_scale(float p_sun_disk_scale);
|
|
|
|
float get_sun_disk_scale() const;
|
|
|
|
|
|
|
|
void set_ground_color(Color p_ground_color);
|
|
|
|
Color get_ground_color() const;
|
|
|
|
|
2022-08-01 07:20:24 +08:00
|
|
|
void set_energy_multiplier(float p_multiplier);
|
|
|
|
float get_energy_multiplier() const;
|
|
|
|
|
|
|
|
void set_exposure_value(float p_exposure);
|
|
|
|
float get_exposure_value() const;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2022-04-30 03:46:29 +08:00
|
|
|
void set_use_debanding(bool p_use_debanding);
|
|
|
|
bool get_use_debanding() const;
|
2020-03-20 08:32:19 +08:00
|
|
|
|
2020-05-17 03:55:25 +08:00
|
|
|
void set_night_sky(const Ref<Texture2D> &p_night_sky);
|
|
|
|
Ref<Texture2D> get_night_sky() const;
|
|
|
|
|
2020-07-10 18:34:39 +08:00
|
|
|
virtual Shader::Mode get_shader_mode() const override;
|
2021-01-06 07:01:50 +08:00
|
|
|
virtual RID get_shader_rid() const override;
|
2019-09-15 17:58:38 +08:00
|
|
|
|
2021-07-21 19:47:49 +08:00
|
|
|
static void cleanup_shader();
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
|
2020-03-20 08:32:19 +08:00
|
|
|
PhysicalSkyMaterial();
|
|
|
|
~PhysicalSkyMaterial();
|
2019-09-15 17:58:38 +08:00
|
|
|
};
|
|
|
|
|
2022-07-24 05:41:51 +08:00
|
|
|
#endif // SKY_MATERIAL_H
|