diff options
Diffstat (limited to 'scene/resources/immediate_mesh.cpp')
-rw-r--r-- | scene/resources/immediate_mesh.cpp | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp index 247927163b..48d609da97 100644 --- a/scene/resources/immediate_mesh.cpp +++ b/scene/resources/immediate_mesh.cpp @@ -41,8 +41,8 @@ void ImmediateMesh::surface_set_color(const Color &p_color) { if (!uses_colors) { colors.resize(vertices.size()); - for (uint32_t i = 0; i < colors.size(); i++) { - colors[i] = p_color; + for (Color &color : colors) { + color = p_color; } uses_colors = true; } @@ -54,8 +54,8 @@ void ImmediateMesh::surface_set_normal(const Vector3 &p_normal) { if (!uses_normals) { normals.resize(vertices.size()); - for (uint32_t i = 0; i < normals.size(); i++) { - normals[i] = p_normal; + for (Vector3 &normal : normals) { + normal = p_normal; } uses_normals = true; } @@ -66,8 +66,8 @@ 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; + for (Plane &tangent : tangents) { + tangent = p_tangent; } uses_tangents = true; } @@ -78,8 +78,8 @@ 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; + for (Vector2 &uv : uvs) { + uv = p_uv; } uses_uvs = true; } @@ -90,8 +90,8 @@ 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; + for (Vector2 &uv : uv2s) { + uv = p_uv2; } uses_uv2s = true; } @@ -194,25 +194,20 @@ void ImmediateMesh::surface_end() { 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); + Vector2 n = normals[i].octahedron_encode(); 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; + value |= (uint16_t)CLAMP(n.x * 65535, 0, 65535); + value |= (uint16_t)CLAMP(n.y * 65535, 0, 65535) << 16; *normal = value; } if (uses_tangents) { uint32_t *tangent = (uint32_t *)&surface_vertex_ptr[i * vertex_stride + tangent_offset]; - Plane t = tangents[i]; + Vector2 t = tangents[i].normal.octahedron_tangent_encode(tangents[i].d); 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 |= 3UL << 30; - } + value |= (uint16_t)CLAMP(t.x * 65535, 0, 65535); + value |= (uint16_t)CLAMP(t.y * 65535, 0, 65535) << 16; *tangent = value; } |