diff --git a/demo/assets.cpp b/demo/assets.cpp deleted file mode 100644 index 04ae528e..00000000 --- a/demo/assets.cpp +++ /dev/null @@ -1,1024 +0,0 @@ -#include "assets.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Limitless::ms; -using namespace Limitless::fx; -using namespace Limitless; - -void DemoAssets::loadLightingScene() { - { - const fs::path assets_dir {ENGINE_ASSETS_DIR}; - Material::builder() - .name("PBR") - .metallic(TextureLoader::load(*this, assets_dir / "textures/rustediron2_metallic.png")) - .roughness(TextureLoader::load(*this, assets_dir / "textures/rustediron2_roughness.png")) - .diffuse(TextureLoader::load(*this, assets_dir / "textures/rustediron2_basecolor.png", {::TextureLoaderFlags::Space::sRGB})) - .normal(TextureLoader::load(*this, assets_dir / "textures/rustediron2_normal.png")) - .shading(Shading::Lit) - .models({::InstanceType::Instanced, ::InstanceType::Model}) - .build(*this); - } - - { - const fs::path assets_dir {ENGINE_ASSETS_DIR}; - Material::builder() - .name("floor") - .shading(Shading::Lit) - .diffuse(TextureLoader::load(*this, assets_dir / "textures/wood.jpg", {::TextureLoaderFlags::Space::sRGB})) - .normal(TextureLoader::load(*this, assets_dir / "textures/wood_normal.png")) - .two_sided(true) - .models({::InstanceType::Instanced, ::InstanceType::Model}) - .build(*this); - } -} - -void DemoAssets::loadMaterialsScene() { - const fs::path assets_dir {ENGINE_ASSETS_DIR}; - - Material::builder() - .name("color") - .color({1.0f, 0.5f, 1.0f, 1.0f}) - .shading(Shading::Unlit) - .build(*this); - - Material::builder() - .name("albedo") - .diffuse(TextureLoader::load(*this, assets_dir / "textures/albedo.jpg", {TextureLoaderFlags::Space::sRGB })) - .shading(Shading::Unlit) - .build(*this); - - Material::builder() - .name("emissive_color") - .emissive_color({5.0f, 5.1f, 0.0f}) - .shading(Shading::Unlit) - .build(*this); - - Material::builder() - .name("emissive_mask") - .emissive_color({2.5f, 0.0f, 5.0f}) - .color({0.0f, 0.0f, 0.0f, 1.0f}) - .emissive_mask(TextureLoader::load(*this, assets_dir / "textures/open_mask.jpg", {TextureLoaderFlags::Filter::Nearest})) - .shading(Shading::Unlit) - .blending(::Blending::Additive) - .two_sided(true) - .build(*this); - - Material::builder() - .name("blend_mask") - .blend_mask(TextureLoader::load(*this, assets_dir / "textures/blend_mask.jpg", {TextureLoaderFlags::Filter::Nearest})) - .color({1.0f, 0.0f, 0.0f, 1.0f}) - .shading(Shading::Unlit) - .two_sided(true) - .build(*this); - - Material::builder() - .name("basic1") - .metallic(0.3f) - .roughness(TextureLoader::load(*this, assets_dir / "textures/stonework_roughness.png")) - .diffuse(TextureLoader::load(*this, assets_dir / "textures/stonework_albedo.png")) - .ao(TextureLoader::load(*this, assets_dir / "textures/stonework_ao.png")) - .normal(TextureLoader::load(*this, assets_dir / "textures/stonework_normal.png")) - .shading(Shading::Lit) - .models({InstanceType::Model, InstanceType::Instanced}) - .build(*this); - - Material::builder() - .name("basic2") - .metallic(TextureLoader::load(*this, assets_dir / "textures/metall_metallic.png")) - .roughness(TextureLoader::load(*this, assets_dir / "textures/metall_roughness.png")) - .diffuse(TextureLoader::load(*this, assets_dir / "textures/metall_albedo.png")) - .ao(TextureLoader::load(*this, assets_dir / "textures/metall_ao.png")) - .normal(TextureLoader::load(*this, assets_dir / "textures/metall_normal.png")) - .shading(Shading::Lit) - .build(*this); - - Material::builder() - .name("basic3") - .metallic(TextureLoader::load(*this, assets_dir / "textures/green_metallic.png")) - .roughness(TextureLoader::load(*this, assets_dir / "textures/green_roughness.png")) - .diffuse(TextureLoader::load(*this, assets_dir / "textures/green_albedo.png")) - .ao(TextureLoader::load(*this, assets_dir / "textures/green_ao.png")) - .normal(TextureLoader::load(*this, assets_dir / "textures/green_normal.png")) - .shading(Shading::Lit) - .build(*this); - - Material::builder() - .name("basic4") - .metallic(TextureLoader::load(*this, assets_dir / "textures/charcoal_metallic.png")) - .roughness( TextureLoader::load(*this, assets_dir / "textures/charcoal_roughness.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/charcoal_albedo.png")) - .normal( TextureLoader::load(*this, assets_dir / "textures/charcoal_normal.png")) - .shading(Shading::Lit) -// .two_sided(true) - .build(*this); - - Material::builder() - .name("basic5") - .metallic(TextureLoader::load(*this, assets_dir / "textures/pirate_metallic.png")) - .roughness( TextureLoader::load(*this, assets_dir / "textures/pirate_roughness.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/pirate_albedo.png")) - .normal( TextureLoader::load(*this, assets_dir / "textures/pirate_normal.png")) - .shading(Shading::Lit) - .two_sided(true) - .build(*this); - - Material::builder() - .name("basic6") - .metallic(TextureLoader::load(*this, assets_dir / "textures/ornate_metallic.png")) - .roughness( TextureLoader::load(*this, assets_dir / "textures/ornate_roughness.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/ornate_albedo.png")) - .normal( TextureLoader::load(*this, assets_dir / "textures/ornate_normal.png")) - .shading(Shading::Lit) - .build(*this); - - Material::builder().name("basic7") - .metallic(TextureLoader::load(*this, assets_dir / "textures/streaked_metallic.png")) - .roughness( TextureLoader::load(*this, assets_dir / "textures/streaked_roughness.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/streaked_albedo.png")) - .normal( TextureLoader::load(*this, assets_dir / "textures/streaked_normal.png")) - .shading(Shading::Lit) - .build(*this); - - Material::builder().name("basic8") - .metallic(TextureLoader::load(*this, assets_dir / "textures/fabric_metallic.png")) - .roughness( TextureLoader::load(*this, assets_dir / "textures/fabric_roughness.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/fabric_albedo.png")) - .normal( TextureLoader::load(*this, assets_dir / "textures/fabric_normal.png")) - .shading(Shading::Lit) - .build(*this); - - Material::builder().name("refraction") - .blending(Blending::Translucent) - .refraction(true) - .ior(1.5) - .time() - .custom("noise", TextureLoader::load(*this, assets_dir / "textures/true_noise.tga")) - .fragment("mctx.IoR = texture(noise, vec2(getVertexUV().x, getVertexUV().y + time * 0.1)).r;" - "mctx.IoR = clamp(mctx.IoR, 0.0, 1.0);" - ) - .shading(Shading::Unlit) - .build(*this); - - Material::builder().name("blending1") - .color(glm::vec4(2.0f, 0.0f, 0.0f, 0.5f)) - .shading(Shading::Unlit) - .blending(Blending::Translucent) - .two_sided(true) - .build(*this); - - Material::builder().name("decal") -// .color({1.0f, 1.0f, 1.0f, 1.0f}) -// .diffuse(TextureLoader::load(*this, assets_dir / "textures/metall_albedo.png")) - .normal(TextureLoader::load(*this, assets_dir / "textures/stonework_normal.png")) -// .normal( TextureLoader::load(*this, assets_dir / "textures/charcoal_normal.png")) -// .custom("decal_blend", 1.0f) - .shading(Shading::Lit) - .blending(Blending::Opaque) - .models({InstanceType::Decal}) - .build(*this); - - Material::builder().name("blending2") - .color(glm::vec4(0.0f, 2.0f, 0.0f, 0.4f)) - .shading(Shading::Unlit) - .blending(Blending::Translucent) - .two_sided(true) - .build(*this); - - Material::builder().name("blending3") - .color(glm::vec4(0.0f, 0.0f, 2.0f, 0.3f)) - .shading(Shading::Unlit) - .blending(Blending::Translucent) - .two_sided(true) - .build(*this); - - Material::builder().name("blending4") - .color(glm::vec4(1.0f, 0.5f, 0.5f, 1.0f)) - .shading(Shading::Unlit) - .blending(Blending::Additive) - .two_sided(true) - .build(*this); - - Material::builder().name("blending5") - .color(glm::vec4(2.0f, 0.3f, 0.3f, 1.0f)) - .shading(Shading::Unlit) - .blending(Blending::Modulate) - .two_sided(true) - .build(*this); - - Material::builder().name("lava") - .diffuse( TextureLoader::load(*this, assets_dir / "textures/lava.png", { - TextureLoaderFlags::Space::sRGB - })) - .emissive_color( glm::vec4(2.5f, 0.9f, 0.1f, 1.0f)) - .color(glm::vec4(2.5f, 0.9f, 0.1f, 1.0f)) - .custom("noise", TextureLoader::load(*this, assets_dir / "textures/true_noise.tga")) - .time() - .fragment( - "vec2 panned = vec2(getVertexUV().x + time * 0.1, getVertexUV().y + time * 0.05);" - "vec2 uv = getVertexUV() + texture(noise, panned).r;" - "mctx.color.rgb = getMaterialDiffuse(uv).rgb;" - "mctx.emissive_color *= texture(noise, panned).g;" - ) - .shading(Shading::Unlit) - .build(*this); - - Material::builder().name("ice") - .emissive_color( glm::vec4(1.0f)) - .color(glm::vec4(1.0f)) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/ice.jpg", { - TextureLoaderFlags::Space::sRGB - })) - .custom("snow", TextureLoader::load(*this, assets_dir / "textures/snow.jpg")) - .time() - .fragment( - "vec2 uv = getVertexUV() + time * 0.05;" - "mctx.color.rgb += texture(snow, uv).rgb * abs(cos(time * 0.5));" - "mctx.emissive_color *= texture(snow, uv).r;" - ) - .shading(Shading::Unlit) - .build(*this); - - Material::builder().name("poison") - .emissive_color( glm::vec4(0.1f, 4.0f, 0.1f, 1.0f)) - .color(glm::vec4(0.1f, 4.0f, 0.1f, 1.0f)) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/poison.jpg", { - TextureLoaderFlags::Space::sRGB - })) - .custom("noise", TextureLoader::load(*this, assets_dir / "textures/true_noise.tga")) - .time() - .fragment( - "vec2 panned = vec2(getVertexUV().x + time * 0.05, getVertexUV().y);" - "vec2 uv = vec2(getVertexUV().x, getVertexUV().y + texture(noise, panned).g);" - "mctx.color.rgb = getMaterialDiffuse(uv).rgb;" - "mctx.emissive_color *= getMaterialDiffuse(uv).g;" - ) - .shading(Shading::Unlit) - .build(*this); - - Material::builder() - .name("fireball") - .vertex("vec2 uv_1 = vec2(uv.x + time * 0.05, uv.y + time * 0.0);\n" - "vec2 uv_2 = vec2(uv.x - time * 0.05, uv.y - time * 0.0);\n" - " \n" - "float s = texture(fire_mask, uv_1).r;\n" - "float t = texture(fire_mask, uv_2).r;\n" - "\n" - "vertex_position.xyz -= getVertexNormal() * texture(fire_mask, uv + vec2(s, t)).r * 0.6;") - .fragment("vec2 uv = getVertexUV();" - "vec2 uv_1 = vec2(uv.x + time * 0.05, uv.y + time * 0.0);\n" - "vec2 uv_2 = vec2(uv.x - time * 0.05, uv.y - time * 0.0);\n" - " \n" - "float s = texture(fire_mask, uv_1).r;\n" - "float t = texture(fire_mask, uv_2).r;\n" - "\n" - "mctx.emissive_color = getMaterialDiffuse(uv + vec2(s, t)).rgb;\n" - "\n" - "if (mctx.emissive_color.r <= 0.2) discard;") - .time() - .custom("fire_mask", TextureLoader::load(*this, assets_dir / "textures/fireball_mask.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/rock_lava.png")) - .color(glm::vec4{15.0f, 5.0f, 0.0f, 1.0f}) - .emissive_color( glm::vec4{1.0f}) - .shading(Shading::Unlit) - .blending(Blending::Additive) - .two_sided(true) - .build(*this); - - Material::builder().name("bump_mapping") - .metallic(TextureLoader::load(*this, assets_dir / "textures/brickwork_metallic.png")) - .roughness( TextureLoader::load(*this, assets_dir / "textures/brickwork_roughness.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/brickwork_albedo.png")) - .normal( TextureLoader::load(*this, assets_dir / "textures/brickwork_normal.png")) - .ao(TextureLoader::load(*this, assets_dir / "textures/brickwork_ao.png")) - .custom("height", TextureLoader::load(*this, assets_dir / "textures/brickwork_height.png")) - .shading(Shading::Lit) - .vertex( - "vertex_position += getVertexNormal() * texture(height, getVertexUV()).xyz * 0.25;" - ) - .build(*this); - - Material::builder().name("fresnel") - .emissive_color(glm::vec4(5.0, 0.7, 0.3, 1.0)) - .time() - .shading(Shading::Unlit) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/albedo.jpg", { - TextureLoaderFlags::Space::sRGB - })) - .global( - "#include \"../functions/fresnel.glsl\"" - ) - .fragment( - "mctx.emissive_color *= fresnel(getVertexNormal(), getCameraPosition() - getVertexPosition(), 5.0);" - ) - .build(*this); - - Material::builder().name("hue_shift") - .time() - .shading(Shading::Unlit) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/albedo.jpg", { - TextureLoaderFlags::Space::sRGB - })) - .color(glm::vec4(1.0)) - .global( - "#include \"../functions/hue_shift.glsl\"" - ) - .fragment( - "mctx.color.rgb = hue_shift(mctx.color.rgb, time);" - ) - .build(*this); -} - -void DemoAssets::loadEffectsScene() { - { - const fs::path assets_dir {ENGINE_ASSETS_DIR}; - - Material::builder() - .name("blink") - .color(glm::vec4(1.0f)) - .custom("mask", TextureLoader::load(*this, assets_dir / "textures/fireball_mask.png")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/blink.jpg")) - .shading(Shading::Unlit) - .blending(Blending::Translucent) - .two_sided(true) - .fragment("vec2 uv = getVertexUV();" - "float tile = getParticleProperties().z;\n" - "float erode = getParticleProperties().y;\n" - "float dist = getParticleProperties().x;\n" - "\n" - "float r = texture(mask, uv * tile).r;\n" - "\n" - "vec2 uv1 = vec2(0.0, dist) * r + uv;\n" - "\n" - "float m_a = getMaterialDiffuse(uv1).r;\n" - "\n" - "mctx.color.a = mix(0.0, m_a, pow(r, erode));" - ) - .model(InstanceType::Effect) - .build(*this); - } - - { - EffectBuilder builder {*this}; - builder .create("blink") - .createEmitter("smoke_purple") - .setSpawnMode(::EmitterSpawn::Mode::Burst) - .setBurstCount(std::make_unique>(100)) - .setMaxCount(100) - .setSpawnRate(100.0f) - .addInitialSize(std::make_unique>(512.0f, 1024.0f)) - .addSizeByLife(std::make_unique>(2048.0f)) - .addInitialRotation(std::make_unique>(glm::vec3(0.0f), glm::vec3(6.28f))) - .addInitialMeshLocation(meshes.at("sphere"), glm::vec3(1.0f), glm::vec3(0.0f)) - .addInitialVelocity(std::make_unique>(glm::vec3(-0.05f, 0.01f, -0.05f), glm::vec3(0.05f))) - .addInitialAcceleration(std::make_unique>(glm::vec3(-0.01f, 0.2f, -0.01f), glm::vec3(0.01f, 0.2f, 0.01f))) - .addLifetime(std::make_unique>(2.0f)) - .setMaterial(materials.at("blink")) - .addInitialColor(std::make_unique>(glm::vec4(0.54f * 2.0f, 0.0f, 1.0f * 2.0f, 1.0f))) - .addColorByLife(std::make_unique>(glm::vec4(0.54f * 4.0f, 0.0f, 1.0f * 4.0f, 1.0f))) - .addCustomMaterial(std::make_unique>(0.0f, 0.3f), std::make_unique>(0.0f, 2.5f), std::make_unique>(0.0, 5.0f), nullptr) - .addCustomMaterialByLife(std::make_unique>(1.0f), std::make_unique>(10.0f), nullptr, nullptr) - .createEmitter("smoke_black") - .setSpawnMode(::EmitterSpawn::Mode::Burst) - .setBurstCount(std::make_unique>(50)) - .setMaxCount(50) - .setSpawnRate(50.0f) - .addInitialSize(std::make_unique>(64.0f, 128.0f)) - .addSizeByLife(std::make_unique>(256.0f)) - .addInitialRotation(std::make_unique>(glm::vec3(0.0f), glm::vec3(6.28f))) - .addInitialLocation(std::make_unique>(glm::vec3(-0.5f), glm::vec3(0.5f))) - .addLifetime(std::make_unique>(2.0f)) - .setMaterial(materials.at("blink")) - .addInitialColor(std::make_unique>(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f))) - .addCustomMaterial(std::make_unique>(0.0f, 0.3f), std::make_unique>(0.0f, 3.0f), std::make_unique>(0.0, 5.0f), nullptr) - .addCustomMaterialByLife(std::make_unique>(1.0f), std::make_unique>(10.0f), nullptr, nullptr) - .build(); - } - - { - const fs::path assets_dir{ENGINE_ASSETS_DIR}; - Material::builder() - .name("shield") - .shading(::Shading::Unlit) - .blending(::Blending::Additive) - .model(::InstanceType::Effect) - .color(glm::vec4(1.0f)) - .custom("maintexture", TextureLoader::load(*this, assets_dir / "textures/shield_texture.jpg")) - .custom("noise", TextureLoader::load(*this, assets_dir / "textures/noise.png")) - .custom("vertex_offset_freq", 2.0f) - .custom("vertex_offset_dir", glm::vec3(0.2)) - .fragment("vec2 uv = getVertexUV();" - "float fres = fresnel(getVertexNormal(), getCameraPosition() - getVertexPosition(), 3.5);" - "mctx.color.rgb *= 1.0 - texture(maintexture, uv).r;" - "mctx.color.rgb *= fres * vec3(33.0 / 255.0 * 15.0f, 99.0 / 255.0 * 15.0f, 1000.0 / 255.0 * 25.0f);" - ) - .vertex( - "vertex_position.xyz += sin(getParticleTime() * vertex_offset_freq) * getVertexNormal() * vertex_offset_dir *texture(noise, getParticleTime() + uv).r;") - - .global("#include \"../functions/fresnel.glsl\"") - .build(*this); - } - - { - EffectBuilder builder {*this}; - builder .create("shield") - .createEmitter("shield") - .addInitialSize(std::make_unique>(glm::vec3(0.5f))) - .setMaterial(materials.at("shield")) - .setMesh(meshes.at("sphere")) - .addTime() - .setMaxCount(1) - .build(); - } - - { - const fs::path assets_dir {ENGINE_ASSETS_DIR}; - Material::builder() - .name("fireball_material") - .fragment("vec2 uv = getVertexUV();" - "uv.y -= 0.1;\n" - "vec2 panned = vec2(uv.x + getParticleTime() * 0.5 + getParticleProperties().x, " - "uv.y + getParticleTime() * 0.8 + getParticleProperties().y);\n" - "uv += texture(noise, panned).g * 0.3;\n" - "\n" - "vec2 offset_panned1 = vec2(uv.x + getParticleTime() * 0.66, uv.y + getParticleTime() * 0.33);\n" - "float offset1 = texture(noise, offset_panned1).r;\n" - "\n" - "vec2 offset_panned2 = vec2(uv.x + getParticleTime() * 0.45, uv.y + getParticleTime() * 0.71);\n" - "float offset2 = texture(noise, offset_panned2).r;\n" - "\n" - "float r = offset1 * offset2;\n" - "\n" - "mctx.color.rgb = getMaterialDiffuse(uv).rgb;\n" - "mctx.color.rgb *= clamp((1.0 - getParticleProperties().z) * r, 0, 1);" - ) - .custom("noise", TextureLoader::load(*this, assets_dir /"textures/true_noise.tga")) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/true_fire.tga")) - .color(glm::vec4(1.0f)) - .shading(Shading::Unlit) - .blending(Blending::Additive) - .global("#include \"../functions/tone_mapping.glsl\"") - .model(::InstanceType::Effect) - .build(*this); - - Material::builder().name("fireball_sparks") - .fragment("mctx.emissive_color *= circle(getVertexUV(), 0.7);" - "mctx.color.rgb *= circle(getVertexUV(), 0.7);") - .global("#include \"../functions/circle.glsl\"") - - .emissive_color( glm::vec4{5.0f, 1.5f, 1.0f, 1.0f}) - .color(glm::vec4(1.0)) - .shading(Shading::Unlit) - .blending(Blending::Additive) - .model(::InstanceType::Effect) - .build(*this); - } - { - EffectBuilder builder {*this}; - builder.create("fireball") - .createEmitter<::SpriteEmitter>("fire") - .addInitialRotation(std::make_unique>(glm::vec3{0.0f, 0.0f, 0.0f}, glm::vec3{6.28f, 0.0f, 0.0f})) - .addLifetime(std::make_unique>(0.5f, 0.7f)) - .addInitialSize(std::make_unique>(512.0f)) - .addSizeByLife(std::make_unique>(1024.0f)) - .addCustomMaterial(std::make_unique>(0.0f, 0.9f), std::make_unique>(0.0f, 0.9f), std::make_unique>(0.0f), nullptr) - .addCustomMaterialByLife(nullptr, nullptr, std::make_unique>(1.0f), nullptr) - .setMaterial(materials.at("fireball_material")) - .setSpawnMode(::EmitterSpawn::Mode::Spray) - .addInitialVelocity(std::make_unique>(glm::vec3(1.0, -1.0, -1.0), glm::vec3(2.0, 1.0, 1.0))) - .setMaxCount(1000) - .setSpawnRate(200.0f) - .createEmitter("sparks") - .addLifetime(std::make_unique>(0.5f, 0.7f)) - .addInitialSize(std::make_unique>(30.0f)) - .addSizeByLife(std::make_unique>(0.0f)) - .setMaterial(materials.at("fireball_sparks")) - .addInitialVelocity(std::make_unique>(glm::vec3(1.0, -1.0, -1.0), glm::vec3(2.0, 1.0, 1.0))) - .addInitialColor(std::make_unique>(glm::vec4(1.5, 1.0, 1.0, 1.0), glm::vec4(2.5, 2.5, 2.5, 2.5))) - .addColorByLife(std::make_unique>(glm::vec4(1.5, 0.5, 0.0, 1.0))) - .addInitialMeshLocation(meshes.at("sphere"), glm::vec3(0.5f), glm::vec3(0.0f)) - .setMaxCount(200) - .setSpawnRate(200.0f) - .build(); - } - - { - Material::builder() - .name("explosion") - .shading(Shading::Unlit) - .blending(Blending::Additive) - .emissive_color(glm::vec4(2.0, 1.0, 0.3, 1.0)) - .color( glm::vec4(1.0, 1.0, 0.3, 1.0)) - .fragment("mctx.emissive_color *= circle(getVertexUV(), 0.7) * getParticleColor().rgb;" - "mctx.color.rgb *= circle(getVertexUV(), 0.7);") - .global("#include \"../functions/circle.glsl\"") - .model(InstanceType::Effect) - .build(*this); - } - - { - EffectBuilder builder{*this}; - builder.create("explosion") - .createEmitter("generate") - .addInitialVelocity(std::make_unique>(glm::vec3{-1.0f, 0.0f, -1.0f}, glm::vec3{1.0f})) - .addInitialAcceleration(std::make_unique>(glm::vec3{0.0f}, glm::vec3{0.0f, 5.0f, 0.0f})) - .addLifetime(std::make_unique>(0.2f, 1.0f)) - .addInitialSize(std::make_unique>(1.0f, 25.0f)) - .addSizeByLife(std::make_unique>(0.0f)) - .addInitialColor(std::make_unique>(glm::vec4{0.0f}, glm::vec4{2.0f})) - .setMaterial(materials.at("explosion")) - .setSpawnMode(EmitterSpawn::Mode::Burst) - .setBurstCount(std::make_unique>(250)) - .setMaxCount(250) - .setSpawnRate(1.0f) - .setLocalSpace(true) - .build(); - } - - { - Material::builder().name("hurricane") - .blending(Blending::Additive) - .emissive_color(glm::vec4(5.0, 0.0, 5.0, 1.0)) - .color(glm::vec4(1.0, 0.0, 1.0, 1.0)) - .fragment("mctx.emissive_color *= circle(getVertexUV(), 0.5);" - "mctx.color.rgb = vec3(0.0);") - .global("#include \"../functions/circle.glsl\"") - .model(InstanceType::Effect) - .shading(Shading::Unlit) - .build(*this); - } - - { - EffectBuilder builder{*this}; - builder .create("hurricane") - .createEmitter("generate") - .addInitialVelocity(std::make_unique>(glm::vec3{-1.0f, 0.5f, -1.0f}, glm::vec3{1.0f})) - .addInitialAcceleration(std::make_unique>(glm::vec3{0.0f}, glm::vec3{0.0f, 5.0f, 0.0f})) - .addLifetime(std::make_unique>(0.5f, 1.0f)) - .addInitialSize(std::make_unique>(5.0f, 25.0f)) - .addSizeByLife(std::make_unique>(0.0f)) - .setMaterial(materials.at("hurricane")) - .setSpawnMode(EmitterSpawn::Mode::Spray) - .addInitialMeshLocation(meshes.at("sphere"), glm::vec3(1.0f), glm::vec3(0.0f)) - .setMaxCount(1000) - .setSpawnRate(1000.0f) - .setLocalSpace(true) - .build(); - } - - { - Material::builder() - .name("drop") - .emissive_color( glm::vec4(0.3f, 1.5f, 0.5f, 1.0f)) - .color(glm::vec4(0.3f, 1.5f, 0.5f, 1.0f)) - .fragment("mctx.emissive_color *= circle(getVertexUV(), 0.7) * getParticleColor().rgb;" - "mctx.color.rgb *= circle(getVertexUV(), 0.7) * getParticleColor().rgb;") - .shading(Shading::Unlit) - .blending(Blending::Additive) - .global("#include \"../functions/circle.glsl\"") - .model(InstanceType::Effect) - .build(*this); - } - - { - EffectBuilder builder{*this}; - builder.create("modeldrop") - .createEmitter("sparks") - .addLifetime(std::make_unique>(0.8f)) - .addInitialSize(std::make_unique>(5.0f)) - .addInitialVelocity(std::make_unique>(glm::vec3(-0.15f, -0.025f, -0.15f), glm::vec3(0.15f, -0.15f, 0.15f))) - .addInitialAcceleration(std::make_unique>(glm::vec3(-0.15f, 0.05f, -0.15f), glm::vec3(0.15f, 0.1f, 0.15f))) - .addInitialColor(std::make_unique>(glm::vec4{1.0f, 0.5f, 0.8f, 1.0f}, glm::vec4{2.0f, 1.0f, 1.5f, 1.0f})) - .addInitialMeshLocation(dynamic_cast(*models.at("bob")).getMeshes().at(3)) - .setMaterial(materials.at("drop")) - .setMaxCount(1000) - .setSpawnRate(1000.0f) - .build(); - } - - { - - Material::builder() - .name("beam_lightning") - .emissive_color( glm::vec4(2.8f, 2.8f, 4.8f, 1.0f)) - .fragment("mctx.emissive_color *= getParticleColor().rgb;") - .shading(Shading::Unlit) - .blending(Blending::Opaque) - .model(InstanceType::Effect) - .build(*this); - } - - { - EffectBuilder builder{*this}; - builder.create("lightning") - .createEmitter("beam") - .setSpawnMode(::EmitterSpawn::Mode::Burst) - .setBurstCount(std::make_unique>(15)) - .setMaxCount(15) - .addTime() - .setSpawnRate(15.0f) - .addInitialColor(std::make_unique>(glm::vec4(1.0f), glm::vec4(2.0f))) - .addLifetime(std::make_unique>(5.0f)) - .addInitialSize(std::make_unique>(6.0f, 8.0f)) - .addBeamInitialTarget(std::make_unique>(glm::vec3{29.0f, 3.0f, 16.0f})) - .addBeamInitialDisplacement(std::make_unique>(0.2f, 0.4f)) - .addBeamInitialOffset(std::make_unique>(0.1f, 0.2f)) - .addBeamInitialRebuild(std::make_unique>(0.2f, 0.3f)) - .setMaterial(materials.at("beam_lightning")) - .addBeamSpeed(std::make_unique>(0.2f, 0.3f)) - .build(); - } - - { - Material::builder() - .name("skeleton4ik") - .emissive_color( glm::vec4(0.3f, 1.5f, 0.5f, 1.0f)) - .color(glm::vec4(0.3f, 1.5f, 0.5f, 1.0f)) - .fragment("mctx.emissive_color *= circle(getVertexUV(), 0.7);" - "mctx.color.rgb *= circle(getVertexUV(), 0.7);") - .shading(Shading::Unlit) - .blending(Blending::Additive) - .global("#include \"../functions/circle.glsl\"") - .model(InstanceType::Effect) - .build(*this); - } - - { - EffectBuilder builder{*this}; - builder.create("skeleton") - .createEmitter("sparks") - .addLifetime(std::make_unique>(0.8f)) - .addInitialSize(std::make_unique>(5.0f)) - .addInitialMeshLocation(models.at("skeleton"), glm::vec3(0.025f), glm::vec3(-M_PI_2, 0.0f, M_PI_2)) - .setMaterial(materials.at("skeleton4ik")) - .setMaxCount(4000) - .setSpawnRate(4000.0f) - .build(); - } - - { - const fs::path assets_dir {ENGINE_ASSETS_DIR}; - Material::builder() - .name("aura") - .shading(::Shading::Unlit) - .blending(::Blending::Additive) - .two_sided(true) - .diffuse( TextureLoader::load(*this, assets_dir / "textures/aura.png")) - .model(::InstanceType::Effect) - .build(*this); - - Material::builder().name("aura_sparks") - .shading(::Shading::Unlit) - .blending(::Blending::Additive) - .two_sided(true) - .blend_mask(TextureLoader::load(*this, assets_dir / "textures/pirate.jpg", { - TextureLoaderFlags::Origin::TopLeft, - TextureLoaderFlags::Filter::Nearest - })) - .emissive_color( glm::vec4(3.5f, 0.0f, 0.0f, 1.0f)) - .model(::InstanceType::Effect) - .build(*this); - - Material::builder().name("aura_beam") - .shading(::Shading::Unlit) - .blending(::Blending::Additive) - .two_sided(true) - .emissive_color( glm::vec4(3.5f, 0.0f, 0.0f, 1.0f)) - .model(::InstanceType::Effect) - .build(*this); - } - - { - EffectBuilder builder{*this}; - builder.create("aura") - .createEmitter("aura") - .setMesh(meshes.at("plane")) - .setMaterial(materials.at("aura")) - .setLocalSpace(true) - .setSpawnMode(::EmitterSpawn::Mode::Spray) - .setMaxCount(1) - .setSpawnRate(5.0f) - .addInitialSize(std::make_unique>(glm::vec3(2.0f))) - .addRotationRate(std::make_unique>(glm::vec3(0.0f, 1.0f, 0.0f))) - .createEmitter("sparks") - .addLifetime(std::make_unique>(1.5f)) - .addInitialSize(std::make_unique>(100.0f)) - .addInitialVelocity(std::make_unique>(glm::vec3(0.0f, 0.1f, 0.0f), glm::vec3(0.0f, 0.5f, 0.0f))) - .addInitialLocation(std::make_unique>(glm::vec3(-1.0f, 0.0f, -1.0f), glm::vec3(1.0f, 0.0f, 1.0f))) - .setMaterial(materials.at("aura_sparks")) - .setMaxCount(20) - .setSpawnRate(15.0f) - .createEmitter("beam") - .setSpawnMode(::EmitterSpawn::Mode::Spray) - .setMaxCount(10) - .addTime() - .setSpawnRate(10.0f) - .addLifetime(std::make_unique>(1.0f, 2.0f)) - .addInitialSize(std::make_unique>(10.0f)) - .addInitialLocation(std::make_unique>(glm::vec3(-1.0f, 0.0f, -1.0f), glm::vec3(1.0f, 0.0f, 1.0f))) - .addBeamInitialTarget(std::make_unique>(glm::vec3(22.5f, 2.0f, 3.5f), glm::vec3(23.5f, 2.0f, 4.5f))) - .addBeamInitialDisplacement(std::make_unique>(0.2f, 0.4f)) - .addBeamInitialOffset(std::make_unique>(0.1f, 0.2f)) - .addBeamInitialRebuild(std::make_unique>(0.2f, 0.3f)) - .setMaterial(materials.at("aura_beam")) - .addBeamSpeed(std::make_unique>(0.2f, 0.3f)) - .build(); - } -} - -void DemoAssets::loadModelsScene() { -// { -// const fs::path assets_dir{ENGINE_ASSETS_DIR}; -// -// models.add("thanos", ModelLoader::loadModel(*this, assets_dir / "models/thanos/thanos.fbx")); -// -// auto& thanos = dynamic_cast(*models.at("thanos")); -// -// auto& materials = thanos.getMaterials(); -// -// auto yellowenv = -// Material::builder() -// .name("yellowenv") -// .color(glm::vec4(0.546171f, 0.532152f, 0.546140f, 1.0f)) -// .emissive_color( glm::vec4(0.546171f, 0.532152f, 0.546140f, 1.0f)) -// .diffuse( TextureLoader::load(*this, assets_dir / "models/thanos/bodyyellow_m.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/thanos/body_n.tga")) -// .custom("emissive_map", TextureLoader::load(*this, assets_dir / "models/thanos/yellow_env.tga")) -// .fragment("mctx.emissive_color = texture(emissive_map, getVertexUV()).rgb;") -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto grayenv = Material::builder() -// .name("grayenv") -// .color(glm::vec4(0.636099f, 0.753402f, 0.750975f, 1.0f)) -// .emissive_color( glm::vec4(0.636099f, 0.753402f, 0.750975f, 1.0f)) -// .diffuse( TextureLoader::load(*this, assets_dir / "models/thanos/bodygray_m.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/thanos/body_n.tga")) -// .custom("emissive_map", TextureLoader::load(*this, assets_dir / "models/thanos/gray_env.tga")) -// .fragment("mctx.emissive_color = texture(emissive_map, getVertexUV()).rgb;") -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto eyesenv = Material::builder().name("eyesenv") -// .color(glm::vec4(0.539415f, 0.560208f, 0.510821f, 1.0f)) -// .emissive_color( glm::vec4(1.0f)) -// .diffuse( TextureLoader::load(*this, assets_dir / "models/thanos/body_d.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/thanos/body_n.tga")) -// .custom("emissive_map", TextureLoader::load(*this, assets_dir / "models/thanos/eye_env.tga")) -// .fragment("mctx.emissive_color = texture(emissive_map, getVertexUV()).rgb;") -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto blueenv = Material::builder() -// .name("blueenv") -// .color(glm::vec4(0.576473f, 0.481502f, 0.448319f, 1.0f)) -// .emissive_color( glm::vec4(1.0f)) -// .diffuse( TextureLoader::load(*this, assets_dir / "models/thanos/bodyblue_m.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/thanos/body_n.tga")) -// .custom("emissive_map", TextureLoader::load(*this, assets_dir / "models/thanos/blue_env.tga")) -// .fragment("mctx.emissive_color = texture(emissive_map, getVertexUV()).rgb;") -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto eyes = Material::builder() -// .name("eyes") -// .color(glm::vec4(0.551182f, 0.681717f, 0.402268f, 1.0f)) -// .diffuse( TextureLoader::load(*this, assets_dir / "models/thanos/body_d.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/thanos/body_n.tga")) -// .metallic(TextureLoader::load(*this, assets_dir / "models/thanos/body_s.tga")) -// .roughness(0.2f) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto body = Material::builder() -// .name("body") -// .color(glm::vec4(0.566327f, 0.533939f, 0.783312f, 1.0f)) -// .diffuse( TextureLoader::load(*this, assets_dir / "models/thanos/body_d.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/thanos/body_n.tga")) -// .metallic( TextureLoader::load(*this, assets_dir / "models/thanos/body_s.tga")) -// .roughness( 0.2f) -// .ao(TextureLoader::load(*this, assets_dir / "models/thanos/body_ao.tga")) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto skin = Material::builder() -// .name("skin") -// .diffuse(TextureLoader::load(*this, assets_dir / "models/thanos/body_d.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/thanos/body_n.tga")) -// .metallic( TextureLoader::load(*this, assets_dir / "models/thanos/body_s.tga")) -// .roughness( 0.2f) -// .ao( TextureLoader::load(*this, assets_dir / "models/thanos/skin_ao.tga")) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// materials[0] = skin; -// materials[1] = body; -// materials[2] = eyes; -// materials[3] = blueenv; -// materials[4] = eyesenv; -// materials[5] = grayenv; -// materials[6] = skin; -// } - -// { -// const fs::path assets_dir{ENGINE_ASSETS_DIR}; -// -// models.add("daenerys", ModelLoader::loadModel(*this, assets_dir / "models/daenerys/daenerys.fbx")); -// -// auto& daenerys = dynamic_cast(*models.at("daenerys")); -// -// auto& materials = daenerys.getMaterials(); -// -// auto head = Material::builder() -// .name("dae_head") -// .color( glm::vec4(0.657693f, 0.475201f, 0.647254f, 1.0f)) -// .diffuse(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_face_d.png")) -// .normal(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_face_n.png")) -// .metallic(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_face_m.png")) -// .roughness( 0.2f) -// .ao(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_face_L.png")) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto cloth = Material::builder() -// .name("dae_cloth") -// .diffuse(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_cloth_d.png")) -// .normal(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_cloth_ns.png")) -// .metallic(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_cloth_m.png")) -// .roughness( 0.2f) -// .ao(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_cloth_L.png")) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto hair = Material::builder() -// .name("dae_hair") -// .color( glm::vec4(0.657236f, 0.567879f, 0.703609f, 1.0f)) -// .diffuse(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_hair_d.png")) -// .normal(TextureLoader::load(*this, assets_dir / "models/daenerys/tex_commander1_daenerys_hair_n.png")) -// .metallic(TextureLoader::load(*this, assets_dir / "models/daenerys/jitter2.png")) -// .roughness( 0.2f) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// materials[0] = hair; -// materials[1] = cloth; -// materials[2] = head; -// } - -// { -// const fs::path assets_dir{ENGINE_ASSETS_DIR}; -// -// models.add("skeleton", ModelLoader::loadModel(*this, assets_dir / "models/skeleton/skeleton.fbx", {{ -// ModelLoaderOption::NoMaterials -// }})); -// -// auto& materials = dynamic_cast(*models.at("skeleton")).getMaterials(); -// materials.resize(1); -// -// auto skin = Material::builder() -// .name("skeleton") -// .diffuse(TextureLoader::load(*this, assets_dir / "models/skeleton/Skeleton_Body.png")) -// .ao(TextureLoader::load(*this, assets_dir / "models/skeleton/Skeleton_Body_OcclusionRoughnessMetallic.png")) -// .custom("ao_r_m", TextureLoader::load(*this, assets_dir / "models/skeleton/Skeleton_Body_OcclusionRoughnessMetallic.png")) -// .fragment("vec3 skin = texture(ao_r_m, getVertexUV()).rgb;" -// "mctx.ao = skin.r;" -// "mctx.roughness = skin.g;" -// "mctx.metallic = skin.b;") -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// materials[0] = skin; -// } - -// { -// const fs::path assets_dir{ENGINE_ASSETS_DIR}; -// models.add("taskmaster", ModelLoader::loadModel(*this, assets_dir / "models/taskmaster/Taskmaster.fbx")); -// } - -// { -// const fs::path assets_dir{ENGINE_ASSETS_DIR}; -// -// models.add("k2", ModelLoader::loadModel(*this, assets_dir / "models/k2/k2.fbx")); -// -// auto& k2 = dynamic_cast(*models.at("k2")); -// -// auto& materials = k2.getMaterials(); -// -// auto body = Material::builder() -// .name("k2_body") -// .diffuse( TextureLoader::load(*this, assets_dir / "models/k2/K2_D.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/k2/K2_D.tga")) -// .metallic( TextureLoader::load(*this, assets_dir / "models/k2/K2_S.tga")) -// .roughness( 0.2f) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// auto head = Material::builder() -// .name("k2_head") -// .diffuse( TextureLoader::load(*this, assets_dir / "models/k2/K2_Head_D.tga")) -// .normal( TextureLoader::load(*this, assets_dir / "models/k2/K2_Head_N.tga")) -// .metallic( TextureLoader::load(*this, assets_dir / "models/k2/K2_Head_S.tga")) -// .roughness( 0.2f) -// .shading(Shading::Lit) -// .model(InstanceType::Skeletal) -// .build(*this); -// -// materials[0] = head; -// materials[1] = body; -// } - -// { -// const fs::path assets_dir{ENGINE_ASSETS_DIR}; -// -// models.add("elemental", ModelLoader::loadModel(*this, assets_dir / "models/elemental/elemental.fbx")); -// -// auto& elemental = dynamic_cast(*models.at("elemental")); -// -// auto& materials = elemental.getMaterials(); -// -// auto body = Material::builder() -// .name("elemental_body") -// .diffuse( TextureLoader::load(*this, assets_dir / "models/elemental/Textures/Albedo FireElemental.png")) -// .emissive_color(glm::vec4(1.0f)) -// .normal( TextureLoader::load(*this, assets_dir / "models/elemental/Textures/Normal FireElemental.png")) -// .roughness(TextureLoader::load(*this, assets_dir / "models/elemental/Textures/Rougness FireElemental.png")) -// .metallic(0.1f) -// .custom("emissive_map", TextureLoader::load(*this, assets_dir / "models/elemental/Textures/Emission FireElemental.png")) -// .fragment("mctx.emissive_color = texture(emissive_map, getVertexUV()).rgb;") -// .shading(Shading::Lit) -// .build(*this); -// -// materials[0] = body; -// } -// -// { -// const fs::path assets_dir {ENGINE_ASSETS_DIR}; -// -// models.add("bob", ModelLoader::loadModel(*this, assets_dir / "models/boblamp/boblampclean.md5mesh")); -// models.add("backpack", ModelLoader::loadModel(*this, assets_dir / "models/backpack/backpack.obj", {{ -// ::ModelLoaderOption::FlipUV -// }})); -// models.add("cyborg", ModelLoader::loadModel(*this, assets_dir / "models/cyborg/cyborg.obj")); -// models.add("drone", ModelLoader::loadModel(*this, assets_dir / "models/drone/model/BusterDrone.fbx")); -// } -} - -void DemoAssets::loadSponzaScene() { -// const fs::path assets_dir {getAssetsDir()}; -// models.add("sponza", ModelLoader::loadModel(*this, assets_dir / "models/sponza/sponza.obj")); -} - -void DemoAssets::loadAssets() { - loadMaterialsScene(); - loadModelsScene(); - loadLightingScene(); - loadEffectsScene(); -// loadSponzaScene(); - - { - const fs::path assets_dir{ENGINE_ASSETS_DIR}; - - skyboxes.add("skybox", std::make_shared(*this, assets_dir / "skyboxes/sky/sky.png", TextureLoaderFlags { - TextureLoaderFlags::Origin::TopLeft, - TextureLoaderFlags::Space::sRGB - })); - fonts.add("nunito", std::make_shared(assets_dir / "fonts/nunito.ttf", 48)); - } -} - -DemoAssets::DemoAssets(::Context& ctx, ::Renderer& renderer, const fs::path& path) - : ::Assets(path) { - ::Assets::load(ctx); - - { - const fs::path assets_dir{ENGINE_ASSETS_DIR}; - - ctx.setWindowIcon(TextureLoader::loadGLFWImage(*this, assets_dir / "icons/demo.png")); - - loadAssets(); - - compileAssets(ctx, renderer.getSettings()); - } -} diff --git a/demo/assets.hpp b/demo/assets.hpp deleted file mode 100644 index 67558862..00000000 --- a/demo/assets.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -class DemoAssets : public Limitless::Assets { -private: - void loadLightingScene(); - void loadMaterialsScene(); - void loadEffectsScene(); - void loadModelsScene(); - void loadSponzaScene(); - void loadAssets(); -public: - DemoAssets(Limitless::Context& ctx, Limitless::Renderer& renderer, const fs::path& path); - ~DemoAssets() override = default; -}; diff --git a/demo/demo.cpp b/demo/demo.cpp deleted file mode 100644 index bdce2bec..00000000 --- a/demo/demo.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "assets.hpp" -//#include "scene.hpp" - -#include -#include -#include -#include -#include - -using namespace Limitless; - - -class Game : public MouseMoveObserver, public KeyObserver, public FramebufferObserver { -private: - glm::uvec2 window_size {1080, 720}; - - ContextEventObserver context; - Camera camera; - Renderer render; - DemoAssets assets; -// LimitlessDemo::DemoScene scene; - - bool done {}; - bool hidden_text {}; -public: - Game() - : context {"Limitless-demo", window_size, {{ WindowHint::Resizable, false }}} - , camera {window_size} - , render {context} - , assets {context, render, 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(CursorMode::Normal); - context.setSwapInterval(1); - context.setStickyKeys(true); - - context.registerObserver(static_cast(this)); - context.registerObserver(static_cast(this)); - context.registerObserver(static_cast(this)); - - assets.recompileAssets(context, render.getSettings()); - } - - ~Game() override { - context.unregisterObserver(static_cast(this)); - context.unregisterObserver(static_cast(this)); - context.unregisterObserver(static_cast(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, InputState state, [[maybe_unused]] Modifier modifier) override { - if (key == GLFW_KEY_ESCAPE && state == InputState::Pressed) { - done = true; - } - - if (key == GLFW_KEY_TAB && state == InputState::Pressed) { -// scene.next(camera); - } - - if (key == GLFW_KEY_SPACE && state == InputState::Pressed) { - camera.getMoveSpeed() *= 5.0f; - } - - if (key == GLFW_KEY_SPACE && state == InputState::Released) { - camera.getMoveSpeed() /= 5.0f; - } - - if (key == GLFW_KEY_GRAVE_ACCENT && state == InputState::Released) { - hidden_text = !hidden_text; - } - } - - void onFramebufferChange(glm::uvec2 size) override { - camera.updateProjection(size); - window_size = size; - - } - - void handleInput(float delta) noexcept { - 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>(current_time - last_time).count(); - last_time = current_time; - -// scene.update(context, camera); -// render.draw(context, assets, scene.getCurrentScene(), camera); - - context.swapBuffers(); - context.pollEvents(); - - handleInput(delta_time); - } - } -}; - -int main() { - Game game; - game.gameLoop(); - return 0; -} diff --git a/demo/effects_demoscene.cpp b/demo/effects_demoscene.cpp deleted file mode 100644 index 17cbbf67..00000000 --- a/demo/effects_demoscene.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "effects_demoscene.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace LimitlessDemo; -using namespace Limitless; -using namespace Limitless::ms; -using namespace Limitless::fx; - -void EffectsScene::addInstances(Limitless::Assets& assets) { - 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 bob = Instance::builder() -// .model(assets.models.at("bob")) -// .position({29.0f, 1.0f, 19.0f}) -// .rotation(glm::vec3{0.0f, -M_PI_2, M_PI}) -// .scale(glm::vec3(0.025f)) -// .asSkeletal(); -// bob->play(""); -// scene.add(bob); - -// auto mod = Instance::builder() -// .effect(assets.effects.at("modeldrop")) -// .position({0.0f, 0.0f, 0.0f}) -// .asEffect(); -// -// const auto& module = mod->get("sparks") -// .getModule(fx::ModuleType::InitialMeshLocation); -// dynamic_cast&>(*module) -// .attachModelInstance(bob.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() - ); -} - -EffectsScene::EffectsScene(Limitless::Context& ctx, Limitless::Assets& assets) - : scene(ctx) { - addInstances(assets); - - scene.setSkybox(assets.skyboxes.at("skybox")); - - scene.getLighting().getAmbientColor().a *= 0.5; - - scene.add(Light::builder() - .color({0.6, 1.0, 0.3, 1.0f}) - .direction(glm::vec3{-1.0f}) - .build() - ); - - auto floor = std::make_shared>(glm::vec3{0.0f}); - for (int i = 0; i < 30; ++i) { - for (int j = 0; j < 30; ++j) { - floor->addInstance( - std::make_unique( - assets.models.at("plane"), - assets.materials.at("basic4"), - glm::vec3{i, 0.0f, j} - ) - ); - } - } - scene.add(floor); -} - -void EffectsScene::update(Context& context, const Camera& camera) { - scene.update(context, camera); - - hurricane->rotateBy(glm::vec3(0.0f, 0.3f, 0.0f)); -} diff --git a/demo/effects_demoscene.hpp b/demo/effects_demoscene.hpp deleted file mode 100644 index 551e70a3..00000000 --- a/demo/effects_demoscene.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -namespace LimitlessDemo { - class EffectsScene { - private: - Limitless::Scene scene; - std::shared_ptr hurricane {}; - - void addInstances(Limitless::Assets& assets); - public: - EffectsScene(Limitless::Context& ctx, Limitless::Assets& assets); - - auto& getScene() { return scene; } - - void update(Limitless::Context& context, const Limitless::Camera& camera); - }; -} \ No newline at end of file diff --git a/demo/models_demoscene.cpp b/demo/models_demoscene.cpp deleted file mode 100644 index 37405712..00000000 --- a/demo/models_demoscene.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "models_demoscene.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace LimitlessDemo; -using namespace Limitless; - -ModelsScene::ModelsScene(Limitless::Context& ctx, Limitless::Assets& assets) - : scene{ctx} { - scene.setSkybox(assets.skyboxes.at("skybox")); - - scene.add(Light::builder() - .color({1.0, 1.0, 1.0, 1.0f}) - .direction({0.5f, -1.0f, 0.0f}) - .build() - ); - - addInstances(assets); -} - -void ModelsScene::addInstances(Limitless::Assets& assets) { - using namespace Limitless; - - auto floor = std::make_shared>(glm::vec3{0.0f}); - for (int i = 0; i < 30; ++i) { - for (int j = 0; j < 30; ++j) { - floor->addInstance( - std::make_unique( - assets.models.at("plane"), - assets.materials.at("basic4"), - glm::vec3{i, 0.0f, j} - ) - ); - } - } - scene.add(floor); - - scene.add(Instance::builder() - .model(assets.models.at("thanos")) - .position(glm::vec3(25.0f, 1.0f, 1.0f)) - .rotation(glm::vec3{-M_PI_2, -M_PI_2, 0.0f}) - .build() - ); - - scene.add(Instance::builder() - .model(assets.models.at("daenerys")) - .position(glm::vec3(25.0f, 1.0f, 4.0f)) - .rotation(glm::vec3{-M_PI_2, -M_PI_2, 0.0f}) - .build() - ); - - scene.add(Instance::builder() - .model(assets.models.at("taskmaster")) - .position(glm::vec3(25.0f, 1.0f, 7.0f)) - .rotation(glm::vec3{-M_PI_2, -M_PI_2, 0.0f}) - .scale(glm::vec3(0.03f)) - .build() - ); - - scene.add(Instance::builder() - .model(assets.models.at("k2")) - .position(glm::vec3(25.0f, 1.0f, 10.0f)) - .rotation(glm::vec3{-M_PI_2, -M_PI_2, 0.0f}) - .build() - ); - - scene.add(Instance::builder() - .model(assets.models.at("skeleton")) - .position(glm::vec3(25.0f, 1.0f, 13.0f)) - .rotation(glm::vec3{-M_PI_2, -M_PI_2, 0.0f}) - .scale(glm::vec3(0.03f)) - .build() - ); - - scene.add(Instance::builder() - .model(assets.models.at("bob")) - .position(glm::vec3(25.0f, 1.0f, 16.0f)) - .rotation(glm::vec3{0.0f, -M_PI_2, 0.0f}) - .scale(glm::vec3(0.03f)) - .build() - ); - - scene.add(Instance::builder() - .model(assets.models.at("backpack")) - .position(glm::vec3(25.0f, 1.5f, 19.0f)) - .rotation(glm::vec3{0.0f, -M_PI_2, 0.0f}) - .scale(glm::vec3(0.5f)) - .asModel() - ); - - scene.add(Instance::builder() - .model(assets.models.at("cyborg")) - .position(glm::vec3(25.0f, 1.0f, 21.0f)) - .rotation(glm::vec3{0.0f, -M_PI_2, 0.0f}) - .scale(glm::vec3(0.5f)) - .asModel() - ); - - scene.add(Instance::builder() - .model(assets.models.at("drone")) - .position(glm::vec3(25.0f, 2.0f, 24.0f)) - .rotation(glm::vec3{M_PI, M_PI_2, 0.0f}) - .scale(glm::vec3(0.01f)) - .asModel() - ); - - scene.add(Instance::builder() - .model(assets.models.at("elemental")) - .position(glm::vec3(25.0f, 2.0f, 27.0f)) - .rotation(glm::vec3{-M_PI_2, -M_PI_2, 0.0f}) - .scale(glm::vec3(10.0f)) - .asModel() - ); -} - -void ModelsScene::update(Limitless::Context& context, const Limitless::Camera& camera) { - scene.update(context, camera); -} \ No newline at end of file diff --git a/demo/models_demoscene.hpp b/demo/models_demoscene.hpp deleted file mode 100644 index 45ee3f0c..00000000 --- a/demo/models_demoscene.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace LimitlessDemo { - class ModelsScene { - private: - Limitless::Scene scene; - void addInstances(Limitless::Assets& assets); - public: - ModelsScene(Limitless::Context& ctx, Limitless::Assets& assets); - - auto& getScene() { return scene; } - - void update(Limitless::Context& context, const Limitless::Camera& camera); - }; -} \ No newline at end of file diff --git a/demo/scene.hpp b/demo/scene.hpp deleted file mode 100644 index b29c14b1..00000000 --- a/demo/scene.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#pragma once - -#include -#include "lighting_demoscene.hpp" -#include "../samples/materials_scene/scene.hpp" -#include "effects_demoscene.hpp" -#include "models_demoscene.hpp" - -using namespace Limitless; - -namespace LimitlessDemo { - class DemoScene { - private: - LightingScene lightingScene; - MaterialsScene materialsScene; - EffectsScene effectsScene; - ModelsScene modelsScene; - uint32_t current {0}; - public: - DemoScene(Context& ctx, Assets& assets) - : lightingScene {ctx, assets} - , materialsScene {ctx, assets} - , effectsScene {ctx, assets} - , modelsScene {ctx, assets} { - } - - static void setCameraDefault(Camera& camera) { - camera.setPosition({15.0f, 10.0f, 15.0f}); - } - - void next(Camera& camera) { - ++current; - - if (current > 4 - 1) { - current = 0; - } - - setCameraDefault(camera); - } - - void update(Context& ctx, Camera& camera) { - switch (current) { - case 0: - lightingScene.update(ctx, camera); - case 1: - materialsScene.update(ctx, camera); - case 2: - effectsScene.update(ctx, camera); - case 3: - modelsScene.update(ctx, camera); - default: - lightingScene.update(ctx, camera); - } - } - - Limitless::Scene& getCurrentScene() noexcept { - switch (current) { - case 0: - return lightingScene.getScene(); - case 1: - return materialsScene.getScene(); - case 2: - return effectsScene.getScene(); - case 3: - return modelsScene.getScene(); - default: - return lightingScene.getScene(); - } - } - }; -} diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index cccab3a4..a52717cb 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -28,4 +28,12 @@ add_executable(limitless-effects effects/assets.cpp effects/scene.cpp ) -target_link_libraries(limitless-effects PRIVATE limitless-engine) \ No newline at end of file +target_link_libraries(limitless-effects PRIVATE limitless-engine) + +# test lighting scene +add_executable(limitless-lighting + lighting/main.cpp + lighting/assets.cpp + lighting/scene.cpp +) +target_link_libraries(limitless-lighting PRIVATE limitless-engine) \ No newline at end of file diff --git a/samples/effects/assets.cpp b/samples/effects/assets.cpp index 76395dda..aeeac6ed 100644 --- a/samples/effects/assets.cpp +++ b/samples/effects/assets.cpp @@ -231,7 +231,7 @@ void LimitlessMaterials::Assets::setUpEffects() { { Material::builder().name("hurricane") .blending(Blending::Additive) - .emissive_color(glm::vec4(5.0, 0.0, 5.0, 1.0)) + .emissive_color(glm::vec4(50.0, 0.0, 50.0, 1.0)) .color(glm::vec4(0.0)) .fragment("mctx.emissive_color *= circle(getVertexUV(), 0.5);") .global("#include \"../functions/circle.glsl\"") diff --git a/samples/lighting/assets.cpp b/samples/lighting/assets.cpp new file mode 100644 index 00000000..2626ab0a --- /dev/null +++ b/samples/lighting/assets.cpp @@ -0,0 +1,54 @@ +#include "assets.hpp" + +#include +#include +#include +#include + +void LimitlessMaterials::Assets::setUpMaterials() { + using namespace Limitless; + using namespace Limitless::ms; + + const fs::path assets_dir {ENGINE_ASSETS_DIR}; + + Material::builder() + .name("basic1") + .metallic(0.3f) + .roughness(TextureLoader::load(*this, assets_dir / "textures/stonework_roughness.png")) + .diffuse(TextureLoader::load(*this, assets_dir / "textures/stonework_albedo.png")) + .ao(TextureLoader::load(*this, assets_dir / "textures/stonework_ao.png")) + .normal(TextureLoader::load(*this, assets_dir / "textures/stonework_normal.png")) + .shading(Shading::Lit) + .models({InstanceType::Model, InstanceType::Instanced}) + .build(*this); + + Material::builder() + .name("PBR") + .metallic(TextureLoader::load(*this, assets_dir / "textures/rustediron2_metallic.png")) + .roughness(TextureLoader::load(*this, assets_dir / "textures/rustediron2_roughness.png")) + .diffuse(TextureLoader::load(*this, assets_dir / "textures/rustediron2_basecolor.png", {TextureLoaderFlags::Space::sRGB})) + .normal(TextureLoader::load(*this, assets_dir / "textures/rustediron2_normal.png")) + .shading(Shading::Lit) + .models({InstanceType::Instanced, InstanceType::Model}) + .build(*this); +} + +LimitlessMaterials::Assets::Assets(Limitless::Context &ctx, Limitless::Renderer &renderer, const fs::path &path) + : Limitless::Assets {path} { + Assets::load(ctx); + setUpCommon(ctx); + setUpMaterials(); +} + +void LimitlessMaterials::Assets::setUpCommon(Limitless::Context &ctx) { + const fs::path assets_dir {ENGINE_ASSETS_DIR}; + + skyboxes.add("skybox", std::make_shared(*this, assets_dir / "skyboxes/sky/sky.png", Limitless::TextureLoaderFlags { + Limitless::TextureLoaderFlags::Origin::TopLeft, + Limitless::TextureLoaderFlags::Space::sRGB + })); + + fonts.add("nunito", std::make_shared(assets_dir / "fonts/nunito.ttf", 48)); + + ctx.setWindowIcon(Limitless::TextureLoader::loadGLFWImage(*this, assets_dir / "icons/demo.png")); +} diff --git a/samples/lighting/assets.hpp b/samples/lighting/assets.hpp new file mode 100644 index 00000000..44318ca6 --- /dev/null +++ b/samples/lighting/assets.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +namespace LimitlessMaterials { + class Assets : public Limitless::Assets { + private: + void setUpMaterials(); + void setUpCommon(Limitless::Context &ctx); + public: + Assets(Limitless::Context& ctx, Limitless::Renderer& renderer, const fs::path& path); + }; +} \ No newline at end of file diff --git a/samples/lighting/main.cpp b/samples/lighting/main.cpp new file mode 100644 index 00000000..3d3ec8d9 --- /dev/null +++ b/samples/lighting/main.cpp @@ -0,0 +1,135 @@ +#include "scene.hpp" +#include "assets.hpp" + +#include +#include +#include +#include +#include +#include + +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, render, 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(this)); + context.registerObserver(static_cast(this)); + context.registerObserver(static_cast(this)); + + assets.recompileAssets(context, render.getSettings()); + } + + ~MaterialsScene() override { + context.unregisterObserver(static_cast(this)); + context.unregisterObserver(static_cast(this)); + context.unregisterObserver(static_cast(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>(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; +} diff --git a/demo/lighting_demoscene.cpp b/samples/lighting/scene.cpp similarity index 56% rename from demo/lighting_demoscene.cpp rename to samples/lighting/scene.cpp index 8447c4a1..497fa72c 100644 --- a/demo/lighting_demoscene.cpp +++ b/samples/lighting/scene.cpp @@ -1,48 +1,22 @@ -#include "lighting_demoscene.hpp" +#include "scene.hpp" -#include +#include #include +#include +#include #include -using namespace LimitlessDemo; +using namespace LimitlessMaterials; using namespace Limitless; -void LightingScene::addFloor(const Limitless::Assets& assets) { - using namespace Limitless; - - auto floor = std::make_shared>(glm::vec3{0.0f}); - for (int i = 0; i < FLOOR_INSTANCE_COUNT / 2; ++i) { - for (int j = 0; j < FLOOR_INSTANCE_COUNT / 2; ++j) { - floor->addInstance( - std::make_unique( - assets.models.at("plane"), - assets.materials.at("basic1"), - glm::vec3{i, 0.0f, j} - ) - ); - } - } - scene.add(floor); +LimitlessMaterials::Scene::Scene(Limitless::Context& ctx, Limitless::Assets& assets) + : scene(ctx) + , assets {assets} { + setUpLighting(); + setUpModels(); } -void LightingScene::addSpheres(const Limitless::Assets& assets) { - using namespace Limitless; - auto spheres = std::make_shared>(glm::vec3{0.0f}); - for (int i = 0; i < FLOOR_INSTANCE_COUNT / 4; ++i) { - for (int j = 0; j < FLOOR_INSTANCE_COUNT / 4; ++j) { - spheres->addInstance( - std::make_unique( - assets.models.at("sphere"), - assets.materials.at("PBR"), - glm::vec3{i * 2.0, 1.0f, j * 2.0} - ) - ); - } - } - scene.add(spheres); -} - -bool LightingScene::isInsideFloor(const glm::vec3& position) { +bool LimitlessMaterials::Scene::isInsideFloor(const glm::vec3& position) { if (position.x > FLOOR_INSTANCE_COUNT / 2.0f || position.x < 0.0f) { return false; } @@ -54,33 +28,9 @@ bool LightingScene::isInsideFloor(const glm::vec3& position) { return true; } -void LightingScene::addLights() { - for (int i = 0; i < LIGHT_COUNT; ++i) { - scene.add(Light::builder() - .position({FLOOR_INSTANCE_COUNT / 4.0f, 1.0f, FLOOR_INSTANCE_COUNT / 4.0f}) - .color({1.0f, 1.0f, 1.0f, 1.0f}) - .radius(2.0f) - .build() - ); - } -} - -LightingScene::LightingScene(Limitless::Context& ctx, const Limitless::Assets& assets) - : scene {ctx} { - addFloor(assets); - addSpheres(assets); - addLights(); - - scene.setSkybox(assets.skyboxes.at("skybox")); - scene.getLighting().getAmbientColor().a = 0.7f; - scene.add(Light::builder() - .color(glm::vec4(1.0, 1.0, 0.5, 1.0f)) - .direction(glm::vec3{-1.0f}) - .build() - ); -} +void LimitlessMaterials::Scene::update(Limitless::Context& context, const Limitless::Camera& camera) { + scene.update(context, camera); -void LightingScene::update(Limitless::Context& context, const Limitless::Camera& camera) { using namespace std::chrono; auto current_time = steady_clock::now(); static auto last_time = steady_clock::now(); @@ -97,7 +47,7 @@ void LightingScene::update(Limitless::Context& context, const Limitless::Camera& auto& light_data = data[i++]; light.getPosition() += glm::vec3(light_data.direction) * delta_time * 10.0f; - light.getPosition() = glm::clamp(light.getPosition(), glm::vec3(0.0f), glm::vec3(FLOOR_INSTANCE_COUNT / 2.0f)); + light.getPosition() = glm::clamp(light.getPosition(), glm::vec3(0.0f), glm::vec3(64 / 2.0f)); if (light_data.duration <= 0.0f) { light_data.direction = glm::vec3(dis_direction(e), 0.0f, dis_direction(e)); @@ -111,6 +61,53 @@ void LightingScene::update(Limitless::Context& context, const Limitless::Camera& light_data.direction *= -0.3f; } } +} - scene.update(context, camera); +void LimitlessMaterials::Scene::setUpModels() { + using namespace Limitless; + + auto floor = std::make_shared(); + for (int i = 0; i < FLOOR_INSTANCE_COUNT / 2; ++i) { + for (int j = 0; j < FLOOR_INSTANCE_COUNT / 2; ++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); + + using namespace Limitless; + auto spheres = std::make_shared(); + for (int i = 0; i < FLOOR_INSTANCE_COUNT / 4; ++i) { + for (int j = 0; j < FLOOR_INSTANCE_COUNT / 4; ++j) { + spheres->add(Instance::builder() + .model(assets.models.at("sphere")) + .material(assets.materials.at("PBR")) + .position(glm::vec3{i * 2.0, 1.0f, j * 2.0}) + .asModel() + ); + } + } + scene.add(spheres); +} + +void LimitlessMaterials::Scene::setUpLighting() { + scene.getLighting().getAmbientColor().a = 0.7f; + scene.add(Light::builder() + .color(glm::vec4(1.0, 1.0, 0.5, 1.0f)) + .direction(glm::vec3{-1.0f}) + .build() + ); + + for (int i = 0; i < LIGHT_COUNT; ++i) { + scene.add(Light::builder() + .position({FLOOR_INSTANCE_COUNT / 4.0f, 1.0f, FLOOR_INSTANCE_COUNT / 4.0f}) + .color({1.0f, 1.0f, 1.0f, 1.0f}) + .radius(2.0f) + .build() + ); + } } diff --git a/demo/lighting_demoscene.hpp b/samples/lighting/scene.hpp similarity index 51% rename from demo/lighting_demoscene.hpp rename to samples/lighting/scene.hpp index fc5cccaa..34bf34d9 100644 --- a/demo/lighting_demoscene.hpp +++ b/samples/lighting/scene.hpp @@ -1,13 +1,13 @@ #pragma once #include -#include -#include #include +#include -namespace LimitlessDemo { - class LightingScene { +namespace LimitlessMaterials { + class Scene { private: + Limitless::Assets& assets; Limitless::Scene scene; static constexpr auto FLOOR_INSTANCE_COUNT = 64; @@ -17,14 +17,13 @@ namespace LimitlessDemo { glm::vec3 direction {}; float duration {}; }; - std::array data; + std::array data; - void addFloor(const Limitless::Assets& assets); - void addSpheres(const Limitless::Assets& assets); - static bool isInsideFloor(const glm::vec3& position); - void addLights(); + void setUpModels(); + void setUpLighting(); + bool isInsideFloor(const glm::vec3& position); public: - LightingScene(Limitless::Context& ctx, const Limitless::Assets& assets); + Scene(Limitless::Context& ctx, Limitless::Assets& assets); auto& getScene() { return scene; }