Skip to content
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

Use full float UVs in Sprite3D #42537

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions scene/3d/sprite_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ SpriteBase3D::SpriteBase3D() {
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);
VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VS::PRIMITIVE_TRIANGLE_FAN, mesh_array, Array(), VS::ARRAY_COMPRESS_DEFAULT & ~VS::ARRAY_COMPRESS_TEX_UV);
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);

Expand Down Expand Up @@ -551,7 +551,7 @@ void Sprite3D::_draw() {

AABB aabb;

// Buffer is using default compression, so everything except position is compressed
// Everything except position and UV is compressed
PoolVector<uint8_t>::Write write_buffer = mesh_buffer.write();

int8_t v_normal[4] = {
Expand Down Expand Up @@ -585,16 +585,11 @@ void Sprite3D::_draw() {
} else {
aabb.expand_to(vtx);
}
if (mesh_surface_format & VS::ARRAY_COMPRESS_TEX_UV) {
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_TEX_UV]], v_uv, 4);
} else {
float v_uv[2] = { uvs[i].x, uvs[i].y };
copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TEX_UV]], v_uv, 8);
}

float v_vertex[3] = { vtx.x, vtx.y, vtx.z };
float v_uv[2] = { uvs[i].x, uvs[i].y };
copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TEX_UV]], v_uv, 8);

float v_vertex[3] = { vtx.x, vtx.y, vtx.z };
copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3);
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);
Expand Down Expand Up @@ -918,7 +913,7 @@ void AnimatedSprite3D::_draw() {

AABB aabb;

// Buffer is using default compression, so everything except position is compressed
// Everything except position and UV is compressed
PoolVector<uint8_t>::Write write_buffer = mesh_buffer.write();

int8_t v_normal[4] = {
Expand Down Expand Up @@ -953,15 +948,10 @@ void AnimatedSprite3D::_draw() {
aabb.expand_to(vtx);
}

if (mesh_surface_format & VS::ARRAY_COMPRESS_TEX_UV) {
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_TEX_UV]], v_uv, 4);
} else {
float v_uv[2] = { uvs[i].x, uvs[i].y };
copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TEX_UV]], v_uv, 8);
}
float v_vertex[3] = { vtx.x, vtx.y, vtx.z };
float v_uv[2] = { uvs[i].x, uvs[i].y };
copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_TEX_UV]], v_uv, 8);

float v_vertex[3] = { vtx.x, vtx.y, vtx.z };
copymem(&write_buffer[i * mesh_stride + mesh_surface_offsets[VS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3);
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);
Expand Down