| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  sky_box.h                                                            */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2019-01-01 12:53:14 +01:00
										 |  |  | /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */ | 
					
						
							| 
									
										
										
										
											2017-03-05 15:47:28 +01: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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef SKY_BOX_H
 | 
					
						
							|  |  |  | #define SKY_BOX_H
 | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/os/thread.h"
 | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | #include "scene/resources/texture.h"
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:53:59 -03:00
										 |  |  | class Sky : public Resource { | 
					
						
							|  |  |  | 	GDCLASS(Sky, Resource); | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	enum RadianceSize { | 
					
						
							| 
									
										
										
										
											2017-07-22 14:07:38 -03:00
										 |  |  | 		RADIANCE_SIZE_32, | 
					
						
							|  |  |  | 		RADIANCE_SIZE_64, | 
					
						
							|  |  |  | 		RADIANCE_SIZE_128, | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 		RADIANCE_SIZE_256, | 
					
						
							|  |  |  | 		RADIANCE_SIZE_512, | 
					
						
							|  |  |  | 		RADIANCE_SIZE_1024, | 
					
						
							|  |  |  | 		RADIANCE_SIZE_2048, | 
					
						
							|  |  |  | 		RADIANCE_SIZE_MAX | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 	RadianceSize radiance_size; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | protected: | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	virtual void _radiance_changed() = 0; | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 	void set_radiance_size(RadianceSize p_size); | 
					
						
							|  |  |  | 	RadianceSize get_radiance_size() const; | 
					
						
							| 
									
										
										
										
											2017-05-25 13:53:59 -03:00
										 |  |  | 	Sky(); | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:53:59 -03:00
										 |  |  | VARIANT_ENUM_CAST(Sky::RadianceSize) | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:53:59 -03:00
										 |  |  | class PanoramaSky : public Sky { | 
					
						
							|  |  |  | 	GDCLASS(PanoramaSky, Sky); | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2017-05-25 13:53:59 -03:00
										 |  |  | 	RID sky; | 
					
						
							|  |  |  | 	Ref<Texture> panorama; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | protected: | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							|  |  |  | 	virtual void _radiance_changed(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-05-25 13:53:59 -03:00
										 |  |  | 	void set_panorama(const Ref<Texture> &p_panorama); | 
					
						
							|  |  |  | 	Ref<Texture> get_panorama() const; | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	virtual RID get_rid() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:53:59 -03:00
										 |  |  | 	PanoramaSky(); | 
					
						
							|  |  |  | 	~PanoramaSky(); | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | class ProceduralSky : public Sky { | 
					
						
							|  |  |  | 	GDCLASS(ProceduralSky, Sky); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	enum TextureSize { | 
					
						
							| 
									
										
										
										
											2017-07-22 14:07:38 -03:00
										 |  |  | 		TEXTURE_SIZE_256, | 
					
						
							|  |  |  | 		TEXTURE_SIZE_512, | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 		TEXTURE_SIZE_1024, | 
					
						
							|  |  |  | 		TEXTURE_SIZE_2048, | 
					
						
							|  |  |  | 		TEXTURE_SIZE_4096, | 
					
						
							|  |  |  | 		TEXTURE_SIZE_MAX | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2017-08-18 19:16:32 -03:00
										 |  |  | 	Thread *sky_thread; | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 	Color sky_top_color; | 
					
						
							|  |  |  | 	Color sky_horizon_color; | 
					
						
							|  |  |  | 	float sky_curve; | 
					
						
							|  |  |  | 	float sky_energy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Color ground_bottom_color; | 
					
						
							|  |  |  | 	Color ground_horizon_color; | 
					
						
							|  |  |  | 	float ground_curve; | 
					
						
							|  |  |  | 	float ground_energy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Color sun_color; | 
					
						
							|  |  |  | 	float sun_latitude; | 
					
						
							|  |  |  | 	float sun_longitude; | 
					
						
							|  |  |  | 	float sun_angle_min; | 
					
						
							|  |  |  | 	float sun_angle_max; | 
					
						
							|  |  |  | 	float sun_curve; | 
					
						
							|  |  |  | 	float sun_energy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TextureSize texture_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RID sky; | 
					
						
							|  |  |  | 	RID texture; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool update_queued; | 
					
						
							| 
									
										
										
										
											2017-08-18 19:16:32 -03:00
										 |  |  | 	bool regen_queued; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool first_time; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void _thread_done(const Ref<Image> &p_image); | 
					
						
							|  |  |  | 	static void _thread_function(void *p_ud); | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	static void _bind_methods(); | 
					
						
							|  |  |  | 	virtual void _radiance_changed(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 19:16:32 -03:00
										 |  |  | 	Ref<Image> _generate_sky(); | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 	void _update_sky(); | 
					
						
							| 
									
										
										
										
											2017-08-18 19:16:32 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-28 21:46:48 -03:00
										 |  |  | 	void _queue_update(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_sky_energy(float p_energy); | 
					
						
							|  |  |  | 	float get_sky_energy() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_ground_energy(float p_energy); | 
					
						
							|  |  |  | 	float get_ground_energy() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_sun_color(const Color &p_sun); | 
					
						
							|  |  |  | 	Color get_sun_color() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_sun_latitude(float p_angle); | 
					
						
							|  |  |  | 	float get_sun_latitude() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_sun_longitude(float p_angle); | 
					
						
							|  |  |  | 	float get_sun_longitude() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_sun_angle_min(float p_angle); | 
					
						
							|  |  |  | 	float get_sun_angle_min() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_sun_energy(float p_energy); | 
					
						
							|  |  |  | 	float get_sun_energy() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void set_texture_size(TextureSize p_size); | 
					
						
							|  |  |  | 	TextureSize get_texture_size() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	virtual RID get_rid() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ProceduralSky(); | 
					
						
							|  |  |  | 	~ProceduralSky(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | VARIANT_ENUM_CAST(ProceduralSky::TextureSize) | 
					
						
							| 
									
										
										
										
											2016-11-19 13:23:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | #endif // SKY_BOX_H
 |