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

update with reworked rendering API

parent 8ac9e28d
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ static com::Folder *generate_grid() {
auto material = gfx::material_system()->insert_default_material("grid_material", { "materials" }, vec3{ 0 });
auto grid =
gfx::object_system()->insert_object({ "grid" }, material, gfx::buffer_generators()->insert_procedural_grid());
gfx::object_system()->insert_object({ "forward", "grid" }, material, gfx::buffer_generators()->insert_procedural_grid());
gfx::object_system()->push_frame_back(grid, grid_frame());
return grid;
......@@ -51,18 +51,15 @@ void main()
static com::Folder *default_text_material_box() {
auto material = gfx::material_system()->insert_material(
"default-text-material",
gfx::shader_system()->insert_shader<gfx::TextShader>(
{ "shaders" }, "default-text-shader",
default_vertex_shader, default_fragment_shader
),
{"materials"}
);
gfx::shader_system()->insert_shader<gfx::TextShader>({ "shaders" }, "default-text-shader", gfx::Shader::UNLIT,
default_vertex_shader, default_fragment_shader),
{ "materials" });
auto box = gfx::object_system()->insert_object(
{ "default-text-material-box" }, material,
gfx::buffer_generators()->insert_procedural_box_solid({1, 1, 1}, "default-text-material-box", { "maker" }));
{ "forward", "default-text-material-box" }, material,
gfx::buffer_generators()->insert_procedural_box_solid({ 1, 1, 1 }, "default-text-material-box", { "maker" }));
auto frame = root()->push_back<com::Folder>("default-text-material-box")->push_back<com::Frame>();
frame->set_origin({4, 4, 4});
frame->set_origin({ 4, 4, 4 });
gfx::object_system()->push_frame_back(box, frame);
return box;
......@@ -97,44 +94,42 @@ void main()
)";
static com::Folder *generate_rectangle() {
auto shader = gfx::shader_system()->insert_shader<gfx::TextShader>(
{"test-rectangle"}, "test-rectangle-shader", gfx::Shader::UNLIT, rectangle_vertex_shader, rectangle_fragment_shader);
auto shader = gfx::shader_system()->insert_shader<gfx::TextShader>({ "test-rectangle" }, "test-rectangle-shader",
gfx::Shader::UNLIT, rectangle_vertex_shader,
rectangle_fragment_shader);
auto material = gfx::material_system()->insert_material("test-rectangle-material", shader, {"test-rectangle"});
auto material = gfx::material_system()->insert_material("test-rectangle-material", shader, { "test-rectangle" });
auto rect = gfx::object_system()->insert_object(
{ "test-rectangle" }, material,
gfx::buffer_generators()->insert_procedural_rectangle({ 1, 1 }, "test-rectangle", { "maker" }));
gfx::object_system()->push_frame_back(rect, root()->push_back<com::Folder>("test-rectangle")->push_back<com::Frame>());
{ "forward", "test-rectangle" }, material,
gfx::buffer_generators()->insert_procedural_rectangle({ 1, 1 }, "test-rectangle", { "maker" }));
gfx::object_system()->push_frame_back(rect,
root()->push_back<com::Folder>("test-rectangle")->push_back<com::Frame>());
return rect;
}
static com::Folder *generate_box(vec3 position, vec3 half_sizes_along_axes) {
auto shader = gfx::shader_system()->insert_shader("box_shader", gfx::Shader::Pipeline::FORWARD, gfx::Shader::LIT,
{ "shaders" });
auto texture =
shader->insert<gfx::Shader::TextureNode>("/home/pbabic/Repositories/age_app_template/data/age/texture/UV.jpeg");
auto container = shader->insert<gfx::Shader::TextureNode>(
"/home/pbabic/Repositories/age_app_template/data/age/texture/container.jpg");
auto shader =
gfx::shader_system()->insert_shader<gfx::ShaderGraph>({ "shaders" }, "box_shader", gfx::ShaderGraph::DEFERRED);
auto container =
shader->insert<gfx::ShaderGraph::TextureNode>(com::ContextPath{ "age", "texture", "container2.png" });
// auto specular = shader->insert<gfx::ShaderGraph::TextureNode>(
// "/home/pbabic/Repositories/age_app_template/data/age/texture/container2_specular.png");
auto tex_coords = shader->insert<gfx::Shader::NodeVaryingTexcoord>();
shader->connect(texture, gfx::Shader::TextureNode::inputs::tex_coord, tex_coords, 0);
shader->connect(container, gfx::Shader::TextureNode::inputs::tex_coord, tex_coords, 0);
auto tex_coords = shader->insert<gfx::ShaderGraph::NodeVaryingTexcoord>();
shader->connect(container, gfx::ShaderGraph::TextureNode::inputs::tex_coord, tex_coords, 0);
// shader->connect(container, gfx::ShaderGraph::TextureNode::inputs::tex_coord, tex_coords, 0);
auto add = shader->insert<gfx::Shader::NodeVectorAdd>(gfx::Shader::Node::DataType::ElementType::VEC3);
shader->connect(add, 0, texture, 0);
shader->connect(add, 1, container, 0);
shader->connect(shader->root(), gfx::Shader::MasterNodeLit::inputs::ambient, add, 0);
shader->connect(shader->root(), gfx::Shader::MasterNodeLit::inputs::diffuse, add, 0);
shader->connect(shader->root(), gfx::Shader::MasterNodeLit::inputs::specular, add, 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, container, 0);
auto material = gfx::material_system()->insert_material("box_material", shader,
{ gfx::material_system()->materials()->name() });
auto box = gfx::object_system()->insert_object(
{ "test_box" }, material,
{ "deferred", "test_box" }, material,
gfx::buffer_generators()->insert_procedural_box_solid(half_sizes_along_axes, "test_box", { "maker" }));
auto frame = root()->push_back<com::Folder>("test_box")->push_back<com::Frame>();
frame->set_origin(position);
......@@ -143,19 +138,18 @@ static com::Folder *generate_box(vec3 position, vec3 half_sizes_along_axes) {
return box;
}
static com::Folder *generate_point_light(vec3 position, vec3 color, float radius) {
auto point_light_frame = root()->push_back<com::Folder>("point_light")->push_back<com::Frame>();
static com::Folder *generate_point_light(const std::string &name, vec3 position, vec3 color, float radius) {
auto point_light_frame = root()->push_back<com::Folder>(name)->push_back<com::Frame>();
point_light_frame->move_origin(position);
auto point_light =
gfx::light_system()->insert_light<gfx::PointLight>({ "point_light" }, point_light_frame, color, radius);
auto point_light = gfx::light_system()->insert_light<gfx::PointLight>({ name }, point_light_frame, color, radius);
auto material = gfx::material_system()->insert_default_material("point_light_material", { "materials" }, color);
auto material = gfx::material_system()->insert_default_material(name + "_material", { "materials" }, color);
// point light visualizer box
gfx::object_system()->push_frame_back(
gfx::object_system()->insert_object(
{ "point_light_box" }, material,
gfx::buffer_generators()->insert_procedural_box_solid({ 0.1, 0.1, 0.1 }, "point_light_box", { "maker" })),
{ "forward", name + "_box" }, material,
gfx::buffer_generators()->insert_procedural_box_solid({ 0.1, 0.1, 0.1 }, name + "_box", { "maker" })),
point_light_frame);
return point_light;
......@@ -167,14 +161,19 @@ void Presenter::initialize() {
auto grid = generate_grid();
auto box = generate_box(vec3{ 0 }, vec3{ 0.5 });
auto point_light = generate_point_light({ 2, 1, 1 }, { 0, 1, 1 }, 20);
gfx::object_system()->insert_light(box, point_light);
std::vector point_lights{
generate_point_light("point_light_1", { 1, 1, 1 }, { 0, 1, 1 }, 5),
generate_point_light("point_light_2", { -1, -1.5, -1 }, { 1, 0, 1 }, 7),
generate_point_light("point_light_3", { 0.25, 1.25, -0.25 }, { 1, 1, 0 }, 3),
};
for (auto &pl : point_lights)
gfx::object_system()->insert_light(box, pl);
// directional light
auto light_frame = root()->push_back<com::Folder>("dir_light")->push_back<com::Frame>();
light_frame->set_rotation(quat{ { 1.2, 0.8, 0.3 } });
auto light =
gfx::light_system()->insert_light<gfx::DirectionalLight>({ "dir_light" }, light_frame, vec3{ 0.75, 0.5, 0.5 });
auto light = gfx::light_system()->insert_light<gfx::DirectionalLight>({ "dir_light" }, light_frame,
vec3{ 0.75, 0.75, 0.75 });
gfx::object_system()->insert_light(box, light);
// ambient light
......@@ -193,7 +192,10 @@ void Presenter::release() {
void Presenter::next_round() {
gfx::renderer()->clear_render_buffers();
gfx::renderer()->present_collection(gfx::object_system()->objects());
gfx::renderer()->present_collection(gfx::object_system()->objects()->find<com::Folder>("deferred"), gfx::Renderer::DEFERRED);
gfx::renderer()->lighting_pass(*gfx::light_system()->lights());
gfx::renderer()->copy_depth_buffer();
gfx::renderer()->present_collection(gfx::object_system()->objects()->find<com::Folder>("forward"), gfx::Renderer::FORWARD);
}
} // 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