Skip to content
Snippets Groups Projects
Commit 34cdab6a authored by Petr Babic's avatar Petr Babic
Browse files

add transparent box examples


Signed-off-by: default avatarPetr Babic <pbabic@redhat.com>
parent 655a7398
No related branches found
No related tags found
No related merge requests found
...@@ -171,6 +171,87 @@ static com::Folder *generate_point_light( ...@@ -171,6 +171,87 @@ static com::Folder *generate_point_light(
return point_light; return point_light;
} }
static com::Folder *alpha_box() {
auto shader = gfx::shader_system()->insert_shader<gfx::ShaderGraph>(
{ "shaders" }, "alpha-box-shader", gfx::ShaderGraph::LIT, gfx::ShaderGraph::PARTIAL
);
auto container = shader->insert<gfx::ShaderGraph::TextureNode>(
com::ContextPath{ "age", "texture", "container2.png" });
auto specular = shader->insert<gfx::ShaderGraph::TextureNode>(
com::ContextPath{ "age", "texture", "container2_specular.png" });
auto tex_coords = shader->insert<gfx::ShaderGraph::NodeVaryingTexcoord>();
shader->connect(container, gfx::ShaderGraph::TextureNode::inputs::tex_coord, tex_coords, 0);
shader->connect(specular, gfx::ShaderGraph::TextureNode::inputs::tex_coord, tex_coords, 0);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::ambient, container, 0);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::diffuse, container, 0);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::specular, specular, 0);
auto alpha = shader->insert<gfx::ShaderGraph::NodeConstant>(0.5f);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::alpha, alpha, 0);
auto material = gfx::material_system()->insert_material(
"alpha-box-material", shader, { gfx::material_system()->materials()->name() }
);
auto box = gfx::object_system()->insert_object(
{ "transparent", "alpha-box" }, material,
gfx::buffer_generators()->insert_procedural_box_solid(
vec3{0.5}, "alpha-box", { "maker" }
)
);
auto frame = root()->push_back<com::Folder>("alpha-box")->push_back<com::Frame>();
gfx::object_system()->push_frame_back(box, frame);
gfx::Renderer::configure_blending(true);
return box;
}
static com::Folder *alpha_box_threshold() {
auto shader = gfx::shader_system()->insert_shader<gfx::ShaderGraph>(
{ "shaders" }, "alpha-box-thresh-shader", gfx::ShaderGraph::LIT, gfx::ShaderGraph::THRESHOLD
);
auto tex_coords = shader->insert<gfx::ShaderGraph::NodeVaryingTexcoord>();
auto specular = shader->insert<gfx::ShaderGraph::TextureNode>(
com::ContextPath{ "age", "texture", "container2_specular.png" });
shader->connect(specular, gfx::ShaderGraph::TextureNode::inputs::tex_coord, tex_coords, 0);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::ambient, specular, 0);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::diffuse, specular, 0);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::specular, specular, 0);
auto decomp = shader->insert<gfx::ShaderGraph::NodeDecomposeVector>(gfx::ShaderGraph::Node::DataType::VEC3);
shader->connect(decomp, 0, specular, 0);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::alpha, decomp, 0);
auto thresh = shader->insert<gfx::ShaderGraph::NodeConstant>(0.01f);
shader->connect(shader->root(), gfx::ShaderGraph::MasterNodeLit::inputs::alpha_threshold, thresh, 0);
auto material = gfx::material_system()->insert_material(
"alpha-box-thresh-material", shader, { gfx::material_system()->materials()->name() }
);
auto box = gfx::object_system()->insert_object(
{ "transparent", "alpha-box-thresh" }, material,
gfx::buffer_generators()->insert_procedural_box_solid(
vec3{0.5}, "alpha-box-thresh", { "maker" }
)
);
auto frame = root()->push_back<com::Folder>("alpha-box-thresh")->push_back<com::Frame>();
gfx::object_system()->push_frame_back(box, frame);
gfx::Renderer::configure_blending(true);
return box;
}
void Presenter::initialize() { void Presenter::initialize() {
osi::presenters()->push_back<com::Folder>("maker")->push_back<com::Link>(self_name() + ".link", this); osi::presenters()->push_back<com::Folder>("maker")->push_back<com::Link>(self_name() + ".link", this);
...@@ -223,6 +304,10 @@ void Presenter::next_round() { ...@@ -223,6 +304,10 @@ void Presenter::next_round() {
auto forward = gfx::object_system()->objects()->find<com::Folder>("forward"); auto forward = gfx::object_system()->objects()->find<com::Folder>("forward");
if (forward != nullptr) if (forward != nullptr)
gfx::renderer()->present_collection(forward, gfx::Renderer::FORWARD); gfx::renderer()->present_collection(forward, gfx::Renderer::FORWARD);
auto transparent = gfx::object_system()->objects()->find<com::Folder>("transparent");
if (transparent != nullptr)
gfx::renderer()->present_collection(transparent, gfx::Renderer::FORWARD);
} }
} // namespace mak } // namespace mak
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment