Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From ec416813e75ca4270fc76d781d80151cdd7a480f Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= <foucault.clem@gmail.com>
- Date: Tue, 13 Aug 2019 00:11:36 +0200
- Subject: Eevee: Remove Additive & Multiply Blend mode
- This commit also provide a compatibility code that will convert old
- materials using Additive or Multiply Blend mode to their node equivalent.
- This conversion is only done on outputs that are enabled for eevee.
- diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
- index ced9f4a3153..0c55ae8ee83 100644
- --- a/source/blender/blenkernel/BKE_blender_version.h
- +++ b/source/blender/blenkernel/BKE_blender_version.h
- @@ -27,7 +27,7 @@
- * \note Use #STRINGIFY() rather than defining with quotes.
- */
- #define BLENDER_VERSION 281
- -#define BLENDER_SUBVERSION 1
- +#define BLENDER_SUBVERSION 2
- /** Several breakages with 280, e.g. collections vs layers. */
- #define BLENDER_MINVERSION 280
- #define BLENDER_MINSUBVERSION 0
- diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
- index 15b4f513050..e04be9aaefd 100644
- --- a/source/blender/blenloader/intern/versioning_280.c
- +++ b/source/blender/blenloader/intern/versioning_280.c
- @@ -734,6 +734,108 @@ static void do_versions_seq_alloc_transform_and_crop(ListBase *seqbase)
- }
- }
- +static void do_versions_material_convert_legacy_blend_mode(Material *ma)
- +{
- + bNodeTree *ntree = ma->nodetree;
- + bool need_update = false;
- + char blend_method = ma->blend_method;
- +
- + /* MA_BM_ADD and MA_BM_MULTIPLY */
- + if (ELEM(blend_method, 1, 2)) {
- + ma->blend_method = MA_BM_BLEND;
- + }
- + else {
- + return;
- + }
- +
- + /* We can't do much with material without nodetrees. */
- + if (!ma->use_nodes) {
- + return;
- + }
- +
- + /* Iterate backwards from end so we don't encounter newly added links. */
- + bNodeLink *prevlink;
- + for (bNodeLink *link = ntree->links.last; link; link = prevlink) {
- + prevlink = link->prev;
- +
- + /* Detect link to replace. */
- + bNode *fromnode = link->fromnode;
- + bNodeSocket *fromsock = link->fromsock;
- + bNode *tonode = link->tonode;
- + bNodeSocket *tosock = link->tosock;
- +
- + if (!(tonode->type && STREQ(tosock->identifier, "Surface"))) {
- + continue;
- + }
- +
- + /* Only do outputs that are enabled for EEVEE */
- + if (!ELEM(tonode->custom1, SHD_OUTPUT_ALL, SHD_OUTPUT_EEVEE)) {
- + continue;
- + }
- +
- + /* Replace link with additive setup. */
- + nodeRemLink(ntree, link);
- +
- + if (blend_method == 1 /* MA_BM_ADD */) {
- + bNode *add_node = nodeAddStaticNode(NULL, ntree, SH_NODE_ADD_SHADER);
- + add_node->locx = 0.5f * (fromnode->locx + tonode->locx);
- + add_node->locy = 0.5f * (fromnode->locy + tonode->locy);
- +
- + bNodeSocket *shader1_socket = add_node->inputs.first;
- + bNodeSocket *shader2_socket = add_node->inputs.last;
- + bNodeSocket *add_socket = nodeFindSocket(add_node, SOCK_OUT, "Shader");
- +
- + bNode *transp_node = nodeAddStaticNode(NULL, ntree, SH_NODE_BSDF_TRANSPARENT);
- + transp_node->locx = add_node->locx;
- + transp_node->locy = add_node->locy - 110.0f;
- +
- + bNodeSocket *transp_socket = nodeFindSocket(transp_node, SOCK_OUT, "BSDF");
- +
- + /* Link to input and material output node. */
- + nodeAddLink(ntree, fromnode, fromsock, add_node, shader1_socket);
- + nodeAddLink(ntree, transp_node, transp_socket, add_node, shader2_socket);
- + nodeAddLink(ntree, add_node, add_socket, tonode, tosock);
- + }
- + else if (blend_method == 2 /* MA_BM_MULTIPLY */) {
- + bNode *transp_node = nodeAddStaticNode(NULL, ntree, SH_NODE_BSDF_TRANSPARENT);
- +
- + bNodeSocket *color_socket = nodeFindSocket(transp_node, SOCK_IN, "Color");
- + bNodeSocket *transp_socket = nodeFindSocket(transp_node, SOCK_OUT, "BSDF");
- +
- + /* If incomming link is from a closure socket, we need to convert it. */
- + if (fromsock->type == SOCK_SHADER) {
- + transp_node->locx = 0.33f * fromnode->locx + 0.66f * tonode->locx;
- + transp_node->locy = 0.33f * fromnode->locy + 0.66f * tonode->locy;
- +
- + bNode *shtorgb_node = nodeAddStaticNode(NULL, ntree, SH_NODE_SHADERTORGB);
- + shtorgb_node->locx = 0.66f * fromnode->locx + 0.33f * tonode->locx;
- + shtorgb_node->locy = 0.66f * fromnode->locy + 0.33f * tonode->locy;
- +
- + bNodeSocket *shader_socket = nodeFindSocket(shtorgb_node, SOCK_IN, "Shader");
- + bNodeSocket *rgba_socket = nodeFindSocket(shtorgb_node, SOCK_OUT, "Color");
- +
- + nodeAddLink(ntree, fromnode, fromsock, shtorgb_node, shader_socket);
- + nodeAddLink(ntree, shtorgb_node, rgba_socket, transp_node, color_socket);
- + }
- + else {
- + transp_node->locx = 0.5f * (fromnode->locx + tonode->locx);
- + transp_node->locy = 0.5f * (fromnode->locy + tonode->locy);
- +
- + nodeAddLink(ntree, fromnode, fromsock, transp_node, color_socket);
- + }
- +
- + /* Link to input and material output node. */
- + nodeAddLink(ntree, transp_node, transp_socket, tonode, tosock);
- + }
- +
- + need_update = true;
- + }
- +
- + if (need_update) {
- + ntreeUpdateTree(NULL, ntree);
- + }
- +}
- +
- void do_versions_after_linking_280(Main *bmain)
- {
- bool use_collection_compat_28 = true;
- @@ -1129,6 +1231,14 @@ void do_versions_after_linking_280(Main *bmain)
- camera->dof_ob = NULL;
- }
- }
- +
- + if (!MAIN_VERSION_ATLEAST(bmain, 281, 2)) {
- + /* Replace Multiply and Additive blend mode by Alpha Blend
- + * now that we use dualsource blending. */
- + for (Material *mat = bmain->materials.first; mat; mat = mat->id.next) {
- + do_versions_material_convert_legacy_blend_mode(mat);
- + }
- + }
- }
- /* NOTE: This version patch is intended for versions < 2.52.2,
- diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
- index ccc2d6ba020..738745f3072 100644
- --- a/source/blender/draw/engines/eevee/eevee_materials.c
- +++ b/source/blender/draw/engines/eevee/eevee_materials.c
- @@ -1474,21 +1474,10 @@ static void material_transparent(Material *ma,
- DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_DEPTH_EQUAL |
- DRW_STATE_BLEND_CUSTOM);
- - DRWState cur_state = DRW_STATE_WRITE_COLOR;
- + DRWState cur_state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM;
- cur_state |= (use_prepass) ? DRW_STATE_DEPTH_EQUAL : DRW_STATE_DEPTH_LESS_EQUAL;
- cur_state |= (do_cull) ? DRW_STATE_CULL_BACK : 0;
- - switch (ma->blend_method) {
- - case MA_BM_ADD:
- - case MA_BM_MULTIPLY:
- - case MA_BM_BLEND:
- - cur_state |= DRW_STATE_BLEND_CUSTOM;
- - break;
- - default:
- - BLI_assert(0);
- - break;
- - }
- -
- /* Disable other blend modes and use the one we want. */
- DRW_shgroup_state_disable(*shgrp, all_state);
- DRW_shgroup_state_enable(*shgrp, cur_state);
- @@ -1564,8 +1553,6 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata,
- &shgrp_depth_array[i],
- &shgrp_depth_clip_array[i]);
- break;
- - case MA_BM_ADD:
- - case MA_BM_MULTIPLY:
- case MA_BM_BLEND:
- material_transparent(ma_array[i],
- sldata,
- diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h
- index 152ecb85991..1d1ccef8846 100644
- --- a/source/blender/makesdna/DNA_material_types.h
- +++ b/source/blender/makesdna/DNA_material_types.h
- @@ -306,12 +306,12 @@ typedef struct Material {
- /* blend_method */
- enum {
- - MA_BM_SOLID,
- - MA_BM_ADD,
- - MA_BM_MULTIPLY,
- - MA_BM_CLIP,
- - MA_BM_HASHED,
- - MA_BM_BLEND,
- + MA_BM_SOLID = 0,
- + // MA_BM_ADD = 1, /* deprecated */
- + // MA_BM_MULTIPLY = 2, /* deprecated */
- + MA_BM_CLIP = 3,
- + MA_BM_HASHED = 4,
- + MA_BM_BLEND = 5,
- };
- /* blend_flag */
- diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
- index 6378ee15279..8bfc4bf6313 100644
- --- a/source/blender/makesrna/intern/rna_material.c
- +++ b/source/blender/makesrna/intern/rna_material.c
- @@ -719,16 +719,6 @@ void RNA_def_material(BlenderRNA *brna)
- static EnumPropertyItem prop_eevee_blend_items[] = {
- {MA_BM_SOLID, "OPAQUE", 0, "Opaque", "Render surface without transparency"},
- - {MA_BM_ADD,
- - "ADD",
- - 0,
- - "Additive",
- - "Render surface and blend the result with additive blending"},
- - {MA_BM_MULTIPLY,
- - "MULTIPLY",
- - 0,
- - "Multiply",
- - "Render surface and blend the result with multiplicative blending"},
- {MA_BM_CLIP,
- "CLIP",
- 0,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement