diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 813e140..65c46f1 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -495,10 +495,12 @@ void setup_rendering(game_context* ctx) // Setup overworld compositor ctx->overworld_shadow_map_clear_pass = new clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer); ctx->overworld_shadow_map_clear_pass->set_cleared_buffers(false, true, false); + ctx->overworld_shadow_map_clear_pass->set_clear_depth(1.0f); ctx->overworld_shadow_map_pass = new shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager); ctx->overworld_shadow_map_pass->set_split_scheme_weight(0.75f); ctx->overworld_clear_pass = new clear_pass(ctx->rasterizer, ctx->framebuffer_hdr); ctx->overworld_clear_pass->set_cleared_buffers(true, true, true); + ctx->overworld_clear_pass->set_clear_depth(0.0f); ctx->overworld_sky_pass = new sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager); ctx->app->get_event_dispatcher()->subscribe(ctx->overworld_sky_pass); ctx->overworld_sky_pass->set_enabled(false); @@ -548,6 +550,7 @@ void setup_rendering(game_context* ctx) // Setup UI camera compositor ctx->ui_clear_pass = new clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer()); ctx->ui_clear_pass->set_cleared_buffers(false, true, false); + ctx->ui_clear_pass->set_clear_depth(0.0f); ctx->ui_material_pass = new material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager); ctx->ui_material_pass->set_fallback_material(ctx->fallback_material); ctx->ui_compositor = new compositor(); diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index f3118a5..d9a24c8 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -119,6 +119,7 @@ void play_state_enter(game_context* ctx) ecs::archetype* lens_light_cone_archetype = resource_manager->load("lens-light-cone.ent"); ecs::archetype* ant_head_archetype = resource_manager->load("ant-head.ent"); ecs::archetype* dandelion_plant_archetype = resource_manager->load("dandelion-plant.ent"); + ecs::archetype* grassland_road_archetype = resource_manager->load("grassland-road.ent"); // Create tools forceps_archetype->assign(ecs_registry, ctx->forceps_entity); @@ -158,6 +159,20 @@ void play_state_enter(game_context* ctx) // Activate brush tool ctx->tool_system->set_active_tool(ctx->brush_entity); + + // Create background + for (int i = 0; i < 4; ++i) + { + auto road_entity = grassland_road_archetype->create(ecs_registry); + auto& transform = ecs_registry.get(road_entity); + + math::quaternion rotation = math::angle_axis(math::half_pi * static_cast(i), float3{0, 1, 0}); + float3 translation = rotation * float3{0, 0, 1600.0f}; + + transform.local = math::identity_transform; + transform.local.rotation = rotation; + transform.local.translation = translation; + } // Create ant-hill auto ant_hill_entity = ant_hill_archetype->create(ecs_registry); @@ -165,7 +180,7 @@ void play_state_enter(game_context* ctx) // Generate pebbles float pebble_radius = 300.0f; - int pebble_count = 100; + int pebble_count = 20; for (int i = 0; i < pebble_count; ++i) { float x = math::random(-pebble_radius, pebble_radius); @@ -189,7 +204,7 @@ void play_state_enter(game_context* ctx) auto nest_entity = nest_archetype->create(ecs_registry); // Create terrain - int terrain_radius = 2; + int terrain_radius = 8; for (int x = -terrain_radius; x <= terrain_radius; ++x) { for (int z = -terrain_radius; z <= terrain_radius; ++z) diff --git a/src/game/systems/camera-system.cpp b/src/game/systems/camera-system.cpp index 666a548..d83fde7 100644 --- a/src/game/systems/camera-system.cpp +++ b/src/game/systems/camera-system.cpp @@ -39,7 +39,7 @@ camera_system::camera_system(entt::registry& registry): orbit_cam.set_focal_distance_limits({2.0f, 200.0f}); orbit_cam.set_fov_limits({math::radians(80.0f), math::radians(35.0f)}); orbit_cam.set_clip_near_limits({0.1f, 5.0f}); - orbit_cam.set_clip_far_limits({100.0f, 2000.0f}); + orbit_cam.set_clip_far_limits({5000.0f, 5000.0f}); orbit_cam.set_target_focal_point({0.0f, 0.0f, 0.0f}); orbit_cam.set_target_azimuth(0.0f); diff --git a/src/game/systems/vegetation-system.cpp b/src/game/systems/vegetation-system.cpp index 6fce8a9..6c65da3 100644 --- a/src/game/systems/vegetation-system.cpp +++ b/src/game/systems/vegetation-system.cpp @@ -39,8 +39,8 @@ vegetation_system::vegetation_system(entt::registry& registry): vegetation_density(1.0f), vegetation_model(nullptr) { - registry.on_construct().connect<&vegetation_system::on_terrain_construct>(this); - registry.on_destroy().connect<&vegetation_system::on_terrain_destroy>(this); + //registry.on_construct().connect<&vegetation_system::on_terrain_construct>(this); + //registry.on_destroy().connect<&vegetation_system::on_terrain_destroy>(this); } vegetation_system::~vegetation_system() diff --git a/src/math/matrix-functions.hpp b/src/math/matrix-functions.hpp index 1c8dc3a..8b35302 100644 --- a/src/math/matrix-functions.hpp +++ b/src/math/matrix-functions.hpp @@ -660,8 +660,8 @@ matrix perspective(T vertical_fov, T aspect_ratio, T z_near, T z_far) {{ {f / aspect_ratio, T(0), T(0), T(0)}, {T(0), f, T(0), T(0)}, - {T(0), T(0), (z_near + z_far) / (z_near - z_far), T(-1)}, - {T(0), T(0), (T(2) * z_near * z_far) / (z_near - z_far), T(0)} + {T(0), T(0), (z_far + z_near) / (z_near - z_far), T(-1)}, + {T(0), T(0), (T(2) * z_far * z_near) / (z_near - z_far), T(0)} }}; } diff --git a/src/renderer/passes/material-pass.cpp b/src/renderer/passes/material-pass.cpp index fa77c30..83eb04d 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/renderer/passes/material-pass.cpp @@ -106,9 +106,8 @@ void material_pass::render(render_context* context) const glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); - glDepthFunc(GL_LESS); + glDepthFunc(GL_GREATER); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glDisable(GL_STENCIL_TEST); @@ -354,7 +353,7 @@ void material_pass::render(render_context* context) const if (material_flags & MATERIAL_FLAG_DECAL) { glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); + glDepthFunc(GL_GEQUAL); glDepthMask(GL_FALSE); glEnable(GL_STENCIL_TEST); @@ -367,7 +366,7 @@ void material_pass::render(render_context* context) const else { glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); + glDepthFunc(GL_GREATER); glDepthMask(GL_TRUE); glDisable(GL_STENCIL_TEST); glStencilMask(0); diff --git a/src/scene/camera.cpp b/src/scene/camera.cpp index 93c82d3..3226e8c 100644 --- a/src/scene/camera.cpp +++ b/src/scene/camera.cpp @@ -40,16 +40,16 @@ static float4x4 interpolate_projection(const camera* camera, const float4x4& x, camera->get_clip_right_tween().interpolate(a), camera->get_clip_bottom_tween().interpolate(a), camera->get_clip_top_tween().interpolate(a), - camera->get_clip_near_tween().interpolate(a), - camera->get_clip_far_tween().interpolate(a)); + camera->get_clip_far_tween().interpolate(a), + camera->get_clip_near_tween().interpolate(a)); } else { return math::perspective( camera->get_fov_tween().interpolate(a), camera->get_aspect_ratio_tween().interpolate(a), - camera->get_clip_near_tween().interpolate(a), - camera->get_clip_far_tween().interpolate(a)); + camera->get_clip_far_tween().interpolate(a), + camera->get_clip_near_tween().interpolate(a)); } } @@ -94,7 +94,8 @@ float3 camera::unproject(const float3& window, const float4& viewport) const result[0] = ((window[0] - viewport[0]) / viewport[2]) * 2.0f - 1.0f; result[1] = ((window[1] - viewport[1]) / viewport[3]) * 2.0f - 1.0f; //result[2] = window[2] * 2.0f - 1.0f; z: [-1, 1] - result[2] = window[2]; // z: [0, 1] + //result[2] = window[2]; // z: [0, 1] + result[2] = 1.0f - window[2]; // z: [1, 0] result[3] = 1.0f; result = math::inverse(view_projection[1]) * result; @@ -111,7 +112,7 @@ void camera::set_perspective(float fov, float aspect_ratio, float clip_near, flo this->clip_near[1] = clip_near; this->clip_far[1] = clip_far; - projection[1] = math::perspective_half_z(fov, aspect_ratio, clip_near, clip_far); + projection[1] = math::perspective_half_z(fov, aspect_ratio, clip_far, clip_near); // Recalculate view-projection matrix view_projection[1] = projection[1] * view[1]; @@ -131,7 +132,7 @@ void camera::set_orthographic(float clip_left, float clip_right, float clip_bott this->clip_near[1] = clip_near; this->clip_far[1] = clip_far; - projection[1] = math::ortho(clip_left, clip_right, clip_bottom, clip_top, clip_near, clip_far); + projection[1] = math::ortho_half_z(clip_left, clip_right, clip_bottom, clip_top, clip_far, clip_near); // Recalculate view-projection matrix view_projection[1] = projection[1] * view[1];