summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/animation.cpp14
-rw-r--r--scene/resources/box_shape_3d.cpp1
-rw-r--r--scene/resources/capsule_shape_2d.cpp2
-rw-r--r--scene/resources/capsule_shape_3d.cpp2
-rw-r--r--scene/resources/circle_shape_2d.cpp1
-rw-r--r--scene/resources/cylinder_shape_3d.cpp2
-rw-r--r--scene/resources/importer_mesh.cpp2
-rw-r--r--scene/resources/material.cpp34
-rw-r--r--scene/resources/material.h10
-rw-r--r--scene/resources/mesh.cpp1
-rw-r--r--scene/resources/rectangle_shape_2d.cpp1
-rw-r--r--scene/resources/sphere_shape_3d.cpp1
-rw-r--r--scene/resources/tile_set.cpp4
-rw-r--r--scene/resources/visual_shader.cpp2
-rw-r--r--scene/resources/visual_shader_nodes.cpp3
15 files changed, 46 insertions, 34 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index bc533ff022..312a557602 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -2413,7 +2413,7 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol
real_t c = 0.0;
// prepare for all cases of interpolation
- if ((loop_mode == LOOP_LINEAR || loop_mode == LOOP_PINGPONG) && p_loop_wrap) {
+ if (loop_mode == LOOP_LINEAR && p_loop_wrap) {
// loop
if (!p_backward) {
// no backward
@@ -2567,11 +2567,19 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol
case INTERPOLATION_CUBIC: {
int pre = idx - 1;
if (pre < 0) {
- pre = 0;
+ if (loop_mode == LOOP_LINEAR && p_loop_wrap) {
+ pre = len - 1;
+ } else {
+ pre = 0;
+ }
}
int post = next + 1;
if (post >= len) {
- post = next;
+ if (loop_mode == LOOP_LINEAR && p_loop_wrap) {
+ post = 0;
+ } else {
+ post = next;
+ }
}
return _cubic_interpolate(p_keys[pre].value, p_keys[idx].value, p_keys[next].value, p_keys[post].value, c);
diff --git a/scene/resources/box_shape_3d.cpp b/scene/resources/box_shape_3d.cpp
index a1ec9a2230..1abbf366fd 100644
--- a/scene/resources/box_shape_3d.cpp
+++ b/scene/resources/box_shape_3d.cpp
@@ -77,6 +77,7 @@ bool BoxShape3D::_get(const StringName &p_name, Variant &r_property) const {
#endif // DISABLE_DEPRECATED
void BoxShape3D::set_size(const Vector3 &p_size) {
+ ERR_FAIL_COND_MSG(p_size.x < 0 || p_size.y < 0 || p_size.z < 0, "BoxShape3D size cannot be negative.");
size = p_size;
_update_shape();
notify_change_to_owners();
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp
index 4d2698d27d..a1ad487bff 100644
--- a/scene/resources/capsule_shape_2d.cpp
+++ b/scene/resources/capsule_shape_2d.cpp
@@ -59,6 +59,7 @@ void CapsuleShape2D::_update_shape() {
}
void CapsuleShape2D::set_radius(real_t p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CapsuleShape2D radius cannot be negative.");
radius = p_radius;
if (radius > height * 0.5) {
height = radius * 2.0;
@@ -71,6 +72,7 @@ real_t CapsuleShape2D::get_radius() const {
}
void CapsuleShape2D::set_height(real_t p_height) {
+ ERR_FAIL_COND_MSG(p_height < 0, "CapsuleShape2D height cannot be negative.");
height = p_height;
if (radius > height * 0.5) {
radius = height * 0.5;
diff --git a/scene/resources/capsule_shape_3d.cpp b/scene/resources/capsule_shape_3d.cpp
index c16ddad984..2179ce82dd 100644
--- a/scene/resources/capsule_shape_3d.cpp
+++ b/scene/resources/capsule_shape_3d.cpp
@@ -79,6 +79,7 @@ void CapsuleShape3D::_update_shape() {
}
void CapsuleShape3D::set_radius(float p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CapsuleShape3D radius cannot be negative.");
radius = p_radius;
if (radius > height * 0.5) {
height = radius * 2.0;
@@ -92,6 +93,7 @@ float CapsuleShape3D::get_radius() const {
}
void CapsuleShape3D::set_height(float p_height) {
+ ERR_FAIL_COND_MSG(p_height < 0, "CapsuleShape3D height cannot be negative.");
height = p_height;
if (radius > height * 0.5) {
radius = height * 0.5;
diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp
index 9c16ac2eed..de931fca7e 100644
--- a/scene/resources/circle_shape_2d.cpp
+++ b/scene/resources/circle_shape_2d.cpp
@@ -43,6 +43,7 @@ void CircleShape2D::_update_shape() {
}
void CircleShape2D::set_radius(real_t p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CircleShape2D radius cannot be negative.");
radius = p_radius;
_update_shape();
}
diff --git a/scene/resources/cylinder_shape_3d.cpp b/scene/resources/cylinder_shape_3d.cpp
index 5eeb62d17b..c4f1cba341 100644
--- a/scene/resources/cylinder_shape_3d.cpp
+++ b/scene/resources/cylinder_shape_3d.cpp
@@ -72,6 +72,7 @@ void CylinderShape3D::_update_shape() {
}
void CylinderShape3D::set_radius(float p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CylinderShape3D radius cannot be negative.");
radius = p_radius;
_update_shape();
notify_change_to_owners();
@@ -82,6 +83,7 @@ float CylinderShape3D::get_radius() const {
}
void CylinderShape3D::set_height(float p_height) {
+ ERR_FAIL_COND_MSG(p_height < 0, "CylinderShape3D height cannot be negative.");
height = p_height;
_update_shape();
notify_change_to_owners();
diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp
index 92ab091b86..a27da11f8d 100644
--- a/scene/resources/importer_mesh.cpp
+++ b/scene/resources/importer_mesh.cpp
@@ -287,7 +287,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
const int *indices_ptr = indices.ptr();
if (normals.is_empty()) {
- normals.resize(vertices.size());
+ normals.resize(index_count);
Vector3 *n_ptr = normals.ptrw();
for (unsigned int j = 0; j < index_count; j += 3) {
const Vector3 &v0 = vertices_ptr[indices_ptr[j + 0]];
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index b74f44c52f..6fb0c0468d 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -330,7 +330,7 @@ void BaseMaterial3D::init_shaders() {
shader_names->rim = "rim";
shader_names->rim_tint = "rim_tint";
shader_names->clearcoat = "clearcoat";
- shader_names->clearcoat_gloss = "clearcoat_gloss";
+ shader_names->clearcoat_roughness = "clearcoat_roughness";
shader_names->anisotropy = "anisotropy_ratio";
shader_names->heightmap_scale = "heightmap_scale";
shader_names->subsurface_scattering_strength = "subsurface_scattering_strength";
@@ -541,12 +541,6 @@ void BaseMaterial3D::_update_shader() {
case SPECULAR_SCHLICK_GGX:
code += ",specular_schlick_ggx";
break;
- case SPECULAR_BLINN:
- code += ",specular_blinn";
- break;
- case SPECULAR_PHONG:
- code += ",specular_phong";
- break;
case SPECULAR_TOON:
code += ",specular_toon";
break;
@@ -690,7 +684,7 @@ void BaseMaterial3D::_update_shader() {
}
if (features[FEATURE_CLEARCOAT]) {
code += "uniform float clearcoat : hint_range(0,1);\n";
- code += "uniform float clearcoat_gloss : hint_range(0,1);\n";
+ code += "uniform float clearcoat_roughness : hint_range(0,1);\n";
code += "uniform sampler2D texture_clearcoat : hint_white," + texfilter_str + ";\n";
}
if (features[FEATURE_ANISOTROPY]) {
@@ -1166,7 +1160,7 @@ void BaseMaterial3D::_update_shader() {
code += " vec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy;\n";
}
code += " CLEARCOAT = clearcoat*clearcoat_tex.x;";
- code += " CLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n";
+ code += " CLEARCOAT_ROUGHNESS = clearcoat_roughness*clearcoat_tex.y;\n";
}
if (features[FEATURE_ANISOTROPY]) {
@@ -1408,13 +1402,13 @@ float BaseMaterial3D::get_clearcoat() const {
return clearcoat;
}
-void BaseMaterial3D::set_clearcoat_gloss(float p_clearcoat_gloss) {
- clearcoat_gloss = p_clearcoat_gloss;
- RS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat_gloss, p_clearcoat_gloss);
+void BaseMaterial3D::set_clearcoat_roughness(float p_clearcoat_roughness) {
+ clearcoat_roughness = p_clearcoat_roughness;
+ RS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat_roughness, p_clearcoat_roughness);
}
-float BaseMaterial3D::get_clearcoat_gloss() const {
- return clearcoat_gloss;
+float BaseMaterial3D::get_clearcoat_roughness() const {
+ return clearcoat_roughness;
}
void BaseMaterial3D::set_anisotropy(float p_anisotropy) {
@@ -2271,8 +2265,8 @@ void BaseMaterial3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_clearcoat", "clearcoat"), &BaseMaterial3D::set_clearcoat);
ClassDB::bind_method(D_METHOD("get_clearcoat"), &BaseMaterial3D::get_clearcoat);
- ClassDB::bind_method(D_METHOD("set_clearcoat_gloss", "clearcoat_gloss"), &BaseMaterial3D::set_clearcoat_gloss);
- ClassDB::bind_method(D_METHOD("get_clearcoat_gloss"), &BaseMaterial3D::get_clearcoat_gloss);
+ ClassDB::bind_method(D_METHOD("set_clearcoat_roughness", "clearcoat_roughness"), &BaseMaterial3D::set_clearcoat_roughness);
+ ClassDB::bind_method(D_METHOD("get_clearcoat_roughness"), &BaseMaterial3D::get_clearcoat_roughness);
ClassDB::bind_method(D_METHOD("set_anisotropy", "anisotropy"), &BaseMaterial3D::set_anisotropy);
ClassDB::bind_method(D_METHOD("get_anisotropy"), &BaseMaterial3D::get_anisotropy);
@@ -2438,7 +2432,7 @@ void BaseMaterial3D::_bind_methods() {
ADD_GROUP("Shading", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "shading_mode", PROPERTY_HINT_ENUM, "Unshaded,Per-Pixel,Per-Vertex"), "set_shading_mode", "get_shading_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "diffuse_mode", PROPERTY_HINT_ENUM, "Burley,Lambert,Lambert Wrap,Toon"), "set_diffuse_mode", "get_diffuse_mode");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "specular_mode", PROPERTY_HINT_ENUM, "SchlickGGX,Blinn,Phong,Toon,Disabled"), "set_specular_mode", "get_specular_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "specular_mode", PROPERTY_HINT_ENUM, "SchlickGGX,Toon,Disabled"), "set_specular_mode", "get_specular_mode");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "disable_ambient_light"), "set_flag", "get_flag", FLAG_DISABLE_AMBIENT_LIGHT);
ADD_GROUP("Vertex Color", "vertex_color");
@@ -2486,7 +2480,7 @@ void BaseMaterial3D::_bind_methods() {
ADD_GROUP("Clearcoat", "clearcoat_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "clearcoat_enabled"), "set_feature", "get_feature", FEATURE_CLEARCOAT);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "clearcoat", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_clearcoat", "get_clearcoat");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "clearcoat_gloss", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_clearcoat_gloss", "get_clearcoat_gloss");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "clearcoat_roughness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_clearcoat_roughness", "get_clearcoat_roughness");
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "clearcoat_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_CLEARCOAT);
ADD_GROUP("Anisotropy", "anisotropy_");
@@ -2693,8 +2687,6 @@ void BaseMaterial3D::_bind_methods() {
BIND_ENUM_CONSTANT(DIFFUSE_TOON);
BIND_ENUM_CONSTANT(SPECULAR_SCHLICK_GGX);
- BIND_ENUM_CONSTANT(SPECULAR_BLINN);
- BIND_ENUM_CONSTANT(SPECULAR_PHONG);
BIND_ENUM_CONSTANT(SPECULAR_TOON);
BIND_ENUM_CONSTANT(SPECULAR_DISABLED);
@@ -2732,7 +2724,7 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) :
set_rim(1.0);
set_rim_tint(0.5);
set_clearcoat(1);
- set_clearcoat_gloss(0.5);
+ set_clearcoat_roughness(0.5);
set_anisotropy(0);
set_heightmap_scale(0.05);
set_subsurface_scattering_strength(0);
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 57591bee2f..a79f072f9a 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -252,8 +252,6 @@ public:
enum SpecularMode {
SPECULAR_SCHLICK_GGX,
- SPECULAR_BLINN,
- SPECULAR_PHONG,
SPECULAR_TOON,
SPECULAR_DISABLED,
SPECULAR_MAX
@@ -387,7 +385,7 @@ private:
StringName rim;
StringName rim_tint;
StringName clearcoat;
- StringName clearcoat_gloss;
+ StringName clearcoat_roughness;
StringName anisotropy;
StringName heightmap_scale;
StringName subsurface_scattering_strength;
@@ -454,7 +452,7 @@ private:
float rim;
float rim_tint;
float clearcoat;
- float clearcoat_gloss;
+ float clearcoat_roughness;
float anisotropy;
float heightmap_scale;
float subsurface_scattering_strength;
@@ -572,8 +570,8 @@ public:
void set_clearcoat(float p_clearcoat);
float get_clearcoat() const;
- void set_clearcoat_gloss(float p_clearcoat_gloss);
- float get_clearcoat_gloss() const;
+ void set_clearcoat_roughness(float p_clearcoat_roughness);
+ float get_clearcoat_roughness() const;
void set_anisotropy(float p_anisotropy);
float get_anisotropy() const;
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index 441e84eccc..6b44b05e02 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -1684,6 +1684,7 @@ Error ArrayMesh::lightmap_unwrap(const Transform3D &p_base_transform, float p_te
Error ArrayMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache, bool p_generate_cache) {
ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED);
ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes.");
+ ERR_FAIL_COND_V_MSG(p_texel_size <= 0.0f, ERR_PARAMETER_RANGE_ERROR, "Texel size must be greater than 0.");
LocalVector<float> vertices;
LocalVector<float> normals;
diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp
index 27659f724e..5e88c9974c 100644
--- a/scene/resources/rectangle_shape_2d.cpp
+++ b/scene/resources/rectangle_shape_2d.cpp
@@ -58,6 +58,7 @@ bool RectangleShape2D::_get(const StringName &p_name, Variant &r_property) const
#endif // DISABLE_DEPRECATED
void RectangleShape2D::set_size(const Vector2 &p_size) {
+ ERR_FAIL_COND_MSG(p_size.x < 0 || p_size.y < 0, "RectangleShape2D size cannot be negative.");
size = p_size;
_update_shape();
}
diff --git a/scene/resources/sphere_shape_3d.cpp b/scene/resources/sphere_shape_3d.cpp
index ee789362c9..8282992401 100644
--- a/scene/resources/sphere_shape_3d.cpp
+++ b/scene/resources/sphere_shape_3d.cpp
@@ -63,6 +63,7 @@ void SphereShape3D::_update_shape() {
}
void SphereShape3D::set_radius(float p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "SphereShape3D radius cannot be negative.");
radius = p_radius;
_update_shape();
notify_change_to_owners();
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 1e84947b87..1174117028 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -4432,6 +4432,10 @@ void TileSetAtlasSource::_update_padded_texture() {
Ref<Image> src = texture->get_image();
+ if (!src.is_valid()) {
+ return;
+ }
+
Ref<Image> image;
image.instantiate();
image->create(size.x, size.y, false, src->get_format());
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index dae61c8609..47ca643029 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -3163,7 +3163,7 @@ const VisualShaderNodeOutput::Port VisualShaderNodeOutput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "rim", "RIM" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "rim_tint", "RIM_TINT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "clearcoat", "CLEARCOAT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "clearcoat_gloss", "CLEARCOAT_GLOSS" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "clearcoat_roughness", "CLEARCOAT_ROUGHNESS" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "anisotropy", "ANISOTROPY" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "anisotropy_flow", "ANISOTROPY_FLOW" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "subsurf_scatter", "SSS_STRENGTH" },
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index f2479199ee..a6aa6d8c49 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -2843,8 +2843,7 @@ String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShade
code += " vec3 c = " + p_input_vars[0] + ";\n";
code += " float max1 = max(c.r, c.g);\n";
code += " float max2 = max(max1, c.b);\n";
- code += " float max3 = max(max1, max2);\n";
- code += " " + p_output_vars[0] + " = vec3(max3, max3, max3);\n";
+ code += " " + p_output_vars[0] + " = vec3(max2, max2, max2);\n";
code += " }\n";
break;
case FUNC_SEPIA: