Commit: a830280688b43e9c73e5a16dbe9d180720eb624f Author: Sergey Sharybin Date: Sun May 22 18:24:53 2016 +0200 Branches: master https://developer.blender.org/rBa830280688b43e9c73e5a16dbe9d180720eb624f
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 =================================================================== M source/blender/blenkernel/intern/DerivedMesh.c M source/blender/gpu/intern/gpu_buffers.c M source/blender/gpu/shaders/gpu_shader_material.glsl M source/blender/makesdna/DNA_customdata_types.h M source/blender/nodes/shader/nodes/node_shader_attribute.c =================================================================== diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 1bfc3d9..9c500fa 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) { diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 072ff52..09d0a38 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -823,7 +823,7 @@ void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numda for (i = 0; i < numdata; i++) { glEnableVertexAttribArray(data[i].index); glVertexAttribPointer(data[i].index, data[i].size, data[i].type, - GL_FALSE, elementsize, BUFFER_OFFSET(offset)); + GL_TRUE, elementsize, BUFFER_OFFSET(offset)); offset += data[i].size * GPU_typesize(data[i].type); attribData[i].index = data[i].index; diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index dcb888b..be7228b 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2573,11 +2573,11 @@ void node_gamma(vec4 col, float gamma, out vec4 outcol) /* geometry */ -void node_attribute(vec3 attr_uv, out vec4 outcol, out vec3 outvec, out float outf) +void node_attribute(vec3 attr, out vec4 outcol, out vec3 outvec, out float outf) { - outcol = vec4(attr_uv, 1.0); - outvec = attr_uv; - outf = (attr_uv.x + attr_uv.y + attr_uv.z)/3.0; + outcol = vec4(attr, 1.0); + outvec = attr; + outf = (attr.x + attr.y + attr.z)/3.0; } void node_uvmap(vec3 attr_uv, out vec3 outvec) diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 3807bb2..2d1ffaa 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -75,6 +75,12 @@ typedef struct CustomData { /* CustomData.type */ typedef enum CustomDataType { + /* Used by GLSL attributes in the cases when we need a delayed CD type + * assignment (in the cases when we don't know in advance which layer + * we are addressing). + */ + CD_AUTO_FROM_NAME = -1, + CD_MVERT = 0, #ifdef DNA_DEPRECATED CD_MSTICKY = 1, /* DEPRECATED */ diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.c b/source/blender/nodes/shader/nodes/node_shader_attribute.c index 61bdfb3..0a69593 100644 --- a/source/blender/nodes/shader/nodes/node_shader_attribute.c +++ b/source/blender/nodes/shader/nodes/node_shader_attribute.c @@ -45,9 +45,9 @@ static void node_shader_init_attribute(bNodeTree *UNUSED(ntree), bNode *node) static int node_shader_gpu_attribute(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { NodeShaderAttribute *attr = node->storage; - GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, attr->name); + GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name); - return GPU_stack_link(mat, "node_attribute", in, out, mtface); + return GPU_stack_link(mat, "node_attribute", in, out, cd_attr); } /* node type definition */ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
