Merge pull request #84576 from clayjohn/mesh-tangents-always
Create tangent array if mesh created without tangents
This commit is contained in:
@@ -166,7 +166,7 @@ void ImmediateMesh::surface_end() {
|
||||
normal_tangent_stride += sizeof(uint32_t);
|
||||
}
|
||||
uint32_t tangent_offset = 0;
|
||||
if (uses_tangents) {
|
||||
if (uses_tangents || uses_normals) {
|
||||
format |= ARRAY_FORMAT_TANGENT;
|
||||
tangent_offset = vertex_stride * vertices.size() + normal_tangent_stride;
|
||||
normal_tangent_stride += sizeof(uint32_t);
|
||||
@@ -202,9 +202,16 @@ void ImmediateMesh::surface_end() {
|
||||
|
||||
*normal = value;
|
||||
}
|
||||
if (uses_tangents) {
|
||||
if (uses_tangents || uses_normals) {
|
||||
uint32_t *tangent = (uint32_t *)&surface_vertex_ptr[i * normal_tangent_stride + tangent_offset];
|
||||
Vector2 t = tangents[i].normal.octahedron_tangent_encode(tangents[i].d);
|
||||
Vector2 t;
|
||||
if (uses_tangents) {
|
||||
t = tangents[i].normal.octahedron_tangent_encode(tangents[i].d);
|
||||
} else {
|
||||
Vector3 tan = Vector3(0.0, 1.0, 0.0).cross(normals[i].normalized());
|
||||
t = tan.octahedron_tangent_encode(1.0);
|
||||
}
|
||||
|
||||
uint32_t value = 0;
|
||||
value |= (uint16_t)CLAMP(t.x * 65535, 0, 65535);
|
||||
value |= (uint16_t)CLAMP(t.y * 65535, 0, 65535) << 16;
|
||||
|
||||
Reference in New Issue
Block a user