Fix T65534 Eevee don't respect active UVmap

This commit is contained in:
Clément Foucault 2019-07-08 13:35:55 +02:00
parent 8a7c2c4192
commit 1715c396e4
Notes: blender-bot 2023-02-14 08:33:26 +01:00
Referenced by issue #65534, Eevee don't respect active UVmap
6 changed files with 74 additions and 24 deletions

View File

@ -2,14 +2,14 @@
#ifndef HAIR_SHADER
in vec3 pos;
in vec3 nor;
in vec2 u; /* active texture layer */
in vec2 au; /* active texture layer */
# ifdef V3D_SHADING_VERTEX_COLOR
in vec3 c; /* active color */
in vec3 ac; /* active color */
# endif
# define uv u
# define uv au
#else /* HAIR_SHADER */
# ifdef V3D_SHADING_TEXTURE_COLOR
uniform samplerBuffer u; /* active texture layer */
uniform samplerBuffer au; /* active texture layer */
# endif
flat out float hair_rand;
#endif /* HAIR_SHADER */
@ -58,7 +58,7 @@ void main()
{
#ifdef HAIR_SHADER
# ifdef V3D_SHADING_TEXTURE_COLOR
vec2 uv = hair_get_customdata_vec2(u);
vec2 uv = hair_get_customdata_vec2(au);
# endif
float time, thick_time, thickness;
vec3 world_pos, tan, binor;
@ -86,7 +86,7 @@ void main()
#ifdef V3D_SHADING_VERTEX_COLOR
# ifndef HAIR_SHADER
vertexColor = srgb_to_linear_attr(c);
vertexColor = srgb_to_linear_attr(ac);
# endif
#endif

View File

@ -246,17 +246,21 @@ typedef struct MeshRenderData {
struct {
struct {
MLoopUV **uv;
MLoopCol **vcol;
float (**tangent)[4];
int uv_len;
int uv_active;
int uv_render;
int uv_mask_active;
MLoopCol **vcol;
int vcol_len;
int vcol_active;
int vcol_render;
float (**tangent)[4];
int tangent_len;
int tangent_active;
int tangent_render;
bool *auto_vcol;
} layers;
@ -471,7 +475,7 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
case CD_MTFACE: {
if (layer == -1) {
layer = (name[0] != '\0') ? CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) :
CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
CustomData_get_render_layer(cd_ldata, CD_MLOOPUV);
}
if (layer != -1) {
cd_used.uv |= (1 << layer);
@ -481,11 +485,11 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
case CD_TANGENT: {
if (layer == -1) {
layer = (name[0] != '\0') ? CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) :
CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
CustomData_get_render_layer(cd_ldata, CD_MLOOPUV);
/* Only fallback to orco (below) when we have no UV layers, see: T56545 */
if (layer == -1 && name[0] != '\0') {
layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
layer = CustomData_get_render_layer(cd_ldata, CD_MLOOPUV);
}
}
if (layer != -1) {
@ -501,7 +505,7 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
case CD_MCOL: {
if (layer == -1) {
layer = (name[0] != '\0') ? CustomData_get_named_layer(cd_ldata, CD_MLOOPCOL, name) :
CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL);
CustomData_get_render_layer(cd_ldata, CD_MLOOPCOL);
}
if (layer != -1) {
cd_used.vcol |= (1 << layer);
@ -885,9 +889,12 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
}
rdata->cd.layers.uv_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
rdata->cd.layers.uv_render = CustomData_get_render_layer(cd_ldata, CD_MLOOPUV);
rdata->cd.layers.uv_mask_active = CustomData_get_stencil_layer(cd_ldata, CD_MLOOPUV);
rdata->cd.layers.vcol_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL);
rdata->cd.layers.vcol_render = CustomData_get_render_layer(cd_ldata, CD_MLOOPCOL);
rdata->cd.layers.tangent_active = rdata->cd.layers.uv_active;
rdata->cd.layers.tangent_render = rdata->cd.layers.uv_render;
#define CD_VALIDATE_ACTIVE_LAYER(active_index, used) \
if ((active_index != -1) && (used & (1 << active_index)) == 0) { \
@ -896,9 +903,12 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
((void)0)
CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.uv_active, cd_used->uv);
CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.uv_render, cd_used->uv);
CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.uv_mask_active, cd_used->uv);
CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.tangent_active, cd_used->tan);
CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.tangent_render, cd_used->tan);
CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.vcol_active, cd_used->vcol);
CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.vcol_render, cd_used->vcol);
#undef CD_VALIDATE_ACTIVE_LAYER
@ -982,6 +992,7 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
* NOTE 2 : Replicate changes to code_generate_vertex_new() in gpu_codegen.c */
if (rdata->cd.layers.vcol_len != 0) {
int act_vcol = rdata->cd.layers.vcol_active;
int ren_vcol = rdata->cd.layers.vcol_render;
for (int i_src = 0, i_dst = 0; i_src < cd_layers_src.vcol_len; i_src++, i_dst++) {
if ((cd_used->vcol & (1 << i_src)) == 0) {
/* This is a non-used VCol slot. Skip. */
@ -989,6 +1000,9 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
if (rdata->cd.layers.vcol_active >= i_src) {
act_vcol--;
}
if (rdata->cd.layers.vcol_render >= i_src) {
ren_vcol--;
}
}
else {
const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPCOL, i_src);
@ -1011,10 +1025,13 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
}
}
}
/* Actual active Vcol slot inside vcol layers used for shading. */
if (rdata->cd.layers.vcol_active != -1) {
/* Actual active Vcol slot inside vcol layers used for shading. */
rdata->cd.layers.vcol_active = act_vcol;
}
if (rdata->cd.layers.vcol_render != -1) {
rdata->cd.layers.vcol_render = ren_vcol;
}
}
/* Start Fresh */
@ -1022,11 +1039,15 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
CustomData_free_layers(cd_ldata, CD_MLOOPTANGENT, rdata->loop_len);
if (rdata->cd.layers.uv_len != 0) {
int ren_uv = rdata->cd.layers.uv_render;
int act_uv = rdata->cd.layers.uv_active;
for (int i_src = 0, i_dst = 0; i_src < cd_layers_src.uv_len; i_src++, i_dst++) {
if ((cd_used->uv & (1 << i_src)) == 0) {
/* This is a non-used UV slot. Skip. */
i_dst--;
if (rdata->cd.layers.uv_render >= i_src) {
ren_uv--;
}
if (rdata->cd.layers.uv_active >= i_src) {
act_uv--;
}
@ -1045,8 +1066,11 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
rdata->cd.uuid.auto_mix[i_dst], sizeof(*rdata->cd.uuid.auto_mix), "a%u", hash);
}
}
/* Actual active / Render UV slot inside uv layers used for shading. */
if (rdata->cd.layers.uv_render != -1) {
rdata->cd.layers.uv_render = ren_uv;
}
if (rdata->cd.layers.uv_active != -1) {
/* Actual active UV slot inside uv layers used for shading. */
rdata->cd.layers.uv_active = act_uv;
}
}
@ -1145,9 +1169,13 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
int i_dst = 0;
int act_tan = rdata->cd.layers.tangent_active;
int ren_tan = rdata->cd.layers.tangent_render;
for (int i_src = 0; i_src < cd_layers_src.uv_len; i_src++, i_dst++) {
if ((cd_used->tan & (1 << i_src)) == 0) {
i_dst--;
if (rdata->cd.layers.tangent_render >= i_src) {
ren_tan--;
}
if (rdata->cd.layers.tangent_active >= i_src) {
act_tan--;
}
@ -1173,10 +1201,13 @@ static MeshRenderData *mesh_render_data_create_ex(Mesh *me,
}
}
}
/* Actual active rangent slot inside uv layers used for shading. */
if (rdata->cd.layers.tangent_active != -1) {
/* Actual active UV slot inside uv layers used for shading. */
rdata->cd.layers.tangent_active = act_tan;
}
if (rdata->cd.layers.tangent_render != -1) {
rdata->cd.layers.tangent_render = ren_tan;
}
if (cd_used->tan_orco != 0) {
const char *name = CustomData_get_layer_name(&rdata->cd.output.ldata, CD_TANGENT, i_dst);
@ -3258,9 +3289,12 @@ static void mesh_create_loop_uv_and_tan(MeshRenderData *rdata, GPUVertBuf *vbo)
attr_name = mesh_render_data_uv_auto_layer_uuid_get(rdata, i);
GPU_vertformat_alias_add(&format, attr_name);
if (i == rdata->cd.layers.uv_active) {
if (i == rdata->cd.layers.uv_render) {
GPU_vertformat_alias_add(&format, "u");
}
if (i == rdata->cd.layers.uv_active) {
GPU_vertformat_alias_add(&format, "au");
}
if (i == rdata->cd.layers.uv_mask_active) {
GPU_vertformat_alias_add(&format, "mu");
}
@ -3274,9 +3308,12 @@ static void mesh_create_loop_uv_and_tan(MeshRenderData *rdata, GPUVertBuf *vbo)
#else
tangent_id[i] = GPU_vertformat_attr_add(&format, attr_name, GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
#endif
if (i == rdata->cd.layers.tangent_active) {
if (i == rdata->cd.layers.tangent_render) {
GPU_vertformat_alias_add(&format, "t");
}
if (i == rdata->cd.layers.tangent_active) {
GPU_vertformat_alias_add(&format, "at");
}
}
/* HACK: Create a dummy attribute in case there is no valid UV/tangent layer. */
@ -3375,9 +3412,12 @@ static void mesh_create_loop_vcol(MeshRenderData *rdata, GPUVertBuf *vbo)
attr_name = mesh_render_data_vcol_auto_layer_uuid_get(rdata, i);
GPU_vertformat_alias_add(&format, attr_name);
}
if (i == rdata->cd.layers.vcol_active) {
if (i == rdata->cd.layers.vcol_render) {
GPU_vertformat_alias_add(&format, "c");
}
if (i == rdata->cd.layers.vcol_active) {
GPU_vertformat_alias_add(&format, "ac");
}
}
GPU_vertbuf_init_with_format(vbo, &format);

View File

@ -835,7 +835,9 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit
ParticleHairCache *cache)
{
int active_uv = 0;
int render_uv = 0;
int active_col = 0;
int render_col = 0;
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
@ -843,10 +845,12 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit
if (CustomData_has_layer(&psmd->mesh_final->ldata, CD_MLOOPUV)) {
cache->num_uv_layers = CustomData_number_of_layers(&psmd->mesh_final->ldata, CD_MLOOPUV);
active_uv = CustomData_get_active_layer(&psmd->mesh_final->ldata, CD_MLOOPUV);
render_uv = CustomData_get_render_layer(&psmd->mesh_final->ldata, CD_MLOOPUV);
}
if (CustomData_has_layer(&psmd->mesh_final->ldata, CD_MLOOPCOL)) {
cache->num_col_layers = CustomData_number_of_layers(&psmd->mesh_final->ldata, CD_MLOOPCOL);
active_col = CustomData_get_active_layer(&psmd->mesh_final->ldata, CD_MLOOPCOL);
render_col = CustomData_get_render_layer(&psmd->mesh_final->ldata, CD_MLOOPCOL);
}
}
@ -897,7 +901,10 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit
BLI_snprintf(cache->uv_layer_names[i][n++], MAX_LAYER_NAME_LEN, "a%u", hash);
if (i == active_uv) {
BLI_strncpy(cache->uv_layer_names[i][n], "u", MAX_LAYER_NAME_LEN);
BLI_strncpy(cache->uv_layer_names[i][n++], "au", MAX_LAYER_NAME_LEN);
}
if (i == render_uv) {
BLI_strncpy(cache->uv_layer_names[i][n++], "u", MAX_LAYER_NAME_LEN);
}
}
/* Vertex colors */
@ -917,7 +924,10 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit
}
if (i == active_col) {
BLI_strncpy(cache->col_layer_names[i][n], "c", MAX_LAYER_NAME_LEN);
BLI_strncpy(cache->col_layer_names[i][n++], "ac", MAX_LAYER_NAME_LEN);
}
if (i == render_col) {
BLI_strncpy(cache->col_layer_names[i][n++], "c", MAX_LAYER_NAME_LEN);
}
}

View File

@ -24,7 +24,7 @@
#ifndef __DRAW_HAIR_PRIVATE_H__
#define __DRAW_HAIR_PRIVATE_H__
#define MAX_LAYER_NAME_CT 3 /* u0123456789, u, a0123456789 */
#define MAX_LAYER_NAME_CT 4 /* u0123456789, u, au, a0123456789 */
#define MAX_LAYER_NAME_LEN DECIMAL_DIGITS_BOUND(uint) + 2
#define MAX_THICKRES 2 /* see eHairType */
#define MAX_HAIR_SUBDIV 4 /* see hair_subdiv rna */

View File

@ -1,6 +1,6 @@
in vec3 pos;
in vec3 c; /* active color */
in vec3 ac; /* active color */
out vec3 finalColor;
@ -17,7 +17,7 @@ void main()
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
finalColor = srgb_to_linear_attr(c);
finalColor = srgb_to_linear_attr(ac);
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(world_pos);

View File

@ -31,7 +31,7 @@
#include "BLI_assert.h"
#define GPU_VERT_ATTR_MAX_LEN 16
#define GPU_VERT_ATTR_MAX_NAMES 4
#define GPU_VERT_ATTR_MAX_NAMES 5
#define GPU_VERT_ATTR_NAME_AVERAGE_LEN 11
#define GPU_VERT_ATTR_NAMES_BUF_LEN ((GPU_VERT_ATTR_NAME_AVERAGE_LEN + 1) * GPU_VERT_ATTR_MAX_LEN)