forked from blender/blender
Implement BSDF Transparent shader #36
@ -44,6 +44,9 @@ class NodeItem {
|
||||
Displacementshader,
|
||||
SurfaceShader,
|
||||
Material,
|
||||
|
||||
/* Special type to retrieve opacity for <surface> */
|
||||
SurfaceOpacity,
|
||||
};
|
||||
enum class CompareOp { Less = 0, LessEq, Eq, GreaterEq, Greater, NotEq };
|
||||
|
||||
|
@ -25,7 +25,7 @@ static int node_shader_gpu_add_shader(GPUMaterial *mat,
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF)) {
|
||||
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF, NodeItem::Type::SurfaceOpacity)) {
|
||||
return empty();
|
||||
}
|
||||
|
||||
@ -41,6 +41,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
if (!shader1 && shader2) {
|
||||
return shader2;
|
||||
}
|
||||
if (to_type_ == NodeItem::Type::SurfaceOpacity) {
|
||||
return (shader1 + shader2) * val(0.5f);
|
||||
}
|
||||
return shader1 + shader2;
|
||||
}
|
||||
#endif
|
||||
|
@ -350,7 +350,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
{"coat_tint", get_input_value("Coat Tint", NodeItem::Type::Color3)},
|
||||
{"ior", get_input_value("IOR", NodeItem::Type::Float)},
|
||||
{"transmission", get_input_value("Transmission Weight", NodeItem::Type::Float)},
|
||||
//{"alpha", get_input_value("Alpha", NodeItem::Type::Float)},
|
||||
{"alpha", get_input_value("Alpha", NodeItem::Type::Float)},
|
||||
{"normal", get_input_link("Normal", NodeItem::Type::Vector3)},
|
||||
{"coat_normal", get_input_link("Coat Normal", NodeItem::Type::Vector3)},
|
||||
{"tangent", get_input_link("Tangent", NodeItem::Type::Vector3)},
|
||||
@ -572,9 +572,16 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
{"emission", in["emission"]},
|
||||
{"emission_color", in["emission_color"]},
|
||||
{"normal", in["normal"]},
|
||||
{"tangent", in["tangent"]}});
|
||||
{"tangent", in["tangent"]},
|
||||
{"opacity", in["alpha"].convert(NodeItem::Type::Color3)}});
|
||||
break;
|
||||
}
|
||||
|
||||
case NodeItem::Type::SurfaceOpacity: {
|
||||
res = get_input_value("Alpha", NodeItem::Type::Float);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
@ -27,6 +27,26 @@ static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat,
|
||||
return GPU_stack_link(mat, node, "node_bsdf_transparent", in, out);
|
||||
}
|
||||
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
switch (to_type_) {
|
||||
case NodeItem::Type::BSDF: {
|
||||
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||
return create_node("oren_nayar_diffuse_bsdf", NodeItem::Type::BSDF, {{"color", color}});
|
||||
}
|
||||
case NodeItem::Type::SurfaceOpacity: {
|
||||
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
|
||||
return val(1.0f) - color.dotproduct(val(1.0f / 3.0f));
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
#endif
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
||||
} // namespace blender::nodes::node_shader_bsdf_transparent_cc
|
||||
|
||||
/* node type definition */
|
||||
@ -40,6 +60,7 @@ void register_node_type_sh_bsdf_transparent()
|
||||
ntype.add_ui_poll = object_shader_nodes_poll;
|
||||
ntype.declare = file_ns::node_declare;
|
||||
ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_transparent;
|
||||
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
|
||||
/* This node isn't supported by MaterialX. This formula was given from OSL shader code in Cycles
|
||||
* node_light_falloff.osl. Considered ray_length=1.0f. */
|
||||
return strength * val(1.0f) / (smooth + val(1.0f));
|
||||
return strength / (smooth + val(1.0f));
|
||||
}
|
||||
#endif
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
@ -26,7 +26,7 @@ static int node_shader_gpu_mix_shader(GPUMaterial *mat,
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF)) {
|
||||
if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF, NodeItem::Type::SurfaceOpacity)) {
|
||||
return empty();
|
||||
}
|
||||
|
||||
|
@ -51,13 +51,10 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
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);
|
||||
}
|
||||
NodeItem opacity = get_input_link("Surface", NodeItem::Type::SurfaceOpacity);
|
||||
surface = create_node("surface",
|
||||
NodeItem::Type::SurfaceShader,
|
||||
{{"bsdf", bsdf}, {"edf", edf}, {"opacity", opacity}});
|
||||
}
|
||||
}
|
||||
return create_node("surfacematerial", NodeItem::Type::Material, {{"surfaceshader", surface}});
|
||||
|
Loading…
Reference in New Issue
Block a user