Fix T53750: Mirrored UV have bad tangent space
I feel silly because it was my fault all along! (see the WATCH IT warning)
This commit is contained in:
parent
0c987aa7ac
commit
735ad525a6
Notes:
blender-bot
2023-10-13 01:54:23 +02:00
Referenced by issue #53750, Mirrored UV have bad tangent space
|
@ -2418,7 +2418,6 @@ void DRW_mesh_batch_cache_free(Mesh *me)
|
|||
static GPUVertBuf *mesh_batch_cache_get_tri_shading_data(MeshRenderData *rdata, MeshBatchCache *cache)
|
||||
{
|
||||
BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
|
||||
#define USE_COMP_MESH_DATA
|
||||
|
||||
if (cache->shaded_triangles_data == NULL) {
|
||||
const uint uv_len = rdata->cd.layers.uv_len;
|
||||
|
@ -2466,6 +2465,8 @@ static GPUVertBuf *mesh_batch_cache_get_tri_shading_data(MeshRenderData *rdata,
|
|||
cache->auto_layer_names = MEM_callocN(auto_names_len * sizeof(char), "Auto layer name buf");
|
||||
cache->auto_layer_is_srgb = MEM_mallocN(cache->auto_layer_len * sizeof(int), "Auto layer value buf");
|
||||
|
||||
#define USE_COMP_MESH_DATA
|
||||
|
||||
for (uint i = 0; i < uv_len; i++) {
|
||||
/* UV */
|
||||
const char *attrib_name = mesh_render_data_uv_layer_uuid_get(rdata, i);
|
||||
|
@ -2491,13 +2492,11 @@ static GPUVertBuf *mesh_batch_cache_get_tri_shading_data(MeshRenderData *rdata,
|
|||
|
||||
for (uint i = 0; i < tangent_len; i++) {
|
||||
const char *attrib_name = mesh_render_data_tangent_layer_uuid_get(rdata, i);
|
||||
/* WATCH IT : only specifying 3 component instead of 4 (4th is sign).
|
||||
* That may cause some problem but I could not make it to fail (fclem) */
|
||||
#ifdef USE_COMP_MESH_DATA
|
||||
/* Tangents need more precision than 10_10_10 */
|
||||
tangent_id[i] = GPU_vertformat_attr_add(format, attrib_name, GPU_COMP_I16, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
tangent_id[i] = GPU_vertformat_attr_add(format, attrib_name, GPU_COMP_I16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
|
||||
#else
|
||||
tangent_id[i] = GPU_vertformat_attr_add(format, attrib_name, GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
|
||||
tangent_id[i] = GPU_vertformat_attr_add(format, attrib_name, GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
||||
#endif
|
||||
|
||||
if (i == rdata->cd.layers.tangent_active) {
|
||||
|
@ -2576,7 +2575,11 @@ static GPUVertBuf *mesh_batch_cache_get_tri_shading_data(MeshRenderData *rdata,
|
|||
float (*layer_data)[4] = rdata->cd.layers.tangent[j];
|
||||
for (uint t = 0; t < 3; t++) {
|
||||
const float *elem = layer_data[BM_elem_index_get(bm_looptri[t])];
|
||||
normal_float_to_short_v3(GPU_vertbuf_raw_step(&tangent_step[j]), elem);
|
||||
#ifdef USE_COMP_MESH_DATA
|
||||
normal_float_to_short_v4(GPU_vertbuf_raw_step(&tangent_step[j]), elem);
|
||||
#else
|
||||
copy_v4_v4(GPU_vertbuf_raw_step(&tangent_step[j]), elem);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/* VCOLs */
|
||||
|
@ -2607,9 +2610,9 @@ static GPUVertBuf *mesh_batch_cache_get_tri_shading_data(MeshRenderData *rdata,
|
|||
for (uint t = 0; t < 3; t++) {
|
||||
const float *elem = layer_data[mlt->tri[t]];
|
||||
#ifdef USE_COMP_MESH_DATA
|
||||
normal_float_to_short_v3(GPU_vertbuf_raw_step(&tangent_step[j]), elem);
|
||||
normal_float_to_short_v4(GPU_vertbuf_raw_step(&tangent_step[j]), elem);
|
||||
#else
|
||||
copy_v3_v3(GPU_vertbuf_raw_step(&tangent_step[j]), elem);
|
||||
copy_v4_v4(GPU_vertbuf_raw_step(&tangent_step[j]), elem);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue