Code improvements + Mix node #30

Merged
Bogdan Nagirniak merged 18 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-22 18:23:13 +02:00
3 changed files with 46 additions and 72 deletions
Showing only changes of commit 9bcb2ff0fb - Show all commits

View File

@ -25,36 +25,23 @@ static int node_shader_gpu_add_shader(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
NodeItem res = empty();
switch (to_type_) {
case NodeItem::Type::BSDF:
case NodeItem::Type::EDF: {
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF)) {
return empty();
}
NodeItem shader1 = get_input_link(0, to_type_);
NodeItem shader2 = get_input_link(1, to_type_);
if (!shader1 && !shader2) {
return empty();
}
if (shader1 && !shader2) {
res = shader1;
return shader1;
}
else if (!shader1 && shader2) {
res = shader2;
if (!shader1 && shader2) {
return shader2;
}
else if (shader1 && shader2) {
res = shader1 + shader2;
}
break;
}
case NodeItem::Type::SurfaceShader: {
/* SurfaceShaders can't be added, returning the first one connected */
res = get_input_link(0, to_type_);
if (!res) {
res = get_input_link(1, to_type_);
}
break;
}
default:
BLI_assert_unreachable();
}
return res;
return shader1 + shader2;
}
#endif
NODE_SHADER_MATERIALX_END

View File

@ -26,37 +26,25 @@ static int node_shader_gpu_mix_shader(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
NodeItem res = empty();
switch (to_type_) {
case NodeItem::Type::BSDF:
case NodeItem::Type::EDF: {
NodeItem fac = get_input_value(0, NodeItem::Type::Float);
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF)) {
return empty();
}
NodeItem shader1 = get_input_link(1, to_type_);
NodeItem shader2 = get_input_link(2, to_type_);
if (!shader1 && !shader2) {
return empty();
}
NodeItem fac = get_input_value(0, NodeItem::Type::Float);
if (shader1 && !shader2) {
res = shader1 * (val(1.0f) - fac);
return shader1 * (val(1.0f) - fac);
}
else if (!shader1 && shader2) {
res = shader2 * fac;
if (!shader1 && shader2) {
return shader2 * fac;
}
else if (shader1 && shader2) {
res = fac.mix(shader1, shader2);
}
break;
}
case NodeItem::Type::SurfaceShader: {
/* SurfaceShaders can't be mixed, returning the first one connected */
res = get_input_link(1, NodeItem::Type::SurfaceShader);
if (!res) {
res = get_input_link(2, NodeItem::Type::SurfaceShader);
}
break;
}
default:
BLI_assert_unreachable();
}
return res;
return fac.mix(shader1, shader2);
}
#endif
NODE_SHADER_MATERIALX_END

View File

@ -46,9 +46,10 @@ static int node_shader_gpu_output_material(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
NodeItem surface = get_input_link("Surface", NodeItem::Type::SurfaceShader);
if (!surface) {
NodeItem bsdf = get_input_link("Surface", NodeItem::Type::BSDF);
NodeItem edf = get_input_link("Surface", NodeItem::Type::EDF);
NodeItem surface = empty();
if (bsdf || edf) {
surface = create_node("surface", NodeItem::Type::SurfaceShader);
if (bsdf) {
@ -58,8 +59,6 @@ NODE_SHADER_MATERIALX_BEGIN
surface.set_input("edf", edf);
}
}
else {
surface = get_input_link("Surface", NodeItem::Type::SurfaceShader);
}
return create_node("surfacematerial", NodeItem::Type::Material, {{"surfaceshader", surface}});
}