diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-22 19:24:53 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-23 11:23:43 +0300 |
commit | a830280688b43e9c73e5a16dbe9d180720eb624f (patch) | |
tree | 3db9db2e88cd465af655f9346f58c3b97efebd78 /source/blender/blenkernel | |
parent | a2669b0cbff0dc02729a7246ac29642aca84929e (diff) |
Support Vertex Color in GLSL viewport for Cycles
The title says it all actually.
Added special custom data type, because we don't know in advance
whether we're referencing UV or Color layer. Also made it so vertex
attributes are normalized.
TODO: Border render in viewport ignores the normalization of the
attribute array for some reason, will be looked into still.
Reviewers: mont29, brecht, campbellbarton
Reviewed By: brecht, campbellbarton
Differential Revision: https://developer.blender.org/D2022
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 70 |
1 files changed, 52 insertions, 18 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 1bfc3d90730..9c500fad2ca 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -3629,12 +3629,41 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, dm->calcLoopTangents(dm, false, (const char (*)[MAX_NAME])tangent_names, tangent_names_count); for (b = 0; b < gattribs->totlayer; b++) { - if (gattribs->layer[b].type == CD_MTFACE) { + int type = gattribs->layer[b].type; + layer = -1; + if (type == CD_AUTO_FROM_NAME) { + /* We need to deduct what exact layer is used. + * + * We do it based on the specified name. + */ + if (gattribs->layer[b].name[0]) { + layer = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, gattribs->layer[b].name); + type = CD_TANGENT; + if (layer == -1) { + layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, gattribs->layer[b].name); + type = CD_MCOL; + } + if (layer == -1) { + layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV, gattribs->layer[b].name); + type = CD_MTFACE; + } + if (layer == -1) { + continue; + } + } + else { + /* Fall back to the UV layer, which matches old behavior. */ + type = CD_MTFACE; + } + } + if (type == CD_MTFACE) { /* uv coordinates */ - if (gattribs->layer[b].name[0]) - layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV, gattribs->layer[b].name); - else - layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV); + if (layer == -1) { + if (gattribs->layer[b].name[0]) + layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV, gattribs->layer[b].name); + else + layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV); + } a = attribs->tottface++; @@ -3650,11 +3679,13 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, attribs->tface[a].gl_index = gattribs->layer[b].glindex; attribs->tface[a].gl_texco = gattribs->layer[b].gltexco; } - else if (gattribs->layer[b].type == CD_MCOL) { - if (gattribs->layer[b].name[0]) - layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, gattribs->layer[b].name); - else - layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL); + else if (type == CD_MCOL) { + if (layer == -1) { + if (gattribs->layer[b].name[0]) + layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, gattribs->layer[b].name); + else + layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL); + } a = attribs->totmcol++; @@ -3670,13 +3701,14 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, attribs->mcol[a].gl_index = gattribs->layer[b].glindex; } - else if (gattribs->layer[b].type == CD_TANGENT) { + else if (type == CD_TANGENT) { /* note, even with 'is_editmesh' this uses the derived-meshes loop data */ - - if (gattribs->layer[b].name[0]) - layer = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, gattribs->layer[b].name); - else - layer = CustomData_get_active_layer_index(&dm->loopData, CD_TANGENT); + if (layer == -1) { + if (gattribs->layer[b].name[0]) + layer = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, gattribs->layer[b].name); + else + layer = CustomData_get_active_layer_index(&dm->loopData, CD_TANGENT); + } a = attribs->tottang++; @@ -3691,9 +3723,11 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, attribs->tang[a].gl_index = gattribs->layer[b].glindex; } - else if (gattribs->layer[b].type == CD_ORCO) { + else if (type == CD_ORCO) { /* original coordinates */ - layer = CustomData_get_layer_index(vdata, CD_ORCO); + if (layer == -1) { + layer = CustomData_get_layer_index(vdata, CD_ORCO); + } attribs->totorco = 1; if (layer != -1) { |