Misc renderer improvements:

- Reuse renderer and gltf loader between scenes
- Use puish descriptors to simplify the management of descriptor sets in the scene renderer
- Don't keep the imgui swapchain in the scene classes
- Fix alpha blending, add alpha masking
- Fix mipmaps not being used in renderer
- Add cache when loading images and models
- Only premultiply the colours if required
- Add support for gltTF animations

Allow removing an object and its descendants from the scene, allow loading from a memory buffer
This commit is contained in:
Guillaume Meunier
2025-10-23 21:39:12 +02:00
parent 1f6ea0d4ca
commit aad1bb6a1b
21 changed files with 918 additions and 375 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ void hand_model::add_hand(scene & scene,
const std::filesystem::path & gltf_path,
uint32_t layer_mask)
{
auto && [entity, node] = scene.load_gltf(gltf_path, layer_mask);
auto && [entity, node] = scene.add_gltf(gltf_path, layer_mask);
node.name = gltf_path.stem();
+10 -16
View File
@@ -182,7 +182,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
id = std::string(root["profileId"]);
std::vector<std::tuple<std::string, entt::entity, entt::registry>> models;
std::vector<std::tuple<std::string, entt::entity, std::shared_ptr<entt::registry>>> models;
std::vector<json_visual_response> json_responses;
// Fill models with the different models to be loaded and their name ("left" or "right")
@@ -193,9 +193,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
// std::string user_path = "/user/hand/" + std::string(layout.key);
std::filesystem::path asset_path = json_profile.parent_path() / std::string(layout.value["assetPath"]);
// scene.load_gltf(asset_path);
entt::registry & data = std::get<2>(models.emplace_back(layout.key, entt::null, (*scene.loader)(asset_path)));
std::shared_ptr<entt::registry> data = std::get<2>(models.emplace_back(layout.key, entt::null, scene.load_gltf(asset_path)));
for (simdjson::dom::key_value_pair component: simdjson::dom::object(layout.value["components"]))
{
@@ -221,14 +219,14 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
vr.component_subpath = component_subpath;
// Check if the node exists
find_node_by_name(data, vr.target_node);
find_node_by_name(*data, vr.target_node);
auto node_property = parse_value_node_property(response.value["valueNodeProperty"]);
switch (node_property)
{
case value_node_property::transform: {
auto min_node = data.get<components::node>(find_node_by_name(data, std::string(response.value["minNodeName"])));
auto max_node = data.get<components::node>(find_node_by_name(data, std::string(response.value["maxNodeName"])));
auto min_node = data->get<components::node>(find_node_by_name(*data, std::string(response.value["minNodeName"])));
auto max_node = data->get<components::node>(find_node_by_name(*data, std::string(response.value["maxNodeName"])));
components::details::node_state_transform min{
min_node.position,
@@ -265,14 +263,10 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
else
continue;
entity = scene.world.create();
scene.world.emplace<bound_space>(entity, space);
scene.world.emplace<components::node>(entity, components::node{
.name = layout,
.layer_mask = layer_mask_controller,
});
scene.loader->add_prefab(scene.world, std::move(model), entity);
auto [e, node] = scene.add_gltf(model, layer_mask_controller);
node.name = layout;
entity = e;
scene.world.emplace<bound_space>(e, space);
spdlog::debug("Created entity {}", layout);
}
@@ -287,7 +281,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
else
continue;
auto && [entity, node] = scene.load_gltf(controller_ray_model_name(), layer_mask_ray);
auto && [entity, node] = scene.add_gltf(controller_ray_model_name(), layer_mask_ray);
node.name = (std::string)layout.key + "_ray";
spdlog::debug("Created entity {}", node.name);
+18 -13
View File
@@ -26,6 +26,7 @@
#include "imgui.h"
#include "openxr/openxr.h"
#include "protocol_version.h"
#include "render/animation.h"
#include "stream.h"
#include "utils/i18n.h"
#include "wivrn_client.h"
@@ -571,7 +572,7 @@ void scenes::lobby::render(const XrFrameState & frame_state)
{
auto session = async_session.get();
if (session)
next_scene = stream::create(std::move(session), 1'000'000'000.f / frame_state.predictedDisplayPeriod, server_name);
next_scene = stream::create(std::move(session), 1'000'000'000.f / frame_state.predictedDisplayPeriod, server_name, *this);
async_session.reset();
}
@@ -724,6 +725,8 @@ void scenes::lobby::render(const XrFrameState & frame_state)
input->apply(world, world_space, frame_state.predictedDisplayTime, hide_left_controller, hide_right_controller, ray_limits);
renderer::animate(world, frame_state.predictedDisplayPeriod * 1.0e-9);
assert(renderer);
world.get<components::node>(lobby_entity).visible = not application::get_config().passthrough_enabled;
@@ -796,10 +799,7 @@ void scenes::lobby::on_focused()
// assert(std::ranges::all_of(views, [width](const XrViewConfigurationView & view) { return view.recommendedImageRectWidth == width; }));
// assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; }));
renderer.emplace(device, physical_device, queue, commandpool);
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
lobby_entity = load_gltf("ground.glb", layer_lobby).first;
lobby_entity = add_gltf("ground.glb", layer_lobby).first;
std::string profile = controller_name();
input.emplace(
@@ -830,8 +830,8 @@ void scenes::lobby::on_focused()
offset_orientation = glm::degrees(glm::eulerAngles(input->offset[xr::spaces::grip_left].second));
ray_offset = input->offset[xr::spaces::aim_left].first.z;
xyz_axes_left_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
xyz_axes_left_controller = add_gltf("xyz-arrows.glb", layer_controllers).first;
xyz_axes_right_controller = add_gltf("xyz-arrows.glb", layer_controllers).first;
#endif
recenter_left_action = get_action("recenter_left").first;
@@ -906,9 +906,17 @@ void scenes::lobby::on_focused()
.z_index = constants::lobby::zindex_recenter_tip,
}};
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 3000, 1300);
xr::swapchain swapchain_imgui(session, device, swapchain_format, 3000, 1300);
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, imgui_inputs, swapchain_imgui, vps);
imgui_ctx.emplace(
physical_device,
device,
queue_family_index,
queue,
imgui_inputs,
std::move(swapchain_imgui),
vps,
image_cache);
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
auto tm = std::localtime(&t);
@@ -937,17 +945,14 @@ void scenes::lobby::on_unfocused()
about_picture = 0;
imgui_ctx.reset();
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
world.clear();
input.reset();
left_hand.reset();
right_hand.reset();
face_tracker.emplace<std::monostate>();
loader.reset();
renderer.reset();
clear_swapchains();
swapchain_imgui = xr::swapchain();
multicast.reset();
}
+1 -3
View File
@@ -80,7 +80,6 @@ class lobby : public scene_impl<lobby>
uint32_t width;
uint32_t height;
xr::swapchain swapchain_imgui;
XrViewConfigurationView stream_view;
#if WIVRN_CLIENT_DEBUG_MENU
@@ -100,8 +99,7 @@ class lobby : public scene_impl<lobby>
XrAction recenter_left_action = XR_NULL_HANDLE;
XrAction recenter_right_action = XR_NULL_HANDLE;
// std::optional<glm::vec3> gui_recenter_position;
// std::optional<float> gui_recenter_distance;
// Which controller is used for recentering, position of the pointed point in the GUI, in GUI axes, and distance between the controller and the pointed point during recentering
std::optional<std::tuple<xr::spaces, glm::vec3, float>> recentering_context;
bool recenter_gui = true;
+11 -15
View File
@@ -151,8 +151,8 @@ static const std::array supported_depth_formats{
vk::Format::eX8D24UnormPack32,
};
scenes::stream::stream(std::string server_name) :
scene_impl<stream>(supported_color_formats, supported_depth_formats),
scenes::stream::stream(std::string server_name, scene & parent_scene) :
scene_impl<stream>(supported_color_formats, supported_depth_formats, parent_scene),
apps{*this, std::move(server_name)},
blitters{blitter(device, 0), blitter(device, 1)}
{
@@ -186,9 +186,9 @@ static from_headset::visibility_mask_changed::masks get_visibility_mask(xr::inst
return res;
}
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps, std::string server_name)
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps, std::string server_name, scene & parent_scene)
{
std::shared_ptr<stream> self{new stream{std::move(server_name)}};
std::shared_ptr<stream> self{new stream{std::move(server_name), parent_scene}};
self->network_session = std::move(network_session);
self->network_session->send_control([&]() {
@@ -390,6 +390,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
});
self->wifi = application::get_wifi_lock().get_wifi_lock();
return self;
}
@@ -402,9 +403,6 @@ void scenes::stream::on_focused()
width = views[0].recommendedImageRectWidth;
height = views[0].recommendedImageRectHeight;
renderer.emplace(device, physical_device, queue, commandpool);
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
std::string profile = controller_name();
input.emplace(
*this,
@@ -448,7 +446,7 @@ void scenes::stream::on_focused()
},
};
swapchain_imgui = xr::swapchain(
xr::swapchain swapchain_imgui(
session,
device,
swapchain_format,
@@ -468,8 +466,9 @@ void scenes::stream::on_focused()
queue_family_index,
queue,
imgui_inputs,
swapchain_imgui,
std::vector{vp});
std::move(swapchain_imgui),
std::vector{vp},
image_cache);
if (application::get_config().enable_stream_gui)
{
@@ -492,17 +491,14 @@ void scenes::stream::on_focused()
void scenes::stream::on_unfocused()
{
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets;
world.clear();
input.reset();
loader.reset();
renderer.reset();
clear_swapchains();
left_hand.reset();
right_hand.reset();
imgui_ctx.reset();
swapchain_imgui = xr::swapchain();
}
scenes::stream::~stream()
+3 -3
View File
@@ -110,7 +110,6 @@ private:
state state_ = state::initializing;
xr::swapchain swapchain;
xr::swapchain swapchain_imgui;
std::optional<audio> audio_handle;
@@ -172,7 +171,7 @@ private:
XrTime running_application_req = 0;
thread_safe<to_headset::running_applications> running_applications;
stream(std::string server_name);
stream(std::string server_name, scene & parent_scene);
public:
~stream();
@@ -180,7 +179,8 @@ public:
static std::shared_ptr<stream> create(
std::unique_ptr<wivrn_session> session,
float guessed_fps,
std::string server_name);
std::string server_name,
scene & parent_scene);
void render(const XrFrameState &) override;
void on_focused() override;