1/**************************************************************************/
2/* sky.cpp */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#include "sky.h"
32
33#include "core/io/image_loader.h"
34
35void Sky::set_radiance_size(RadianceSize p_size) {
36 ERR_FAIL_INDEX(p_size, RADIANCE_SIZE_MAX);
37
38 radiance_size = p_size;
39 static const int size[RADIANCE_SIZE_MAX] = {
40 32, 64, 128, 256, 512, 1024, 2048
41 };
42 RS::get_singleton()->sky_set_radiance_size(sky, size[radiance_size]);
43}
44
45Sky::RadianceSize Sky::get_radiance_size() const {
46 return radiance_size;
47}
48
49void Sky::set_process_mode(ProcessMode p_mode) {
50 mode = p_mode;
51 RS::get_singleton()->sky_set_mode(sky, RS::SkyMode(mode));
52}
53
54Sky::ProcessMode Sky::get_process_mode() const {
55 return mode;
56}
57
58void Sky::set_material(const Ref<Material> &p_material) {
59 sky_material = p_material;
60 RID material_rid;
61 if (sky_material.is_valid()) {
62 material_rid = sky_material->get_rid();
63 }
64 RS::get_singleton()->sky_set_material(sky, material_rid);
65}
66
67Ref<Material> Sky::get_material() const {
68 return sky_material;
69}
70
71RID Sky::get_rid() const {
72 return sky;
73}
74
75void Sky::_bind_methods() {
76 ClassDB::bind_method(D_METHOD("set_radiance_size", "size"), &Sky::set_radiance_size);
77 ClassDB::bind_method(D_METHOD("get_radiance_size"), &Sky::get_radiance_size);
78
79 ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Sky::set_process_mode);
80 ClassDB::bind_method(D_METHOD("get_process_mode"), &Sky::get_process_mode);
81
82 ClassDB::bind_method(D_METHOD("set_material", "material"), &Sky::set_material);
83 ClassDB::bind_method(D_METHOD("get_material"), &Sky::get_material);
84
85 ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sky_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,PanoramaSkyMaterial,ProceduralSkyMaterial,PhysicalSkyMaterial"), "set_material", "get_material");
86 ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Automatic,High-Quality,High-Quality Incremental,Real-Time"), "set_process_mode", "get_process_mode");
87 ADD_PROPERTY(PropertyInfo(Variant::INT, "radiance_size", PROPERTY_HINT_ENUM, "32,64,128,256,512,1024,2048"), "set_radiance_size", "get_radiance_size");
88
89 BIND_ENUM_CONSTANT(RADIANCE_SIZE_32);
90 BIND_ENUM_CONSTANT(RADIANCE_SIZE_64);
91 BIND_ENUM_CONSTANT(RADIANCE_SIZE_128);
92 BIND_ENUM_CONSTANT(RADIANCE_SIZE_256);
93 BIND_ENUM_CONSTANT(RADIANCE_SIZE_512);
94 BIND_ENUM_CONSTANT(RADIANCE_SIZE_1024);
95 BIND_ENUM_CONSTANT(RADIANCE_SIZE_2048);
96 BIND_ENUM_CONSTANT(RADIANCE_SIZE_MAX);
97
98 BIND_ENUM_CONSTANT(PROCESS_MODE_AUTOMATIC);
99 BIND_ENUM_CONSTANT(PROCESS_MODE_QUALITY);
100 BIND_ENUM_CONSTANT(PROCESS_MODE_INCREMENTAL);
101 BIND_ENUM_CONSTANT(PROCESS_MODE_REALTIME);
102}
103
104Sky::Sky() {
105 sky = RS::get_singleton()->sky_create();
106}
107
108Sky::~Sky() {
109 ERR_FAIL_NULL(RenderingServer::get_singleton());
110 RS::get_singleton()->free(sky);
111}
112