Commit bff6ec79 authored by Petr Babič's avatar Petr Babič
Browse files

stop generating redundant boxes

parent 3b0e8d96
Loading
Loading
Loading
Loading
Compare e799da8f to e63463a6
Original line number Diff line number Diff line
Subproject commit e799da8f5b8428db334e2698647c049d88253aa4
Subproject commit e63463a61dc8671bbea8962f13eb6977481c7a60
+5 −43
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#define APP_EXAMPLES_HPP_INCLUDED

#include <gfx/shader_graph.hpp>
#include <gfx/material.hpp>
#include <com/context.hpp>
#include <gfx/text_shader.hpp>
#include <string>
@@ -26,6 +27,8 @@ struct Example : public com::Folder {
    Folder *random_point_light();

    void add_random_frame(Folder *object);

    Folder *m_objects = nullptr;
};

struct DefaultTextShader final : public Example {
@@ -43,9 +46,6 @@ struct QuadTextShader final : public Example {

    void initialize() override;
    void next_round(Folder *grid) override;

  private:
    Folder *m_objects = nullptr;
};

struct ForwardLit final : public Example {
@@ -53,9 +53,6 @@ struct ForwardLit final : public Example {

    void initialize() override;
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
};

struct DeferredShading final : public Example {
@@ -65,7 +62,6 @@ struct DeferredShading final : public Example {
    void next_round(Folder *grid) override;

  private:
    Folder *m_objects = nullptr;
    std::vector<const Folder *> m_gathered_lights;
};

@@ -74,9 +70,6 @@ struct AlphaBlend final : public Example {

    void initialize() override;
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
};

struct AlphaThreshold final : public Example {
@@ -86,9 +79,6 @@ struct AlphaThreshold final : public Example {
    void next_round(Folder *grid) override;
    void activate() override;
    void deactivate() override;

private:
    Folder *m_objects = nullptr;
};

struct Animation final : public Example {
@@ -96,9 +86,6 @@ struct Animation final : public Example {

    void initialize() override;
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
};

struct NormalMap final : public Example {
@@ -106,9 +93,6 @@ struct NormalMap final : public Example {

    void initialize() override;
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
};

struct PBR final : public Example {
@@ -116,9 +100,6 @@ struct PBR final : public Example {

    void initialize() override;
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
};

struct DeferredPBR final : public Example {
@@ -128,7 +109,6 @@ struct DeferredPBR final : public Example {
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
    std::vector<const Folder *> m_gathered_lights;
};

@@ -139,9 +119,6 @@ struct CustomFunction final : public Example {
    void next_round(Folder *grid) override;
    void activate() override;
    void deactivate() override;

private:
    Folder *m_objects = nullptr;
};

struct PerlinNoise final : public Example {
@@ -151,9 +128,6 @@ struct PerlinNoise final : public Example {
    void next_round(Folder *grid) override;
    void activate() override;
    void deactivate() override;

private:
    Folder *m_objects = nullptr;
};

struct Benchmark : public Example {
@@ -161,9 +135,9 @@ struct Benchmark : public Example {

    void activate() override;

    static constexpr unsigned seed = 42;

protected:
    unsigned m_boxes, m_lights;
    gfx::Material *m_material = nullptr;
};

struct BenchmarkForwardPhong final : public Benchmark {
@@ -171,9 +145,6 @@ struct BenchmarkForwardPhong final : public Benchmark {

    void initialize() override;
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
};

struct BenchmarkForwardPhongText final : public Benchmark {
@@ -183,7 +154,6 @@ struct BenchmarkForwardPhongText final : public Benchmark {
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
    std::unique_ptr<gfx::ShaderGraph::TextureNode> diffuse, specular;
};

@@ -194,7 +164,6 @@ struct BenchmarkDeferredPhong final : public Benchmark {
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
    std::vector<const Folder *> m_gathered_lights;
};

@@ -205,7 +174,6 @@ struct BenchmarkDeferredPhongText final : public Benchmark {
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
    std::unique_ptr<gfx::ShaderGraph::TextureNode> diffuse, specular;
    std::vector<const Folder *> m_gathered_lights;
};
@@ -215,9 +183,6 @@ struct BenchmarkForwardPBR final : public Benchmark {

    void initialize() override;
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
};

struct BenchmarkForwardPBRText final : public Benchmark {
@@ -227,7 +192,6 @@ struct BenchmarkForwardPBRText final : public Benchmark {
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
    std::vector<std::unique_ptr<gfx::ShaderGraph::TextureNode>> m_textures;
};

@@ -238,7 +202,6 @@ struct BenchmarkDeferredPBR final : public Benchmark {
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
    std::vector<const Folder *> m_gathered_lights;
};

@@ -249,7 +212,6 @@ struct BenchmarkDeferredPBRText final : public Benchmark {
    void next_round(Folder *grid) override;

private:
    Folder *m_objects = nullptr;
    std::vector<std::unique_ptr<gfx::ShaderGraph::TextureNode>> m_textures;
    std::vector<const Folder *> m_gathered_lights;
};
+37 −157
Original line number Diff line number Diff line
@@ -954,16 +954,38 @@ void PerlinNoise::deactivate() {
}

Benchmark::Benchmark(const std::string &name, unsigned boxes, unsigned lights)
    : Example(name), m_boxes(boxes), m_lights(lights) {}
    : Example(name), m_boxes(boxes), m_lights(lights) {
    static Folder *box = nullptr;
    if (box == nullptr) {
        box = gfx::object_system()->insert_object(
            { folder_name(), "benchmark", "box" },
            gfx::material_system()->insert_default_material(
                "tmp-shader",
                { folder_name(), "benchmark" },
                vec3{1.f, 0.f, 1.f}),
            gfx::buffer_generators()->insert_procedural_box_solid(
                vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
                "box",
                { folder_name(), "benchmark" }));

        detail::generator.seed(42);
        for (unsigned i = 0; i < m_boxes; ++i)
            add_random_frame(box);
        for (unsigned i = 0; i < m_lights; ++i)
            gfx::object_system()->insert_light(box, random_point_light());
    }

    m_objects = box;
}

void Benchmark::activate() {
    Example::activate();
    detail::reset_camera();
    ASSUMPTION(m_material != nullptr);
    gfx::object_system()->set_material(m_objects, m_material);
}

void BenchmarkForwardPhong::initialize() {
    detail::generator.seed(seed);

    auto shader = gfx::shader_system()->insert_shader<Graph>(
            { folder_name(), name() },
            "box-shader",
@@ -989,26 +1011,10 @@ void BenchmarkForwardPhong::initialize() {
    auto emission = shader->insert<Graph::ConstantNode>(vec3{0.});
    shader->connect(shader->root(), Graph::MasterNodeLit::inputs::emission, emission, 0);

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
            "box-material",
            shader,
            { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());
}

void BenchmarkForwardPhong::next_round(Folder *grid) {
@@ -1017,8 +1023,6 @@ void BenchmarkForwardPhong::next_round(Folder *grid) {
}

void BenchmarkForwardPhongText::initialize() {
    detail::generator.seed(seed);

    static const std::string vertex_shader = R"(#version 330 core

layout(location = 0) in vec3 vertex_position;
@@ -1104,26 +1108,10 @@ void main()
    shader->add_texture(diffuse.get());
    shader->add_texture(specular.get());

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
            "box-material",
            shader,
            { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());
}

void BenchmarkForwardPhongText::next_round(Folder *grid) {
@@ -1132,8 +1120,6 @@ void BenchmarkForwardPhongText::next_round(Folder *grid) {
}

void BenchmarkDeferredPhong::initialize() {
    detail::generator.seed(seed);

    auto shader = gfx::shader_system()->insert_shader<Graph>(
            { folder_name(), name() },
            "box-shader",
@@ -1158,28 +1144,12 @@ void BenchmarkDeferredPhong::initialize() {
    auto emission = shader->insert<Graph::ConstantNode>(vec3{0.});
    shader->connect(shader->root(), Graph::MasterNodeDeferred::inputs::emission, emission, 0);

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
        "box-material",
        shader,
        { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());

    gfx::Renderer::gather_lights(box, m_gathered_lights);
    gfx::Renderer::gather_lights(m_objects, m_gathered_lights);
}

void BenchmarkDeferredPhong::next_round(Folder *grid) {
@@ -1190,8 +1160,6 @@ void BenchmarkDeferredPhong::next_round(Folder *grid) {
}

void BenchmarkDeferredPhongText::initialize() {
    detail::generator.seed(seed);

    static const std::string vertex_shader = R"(#version 330 core

layout(location = 0) in vec3 vertex_position;
@@ -1257,28 +1225,12 @@ void main()
    shader->add_texture(diffuse.get());
    shader->add_texture(specular.get());

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
            "box-material",
            shader,
            { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());

    gfx::Renderer::gather_lights(box, m_gathered_lights);
    gfx::Renderer::gather_lights(m_objects, m_gathered_lights);
}

void BenchmarkDeferredPhongText::next_round(Folder *grid) {
@@ -1289,8 +1241,6 @@ void BenchmarkDeferredPhongText::next_round(Folder *grid) {
}

void BenchmarkForwardPBR::initialize() {
    detail::generator.seed(seed);

    auto shader = gfx::shader_system()->insert_shader<Graph>(
            { folder_name(), name() },
            "box-shader",
@@ -1327,26 +1277,10 @@ void BenchmarkForwardPBR::initialize() {
    auto emission = shader->insert<Graph::ConstantNode>(vec3{0.});
    shader->connect(shader->root(), Graph::MasterNodePBR::inputs::emission, emission, 0);

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
            "box-material",
            shader,
            { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());
}

void BenchmarkForwardPBR::next_round(Folder *grid) {
@@ -1355,8 +1289,6 @@ void BenchmarkForwardPBR::next_round(Folder *grid) {
}

void BenchmarkForwardPBRText::initialize() {
    detail::generator.seed(seed);

    static const std::string vertex_shader = R"(#version 330 core

layout(location = 0) in vec3 vertex_position;
@@ -1541,26 +1473,10 @@ void main()
    for (auto &t : m_textures)
        shader->add_texture(t.get());

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
            "box-material",
            shader,
            { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());
}

void BenchmarkForwardPBRText::next_round(Folder *grid) {
@@ -1569,8 +1485,6 @@ void BenchmarkForwardPBRText::next_round(Folder *grid) {
}

void BenchmarkDeferredPBR::initialize() {
    detail::generator.seed(seed);

    auto shader = gfx::shader_system()->insert_shader<Graph>(
            { folder_name(), name() },
            "box-shader",
@@ -1607,28 +1521,12 @@ void BenchmarkDeferredPBR::initialize() {
    auto emission = shader->insert<Graph::ConstantNode>(vec3{0.});
    shader->connect(shader->root(), Graph::MasterNodeDeferredPBR::inputs::emission, emission, 0);

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
        "box-material",
        shader,
        { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());

    gfx::Renderer::gather_lights(box, m_gathered_lights);
    gfx::Renderer::gather_lights(m_objects, m_gathered_lights);
}

void BenchmarkDeferredPBR::next_round(Folder *grid) {
@@ -1639,8 +1537,6 @@ void BenchmarkDeferredPBR::next_round(Folder *grid) {
}

void BenchmarkDeferredPBRText::initialize() {
    detail::generator.seed(seed);

    static const std::string vertex_shader = R"(#version 330 core

layout(location = 0) in vec3 vertex_position;
@@ -1729,28 +1625,12 @@ void main()
    for (auto &t : m_textures)
        shader->add_texture(t.get());

    auto material = gfx::material_system()->insert_material(
    m_material = gfx::material_system()->insert_material(
            "box-material",
            shader,
            { folder_name(), name() });

    auto box = gfx::object_system()->insert_object(
        { folder_name(), name(), "box" },
        material,
        gfx::buffer_generators()->insert_procedural_box_solid(
            vec3{BENCHMARK_BOX_OBJECT_HALF_SIZE},
            "box",
            { folder_name(), name() }));

    m_objects = box;

    for (unsigned i = 0; i < m_boxes; ++i)
        add_random_frame(box);

    for (unsigned i = 0; i < m_lights; ++i)
        gfx::object_system()->insert_light(box, random_point_light());

    gfx::Renderer::gather_lights(box, m_gathered_lights);
    gfx::Renderer::gather_lights(m_objects, m_gathered_lights);
}

void BenchmarkDeferredPBRText::next_round(Folder *grid) {