-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sprite3D is broken in the HTML export #41270
Comments
At first I thought it was drawing the upper 2 quads with 2d and it was batching, but it turns out to be a CSG box, 2 sprite3Ds, and a CSG mesh, looking at the project. One possibility is that the same texture is being used on each and a texture binding optimization. Because the texture is already bound, it could be skipping some steps to set other state (blending perhaps, something like that). We've had bugs using this mechanism before, so it is a possibility. |
No, it breaks our games in HTML export. I put other objects in there just to show that they work. You can take another texture or simply delete that what you don't like ;-) Sprite3D are the two in the middle... |
Ah this is useful. Do problems occur even with a single Sprite3D? |
Yes. (If you agree that scene without camera is useless ;) I took a non-transparent texture, otherwise you wouldn't even see the black square. |
It could be a side effect of backporting #39604 |
There's no rendering support for HTML5 in 4.0 yet as there's no WebGL backend (nor WebGPU), so it can't be tested. But the most likely cause for this change in 3.2.3 would be #39867. Is there any relevant error in the debug console? |
Nothing red in the Godot editor or the web-console
|
I had some hard times to figure out how to compile the web-assembly template: godotengine/godot-docs#3900 Yes, reverting #39867 fixes this issue for me. patch
This reverts commit 6c0ff26. ---
doc/classes/VisualServer.xml | 2 +-
scene/3d/sprite_3d.cpp | 179 +++++++----------------------------
scene/3d/sprite_3d.h | 11 +--
scene/resources/material.cpp | 2 -
4 files changed, 35 insertions(+), 159 deletions(-)
diff --git a/doc/classes/VisualServer.xml b/doc/classes/VisualServer.xml
index 6642152749..81acdf0499 100644
--- a/doc/classes/VisualServer.xml
+++ b/doc/classes/VisualServer.xml
@@ -4431,7 +4431,7 @@
Flag used to mark that the array uses 16-bit bones instead of 8-bit.
</constant>
<constant name="ARRAY_COMPRESS_DEFAULT" value="97280" enum="ArrayFormat">
- Used to set flags [constant ARRAY_COMPRESS_NORMAL], [constant ARRAY_COMPRESS_TANGENT], [constant ARRAY_COMPRESS_COLOR], [constant ARRAY_COMPRESS_TEX_UV], [constant ARRAY_COMPRESS_TEX_UV2] and [constant ARRAY_COMPRESS_WEIGHTS] quickly.
+ Used to set flags [constant ARRAY_COMPRESS_VERTEX], [constant ARRAY_COMPRESS_NORMAL], [constant ARRAY_COMPRESS_TANGENT], [constant ARRAY_COMPRESS_COLOR], [constant ARRAY_COMPRESS_TEX_UV], [constant ARRAY_COMPRESS_TEX_UV2] and [constant ARRAY_COMPRESS_WEIGHTS] quickly.
</constant>
<constant name="PRIMITIVE_POINTS" value="0" enum="PrimitiveType">
Primitive to draw consists of points.
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index 2af30c4e59..a4c81b864d 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -383,73 +383,22 @@ SpriteBase3D::SpriteBase3D() {
modulate = Color(1, 1, 1, 1);
pending_update = false;
opacity = 1.0;
-
- material = VisualServer::get_singleton()->material_create();
- // Set defaults for material, names need to match up those in SpatialMaterial
- VS::get_singleton()->material_set_param(material, "albedo", Color(1, 1, 1, 1));
- VS::get_singleton()->material_set_param(material, "specular", 0.5);
- VS::get_singleton()->material_set_param(material, "metallic", 0.0);
- VS::get_singleton()->material_set_param(material, "roughness", 1.0);
- VS::get_singleton()->material_set_param(material, "uv1_offset", Vector3(0, 0, 0));
- VS::get_singleton()->material_set_param(material, "uv1_scale", Vector3(1, 1, 1));
- VS::get_singleton()->material_set_param(material, "uv2_offset", Vector3(0, 0, 0));
- VS::get_singleton()->material_set_param(material, "uv2_scale", Vector3(1, 1, 1));
-
- mesh = VisualServer::get_singleton()->mesh_create();
-
- PoolVector2Array mesh_vertices;
- PoolVector3Array mesh_normals;
- PoolRealArray mesh_tangents;
- PoolColorArray mesh_colors;
- PoolVector2Array mesh_uvs;
-
- mesh_vertices.resize(4);
- mesh_normals.resize(4);
- mesh_tangents.resize(16);
- mesh_colors.resize(4);
- mesh_uvs.resize(4);
-
- // create basic mesh and store format information
- for (int i = 0; i < 4; i++) {
- mesh_normals.write()[i] = Vector3(0.0, 0.0, 0.0);
- mesh_tangents.write()[i * 4 + 0] = 0.0;
- mesh_tangents.write()[i * 4 + 1] = 0.0;
- mesh_tangents.write()[i * 4 + 2] = 0.0;
- mesh_tangents.write()[i * 4 + 3] = 0.0;
- mesh_colors.write()[i] = Color(1.0, 1.0, 1.0, 1.0);
- mesh_uvs.write()[i] = Vector2(0.0, 0.0);
- mesh_vertices.write()[i] = Vector2(0.0, 0.0);
- }
-
- Array mesh_array;
- mesh_array.resize(VS::ARRAY_MAX);
- mesh_array[VS::ARRAY_VERTEX] = mesh_vertices;
- mesh_array[VS::ARRAY_NORMAL] = mesh_normals;
- mesh_array[VS::ARRAY_TANGENT] = mesh_tangents;
- mesh_array[VS::ARRAY_COLOR] = mesh_colors;
- mesh_array[VS::ARRAY_TEX_UV] = mesh_uvs;
-
- VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VS::PRIMITIVE_TRIANGLE_FAN, mesh_array);
- const uint32_t surface_format = VS::get_singleton()->mesh_surface_get_format(mesh, 0);
- const int surface_vertex_len = VS::get_singleton()->mesh_surface_get_array_len(mesh, 0);
- const int surface_index_len = VS::get_singleton()->mesh_surface_get_array_index_len(mesh, 0);
-
- mesh_buffer = VS::get_singleton()->mesh_surface_get_array(mesh, 0);
- mesh_stride = VS::get_singleton()->mesh_surface_make_offsets_from_format(surface_format, surface_vertex_len, surface_index_len, mesh_surface_offsets);
+ immediate = VisualServer::get_singleton()->immediate_create();
+ set_base(immediate);
}
SpriteBase3D::~SpriteBase3D() {
- VisualServer::get_singleton()->free(mesh);
- VisualServer::get_singleton()->free(material);
+ VisualServer::get_singleton()->free(immediate);
}
///////////////////////////////////////////
void Sprite3D::_draw() {
- set_base(RID());
+ RID immediate = get_immediate();
+ VS::get_singleton()->immediate_clear(immediate);
if (!texture.is_valid())
return;
Vector2 tsize = texture->get_size();
@@ -531,6 +480,11 @@ void Sprite3D::_draw() {
tangent = Plane(1, 0, 0, 1);
}
+ RID mat = SpatialMaterial::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == SpatialMaterial::BILLBOARD_ENABLED, get_billboard_mode() == SpatialMaterial::BILLBOARD_FIXED_Y);
+ VS::get_singleton()->immediate_set_material(immediate, mat);
+
+ VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLE_FAN, texture->get_rid());
+
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
@@ -550,63 +504,25 @@ void Sprite3D::_draw() {
AABB aabb;
- // Buffer is using default compression, so everything except position is compressed
- PoolVector<uint8_t>::Write write_buffer = mesh_buffer.write();
-
- int8_t v_normal[4] = {
- (int8_t)CLAMP(normal.x * 127, -128, 127),
- (int8_t)CLAMP(normal.y * 127, -128, 127),
- (int8_t)CLAMP(normal.z * 127, -128, 127),
- 0,
- };
-
- int8_t v_tangent[4] = {
- (int8_t)CLAMP(tangent.normal.x * 127, -128, 127),
- (int8_t)CLAMP(tangent.normal.y * 127, -128, 127),
- (int8_t)CLAMP(tangent.normal.z * 127, -128, 127),
- (int8_t)CLAMP(tangent.d * 127, -128, 127)
- };
-
- uint8_t v_color[4] = {
- (uint8_t)CLAMP(int(color.r * 255.0), 0, 255),
- (uint8_t)CLAMP(int(color.g * 255.0), 0, 255),
- (uint8_t)CLAMP(int(color.b * 255.0), 0, 255),
- (uint8_t)CLAMP(int(color.a * 255.0), 0, 255)
- };
-
for (int i = 0; i < 4; i++) {
+ VS::get_singleton()->immediate_normal(immediate, normal);
+ VS::get_singleton()->immediate_tangent(immediate, tangent);
+ VS::get_singleton()->immediate_color(immediate, color);
+ VS::get_singleton()->immediate_uv(immediate, uvs[i]);
+
Vector3 vtx;
vtx[x_axis] = vertices[i][0];
vtx[y_axis] = vertices[i][1];
+ VS::get_singleton()->immediate_vertex(immediate, vtx);
if (i == 0) {
aabb.position = vtx;
aabb.size = Vector3();
} else {
aabb.expand_to(vtx);
}
-
- uint16_t v_uv[2] = { Math::make_half_float(uvs[i].x), Math::make_half_float(uvs[i].y) };
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_VERTEX]], &vertices[i], sizeof(float) * 2);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_NORMAL]], v_normal, 4);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TANGENT]], v_tangent, 4);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_COLOR]], v_color, 4);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TEX_UV]], v_uv, 2 * 2);
}
-
- write_buffer.release();
-
- RID mesh = get_mesh();
- VS::get_singleton()->mesh_surface_update_region(mesh, 0, 0, mesh_buffer);
-
- VS::get_singleton()->mesh_set_custom_aabb(mesh, aabb);
set_aabb(aabb);
-
- set_base(mesh);
-
- RID mat = SpatialMaterial::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == SpatialMaterial::BILLBOARD_ENABLED, get_billboard_mode() == SpatialMaterial::BILLBOARD_FIXED_Y);
- VS::get_singleton()->material_set_shader(get_material(), VS::get_singleton()->material_get_shader(mat));
- VS::get_singleton()->material_set_param(get_material(), "texture_albedo", texture->get_rid());
- VS::get_singleton()->instance_set_surface_material(get_instance(), 0, get_material());
+ VS::get_singleton()->immediate_end(immediate);
}
void Sprite3D::set_texture(const Ref<Texture> &p_texture) {
@@ -800,7 +716,8 @@ Sprite3D::Sprite3D() {
void AnimatedSprite3D::_draw() {
- set_base(RID());
+ RID immediate = get_immediate();
+ VS::get_singleton()->immediate_clear(immediate);
if (frames.is_null()) {
return;
@@ -891,6 +808,12 @@ void AnimatedSprite3D::_draw() {
tangent = Plane(1, 0, 0, -1);
}
+ RID mat = SpatialMaterial::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == SpatialMaterial::BILLBOARD_ENABLED, get_billboard_mode() == SpatialMaterial::BILLBOARD_FIXED_Y);
+
+ VS::get_singleton()->immediate_set_material(immediate, mat);
+
+ VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLE_FAN, texture->get_rid());
+
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
@@ -910,63 +833,25 @@ void AnimatedSprite3D::_draw() {
AABB aabb;
- // Buffer is using default compression, so everything except position is compressed
- PoolVector<uint8_t>::Write write_buffer = mesh_buffer.write();
-
- int8_t v_normal[4] = {
- (int8_t)CLAMP(normal.x * 127, -128, 127),
- (int8_t)CLAMP(normal.y * 127, -128, 127),
- (int8_t)CLAMP(normal.z * 127, -128, 127),
- 0,
- };
-
- int8_t v_tangent[4] = {
- (int8_t)CLAMP(tangent.normal.x * 127, -128, 127),
- (int8_t)CLAMP(tangent.normal.y * 127, -128, 127),
- (int8_t)CLAMP(tangent.normal.z * 127, -128, 127),
- (int8_t)CLAMP(tangent.d * 127, -128, 127)
- };
-
- uint8_t v_color[4] = {
- (uint8_t)CLAMP(int(color.r * 255.0), 0, 255),
- (uint8_t)CLAMP(int(color.g * 255.0), 0, 255),
- (uint8_t)CLAMP(int(color.b * 255.0), 0, 255),
- (uint8_t)CLAMP(int(color.a * 255.0), 0, 255)
- };
-
for (int i = 0; i < 4; i++) {
+ VS::get_singleton()->immediate_normal(immediate, normal);
+ VS::get_singleton()->immediate_tangent(immediate, tangent);
+ VS::get_singleton()->immediate_color(immediate, color);
+ VS::get_singleton()->immediate_uv(immediate, uvs[i]);
+
Vector3 vtx;
vtx[x_axis] = vertices[i][0];
vtx[y_axis] = vertices[i][1];
+ VS::get_singleton()->immediate_vertex(immediate, vtx);
if (i == 0) {
aabb.position = vtx;
aabb.size = Vector3();
} else {
aabb.expand_to(vtx);
}
-
- uint16_t v_uv[2] = { Math::make_half_float(uvs[i].x), Math::make_half_float(uvs[i].y) };
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_VERTEX]], &vertices[i], sizeof(float) * 2);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_NORMAL]], v_normal, 4);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TANGENT]], v_tangent, 4);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_COLOR]], v_color, 4);
- copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TEX_UV]], v_uv, 2 * 2);
}
-
- write_buffer.release();
-
- RID mesh = get_mesh();
- VS::get_singleton()->mesh_surface_update_region(mesh, 0, 0, mesh_buffer);
-
- VS::get_singleton()->mesh_set_custom_aabb(mesh, aabb);
set_aabb(aabb);
-
- set_base(mesh);
-
- RID mat = SpatialMaterial::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == SpatialMaterial::BILLBOARD_ENABLED, get_billboard_mode() == SpatialMaterial::BILLBOARD_FIXED_Y);
- VS::get_singleton()->material_set_shader(get_material(), VS::get_singleton()->material_get_shader(mat));
- VS::get_singleton()->material_set_param(get_material(), "texture_albedo", texture->get_rid());
- VS::get_singleton()->instance_set_surface_material(get_instance(), 0, get_material());
+ VS::get_singleton()->immediate_end(immediate);
}
void AnimatedSprite3D::_validate_property(PropertyInfo &property) const {
diff --git a/scene/3d/sprite_3d.h b/scene/3d/sprite_3d.h
index 72416e8922..ddbade147c 100644
--- a/scene/3d/sprite_3d.h
+++ b/scene/3d/sprite_3d.h
@@ -76,8 +76,7 @@ private:
float pixel_size;
AABB aabb;
- RID mesh;
- RID material;
+ RID immediate;
bool flags[FLAG_MAX];
AlphaCutMode alpha_cut;
@@ -93,13 +92,7 @@ protected:
static void _bind_methods();
virtual void _draw() = 0;
_FORCE_INLINE_ void set_aabb(const AABB &p_aabb) { aabb = p_aabb; }
- _FORCE_INLINE_ RID &get_mesh() { return mesh; }
- _FORCE_INLINE_ RID &get_material() { return material; }
-
- uint32_t mesh_surface_offsets[VS::ARRAY_MAX];
- PoolByteArray mesh_buffer;
- uint32_t mesh_stride;
-
+ _FORCE_INLINE_ RID &get_immediate() { return immediate; }
void _queue_update();
public:
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index bb9c3697d4..ab4dbb758a 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -1838,8 +1838,6 @@ RID SpatialMaterial::get_material_rid_for_2d(bool p_shaded, bool p_transparent,
}
materials_for_2d[version] = material;
- // flush before using so we can access the shader right away
- flush_changes();
return materials_for_2d[version]->get_rid();
}
--
2.25.1 |
I got the following error message when running the example scene:
|
Okay, I have figured it out. PR coming soon. |
Fixed by #41314. |
@clayjohn Excellent, the PR fixed for me this issue!
This is comming from the project-settings – the icon and the splash-image. Probably another bug, html export shouldn't process those images. With the second example billboard-test2.zip
Not sure if the settings are ignored or the warning is bogus. |
Not sure why but I still have problems with this in my game, more info on that can be found on this issue jayypluss/BreezyWave#24. |
@jayypluss I don't think this issue is related to the problem you describe in jayypluss/BreezyWave#24 Could you please open a bug report with detailed information about your system and scene so we can track the issue there? |
Godot version:
OS/device including version:
Ubuntu 20.04 LTS, Chrome, Firefox; stable
Issue description:
3.2.2 correct:
3.2.3.rc3 broken:
Minimal reproduction project:
billboard-test.zip
The text was updated successfully, but these errors were encountered: