Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenloader/intern/versioning_cycles.c
| Show All 20 Lines | |||||
| /* allow readfile to use deprecated functionality */ | /* allow readfile to use deprecated functionality */ | ||||
| #define DNA_DEPRECATED_ALLOW | #define DNA_DEPRECATED_ALLOW | ||||
| #include <float.h> | #include <float.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_listbase.h" | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "DNA_color_types.h" | #include "DNA_color_types.h" | ||||
| #include "DNA_light_types.h" | #include "DNA_light_types.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_particle_types.h" | #include "DNA_particle_types.h" | ||||
| #include "DNA_camera_types.h" | #include "DNA_camera_types.h" | ||||
| ▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | if (!(node_has_roughness(tonode) && STREQ(tosock->identifier, "Roughness"))) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Replace links with sqrt node */ | /* Replace links with sqrt node */ | ||||
| nodeRemLink(ntree, link); | nodeRemLink(ntree, link); | ||||
| /* Add sqrt node. */ | /* Add sqrt node. */ | ||||
| bNode *node = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH); | bNode *node = nodeAddStaticNode(NULL, ntree, SH_NODE_MATH); | ||||
| node->custom1 = NODE_MATH_POW; | node->custom1 = NODE_MATH_POWER; | ||||
| node->locx = 0.5f * (fromnode->locx + tonode->locx); | node->locx = 0.5f * (fromnode->locx + tonode->locx); | ||||
| node->locy = 0.5f * (fromnode->locy + tonode->locy); | node->locy = 0.5f * (fromnode->locy + tonode->locy); | ||||
| /* Link to input and material output node. */ | /* Link to input and material output node. */ | ||||
| *cycles_node_socket_float_value(node->inputs.last) = 0.5f; | *cycles_node_socket_float_value(node->inputs.last) = 0.5f; | ||||
| nodeAddLink(ntree, fromnode, fromsock, node, node->inputs.first); | nodeAddLink(ntree, fromnode, fromsock, node, node->inputs.first); | ||||
| nodeAddLink(ntree, node, node->outputs.first, tonode, tosock); | nodeAddLink(ntree, node, node->outputs.first, tonode, tosock); | ||||
| ▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | if (STREQ(engine, "CYCLES")) { | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Disable nodes if scene was configured for Eevee */ | /* Disable nodes if scene was configured for Eevee */ | ||||
| light->use_nodes = false; | light->use_nodes = false; | ||||
| } | } | ||||
| } | } | ||||
| /* The names of the sockets of the Math node were changed. So we have to update | |||||
| * them here. The sockets' identifiers needs to be updated as well since they | |||||
| * are autmatically generated from the names. | |||||
| */ | |||||
| static void update_math_node_socket_names_and_identifiers(bNodeTree *ntree) | |||||
| { | |||||
| for (bNode *node = ntree->nodes.first; node; node = node->next) { | |||||
| if (node->type == SH_NODE_MATH) { | |||||
| bNodeSocket *sockA = node->inputs.first; | |||||
| bNodeSocket *sockB = sockA->next; | |||||
| bNodeSocket *sockResult = node->outputs.first; | |||||
| strcpy(sockA->name, "A"); | |||||
| strcpy(sockB->name, "B"); | |||||
| strcpy(sockResult->name, "Result"); | |||||
| strcpy(sockA->identifier, "A"); | |||||
| strcpy(sockB->identifier, "B"); | |||||
| strcpy(sockResult->identifier, "Result"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* The B input of the Math node is no longer used for single-operand operators. | |||||
| * Previously, if the B input was linked and the A input was not, the B input | |||||
| * was used as the input of the operator. To correct this, we move the link | |||||
| * from B to A if B is linked and A is not. | |||||
| */ | |||||
| static void update_math_node_single_operand_operators(bNodeTree *ntree) | |||||
| { | |||||
| bool need_update = false; | |||||
| for (bNode *node = ntree->nodes.first; node; node = node->next) { | |||||
| if (node->type == SH_NODE_MATH) { | |||||
| if (ELEM(node->custom1, | |||||
| NODE_MATH_SQRT, | |||||
| NODE_MATH_CEIL, | |||||
| NODE_MATH_SINE, | |||||
| NODE_MATH_ROUND, | |||||
| NODE_MATH_FLOOR, | |||||
| NODE_MATH_COSINE, | |||||
| NODE_MATH_ARCSINE, | |||||
| NODE_MATH_TANGENT, | |||||
| NODE_MATH_ABSOLUTE, | |||||
| NODE_MATH_FRACTION, | |||||
| NODE_MATH_ARCCOSINE, | |||||
| NODE_MATH_ARCTANGENT)) { | |||||
| bNodeSocket *sockA = nodeFindSocket(node, SOCK_IN, "A"); | |||||
| bNodeSocket *sockB = nodeFindSocket(node, SOCK_IN, "B"); | |||||
| if (!sockA->link && sockB->link) { | |||||
| nodeAddLink(ntree, sockB->link->fromnode, sockB->link->fromsock, node, sockA); | |||||
| nodeRemLink(ntree, sockB->link); | |||||
| need_update = true; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| if (need_update) { | |||||
| ntreeUpdateTree(NULL, ntree); | |||||
| } | |||||
| } | |||||
| /* The clamp option of the Math node was removed. To correct this, we add a | |||||
| * Clamp node if the clamp option was enabled. | |||||
| */ | |||||
| static void update_math_node_clamp_option(bNodeTree *ntree) | |||||
| { | |||||
| bool need_update = false; | |||||
| for (bNode *node = ntree->nodes.first; node; node = node->next) { | |||||
| if (node->type == SH_NODE_MATH && node->custom2) { | |||||
| bNode *clampNode = nodeAddStaticNode(NULL, ntree, SH_NODE_CLAMP); | |||||
| clampNode->locx = node->locx + node->width + 20.0f; | |||||
| clampNode->locy = node->locy; | |||||
| bNodeSocket *sockMathResult = nodeFindSocket(node, SOCK_OUT, "Result"); | |||||
| bNodeSocket *sockClampValue = nodeFindSocket(clampNode, SOCK_IN, "Value"); | |||||
| bNodeSocket *sockClampResult = nodeFindSocket(clampNode, SOCK_OUT, "Result"); | |||||
| LISTBASE_FOREACH_BACKWARD_MUTABLE(bNodeLink *, link, &ntree->links) | |||||
| { | |||||
| if (link->fromsock == sockMathResult) { | |||||
| nodeAddLink(ntree, clampNode, sockClampResult, link->tonode, link->tosock); | |||||
| nodeRemLink(ntree, link); | |||||
| } | |||||
| } | |||||
| nodeAddLink(ntree, node, sockMathResult, clampNode, sockClampValue); | |||||
| need_update = true; | |||||
| } | |||||
| } | |||||
| if (need_update) { | |||||
| ntreeUpdateTree(NULL, ntree); | |||||
| } | |||||
| } | |||||
| void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bmain) | void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bmain) | ||||
| { | { | ||||
| /* Particle shape shared with Eevee. */ | /* Particle shape shared with Eevee. */ | ||||
| if (!MAIN_VERSION_ATLEAST(bmain, 280, 16)) { | if (!MAIN_VERSION_ATLEAST(bmain, 280, 16)) { | ||||
| for (ParticleSettings *part = bmain->particles.first; part; part = part->id.next) { | for (ParticleSettings *part = bmain->particles.first; part; part = part->id.next) { | ||||
| IDProperty *cpart = cycles_properties_from_ID(&part->id); | IDProperty *cpart = cycles_properties_from_ID(&part->id); | ||||
| if (cpart) { | if (cpart) { | ||||
| Show All 16 Lines | for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { | ||||
| if (cscene) { | if (cscene) { | ||||
| bool cycles_film_transparency = cycles_property_boolean( | bool cycles_film_transparency = cycles_property_boolean( | ||||
| cscene, "film_transparent", false); | cscene, "film_transparent", false); | ||||
| scene->r.alphamode = cycles_film_transparency ? R_ALPHAPREMUL : R_ADDSKY; | scene->r.alphamode = cycles_film_transparency ? R_ALPHAPREMUL : R_ADDSKY; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (1) { | |||||
brecht: Just use `{`, or better, bump the subversion and use `MAIN_VERSION_ATLEAST`. | |||||
| FOREACH_NODETREE_BEGIN (bmain, ntree, id) { | |||||
| if (ntree->type == NTREE_SHADER) { | |||||
| update_math_node_socket_names_and_identifiers(ntree); | |||||
| } | |||||
| } | |||||
| FOREACH_NODETREE_END; | |||||
| } | |||||
| } | } | ||||
| void do_versions_after_linking_cycles(Main *bmain) | void do_versions_after_linking_cycles(Main *bmain) | ||||
| { | { | ||||
| if (!MAIN_VERSION_ATLEAST(bmain, 280, 66)) { | if (!MAIN_VERSION_ATLEAST(bmain, 280, 66)) { | ||||
| /* Shader node tree changes. After lib linking so we have all the typeinfo | /* Shader node tree changes. After lib linking so we have all the typeinfo | ||||
| * pointers and updated sockets and we can use the high level node API to | * pointers and updated sockets and we can use the high level node API to | ||||
| * manipulate nodes. */ | * manipulate nodes. */ | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | if (STREQ(engine, RE_engine_id_CYCLES)) { | ||||
| camera->dof.aperture_fstop = 2.8f; | camera->dof.aperture_fstop = 2.8f; | ||||
| camera->dof.aperture_blades = 0; | camera->dof.aperture_blades = 0; | ||||
| camera->dof.aperture_rotation = 0.0f; | camera->dof.aperture_rotation = 0.0f; | ||||
| camera->dof.aperture_ratio = 1.0f; | camera->dof.aperture_ratio = 1.0f; | ||||
| camera->dof.flag &= ~CAM_DOF_ENABLED; | camera->dof.flag &= ~CAM_DOF_ENABLED; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (1) { | |||||
| FOREACH_NODETREE_BEGIN (bmain, ntree, id) { | |||||
| if (ntree->type == NTREE_SHADER) { | |||||
| update_math_node_single_operand_operators(ntree); | |||||
| update_math_node_clamp_option(ntree); | |||||
| } | |||||
| } | |||||
| FOREACH_NODETREE_END; | |||||
| } | |||||
| } | } | ||||
Just use {, or better, bump the subversion and use MAIN_VERSION_ATLEAST.