summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/camera_effects.cpp8
-rw-r--r--scene/resources/environment.cpp2
-rw-r--r--scene/resources/immediate_mesh.cpp416
-rw-r--r--scene/resources/immediate_mesh.h117
-rw-r--r--scene/resources/material.cpp15
-rw-r--r--scene/resources/material.h2
-rw-r--r--scene/resources/mesh.cpp20
-rw-r--r--scene/resources/mesh.h4
-rw-r--r--scene/resources/particles_material.cpp2
9 files changed, 572 insertions, 14 deletions
diff --git a/scene/resources/camera_effects.cpp b/scene/resources/camera_effects.cpp
index 34c6bc05bc..b633196424 100644
--- a/scene/resources/camera_effects.cpp
+++ b/scene/resources/camera_effects.cpp
@@ -175,11 +175,11 @@ void CameraEffects::_bind_methods() {
ADD_GROUP("DOF Blur", "dof_blur_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_far_enabled"), "set_dof_blur_far_enabled", "is_dof_blur_far_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_distance", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_far_distance", "get_dof_blur_far_distance");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_far_transition", "get_dof_blur_far_transition");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_far_distance", "get_dof_blur_far_distance");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_far_transition", "get_dof_blur_far_transition");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_near_enabled"), "set_dof_blur_near_enabled", "is_dof_blur_near_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_distance", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_near_distance", "get_dof_blur_near_distance");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01"), "set_dof_blur_near_transition", "get_dof_blur_near_transition");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_near_distance", "get_dof_blur_near_distance");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_near_transition", "get_dof_blur_near_transition");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dof_blur_amount", "get_dof_blur_amount");
// Override exposure
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index c04b271d81..8550af8bcb 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -1329,7 +1329,7 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_density", PROPERTY_HINT_RANGE, "0,1,0.0001,or_greater"), "set_volumetric_fog_density", "get_volumetric_fog_density");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "volumetric_fog_light", PROPERTY_HINT_COLOR_NO_ALPHA), "set_volumetric_fog_light", "get_volumetric_fog_light");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_light_energy", PROPERTY_HINT_RANGE, "0,1024,0.01,or_greater"), "set_volumetric_fog_light_energy", "get_volumetric_fog_light_energy");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_gi_inject", PROPERTY_HINT_EXP_RANGE, "0.00,16,0.01"), "set_volumetric_fog_gi_inject", "get_volumetric_fog_gi_inject");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_gi_inject", PROPERTY_HINT_RANGE, "0.00,16,0.01,exp"), "set_volumetric_fog_gi_inject", "get_volumetric_fog_gi_inject");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_length", PROPERTY_HINT_RANGE, "0,1024,0.01,or_greater"), "set_volumetric_fog_length", "get_volumetric_fog_length");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_detail_spread", PROPERTY_HINT_EXP_EASING, "0.01,16,0.01"), "set_volumetric_fog_detail_spread", "get_volumetric_fog_detail_spread");
ADD_SUBGROUP("Temporal Reprojection", "volumetric_fog_temporal_reprojection_");
diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp
new file mode 100644
index 0000000000..ebe65605f8
--- /dev/null
+++ b/scene/resources/immediate_mesh.cpp
@@ -0,0 +1,416 @@
+/*************************************************************************/
+/* immediate_mesh.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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. */
+/*************************************************************************/
+
+#include "immediate_mesh.h"
+
+void ImmediateMesh::surface_begin(PrimitiveType p_primitive, const Ref<Material> &p_material) {
+ ERR_FAIL_COND_MSG(surface_active, "Already creating a new surface.");
+ active_surface_data.primitive = p_primitive;
+ active_surface_data.material = p_material;
+ surface_active = true;
+}
+void ImmediateMesh::surface_set_color(const Color &p_color) {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+
+ if (!uses_colors) {
+ colors.resize(vertices.size());
+ for (uint32_t i = 0; i < colors.size(); i++) {
+ colors[i] = p_color;
+ }
+ uses_colors = true;
+ }
+
+ current_color = p_color;
+}
+void ImmediateMesh::surface_set_normal(const Vector3 &p_normal) {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+
+ if (!uses_normals) {
+ normals.resize(vertices.size());
+ for (uint32_t i = 0; i < normals.size(); i++) {
+ normals[i] = p_normal;
+ }
+ uses_normals = true;
+ }
+
+ current_normal = p_normal;
+}
+void ImmediateMesh::surface_set_tangent(const Plane &p_tangent) {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+ if (!uses_tangents) {
+ tangents.resize(vertices.size());
+ for (uint32_t i = 0; i < tangents.size(); i++) {
+ tangents[i] = p_tangent;
+ }
+ uses_tangents = true;
+ }
+
+ current_tangent = p_tangent;
+}
+void ImmediateMesh::surface_set_uv(const Vector2 &p_uv) {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+ if (!uses_uvs) {
+ uvs.resize(vertices.size());
+ for (uint32_t i = 0; i < uvs.size(); i++) {
+ uvs[i] = p_uv;
+ }
+ uses_uvs = true;
+ }
+
+ current_uv = p_uv;
+}
+void ImmediateMesh::surface_set_uv2(const Vector2 &p_uv2) {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+ if (!uses_uv2s) {
+ uv2s.resize(vertices.size());
+ for (uint32_t i = 0; i < uv2s.size(); i++) {
+ uv2s[i] = p_uv2;
+ }
+ uses_uv2s = true;
+ }
+
+ current_uv2 = p_uv2;
+}
+void ImmediateMesh::surface_add_vertex(const Vector3 &p_vertex) {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+ ERR_FAIL_COND_MSG(vertices.size() && active_surface_data.vertex_2d, "Can't mix 2D and 3D vertices in a surface.");
+
+ if (uses_colors) {
+ colors.push_back(current_color);
+ }
+ if (uses_normals) {
+ normals.push_back(current_normal);
+ }
+ if (uses_tangents) {
+ tangents.push_back(current_tangent);
+ }
+ if (uses_uvs) {
+ uvs.push_back(current_uv);
+ }
+ if (uses_uv2s) {
+ uv2s.push_back(current_uv2);
+ }
+ vertices.push_back(p_vertex);
+}
+
+void ImmediateMesh::surface_add_vertex_2d(const Vector2 &p_vertex) {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+ ERR_FAIL_COND_MSG(vertices.size() && !active_surface_data.vertex_2d, "Can't mix 2D and 3D vertices in a surface.");
+
+ if (uses_colors) {
+ colors.push_back(current_color);
+ }
+ if (uses_normals) {
+ normals.push_back(current_normal);
+ }
+ if (uses_tangents) {
+ tangents.push_back(current_tangent);
+ }
+ if (uses_uvs) {
+ uvs.push_back(current_uv);
+ }
+ if (uses_uv2s) {
+ uv2s.push_back(current_uv2);
+ }
+ Vector3 v(p_vertex.x, p_vertex.y, 0);
+ vertices.push_back(v);
+
+ active_surface_data.vertex_2d = true;
+}
+void ImmediateMesh::surface_end() {
+ ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
+ ERR_FAIL_COND_MSG(!vertices.size(), "No vertices were added, surface cant be created.");
+
+ uint32_t format = ARRAY_FORMAT_VERTEX;
+
+ uint32_t vertex_stride = 0;
+ if (active_surface_data.vertex_2d) {
+ format |= ARRAY_FLAG_USE_2D_VERTICES;
+ vertex_stride = sizeof(float) * 2;
+ } else {
+ vertex_stride = sizeof(float) * 3;
+ }
+
+ uint32_t normal_offset = 0;
+ if (uses_normals) {
+ format |= ARRAY_FORMAT_NORMAL;
+ normal_offset = vertex_stride;
+ vertex_stride += sizeof(uint32_t);
+ }
+ uint32_t tangent_offset = 0;
+ if (uses_tangents) {
+ format |= ARRAY_FORMAT_TANGENT;
+ tangent_offset += vertex_stride;
+ vertex_stride += sizeof(uint32_t);
+ }
+
+ AABB aabb;
+
+ {
+ surface_vertex_create_cache.resize(vertex_stride * vertices.size());
+ uint8_t *surface_vertex_ptr = surface_vertex_create_cache.ptrw();
+ for (uint32_t i = 0; i < vertices.size(); i++) {
+ {
+ float *vtx = (float *)&surface_vertex_ptr[i * vertex_stride];
+ vtx[0] = vertices[i].x;
+ vtx[1] = vertices[i].y;
+ if (!active_surface_data.vertex_2d) {
+ vtx[2] = vertices[i].z;
+ }
+ if (i == 0) {
+ aabb.position = vertices[i];
+ } else {
+ aabb.expand_to(vertices[i]);
+ }
+ }
+ if (uses_normals) {
+ uint32_t *normal = (uint32_t *)&surface_vertex_ptr[i * vertex_stride + normal_offset];
+
+ Vector3 n = normals[i] * Vector3(0.5, 0.5, 0.5) + Vector3(0.5, 0.5, 0.5);
+
+ uint32_t value = 0;
+ value |= CLAMP(int(n.x * 1023.0), 0, 1023);
+ value |= CLAMP(int(n.y * 1023.0), 0, 1023) << 10;
+ value |= CLAMP(int(n.z * 1023.0), 0, 1023) << 20;
+
+ *normal = value;
+ }
+ if (uses_tangents) {
+ uint32_t *tangent = (uint32_t *)&surface_vertex_ptr[i * vertex_stride + tangent_offset];
+ Plane t = tangents[i];
+ uint32_t value = 0;
+ value |= CLAMP(int((t.normal.x * 0.5 + 0.5) * 1023.0), 0, 1023);
+ value |= CLAMP(int((t.normal.y * 0.5 + 0.5) * 1023.0), 0, 1023) << 10;
+ value |= CLAMP(int((t.normal.z * 0.5 + 0.5) * 1023.0), 0, 1023) << 20;
+ if (t.d > 0) {
+ value |= 3 << 30;
+ }
+
+ *tangent = value;
+ }
+ }
+ }
+
+ if (uses_colors || uses_uvs || uses_uv2s) {
+ uint32_t attribute_stride = 0;
+
+ if (uses_colors) {
+ format |= ARRAY_FORMAT_COLOR;
+ attribute_stride += sizeof(uint8_t) * 4;
+ }
+ uint32_t uv_offset = 0;
+ if (uses_uvs) {
+ format |= ARRAY_FORMAT_TEX_UV;
+ uv_offset = attribute_stride;
+ attribute_stride += sizeof(float) * 2;
+ }
+ uint32_t uv2_offset = 0;
+ if (uses_uv2s) {
+ format |= ARRAY_FORMAT_TEX_UV2;
+ uv2_offset = attribute_stride;
+ attribute_stride += sizeof(float) * 2;
+ }
+
+ surface_attribute_create_cache.resize(vertices.size() * attribute_stride);
+
+ uint8_t *surface_attribute_ptr = surface_attribute_create_cache.ptrw();
+
+ for (uint32_t i = 0; i < vertices.size(); i++) {
+ if (uses_colors) {
+ uint8_t *color8 = (uint8_t *)&surface_attribute_ptr[i * attribute_stride];
+
+ color8[0] = uint8_t(CLAMP(colors[i].r * 255.0, 0.0, 255.0));
+ color8[1] = uint8_t(CLAMP(colors[i].g * 255.0, 0.0, 255.0));
+ color8[2] = uint8_t(CLAMP(colors[i].b * 255.0, 0.0, 255.0));
+ color8[3] = uint8_t(CLAMP(colors[i].a * 255.0, 0.0, 255.0));
+ }
+ if (uses_uvs) {
+ float *uv = (float *)&surface_attribute_ptr[i * attribute_stride + uv_offset];
+
+ uv[0] = uvs[i].x;
+ uv[1] = uvs[i].y;
+ }
+
+ if (uses_uv2s) {
+ float *uv2 = (float *)&surface_attribute_ptr[i * attribute_stride + uv2_offset];
+
+ uv2[0] = uv2s[i].x;
+ uv2[1] = uv2s[i].y;
+ }
+ }
+ }
+
+ RS::SurfaceData sd;
+
+ sd.primitive = RS::PrimitiveType(active_surface_data.primitive);
+ sd.format = format;
+ sd.vertex_data = surface_vertex_create_cache;
+ if (uses_colors || uses_uvs || uses_uv2s) {
+ sd.attribute_data = surface_attribute_create_cache;
+ }
+ sd.vertex_count = vertices.size();
+ sd.aabb = aabb;
+ if (active_surface_data.material.is_valid()) {
+ sd.material = active_surface_data.material->get_rid();
+ }
+
+ RS::get_singleton()->mesh_add_surface(mesh, sd);
+
+ active_surface_data.aabb = aabb;
+
+ active_surface_data.format = format;
+ active_surface_data.array_len = vertices.size();
+
+ surfaces.push_back(active_surface_data);
+
+ colors.clear();
+ normals.clear();
+ tangents.clear();
+ uvs.clear();
+ uv2s.clear();
+ vertices.clear();
+
+ uses_colors = false;
+ uses_normals = false;
+ uses_tangents = false;
+ uses_uvs = false;
+ uses_uv2s = false;
+
+ surface_active = false;
+}
+
+void ImmediateMesh::clear_surfaces() {
+ RS::get_singleton()->mesh_clear(mesh);
+ surfaces.clear();
+ surface_active = false;
+
+ colors.clear();
+ normals.clear();
+ tangents.clear();
+ uvs.clear();
+ uv2s.clear();
+ vertices.clear();
+
+ uses_colors = false;
+ uses_normals = false;
+ uses_tangents = false;
+ uses_uvs = false;
+ uses_uv2s = false;
+}
+
+int ImmediateMesh::get_surface_count() const {
+ return surfaces.size();
+}
+int ImmediateMesh::surface_get_array_len(int p_idx) const {
+ ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), -1);
+ return surfaces[p_idx].array_len;
+}
+int ImmediateMesh::surface_get_array_index_len(int p_idx) const {
+ return 0;
+}
+bool ImmediateMesh::surface_is_softbody_friendly(int p_idx) const {
+ return false;
+}
+Array ImmediateMesh::surface_get_arrays(int p_surface) const {
+ ERR_FAIL_INDEX_V(p_surface, int(surfaces.size()), Array());
+ return RS::get_singleton()->mesh_surface_get_arrays(mesh, p_surface);
+}
+Array ImmediateMesh::surface_get_blend_shape_arrays(int p_surface) const {
+ return Array();
+}
+Dictionary ImmediateMesh::surface_get_lods(int p_surface) const {
+ return Dictionary();
+}
+uint32_t ImmediateMesh::surface_get_format(int p_idx) const {
+ ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), 0);
+ return surfaces[p_idx].format;
+}
+Mesh::PrimitiveType ImmediateMesh::surface_get_primitive_type(int p_idx) const {
+ ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), PRIMITIVE_MAX);
+ return surfaces[p_idx].primitive;
+}
+void ImmediateMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) {
+ ERR_FAIL_INDEX(p_idx, int(surfaces.size()));
+ surfaces[p_idx].material = p_material;
+ RID mat;
+ if (p_material.is_valid()) {
+ mat = p_material->get_rid();
+ }
+ RS::get_singleton()->mesh_surface_set_material(mesh, p_idx, mat);
+}
+Ref<Material> ImmediateMesh::surface_get_material(int p_idx) const {
+ ERR_FAIL_INDEX_V(p_idx, int(surfaces.size()), Ref<Material>());
+ return surfaces[p_idx].material;
+}
+int ImmediateMesh::get_blend_shape_count() const {
+ return 0;
+}
+StringName ImmediateMesh::get_blend_shape_name(int p_index) const {
+ return StringName();
+}
+void ImmediateMesh::set_blend_shape_name(int p_index, const StringName &p_name) {
+}
+
+AABB ImmediateMesh::get_aabb() const {
+ AABB aabb;
+ for (uint32_t i = 0; i < surfaces.size(); i++) {
+ if (i == 0) {
+ aabb = surfaces[i].aabb;
+ } else {
+ aabb.merge(surfaces[i].aabb);
+ }
+ }
+ return aabb;
+}
+
+void ImmediateMesh::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("surface_begin", "primitive", "material"), &ImmediateMesh::surface_begin, DEFVAL(Ref<Material>()));
+ ClassDB::bind_method(D_METHOD("surface_set_color", "color"), &ImmediateMesh::surface_set_color);
+ ClassDB::bind_method(D_METHOD("surface_set_normal", "normal"), &ImmediateMesh::surface_set_normal);
+ ClassDB::bind_method(D_METHOD("surface_set_tangent", "tangent"), &ImmediateMesh::surface_set_tangent);
+ ClassDB::bind_method(D_METHOD("surface_set_uv", "uv"), &ImmediateMesh::surface_set_uv);
+ ClassDB::bind_method(D_METHOD("surface_set_uv2", "uv2"), &ImmediateMesh::surface_set_uv2);
+ ClassDB::bind_method(D_METHOD("surface_add_vertex", "vertex"), &ImmediateMesh::surface_add_vertex);
+ ClassDB::bind_method(D_METHOD("surface_add_vertex_2d", "vertex"), &ImmediateMesh::surface_add_vertex_2d);
+ ClassDB::bind_method(D_METHOD("surface_end"), &ImmediateMesh::surface_end);
+
+ ClassDB::bind_method(D_METHOD("clear_surfaces"), &ImmediateMesh::clear_surfaces);
+}
+
+RID ImmediateMesh::get_rid() const {
+ return mesh;
+}
+
+ImmediateMesh::ImmediateMesh() {
+ mesh = RS::get_singleton()->mesh_create();
+}
+ImmediateMesh::~ImmediateMesh() {
+ RS::get_singleton()->free(mesh);
+}
diff --git a/scene/resources/immediate_mesh.h b/scene/resources/immediate_mesh.h
new file mode 100644
index 0000000000..7010d40719
--- /dev/null
+++ b/scene/resources/immediate_mesh.h
@@ -0,0 +1,117 @@
+/*************************************************************************/
+/* immediate_mesh.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* 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 IMMEDIATE_MESH_H
+#define IMMEDIATE_MESH_H
+
+#include "core/templates/local_vector.h"
+#include "scene/resources/mesh.h"
+
+class ImmediateMesh : public Mesh {
+ GDCLASS(ImmediateMesh, Mesh)
+
+ RID mesh;
+
+ bool uses_colors = false;
+ bool uses_normals = false;
+ bool uses_tangents = false;
+ bool uses_uvs = false;
+ bool uses_uv2s = false;
+
+ Color current_color;
+ Vector3 current_normal;
+ Plane current_tangent;
+ Vector2 current_uv;
+ Vector2 current_uv2;
+
+ LocalVector<Color> colors;
+ LocalVector<Vector3> normals;
+ LocalVector<Plane> tangents;
+ LocalVector<Vector2> uvs;
+ LocalVector<Vector2> uv2s;
+ LocalVector<Vector3> vertices;
+
+ struct Surface {
+ PrimitiveType primitive;
+ Ref<Material> material;
+ bool vertex_2d = false;
+ int array_len = 0;
+ uint32_t format = 0;
+ AABB aabb;
+ };
+
+ LocalVector<Surface> surfaces;
+
+ bool surface_active = false;
+ Surface active_surface_data;
+
+ Vector<uint8_t> surface_vertex_create_cache;
+ Vector<uint8_t> surface_attribute_create_cache;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void surface_begin(PrimitiveType p_primitive, const Ref<Material> &p_material = Ref<Material>());
+ void surface_set_color(const Color &p_color);
+ void surface_set_normal(const Vector3 &p_normal);
+ void surface_set_tangent(const Plane &p_tangent);
+ void surface_set_uv(const Vector2 &p_uv);
+ void surface_set_uv2(const Vector2 &p_uv2);
+ void surface_add_vertex(const Vector3 &p_vertex);
+ void surface_add_vertex_2d(const Vector2 &p_vertex);
+ void surface_end();
+
+ void clear_surfaces();
+
+ virtual int get_surface_count() const override;
+ virtual int surface_get_array_len(int p_idx) const override;
+ virtual int surface_get_array_index_len(int p_idx) const override;
+ virtual bool surface_is_softbody_friendly(int p_idx) const override;
+ virtual Array surface_get_arrays(int p_surface) const override;
+ virtual Array surface_get_blend_shape_arrays(int p_surface) const override;
+ virtual Dictionary surface_get_lods(int p_surface) const override;
+ virtual uint32_t surface_get_format(int p_idx) const override;
+ virtual PrimitiveType surface_get_primitive_type(int p_idx) const override;
+ virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) override;
+ virtual Ref<Material> surface_get_material(int p_idx) const override;
+ virtual int get_blend_shape_count() const override;
+ virtual StringName get_blend_shape_name(int p_index) const override;
+ virtual void set_blend_shape_name(int p_index, const StringName &p_name) override;
+
+ virtual AABB get_aabb() const override;
+
+ virtual RID get_rid() const override;
+
+ ImmediateMesh();
+ ~ImmediateMesh();
+};
+
+#endif // IMMEDIATEMESH_H
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index cb66d5724d..d391540a0b 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -2077,7 +2077,7 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_refraction_texture_channel()
return refraction_texture_channel;
}
-RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard, bool p_billboard_y) {
+Ref<Material> BaseMaterial3D::get_material_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard, bool p_billboard_y, RID *r_shader_rid) {
int version = 0;
if (p_shaded) {
version = 1;
@@ -2102,7 +2102,10 @@ RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, b
}
if (materials_for_2d[version].is_valid()) {
- return materials_for_2d[version]->get_rid();
+ if (r_shader_rid) {
+ *r_shader_rid = materials_for_2d[version]->get_shader_rid();
+ }
+ return materials_for_2d[version];
}
Ref<StandardMaterial3D> material;
@@ -2120,7 +2123,11 @@ RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, b
materials_for_2d[version] = material;
- return materials_for_2d[version]->get_rid();
+ if (r_shader_rid) {
+ *r_shader_rid = materials_for_2d[version]->get_shader_rid();
+ }
+
+ return materials_for_2d[version];
}
void BaseMaterial3D::set_on_top_of_alpha() {
@@ -2189,6 +2196,8 @@ BaseMaterial3D::EmissionOperator BaseMaterial3D::get_emission_operator() const {
}
RID BaseMaterial3D::get_shader_rid() const {
+ MutexLock lock(material_mutex);
+ ((BaseMaterial3D *)this)->_update_shader();
ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
return shader_map[current_key].shader;
}
diff --git a/scene/resources/material.h b/scene/resources/material.h
index dc3ecdb5de..cd91d05a60 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -738,7 +738,7 @@ public:
static void finish_shaders();
static void flush_changes();
- static RID get_material_rid_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard = false, bool p_billboard_y = false);
+ static Ref<Material> get_material_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard = false, bool p_billboard_y = false, RID *r_shader_rid = nullptr);
virtual RID get_shader_rid() const override;
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index cf59c6fa22..ce942817c0 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -1335,9 +1335,21 @@ String ArrayMesh::surface_get_name(int p_idx) const {
return surfaces[p_idx].name;
}
-void ArrayMesh::surface_update_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
+void ArrayMesh::surface_update_vertex_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
ERR_FAIL_INDEX(p_surface, surfaces.size());
- RS::get_singleton()->mesh_surface_update_region(mesh, p_surface, p_offset, p_data);
+ RS::get_singleton()->mesh_surface_update_vertex_region(mesh, p_surface, p_offset, p_data);
+ emit_changed();
+}
+
+void ArrayMesh::surface_update_attribute_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
+ ERR_FAIL_INDEX(p_surface, surfaces.size());
+ RS::get_singleton()->mesh_surface_update_attribute_region(mesh, p_surface, p_offset, p_data);
+ emit_changed();
+}
+
+void ArrayMesh::surface_update_skin_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) {
+ ERR_FAIL_INDEX(p_surface, surfaces.size());
+ RS::get_singleton()->mesh_surface_update_skin_region(mesh, p_surface, p_offset, p_data);
emit_changed();
}
@@ -1635,7 +1647,9 @@ void ArrayMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_surface_from_arrays", "primitive", "arrays", "blend_shapes", "lods", "compress_flags"), &ArrayMesh::add_surface_from_arrays, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(0));
ClassDB::bind_method(D_METHOD("clear_surfaces"), &ArrayMesh::clear_surfaces);
- ClassDB::bind_method(D_METHOD("surface_update_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_region);
+ ClassDB::bind_method(D_METHOD("surface_update_vertex_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_vertex_region);
+ ClassDB::bind_method(D_METHOD("surface_update_attribute_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_attribute_region);
+ ClassDB::bind_method(D_METHOD("surface_update_skin_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_skin_region);
ClassDB::bind_method(D_METHOD("surface_get_array_len", "surf_idx"), &ArrayMesh::surface_get_array_len);
ClassDB::bind_method(D_METHOD("surface_get_array_index_len", "surf_idx"), &ArrayMesh::surface_get_array_index_len);
ClassDB::bind_method(D_METHOD("surface_get_format", "surf_idx"), &ArrayMesh::surface_get_format);
diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h
index 2dfb46782b..02cab9a5e1 100644
--- a/scene/resources/mesh.h
+++ b/scene/resources/mesh.h
@@ -233,7 +233,9 @@ public:
void set_blend_shape_mode(BlendShapeMode p_mode);
BlendShapeMode get_blend_shape_mode() const;
- void surface_update_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data);
+ void surface_update_vertex_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data);
+ void surface_update_attribute_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data);
+ void surface_update_skin_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data);
int get_surface_count() const override;
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 60d5566f08..24b56da791 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -1292,7 +1292,7 @@ void ParticlesMaterial::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "damping_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_DAMPING);
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "damping_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_DAMPING);
ADD_GROUP("Angle", "");
- ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater"), "set_param", "get_param", PARAM_ANGLE);
+ ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater,degrees"), "set_param", "get_param", PARAM_ANGLE);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angle_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGLE);
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANGLE);
ADD_GROUP("Scale", "");