1
1
Fork 0

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: {
NodeItem shader1 = get_input_link(0, to_type_);
NodeItem shader2 = get_input_link(1, to_type_);
if (shader1 && !shader2) {
res = shader1;
}
else if (!shader1 && shader2) {
res = 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();
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF)) {
return empty();
}
return res;
NodeItem shader1 = get_input_link(0, to_type_);
NodeItem shader2 = get_input_link(1, to_type_);
if (!shader1 && !shader2) {
return empty();
}
if (shader1 && !shader2) {
return shader1;
}
if (!shader1 && shader2) {
return shader2;
}
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);
NodeItem shader1 = get_input_link(1, to_type_);
NodeItem shader2 = get_input_link(2, to_type_);
if (shader1 && !shader2) {
res = shader1 * (val(1.0f) - fac);
}
else if (!shader1 && shader2) {
res = 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();
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF)) {
return empty();
}
return res;
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) {
return shader1 * (val(1.0f) - fac);
}
if (!shader1 && shader2) {
return shader2 * fac;
}
return fac.mix(shader1, shader2);
}
#endif
NODE_SHADER_MATERIALX_END

View File

@ -46,20 +46,19 @@ static int node_shader_gpu_output_material(GPUMaterial *mat,
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
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) {
surface.set_input("bsdf", bsdf);
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);
if (bsdf || edf) {
surface = create_node("surface", NodeItem::Type::SurfaceShader);
if (bsdf) {
surface.set_input("bsdf", bsdf);
}
if (edf) {
surface.set_input("edf", edf);
}
}
if (edf) {
surface.set_input("edf", edf);
}
}
else {
surface = get_input_link("Surface", NodeItem::Type::SurfaceShader);
}
return create_node("surfacematerial", NodeItem::Type::Material, {{"surfaceshader", surface}});
}