Skip to content

Commit

Permalink
add limitless samples for materials and effects
Browse files Browse the repository at this point in the history
  • Loading branch information
hotstreams committed Feb 9, 2024
1 parent e9e1108 commit 9101618
Show file tree
Hide file tree
Showing 97 changed files with 1,326 additions and 126 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(limitless-engine)

#########################################

OPTION(BUILD_SAMPLES "Builds samples" OFF)
OPTION(BUILD_SAMPLES "Builds samples" ON)
OPTION(BUILD_TESTS "Builds tests" ON)

OPTION(OPENGL_DEBUG "Enables debug mode for OpenGL" OFF)
Expand Down
Binary file added assets/textures/123.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/1_compressed.dds
Binary file not shown.
Binary file added assets/textures/50.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/albedo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/aura.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/blend_mask.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/blink.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/bricks.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwall.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwall_normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwork_albedo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwork_ao.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwork_height.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwork_metallic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwork_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/brickwork_roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/charcoal_albedo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/charcoal_metallic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/charcoal_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/charcoal_roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/compressed
Binary file not shown.
Binary file added assets/textures/fabric_albedo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/fabric_ao.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/fabric_metallic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/fabric_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/fabric_roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/fireball_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/glow.tga
Binary file not shown.
Binary file added assets/textures/grass.jpg
Binary file added assets/textures/green_albedo.png
Binary file added assets/textures/green_ao.png
Binary file added assets/textures/green_metallic.png
Binary file added assets/textures/green_normal.png
Binary file added assets/textures/green_roughness.png
Binary file added assets/textures/ice.jpg
Binary file added assets/textures/lava.jpg
Binary file added assets/textures/lava.png
Binary file added assets/textures/mask.jpg
Binary file added assets/textures/metall_albedo.png
Binary file added assets/textures/metall_ao.png
Binary file added assets/textures/metall_metallic.png
Binary file added assets/textures/metall_normal.png
Binary file added assets/textures/metall_roughness.png
Binary file added assets/textures/noise.png
Binary file added assets/textures/noise_1.png
Binary file added assets/textures/normal_4.png
Binary file added assets/textures/open_mask.jpg
Binary file added assets/textures/opengl.jpg
Binary file added assets/textures/ornate_albedo.png
Binary file added assets/textures/ornate_ao.png
Binary file added assets/textures/ornate_metallic.png
Binary file added assets/textures/ornate_normal.png
Binary file added assets/textures/ornate_roughness.png
Binary file added assets/textures/pirate.jpg
Binary file added assets/textures/pirate_albedo.png
Binary file added assets/textures/pirate_ao.png
Binary file added assets/textures/pirate_metallic.png
Binary file added assets/textures/pirate_normal.png
Binary file added assets/textures/pirate_roughness.png
Binary file added assets/textures/poison.jpg
Binary file added assets/textures/rock_lava.png
Binary file added assets/textures/rustediron2_basecolor.png
Binary file added assets/textures/rustediron2_metallic.png
Binary file added assets/textures/rustediron2_normal.png
Binary file added assets/textures/rustediron2_roughness.png
Binary file added assets/textures/shield_texture.jpg
Binary file added assets/textures/snow.jpg
Binary file added assets/textures/sphere_normal.png
Binary file added assets/textures/stonework_albedo.png
Binary file added assets/textures/stonework_ao.png
Binary file added assets/textures/stonework_normal.png
Binary file added assets/textures/stonework_roughness.png
Binary file added assets/textures/streaked_albedo.png
Binary file added assets/textures/streaked_ao.png
Binary file added assets/textures/streaked_metallic.png
Binary file added assets/textures/streaked_normal.png
Binary file added assets/textures/streaked_roughness.png
Binary file added assets/textures/test.png
Binary file added assets/textures/triangle.jpg
Binary file added assets/textures/true_fire.tga
Binary file not shown.
Binary file added assets/textures/true_noise.tga
Binary file not shown.
Binary file added assets/textures/wood.jpg
Binary file added assets/textures/wood_normal.png
2 changes: 1 addition & 1 deletion demo/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <limitless/scene.hpp>
#include "lighting_demoscene.hpp"
#include "materials_demoscene.hpp"
#include "../samples/materials_scene/scene.hpp"
#include "effects_demoscene.hpp"
#include "models_demoscene.hpp"

Expand Down
1 change: 1 addition & 0 deletions include/limitless/fx/modules/mesh_location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <limitless/instances/skeletal_instance.hpp>
#include <variant>
#include <limitless/models/mesh.hpp>
#include <random>

namespace Limitless::fx {
//TODO: move generation interface to utils
Expand Down
37 changes: 22 additions & 15 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
cmake_minimum_required(VERSION 3.10)

#########################################
project(limitless-engine-samples)
project(limitless-samples)

#if (NOT BUILD_SAMPLES)
# return()
#endif()

#add_executable(limitless-demo
# demo/demo.cpp
# # demo/materials_demoscene.cpp
# # demo/lighting_demoscene.cpp
# # demo/effects_demoscene.cpp
# # demo/models_demoscene.cpp
# demo/assets.cpp
#)
#target_link_libraries(limitless-demo PRIVATE limitless-engine)
if (NOT BUILD_SAMPLES)
return()
endif()

# gltf model viewer
add_executable(limitless-gltf-viewer
gltf_viewer/gltf_viewer.cpp
)
target_link_libraries(limitless-gltf-viewer PUBLIC limitless-engine)
target_link_libraries(limitless-gltf-viewer PRIVATE limitless-engine)

# test materials scene
add_executable(limitless-materials
materials/main.cpp
materials/assets.cpp
materials/scene.cpp
)
target_link_libraries(limitless-materials PRIVATE limitless-engine)

# test effects scene
add_executable(limitless-effects
effects/main.cpp
effects/assets.cpp
effects/scene.cpp
)
target_link_libraries(limitless-effects PRIVATE limitless-engine)
437 changes: 437 additions & 0 deletions samples/effects/assets.cpp

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions samples/effects/assets.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <limitless/assets.hpp>
#include <limitless/renderer/renderer.hpp>

namespace LimitlessMaterials {
class Assets : public Limitless::Assets {
private:
void setUpEffects();
void setUpCommon(Limitless::Context &ctx);
public:
Assets(Limitless::Context& ctx, const fs::path& path);
};
}
135 changes: 135 additions & 0 deletions samples/effects/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include "scene.hpp"
#include "assets.hpp"

#include <limitless/core/context_observer.hpp>
#include <limitless/text/text_instance.hpp>
#include <limitless/util/color_picker.hpp>
#include <limitless/core/state_query.hpp>
#include <limitless/core/texture/state_texture.hpp>
#include <limitless/renderer/renderer.hpp>

namespace LimitlessMaterials {
class MaterialsScene
: public Limitless::MouseMoveObserver,
public Limitless::KeyObserver,
public Limitless::FramebufferObserver {
private:
glm::uvec2 window_size {1080, 720};

Limitless::ContextEventObserver context;
Limitless::Camera camera;
Limitless::Renderer render;
Assets assets;
Scene scene;

bool done{};
bool hidden_text{};
public:
MaterialsScene()
: context {"Limitless-demo", window_size, {{Limitless::WindowHint::Resizable, false}}}
, camera {window_size}
, render {context}
, assets {context, ENGINE_ASSETS_DIR}
, scene {context, assets} {
camera.setPosition({-3.0f, 2.0f, 3.0f});

if (!Limitless::ContextInitializer::checkMinimumRequirements()) {
throw std::runtime_error("Minimum requirements are not met!");
}

context.setCursorMode(Limitless::CursorMode::Normal);
context.setSwapInterval(1);
context.setStickyKeys(true);

context.registerObserver(static_cast<KeyObserver *>(this));
context.registerObserver(static_cast<MouseMoveObserver *>(this));
context.registerObserver(static_cast<FramebufferObserver *>(this));

assets.recompileAssets(context, render.getSettings());
}

~MaterialsScene() override {
context.unregisterObserver(static_cast<KeyObserver *>(this));
context.unregisterObserver(static_cast<MouseMoveObserver *>(this));
context.unregisterObserver(static_cast<FramebufferObserver *>(this));
}

void onMouseMove(glm::dvec2 pos) override {
static glm::dvec2 last_move = {0, 0};

auto offset = glm::vec2{pos.x - last_move.x, last_move.y - pos.y};
last_move = pos;

camera.mouseMove(offset);
}

void onKey(int key, [[maybe_unused]] int scancode, Limitless::InputState state, [[maybe_unused]] Limitless::Modifier modifier) override {
using namespace Limitless;
if (key == GLFW_KEY_ESCAPE && state == Limitless::InputState::Pressed) {
done = true;
}

if (key == GLFW_KEY_SPACE && state == Limitless::InputState::Pressed) {
camera.getMoveSpeed() *= 5.0f;
}

if (key == GLFW_KEY_SPACE && state == Limitless::InputState::Released) {
camera.getMoveSpeed() /= 5.0f;
}

if (key == GLFW_KEY_GRAVE_ACCENT && state == Limitless::InputState::Released) {
hidden_text = !hidden_text;
}
}

void onFramebufferChange(glm::uvec2 size) override {
camera.updateProjection(size);
window_size = size;

}

void handleInput(float delta) noexcept {
using namespace Limitless;

if (context.isPressed(GLFW_KEY_W)) {
camera.movement(CameraMovement::Forward, delta);
}

if (context.isPressed(GLFW_KEY_S)) {
camera.movement(CameraMovement::Backward, delta);
}

if (context.isPressed(GLFW_KEY_A)) {
camera.movement(CameraMovement::Left, delta);
}

if (context.isPressed(GLFW_KEY_D)) {
camera.movement(CameraMovement::Right, delta);
}
}

void gameLoop() {
using namespace std::chrono;
while (!context.shouldClose() && !done) {
auto current_time = steady_clock::now();
static auto last_time = steady_clock::now();
auto delta_time = duration_cast<duration<float>>(current_time - last_time).count();
last_time = current_time;

scene.update(context, camera);
render.draw(context, assets, scene.getScene(), camera);

context.swapBuffers();
context.pollEvents();

handleInput(delta_time);
}
}
};
}

int main() {
LimitlessMaterials::MaterialsScene scene;
scene.gameLoop();
return 0;
}
119 changes: 119 additions & 0 deletions samples/effects/scene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include "scene.hpp"

#include <limitless/scene.hpp>
#include <limitless/instances/instanced_instance.hpp>
#include <limitless/ms/material.hpp>
#include <limitless/lighting/light.hpp>
#include <limitless/fx/modules/mesh_location.hpp>
#include <limitless/fx/particle.hpp>
#include <limitless/fx/emitters/sprite_emitter.hpp>

using namespace LimitlessMaterials;
using namespace Limitless;

LimitlessMaterials::Scene::Scene(Limitless::Context& ctx, Limitless::Assets& assets)
: scene(ctx)
, assets {assets} {
setUpLighting();
setUpEffects();
}

void LimitlessMaterials::Scene::update(Limitless::Context& context, const Limitless::Camera& camera) {
scene.update(context, camera);
hurricane->rotateBy(glm::vec3(0.0f, 0.3f, 0.0f));
}

void LimitlessMaterials::Scene::setUpEffects() {
using namespace Limitless;

auto floor = std::make_shared<InstancedInstance>();
for (int i = 0; i < 30; ++i) {
for (int j = 0; j < 30; ++j) {
floor->add(Instance::builder()
.model(assets.models.at("plane"))
.material(assets.materials.at("basic1"))
.position(glm::vec3{i, 0.0f, j})
.asModel()
);
}
}
scene.add(floor);

scene.add(Instance::builder()
.effect(assets.effects.at("blink"))
.position({29.0f, 1.0f, 1.0f})
.build()
);

scene.add(Instance::builder()
.effect(assets.effects.at("shield"))
.position({29.0f, 1.0f, 4.0f})
.build()
);

scene.add(Instance::builder()
.effect(assets.effects.at("fireball"))
.position({29.0f, 1.0f, 7.0f})
.build()
);

scene.add(Instance::builder()
.effect(assets.effects.at("explosion"))
.position({29.0f, 1.0f, 10.0f})
.build()
);

hurricane = Instance::builder()
.effect(assets.effects.at("hurricane"))
.position({29.0f, 1.0f, 13.0f})
.asEffect();
scene.add(hurricane);

scene.add(Instance::builder()
.effect(assets.effects.at("lightning"))
.position({29.0f, 1.0f, 16.0f})
.build()
);

auto stem = Instance::builder()
.model(assets.models.at("model"))
.position({29.0f, 1.0f, 19.0f})
.asSkeletal();
stem->play(stem->getAllAnimations()[0].name);
scene.add(stem);

auto mod = Instance::builder()
.effect(assets.effects.at("modeldrop"))
.position({0.0f, 0.0f, 0.0f})
.asEffect();

const auto& module = mod->get<fx::SpriteEmitter>("sparks").getModule(fx::ModuleType::InitialMeshLocation);

dynamic_cast<fx::InitialMeshLocation<fx::SpriteParticle>&>(*module).attachModelInstance(stem.get());

scene.add(mod);

scene.add(Instance::builder()
.effect(assets.effects.at("skeleton"))
.position({23.0f, 1.0f, 1.0f})
.build()
);

scene.add(Instance::builder()
.effect(assets.effects.at("aura"))
.position({23.0f, 1.0f, 4.0f})
.build()
);
}

void LimitlessMaterials::Scene::setUpLighting() {
scene.getLighting().setAmbientColor(glm::vec4(1.0f));

scene.setSkybox(assets.skyboxes.at("skybox"));

scene.add(Light::builder()
.color(glm::vec4(1.0, 1.0, 1.0, 1.0f))
.direction(glm::vec3{0.3f, -0.99f, 0.0f})
.build()
);
}
15 changes: 10 additions & 5 deletions demo/materials_demoscene.hpp → samples/effects/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
#include <limitless/assets.hpp>
#include <limitless/instances/model_instance.hpp>

namespace LimitlessDemo {
class MaterialsScene {
namespace LimitlessMaterials {
class Scene {
private:
Limitless::Assets& assets;
Limitless::Scene scene;
std::shared_ptr<Limitless::ModelInstance> open;
void addModels(const Limitless::Assets& assets);

std::shared_ptr<Limitless::EffectInstance> hurricane {};


void setUpEffects();
void setUpLighting();
public:
MaterialsScene(Limitless::Context& ctx, Limitless::Assets& assets);
Scene(Limitless::Context& ctx, Limitless::Assets& assets);

auto& getScene() { return scene; }

Expand Down
Loading

0 comments on commit 9101618

Please sign in to comment.