Handle 32-bit and 64-bit floats for tangents/weights in RenderingServer
This commit is contained in:
parent
854725f400
commit
93b5606e6c
|
@ -412,13 +412,12 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
|
|||
} break;
|
||||
|
||||
case RS::ARRAY_TANGENT: {
|
||||
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_FLOAT32_ARRAY, ERR_INVALID_PARAMETER);
|
||||
|
||||
Vector<real_t> array = p_arrays[ai];
|
||||
|
||||
Variant::Type type = p_arrays[ai].get_type();
|
||||
ERR_FAIL_COND_V(type != Variant::PACKED_FLOAT32_ARRAY && type != Variant::PACKED_FLOAT64_ARRAY, ERR_INVALID_PARAMETER);
|
||||
if (type == Variant::PACKED_FLOAT32_ARRAY) {
|
||||
Vector<float> array = p_arrays[ai];
|
||||
ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
|
||||
|
||||
const real_t *src = array.ptr();
|
||||
const float *src = array.ptr();
|
||||
|
||||
for (int i = 0; i < p_vertex_array_len; i++) {
|
||||
uint32_t value = 0;
|
||||
|
@ -431,7 +430,22 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
|
|||
|
||||
memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], &value, 4);
|
||||
}
|
||||
} else { // if (type == Variant::PACKED_FLOAT64_ARRAY)
|
||||
Vector<double> array = p_arrays[ai];
|
||||
ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER);
|
||||
const double *src = array.ptr();
|
||||
|
||||
for (int i = 0; i < p_vertex_array_len; i++) {
|
||||
uint32_t value = 0;
|
||||
value |= CLAMP(int((src[i * 4 + 0] * 0.5 + 0.5) * 1023.0), 0, 1023);
|
||||
value |= CLAMP(int((src[i * 4 + 1] * 0.5 + 0.5) * 1023.0), 0, 1023) << 10;
|
||||
value |= CLAMP(int((src[i * 4 + 2] * 0.5 + 0.5) * 1023.0), 0, 1023) << 20;
|
||||
if (src[i * 4 + 3] > 0) {
|
||||
value |= 3 << 30;
|
||||
}
|
||||
memcpy(&vw[p_offsets[ai] + i * p_vertex_stride], &value, 4);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case RS::ARRAY_COLOR: {
|
||||
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_COLOR_ARRAY, ERR_INVALID_PARAMETER);
|
||||
|
@ -543,16 +557,13 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
|
|||
|
||||
} break;
|
||||
case RS::ARRAY_WEIGHTS: {
|
||||
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_FLOAT32_ARRAY, ERR_INVALID_PARAMETER);
|
||||
|
||||
Variant::Type type = p_arrays[ai].get_type();
|
||||
ERR_FAIL_COND_V(type != Variant::PACKED_FLOAT32_ARRAY && type != Variant::PACKED_FLOAT64_ARRAY, ERR_INVALID_PARAMETER);
|
||||
uint32_t bone_count = (p_format & ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? 8 : 4;
|
||||
|
||||
Vector<real_t> array = p_arrays[ai];
|
||||
|
||||
if (type == Variant::PACKED_FLOAT32_ARRAY) {
|
||||
Vector<float> array = p_arrays[ai];
|
||||
ERR_FAIL_COND_V(array.size() != (int32_t)(p_vertex_array_len * bone_count), ERR_INVALID_PARAMETER);
|
||||
|
||||
const real_t *src = array.ptr();
|
||||
|
||||
const float *src = array.ptr();
|
||||
{
|
||||
uint16_t data[8];
|
||||
for (int i = 0; i < p_vertex_array_len; i++) {
|
||||
|
@ -563,7 +574,21 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
|
|||
memcpy(&sw[p_offsets[ai] + i * p_skin_stride], data, 2 * bone_count);
|
||||
}
|
||||
}
|
||||
} else { // if (type == Variant::PACKED_FLOAT64_ARRAY)
|
||||
Vector<double> array = p_arrays[ai];
|
||||
ERR_FAIL_COND_V(array.size() != (int32_t)(p_vertex_array_len * bone_count), ERR_INVALID_PARAMETER);
|
||||
const double *src = array.ptr();
|
||||
{
|
||||
uint16_t data[8];
|
||||
for (int i = 0; i < p_vertex_array_len; i++) {
|
||||
for (uint32_t j = 0; j < bone_count; j++) {
|
||||
data[j] = CLAMP(src[i * bone_count + j] * 65535, 0, 65535);
|
||||
}
|
||||
|
||||
memcpy(&sw[p_offsets[ai] + i * p_skin_stride], data, 2 * bone_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case RS::ARRAY_BONES: {
|
||||
ERR_FAIL_COND_V(p_arrays[ai].get_type() != Variant::PACKED_INT32_ARRAY && p_arrays[ai].get_type() != Variant::PACKED_FLOAT32_ARRAY, ERR_INVALID_PARAMETER);
|
||||
|
|
Loading…
Reference in New Issue