summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/spring_arm_3d.cpp4
-rw-r--r--scene/3d/visual_instance_3d.cpp75
-rw-r--r--scene/3d/visual_instance_3d.h12
-rw-r--r--scene/main/shader_globals_override.cpp257
-rw-r--r--scene/main/shader_globals_override.h37
-rw-r--r--scene/register_scene_types.cpp4
-rw-r--r--scene/resources/sky_material.cpp39
-rw-r--r--scene/resources/sky_material.h4
-rw-r--r--scene/scene_string_names.cpp3
-rw-r--r--scene/scene_string_names.h2
10 files changed, 403 insertions, 34 deletions
diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp
index a5460593c9..0ffde7aa8f 100644
--- a/scene/3d/spring_arm_3d.cpp
+++ b/scene/3d/spring_arm_3d.cpp
@@ -45,12 +45,12 @@ void SpringArm3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
if (!Engine::get_singleton()->is_editor_hint()) {
- set_process_internal(true);
+ set_physics_process_internal(true);
}
break;
case NOTIFICATION_EXIT_TREE:
if (!Engine::get_singleton()->is_editor_hint()) {
- set_process_internal(false);
+ set_physics_process_internal(false);
}
break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS:
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index 775a9b76e2..604bc53422 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -217,6 +217,62 @@ float GeometryInstance3D::get_lod_max_hysteresis() const {
void GeometryInstance3D::_notification(int p_what) {
}
+const StringName *GeometryInstance3D::_instance_uniform_get_remap(const StringName p_name) const {
+ StringName *r = instance_uniform_property_remap.getptr(p_name);
+ if (!r) {
+ String s = p_name;
+ if (s.begins_with("shader_params/")) {
+ StringName name = s.replace("shader_params/", "");
+ instance_uniform_property_remap[p_name] = name;
+ return instance_uniform_property_remap.getptr(p_name);
+ }
+
+ return nullptr;
+ }
+
+ return r;
+}
+
+bool GeometryInstance3D::_set(const StringName &p_name, const Variant &p_value) {
+ const StringName *r = _instance_uniform_get_remap(p_name);
+ if (r) {
+ set_shader_instance_uniform(*r, p_value);
+ return true;
+ }
+
+ return false;
+}
+
+bool GeometryInstance3D::_get(const StringName &p_name, Variant &r_ret) const {
+ const StringName *r = _instance_uniform_get_remap(p_name);
+ if (r) {
+ r_ret = get_shader_instance_uniform(*r);
+ return true;
+ }
+
+ return false;
+}
+void GeometryInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
+ List<PropertyInfo> pinfo;
+ RS::get_singleton()->instance_geometry_get_shader_parameter_list(get_instance(), &pinfo);
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ PropertyInfo pi = E->get();
+ bool has_def_value = false;
+ Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), pi.name);
+ if (def_value.get_type() != Variant::NIL) {
+ has_def_value = true;
+ }
+ if (instance_uniforms.has(pi.name)) {
+ pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : 0);
+ } else {
+ pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : 0); //do not save if not changed
+ }
+
+ pi.name = "shader_params/" + pi.name;
+ p_list->push_back(pi);
+ }
+}
+
void GeometryInstance3D::set_flag(Flags p_flag, bool p_value) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
@@ -258,6 +314,22 @@ float GeometryInstance3D::get_extra_cull_margin() const {
return extra_cull_margin;
}
+void GeometryInstance3D::set_shader_instance_uniform(const StringName &p_uniform, const Variant &p_value) {
+
+ if (p_value.get_type() == Variant::NIL) {
+ Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), p_uniform);
+ RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, def_value);
+ instance_uniforms.erase(p_value);
+ } else {
+ instance_uniforms[p_uniform] = p_value;
+ RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, p_value);
+ }
+}
+
+Variant GeometryInstance3D::get_shader_instance_uniform(const StringName &p_uniform) const {
+
+ return RS::get_singleton()->instance_geometry_get_shader_parameter(get_instance(), p_uniform);
+}
void GeometryInstance3D::set_custom_aabb(AABB aabb) {
RS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb);
@@ -280,6 +352,9 @@ void GeometryInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_lod_max_distance", "mode"), &GeometryInstance3D::set_lod_max_distance);
ClassDB::bind_method(D_METHOD("get_lod_max_distance"), &GeometryInstance3D::get_lod_max_distance);
+ ClassDB::bind_method(D_METHOD("set_shader_instance_uniform", "uniform", "value"), &GeometryInstance3D::set_shader_instance_uniform);
+ ClassDB::bind_method(D_METHOD("get_shader_instance_uniform", "uniform"), &GeometryInstance3D::get_shader_instance_uniform);
+
ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis", "mode"), &GeometryInstance3D::set_lod_min_hysteresis);
ClassDB::bind_method(D_METHOD("get_lod_min_hysteresis"), &GeometryInstance3D::get_lod_min_hysteresis);
diff --git a/scene/3d/visual_instance_3d.h b/scene/3d/visual_instance_3d.h
index 9476c28848..cc5f92066f 100644
--- a/scene/3d/visual_instance_3d.h
+++ b/scene/3d/visual_instance_3d.h
@@ -108,9 +108,18 @@ private:
float lod_min_hysteresis;
float lod_max_hysteresis;
+ mutable HashMap<StringName, Variant> instance_uniforms;
+ mutable HashMap<StringName, StringName> instance_uniform_property_remap;
+
float extra_cull_margin;
+ const StringName *_instance_uniform_get_remap(const StringName p_name) const;
+
protected:
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
+
void _notification(int p_what);
static void _bind_methods();
@@ -139,6 +148,9 @@ public:
void set_extra_cull_margin(float p_margin);
float get_extra_cull_margin() const;
+ void set_shader_instance_uniform(const StringName &p_uniform, const Variant &p_value);
+ Variant get_shader_instance_uniform(const StringName &p_uniform) const;
+
void set_custom_aabb(AABB aabb);
GeometryInstance3D();
diff --git a/scene/main/shader_globals_override.cpp b/scene/main/shader_globals_override.cpp
new file mode 100644
index 0000000000..13582cf655
--- /dev/null
+++ b/scene/main/shader_globals_override.cpp
@@ -0,0 +1,257 @@
+#include "shader_globals_override.h"
+
+#include "core/core_string_names.h"
+#include "scene/main/window.h"
+#include "scene/scene_string_names.h"
+
+StringName *ShaderGlobalsOverride::_remap(const StringName &p_name) const {
+
+ StringName *r = param_remaps.getptr(p_name);
+ if (!r) {
+ //not cached, do caching
+ String p = p_name;
+ if (p.begins_with("params/")) {
+ String q = p.replace_first("params/", "");
+ param_remaps[p] = q;
+ r = param_remaps.getptr(q);
+ }
+ }
+
+ return r;
+}
+bool ShaderGlobalsOverride::_set(const StringName &p_name, const Variant &p_value) {
+
+ StringName *r = _remap(p_name);
+
+ if (r) {
+ Override *o = overrides.getptr(*r);
+ if (!o) {
+ Override ov;
+ ov.in_use = false;
+ overrides[*r] = ov;
+ o = overrides.getptr(*r);
+ }
+ if (o) {
+ o->override = p_value;
+ if (active) {
+ RS::get_singleton()->global_variable_set_override(*r, p_value);
+ }
+ o->in_use = p_value.get_type() != Variant::NIL;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool ShaderGlobalsOverride::_get(const StringName &p_name, Variant &r_ret) const {
+
+ StringName *r = _remap(p_name);
+
+ if (r) {
+ const Override *o = overrides.getptr(*r);
+ if (o) {
+ r_ret = o->override;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void ShaderGlobalsOverride::_get_property_list(List<PropertyInfo> *p_list) const {
+
+ Vector<StringName> variables;
+ variables = RS::get_singleton()->global_variable_get_list();
+ for (int i = 0; i < variables.size(); i++) {
+ PropertyInfo pinfo;
+ pinfo.name = "params/" + variables[i];
+ pinfo.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
+
+ switch (RS::get_singleton()->global_variable_get_type(variables[i])) {
+ case RS::GLOBAL_VAR_TYPE_BOOL: {
+ pinfo.type = Variant::BOOL;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_BVEC2: {
+ pinfo.type = Variant::INT;
+ pinfo.hint = PROPERTY_HINT_FLAGS;
+ pinfo.hint_string = "x,y";
+ } break;
+ case RS::GLOBAL_VAR_TYPE_BVEC3: {
+ pinfo.type = Variant::INT;
+ pinfo.hint = PROPERTY_HINT_FLAGS;
+ pinfo.hint_string = "x,y,z";
+ } break;
+ case RS::GLOBAL_VAR_TYPE_BVEC4: {
+ pinfo.type = Variant::INT;
+ pinfo.hint = PROPERTY_HINT_FLAGS;
+ pinfo.hint_string = "x,y,z,w";
+ } break;
+ case RS::GLOBAL_VAR_TYPE_INT: {
+ pinfo.type = Variant::INT;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_IVEC2: {
+ pinfo.type = Variant::VECTOR2I;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_IVEC3: {
+ pinfo.type = Variant::VECTOR3I;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_IVEC4: {
+ pinfo.type = Variant::PACKED_INT32_ARRAY;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_RECT2I: {
+ pinfo.type = Variant::RECT2I;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_UINT: {
+ pinfo.type = Variant::INT;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_UVEC2: {
+ pinfo.type = Variant::VECTOR2I;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_UVEC3: {
+ pinfo.type = Variant::VECTOR3I;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_UVEC4: {
+ pinfo.type = Variant::PACKED_INT32_ARRAY;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_FLOAT: {
+ pinfo.type = Variant::FLOAT;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_VEC2: {
+ pinfo.type = Variant::VECTOR2;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_VEC3: {
+ pinfo.type = Variant::VECTOR3;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_VEC4: {
+ pinfo.type = Variant::PLANE;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_RECT2: {
+ pinfo.type = Variant::RECT2;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_COLOR: {
+ pinfo.type = Variant::COLOR;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_MAT2: {
+ pinfo.type = Variant::PACKED_INT32_ARRAY;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_MAT3: {
+ pinfo.type = Variant::BASIS;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_TRANSFORM_2D: {
+ pinfo.type = Variant::TRANSFORM2D;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_TRANSFORM: {
+ pinfo.type = Variant::TRANSFORM;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_MAT4: {
+ pinfo.type = Variant::PACKED_INT32_ARRAY;
+ } break;
+ case RS::GLOBAL_VAR_TYPE_SAMPLER2D: {
+ pinfo.type = Variant::OBJECT;
+ pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pinfo.hint_string = "Texture2D";
+ } break;
+ case RS::GLOBAL_VAR_TYPE_SAMPLER2DARRAY: {
+ pinfo.type = Variant::OBJECT;
+ pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pinfo.hint_string = "Texture2DArray";
+ } break;
+ case RS::GLOBAL_VAR_TYPE_SAMPLER3D: {
+ pinfo.type = Variant::OBJECT;
+ pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pinfo.hint_string = "Texture3D";
+ } break;
+ case RS::GLOBAL_VAR_TYPE_SAMPLERCUBE: {
+ pinfo.type = Variant::OBJECT;
+ pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
+ pinfo.hint_string = "Cubemap";
+ } break;
+ default: {
+
+ } break;
+ }
+
+ if (!overrides.has(variables[i])) {
+ Override o;
+ o.in_use = false;
+ Callable::CallError ce;
+ o.override = Variant::construct(pinfo.type, NULL, 0, ce);
+ overrides[variables[i]] = o;
+ }
+
+ Override *o = overrides.getptr(variables[i]);
+ if (o->in_use && o->override.get_type() != Variant::NIL) {
+ pinfo.usage |= PROPERTY_USAGE_CHECKED;
+ pinfo.usage |= PROPERTY_USAGE_STORAGE;
+ }
+
+ p_list->push_back(pinfo);
+ }
+}
+
+void ShaderGlobalsOverride::_activate() {
+
+ List<Node *> nodes;
+ get_tree()->get_nodes_in_group(SceneStringNames::get_singleton()->shader_overrides_group_active, &nodes);
+ if (nodes.size() == 0) {
+ //good we are the only override, enable all
+ active = true;
+ add_to_group(SceneStringNames::get_singleton()->shader_overrides_group_active);
+
+ const StringName *K = nullptr;
+ while ((K = overrides.next(K))) {
+ Override *o = overrides.getptr(*K);
+ if (o->in_use && o->override.get_type() != Variant::NIL) {
+ RS::get_singleton()->global_variable_set_override(*K, o->override);
+ }
+ }
+
+ update_configuration_warning(); //may have activated
+ }
+}
+
+void ShaderGlobalsOverride::_notification(int p_what) {
+
+ if (p_what == Node3D::NOTIFICATION_ENTER_TREE) {
+
+ add_to_group(SceneStringNames::get_singleton()->shader_overrides_group);
+ _activate();
+
+ } else if (p_what == Node3D::NOTIFICATION_EXIT_TREE) {
+
+ if (active) {
+ //remove overrides
+ const StringName *K = nullptr;
+ while ((K = overrides.next(K))) {
+ Override *o = overrides.getptr(*K);
+ if (o->in_use) {
+ RS::get_singleton()->global_variable_set_override(*K, Variant());
+ }
+ }
+ }
+
+ remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group_active);
+ remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group);
+ get_tree()->call_group(SceneStringNames::get_singleton()->shader_overrides_group, "_activate"); //another may want to activate when this is removed
+ active = false;
+ }
+}
+
+String ShaderGlobalsOverride::get_configuration_warning() const {
+
+ if (!active) {
+ return TTR("ShaderGlobalsOverride is not active because another node of the same type is in the scene.");
+ }
+
+ return String();
+}
+
+void ShaderGlobalsOverride::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("_activate"), &ShaderGlobalsOverride::_activate);
+}
+
+ShaderGlobalsOverride::ShaderGlobalsOverride() {
+ active = false;
+}
diff --git a/scene/main/shader_globals_override.h b/scene/main/shader_globals_override.h
new file mode 100644
index 0000000000..33d0dc948f
--- /dev/null
+++ b/scene/main/shader_globals_override.h
@@ -0,0 +1,37 @@
+#ifndef SHADER_GLOBALS_OVERRIDE_H
+#define SHADER_GLOBALS_OVERRIDE_H
+
+#include "scene/3d/node_3d.h"
+
+class ShaderGlobalsOverride : public Node {
+
+ GDCLASS(ShaderGlobalsOverride, Node);
+
+ struct Override {
+ bool in_use = false;
+ Variant override;
+ };
+
+ StringName *_remap(const StringName &p_name) const;
+
+ bool active;
+ mutable HashMap<StringName, Override> overrides;
+ mutable HashMap<StringName, StringName> param_remaps;
+
+ void _activate();
+
+protected:
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
+
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ String get_configuration_warning() const;
+
+ ShaderGlobalsOverride();
+};
+
+#endif // SHADER_GLOBALS_OVERRIDE_H
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index ff49dbdc8f..264295325f 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -177,6 +177,8 @@
#include "scene/3d/node_3d.h"
#include "scene/3d/skeleton_3d.h"
+#include "scene/main/shader_globals_override.h"
+
#ifndef _3D_DISABLED
#include "scene/3d/area_3d.h"
#include "scene/3d/audio_stream_player_3d.h"
@@ -403,6 +405,8 @@ void register_scene_types() {
ClassDB::register_class<AnimationNodeTimeSeek>();
ClassDB::register_class<AnimationNodeTransition>();
+ ClassDB::register_class<ShaderGlobalsOverride>(); //can be used in any shader
+
OS::get_singleton()->yield(); //may take time to init
#ifndef _3D_DISABLED
diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp
index 37b88cccea..a0b6ab1e30 100644
--- a/scene/resources/sky_material.cpp
+++ b/scene/resources/sky_material.cpp
@@ -111,16 +111,6 @@ float ProceduralSkyMaterial::get_ground_energy() const {
return ground_energy;
}
-void ProceduralSkyMaterial::set_sun_angle_min(float p_angle) {
-
- sun_angle_min = p_angle;
- RS::get_singleton()->material_set_param(_get_material(), "sun_angle_min", Math::deg2rad(sun_angle_min));
-}
-float ProceduralSkyMaterial::get_sun_angle_min() const {
-
- return sun_angle_min;
-}
-
void ProceduralSkyMaterial::set_sun_angle_max(float p_angle) {
sun_angle_max = p_angle;
@@ -181,9 +171,6 @@ void ProceduralSkyMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_ground_energy", "energy"), &ProceduralSkyMaterial::set_ground_energy);
ClassDB::bind_method(D_METHOD("get_ground_energy"), &ProceduralSkyMaterial::get_ground_energy);
- ClassDB::bind_method(D_METHOD("set_sun_angle_min", "degrees"), &ProceduralSkyMaterial::set_sun_angle_min);
- ClassDB::bind_method(D_METHOD("get_sun_angle_min"), &ProceduralSkyMaterial::get_sun_angle_min);
-
ClassDB::bind_method(D_METHOD("set_sun_angle_max", "degrees"), &ProceduralSkyMaterial::set_sun_angle_max);
ClassDB::bind_method(D_METHOD("get_sun_angle_max"), &ProceduralSkyMaterial::get_sun_angle_max);
@@ -203,7 +190,6 @@ void ProceduralSkyMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ground_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_ground_energy", "get_ground_energy");
ADD_GROUP("Sun", "sun_");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_angle_min", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_min", "get_sun_angle_min");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_angle_max", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_max", "get_sun_angle_max");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sun_curve", PROPERTY_HINT_EXP_EASING), "set_sun_curve", "get_sun_curve");
}
@@ -220,8 +206,7 @@ ProceduralSkyMaterial::ProceduralSkyMaterial() {
code += "uniform vec4 ground_horizon_color : hint_color = vec4(0.37, 0.33, 0.31, 1.0);\n";
code += "uniform float ground_curve : hint_range(0, 1) = 0.02;\n";
code += "uniform float ground_energy = 1.0;\n\n";
- code += "uniform float sun_angle_min = 0.01;\n";
- code += "uniform float sun_angle_max = 1.0;\n";
+ code += "uniform float sun_angle_max = 1.74;\n";
code += "uniform float sun_curve : hint_range(0, 1) = 0.05;\n\n";
code += "const float PI = 3.1415926535897932384626433833;\n\n";
code += "void fragment() {\n";
@@ -231,37 +216,37 @@ ProceduralSkyMaterial::ProceduralSkyMaterial() {
code += "\tsky *= sky_energy;\n";
code += "\tif (LIGHT0_ENABLED) {\n";
code += "\t\tfloat sun_angle = acos(dot(LIGHT0_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < sun_angle_min) {\n";
+ code += "\t\tif (sun_angle < LIGHT0_SIZE) {\n";
code += "\t\t\tsky = LIGHT0_COLOR * LIGHT0_ENERGY;\n";
code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);\n";
+ code += "\t\t\tfloat c2 = (sun_angle - LIGHT0_SIZE) / (sun_angle_max - LIGHT0_SIZE);\n";
code += "\t\t\tsky = mix(LIGHT0_COLOR * LIGHT0_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
code += "\t\t}\n";
code += "\t}\n";
code += "\tif (LIGHT1_ENABLED) {\n";
code += "\t\tfloat sun_angle = acos(dot(LIGHT1_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < sun_angle_min) {\n";
+ code += "\t\tif (sun_angle < LIGHT1_SIZE) {\n";
code += "\t\t\tsky = LIGHT1_COLOR * LIGHT1_ENERGY;\n";
code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);\n";
+ code += "\t\t\tfloat c2 = (sun_angle - LIGHT1_SIZE) / (sun_angle_max - LIGHT1_SIZE);\n";
code += "\t\t\tsky = mix(LIGHT1_COLOR * LIGHT1_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
code += "\t\t}\n";
code += "\t}\n";
code += "\tif (LIGHT2_ENABLED) {\n";
code += "\t\tfloat sun_angle = acos(dot(LIGHT2_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < sun_angle_min) {\n";
+ code += "\t\tif (sun_angle < LIGHT2_SIZE) {\n";
code += "\t\t\tsky = LIGHT2_COLOR * LIGHT2_ENERGY;\n";
code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);\n";
+ code += "\t\t\tfloat c2 = (sun_angle - LIGHT2_SIZE) / (sun_angle_max - LIGHT2_SIZE);\n";
code += "\t\t\tsky = mix(LIGHT2_COLOR * LIGHT2_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
code += "\t\t}\n";
code += "\t}\n";
code += "\tif (LIGHT3_ENABLED) {\n";
code += "\t\tfloat sun_angle = acos(dot(LIGHT3_DIRECTION, EYEDIR));\n";
- code += "\t\tif (sun_angle < sun_angle_min) {\n";
+ code += "\t\tif (sun_angle < LIGHT3_SIZE) {\n";
code += "\t\t\tsky = LIGHT3_COLOR * LIGHT3_ENERGY;\n";
code += "\t\t} else if (sun_angle < sun_angle_max) {\n";
- code += "\t\t\tfloat c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);\n";
+ code += "\t\t\tfloat c2 = (sun_angle - LIGHT3_SIZE) / (sun_angle_max - LIGHT3_SIZE);\n";
code += "\t\t\tsky = mix(LIGHT3_COLOR * LIGHT3_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n";
code += "\t\t}\n";
code += "\t}\n";
@@ -287,7 +272,6 @@ ProceduralSkyMaterial::ProceduralSkyMaterial() {
set_ground_curve(0.02);
set_ground_energy(1.0);
- set_sun_angle_min(1.0);
set_sun_angle_max(100.0);
set_sun_curve(0.05);
}
@@ -535,7 +519,6 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() {
code += "const vec3 UP = vec3( 0.0, 1.0, 0.0 );\n\n";
code += "// Sun constants\n";
- code += "const float SOL_SIZE = 0.00872663806;\n";
code += "const float SUN_ENERGY = 1000.0;\n\n";
code += "// optical length at zenith for molecules\n";
@@ -591,8 +574,8 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() {
code += "\tLin *= mix(ground_color.rgb, vec3(1.0), smoothstep(-0.1, 0.1, dot(UP, EYEDIR)));\n\n";
code += "\t// Solar disk and out-scattering\n";
- code += "\tfloat sunAngularDiameterCos = cos(SOL_SIZE * sun_disk_scale);\n";
- code += "\tfloat sunAngularDiameterCos2 = cos(SOL_SIZE * sun_disk_scale*0.5);\n";
+ code += "\tfloat sunAngularDiameterCos = cos(LIGHT0_SIZE * sun_disk_scale);\n";
+ code += "\tfloat sunAngularDiameterCos2 = cos(LIGHT0_SIZE * sun_disk_scale*0.5);\n";
code += "\tfloat sundisk = smoothstep(sunAngularDiameterCos, sunAngularDiameterCos2, cos_theta);\n";
code += "\tvec3 L0 = (sun_energy * 1900.0 * extinction) * sundisk * LIGHT0_COLOR;\n";
code += "\t// Note: Add nightime here: L0 += night_sky * extinction\n\n";
diff --git a/scene/resources/sky_material.h b/scene/resources/sky_material.h
index 515706b0c5..9bd9d7ec8b 100644
--- a/scene/resources/sky_material.h
+++ b/scene/resources/sky_material.h
@@ -49,7 +49,6 @@ private:
float ground_curve;
float ground_energy;
- float sun_angle_min;
float sun_angle_max;
float sun_curve;
@@ -84,9 +83,6 @@ public:
void set_ground_energy(float p_energy);
float get_ground_energy() 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;
diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp
index ad996e7d50..5e3f8b803b 100644
--- a/scene/scene_string_names.cpp
+++ b/scene/scene_string_names.cpp
@@ -202,4 +202,7 @@ SceneStringNames::SceneStringNames() {
parameters_base_path = "parameters/";
tracks_changed = "tracks_changed";
+
+ shader_overrides_group = StaticCString::create("_shader_overrides_group_");
+ shader_overrides_group_active = StaticCString::create("_shader_overrides_group_active_");
}
diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h
index 58e8c28454..c5de10a6f6 100644
--- a/scene/scene_string_names.h
+++ b/scene/scene_string_names.h
@@ -207,6 +207,8 @@ public:
StringName window_input;
StringName theme_changed;
+ StringName shader_overrides_group;
+ StringName shader_overrides_group_active;
enum {
MAX_MATERIALS = 32