Use custom clipping to clip controller rays
This commit is contained in:
@@ -1037,11 +1037,9 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> imgui_context::end_frame()
|
||||
return quads;
|
||||
}
|
||||
|
||||
std::vector<imgui_context::viewport> imgui_context::windows()
|
||||
std::vector<imgui_context::window_viewport> imgui_context::windows()
|
||||
{
|
||||
std::vector<imgui_context::viewport> w;
|
||||
|
||||
ImGuiWindow * modal_popup = ImGui::GetTopMostAndVisiblePopupModal();
|
||||
std::vector<imgui_context::window_viewport> w;
|
||||
|
||||
for (const imgui_context::viewport & layer: layers_)
|
||||
{
|
||||
@@ -1052,10 +1050,7 @@ std::vector<imgui_context::viewport> imgui_context::windows()
|
||||
|
||||
for (ImGuiWindow * window: context->Windows)
|
||||
{
|
||||
if (not window->Active or window->Hidden /*or window->ParentWindowInBeginStack != nullptr*/)
|
||||
continue;
|
||||
|
||||
if (modal_popup != nullptr and window != modal_popup and not layer.always_show_cursor)
|
||||
if (not window->Active or window->Hidden or (window->Flags & ImGuiWindowFlags_ChildWindow))
|
||||
continue;
|
||||
|
||||
if (not window_intersects_viewport(window, layer))
|
||||
@@ -1066,7 +1061,7 @@ std::vector<imgui_context::viewport> imgui_context::windows()
|
||||
ImVec2 min = ImMax(v.Min, window->Pos);
|
||||
ImVec2 center = (min + max) / 2;
|
||||
|
||||
w.push_back(viewport{
|
||||
w.push_back(window_viewport{
|
||||
.space = layer.space,
|
||||
.position = layer.position +
|
||||
glm::mat3_cast(layer.orientation) *
|
||||
@@ -1079,9 +1074,6 @@ std::vector<imgui_context::viewport> imgui_context::windows()
|
||||
(max.x - min.x) * layer.size.x / layer.vp_size.x,
|
||||
(max.y - min.y) * layer.size.y / layer.vp_size.y,
|
||||
},
|
||||
.vp_origin = {min.x, min.y},
|
||||
.vp_size = {max.x - min.x, max.y - min.y},
|
||||
.always_show_cursor = layer.always_show_cursor,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct window_viewport
|
||||
{
|
||||
// Position of this window in the world
|
||||
xr::spaces space;
|
||||
glm::vec3 position;
|
||||
glm::quat orientation;
|
||||
glm::vec2 size;
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t queue_family_index;
|
||||
|
||||
@@ -215,7 +224,7 @@ public:
|
||||
return layers_;
|
||||
}
|
||||
|
||||
std::vector<viewport> windows();
|
||||
std::vector<window_viewport> windows();
|
||||
|
||||
viewport & layer(ImVec2 position);
|
||||
|
||||
|
||||
@@ -156,8 +156,6 @@ struct node
|
||||
bool visible = true;
|
||||
uint32_t layer_mask = -1;
|
||||
|
||||
std::array<glm::vec4, 4> clipping_planes;
|
||||
|
||||
// TODO: separate component?
|
||||
std::vector<std::pair<entt::entity, glm::mat4>> joints; // Node index, inverse bind matrix of each joint
|
||||
|
||||
|
||||
@@ -1007,7 +1007,6 @@ public:
|
||||
node.orientation = glm::make_quat(TRS.rotation.data());
|
||||
node.scale = glm::make_vec3(TRS.scale.data());
|
||||
node.visible = true;
|
||||
std::ranges::fill(node.clipping_planes, glm::vec4{0, 0, 0, 1});
|
||||
}
|
||||
|
||||
return entities;
|
||||
|
||||
@@ -1135,7 +1135,6 @@ void scene_renderer::render(
|
||||
object_ubo.modelview[frame_index] = frame.view * transform;
|
||||
object_ubo.modelviewproj[frame_index] = viewproj[frame_index] * transform;
|
||||
}
|
||||
object_ubo.clipping_planes = node.clipping_planes;
|
||||
std::ranges::copy(node.extra_shader_data, extra_shader_data.begin());
|
||||
|
||||
// Get the material
|
||||
|
||||
@@ -199,7 +199,6 @@ class scene_renderer
|
||||
glm::mat4 model;
|
||||
std::array<glm::mat4, 2> modelview;
|
||||
std::array<glm::mat4, 2> modelviewproj;
|
||||
std::array<glm::vec4, 4> clipping_planes;
|
||||
};
|
||||
|
||||
struct debug_draw_vertex
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "render/scene_components.h"
|
||||
#include "utils/mapped_file.h"
|
||||
#include "xr/space.h"
|
||||
#include <array>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
@@ -186,6 +187,7 @@ struct json_visual_response
|
||||
|
||||
struct ray_extra_shader_data
|
||||
{
|
||||
std::array<glm::mat4, 4> window_to_world;
|
||||
float emissive_factor;
|
||||
};
|
||||
|
||||
@@ -194,7 +196,14 @@ void setup_ray_shader(entt::registry & scene, entt::entity entity, const ray_ext
|
||||
auto & node = scene.get<components::node>(entity);
|
||||
|
||||
for (auto & primitive: node.mesh->primitives)
|
||||
{
|
||||
if (primitive.vertex_shader == "lit.vert")
|
||||
primitive.vertex_shader = "ray.vert";
|
||||
else if (primitive.vertex_shader == "lit_skinned.vert")
|
||||
primitive.vertex_shader = "ray_skinned.vert";
|
||||
|
||||
primitive.material_->fragment_shader_name = "ray.frag";
|
||||
}
|
||||
|
||||
node.set_extra_shader_data(initial_data);
|
||||
}
|
||||
@@ -316,7 +325,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
|
||||
scene.world.emplace<components::bound_space>(find_node_by_name(scene.world, "Ray", ray_entity), space, 0);
|
||||
scene.world.emplace<components::clipped_by_gui>(find_node_by_name(scene.world, "Ray", ray_entity));
|
||||
scene.world.emplace<components::emissive_trigger>(find_node_by_name(scene.world, "Ray", ray_entity), layout.key == "left" ? left_trigger : right_trigger);
|
||||
setup_ray_shader(scene.world, find_node_by_name(scene.world, "Ray", ray_entity), {0.1});
|
||||
setup_ray_shader(scene.world, find_node_by_name(scene.world, "Ray", ray_entity));
|
||||
|
||||
try
|
||||
{
|
||||
@@ -329,7 +338,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
|
||||
scene.world.emplace<components::bound_space>(find_node_by_name(scene.world, "Trail -40ms", ray_entity), space, -40'000'000);
|
||||
scene.world.emplace<components::clipped_by_gui>(find_node_by_name(scene.world, "Trail", ray_entity));
|
||||
scene.world.emplace<components::emissive_trigger>(find_node_by_name(scene.world, "Trail", ray_entity), layout.key == "left" ? left_trigger : right_trigger);
|
||||
setup_ray_shader(scene.world, find_node_by_name(scene.world, "Trail", ray_entity), {0.1});
|
||||
setup_ray_shader(scene.world, find_node_by_name(scene.world, "Trail", ray_entity));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -413,7 +422,7 @@ void input_profile::apply(
|
||||
bool hide_left_ray,
|
||||
bool hide_right_controller,
|
||||
bool hide_right_ray,
|
||||
std::span<glm::vec4> pointer_limits)
|
||||
std::span<glm::mat4> world_to_window)
|
||||
{
|
||||
for (auto && [entity, node, space]: scene.view<components::node, components::bound_space>().each())
|
||||
{
|
||||
@@ -511,37 +520,24 @@ void input_profile::apply(
|
||||
if (auto opt_value = application::read_action_float(response.action))
|
||||
{
|
||||
float value = opt_value->second * 0.9 + 0.1;
|
||||
node.set_extra_shader_data(ray_extra_shader_data{value});
|
||||
node.set_extra_shader_data(ray_extra_shader_data{{}, value});
|
||||
}
|
||||
}
|
||||
|
||||
for (auto && [entity, node]: scene.view<components::node, components::clipped_by_gui>().each())
|
||||
{
|
||||
// If the ray starts on the wrong side of the GUI, hide it entirely
|
||||
// This assumes the node is a child of the root node
|
||||
// if (node.joints.empty())
|
||||
// {
|
||||
// for (glm::vec4 & plane: pointer_limits)
|
||||
// {
|
||||
// if (glm::dot(plane, glm::vec4(node.position, 1)) < 0)
|
||||
// {
|
||||
// scene.get<components::node>(entity).visible = false;
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
size_t nb_clipping_planes = std::min(node.clipping_planes.size(), pointer_limits.size());
|
||||
auto & data = node.get_extra_shader_data<ray_extra_shader_data>();
|
||||
size_t nb_windows = std::min(data.window_to_world.size(), world_to_window.size());
|
||||
|
||||
auto copy_results = std::ranges::copy_n(
|
||||
pointer_limits.begin(),
|
||||
nb_clipping_planes,
|
||||
node.clipping_planes.begin());
|
||||
world_to_window.begin(),
|
||||
nb_windows,
|
||||
data.window_to_world.begin());
|
||||
|
||||
// Disable the remaining clipping planes
|
||||
std::ranges::fill_n(
|
||||
copy_results.out,
|
||||
node.clipping_planes.size() - nb_clipping_planes,
|
||||
glm::vec4(0, 0, 0, 1));
|
||||
data.window_to_world.size() - nb_windows,
|
||||
glm::mat4{/* TODO */});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,5 +48,5 @@ struct input_profile
|
||||
bool hide_left_ray,
|
||||
bool hide_right_controller,
|
||||
bool hide_right_ray,
|
||||
std::span<glm::vec4> pointer_limits);
|
||||
std::span<glm::mat4> world_to_window);
|
||||
};
|
||||
|
||||
+7
-28
@@ -626,28 +626,7 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_gui(glm::vec3 head_positi
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Return the vector v such that dot(v, x) > 0 iff x is on the side where the composition layer is visible
|
||||
static glm::vec4 compute_ray_limits(const XrPosef & pose, float margin = 0)
|
||||
{
|
||||
glm::quat q{
|
||||
pose.orientation.w,
|
||||
pose.orientation.x,
|
||||
pose.orientation.y,
|
||||
pose.orientation.z,
|
||||
};
|
||||
|
||||
glm::vec3 p{
|
||||
pose.position.x,
|
||||
pose.position.y,
|
||||
pose.position.z,
|
||||
};
|
||||
|
||||
glm::vec3 normal = glm::column(glm::mat3_cast(q), 2);
|
||||
|
||||
return glm::vec4(normal, -glm::dot(p, normal) - margin);
|
||||
}
|
||||
|
||||
static void stick_finger_to_gui(std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & hand, const std::vector<imgui_context::viewport> & layers)
|
||||
static void stick_finger_to_gui(std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & hand, const std::vector<imgui_context::window_viewport> & layers)
|
||||
{
|
||||
// Move XR_HAND_JOINT_INDEX_{TIP,DISTAL,INTERMEDIATE,PROXIMAL}_EXT so that:
|
||||
// - Only the X rotation changes for distal and intermediate (relative to the parent bone)
|
||||
@@ -667,7 +646,7 @@ static void stick_finger_to_gui(std::array<xr::hand_tracker::joint, XR_HAND_JOIN
|
||||
|
||||
// Compute the target position of the tip
|
||||
std::vector<std::pair<glm::vec3, float>> intersections; // Target position of the finger tip, distance to the GUI plane
|
||||
for (const imgui_context::viewport & layer: layers)
|
||||
for (const imgui_context::window_viewport & layer: layers)
|
||||
{
|
||||
// Ignore layers that are not absolutely positionned
|
||||
if (layer.space != xr::spaces::world)
|
||||
@@ -1054,11 +1033,11 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
#endif
|
||||
|
||||
// Get the planes that limit the ray size from the composition layers
|
||||
std::vector<glm::vec4> ray_limits;
|
||||
for (auto & [z_index, layer]: imgui_layers)
|
||||
std::vector<glm::mat4> world_to_window;
|
||||
for (auto & window: imgui_ctx->windows())
|
||||
{
|
||||
if (z_index != constants::lobby::zindex_recenter_tip)
|
||||
ray_limits.push_back(compute_ray_limits(layer.pose));
|
||||
if (window.space == xr::spaces::world)
|
||||
world_to_window.push_back(glm::inverse(glm::translate(window.position) * glm::mat4(glm::mat3_cast(window.orientation)) * glm::scale(glm::vec3(window.size, 1))));
|
||||
}
|
||||
|
||||
input->apply(world,
|
||||
@@ -1068,7 +1047,7 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
not imgui_ctx->is_aim_interaction()[0],
|
||||
hide_right_controller,
|
||||
not imgui_ctx->is_aim_interaction()[1],
|
||||
ray_limits);
|
||||
world_to_window);
|
||||
|
||||
renderer::animate(world, frame_state.predictedDisplayPeriod * 1.0e-9);
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <IconsFontAwesome6.h>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <glm/ext.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <limits>
|
||||
#include <ranges>
|
||||
@@ -729,27 +731,6 @@ void scenes::stream::gui_applications()
|
||||
ImGui::PopStyleVar(3);
|
||||
}
|
||||
|
||||
// Return the vector v such that dot(v, x) > 0 iff x is on the side where the composition layer is visible
|
||||
static glm::vec4 compute_ray_limits(const XrPosef & pose, float margin = 0)
|
||||
{
|
||||
glm::quat q{
|
||||
pose.orientation.w,
|
||||
pose.orientation.x,
|
||||
pose.orientation.y,
|
||||
pose.orientation.z,
|
||||
};
|
||||
|
||||
glm::vec3 p{
|
||||
pose.position.x,
|
||||
pose.position.y,
|
||||
pose.position.z,
|
||||
};
|
||||
|
||||
glm::vec3 normal = glm::column(glm::mat3_cast(q), 2);
|
||||
|
||||
return glm::vec4(normal, -glm::dot(p, normal) - margin);
|
||||
}
|
||||
|
||||
void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period)
|
||||
{
|
||||
if (not(plots_toggle_1 and plots_toggle_2))
|
||||
@@ -1053,10 +1034,12 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
else
|
||||
recentering_context.reset();
|
||||
|
||||
std::vector<glm::vec4> ray_limits;
|
||||
|
||||
for (auto [_, layer]: layers)
|
||||
ray_limits.push_back(compute_ray_limits(layer.pose));
|
||||
std::vector<glm::mat4> world_to_window;
|
||||
for (auto & window: imgui_ctx->windows())
|
||||
{
|
||||
if (window.space == xr::spaces::world)
|
||||
world_to_window.push_back(glm::inverse(glm::translate(window.position) * glm::mat4(glm::mat3_cast(window.orientation)) * glm::scale(glm::vec3(window.size, 1))));
|
||||
}
|
||||
|
||||
bool hide_left_controller = false;
|
||||
bool hide_right_controller = false;
|
||||
@@ -1080,7 +1063,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
hide_left_controller,
|
||||
hide_right_controller,
|
||||
hide_right_controller,
|
||||
ray_limits);
|
||||
world_to_window);
|
||||
|
||||
// Add the layer with the controllers
|
||||
if (composition_layer_depth_test_supported)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// kate: hl glsl
|
||||
|
||||
const int nb_views = 2;
|
||||
const int nb_clipping = 4;
|
||||
const int nb_texcoords = 2;
|
||||
|
||||
const bool use_pbr = false;
|
||||
@@ -20,7 +19,6 @@ layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
mat4 model;
|
||||
mat4 modelview[nb_views];
|
||||
mat4 modelviewproj[nb_views];
|
||||
vec4 clipping_plane[nb_clipping];
|
||||
} mesh;
|
||||
|
||||
layout(set = 0, binding = 2) uniform joints_ubo
|
||||
|
||||
@@ -27,7 +27,6 @@ layout (constant_id = 2) const bool alpha_cutout = false;
|
||||
layout (constant_id = 3) const bool skinning = false;
|
||||
|
||||
const int nb_views = 2;
|
||||
const int nb_clipping = 4;
|
||||
|
||||
layout(set = 0, binding = 0) uniform scene_ubo
|
||||
{
|
||||
@@ -42,7 +41,6 @@ layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
mat4 model;
|
||||
mat4 modelview[nb_views];
|
||||
mat4 modelviewproj[nb_views];
|
||||
vec4 clipping_plane[nb_clipping];
|
||||
} mesh;
|
||||
|
||||
layout(set = 0, binding = 2) uniform joints_ubo
|
||||
|
||||
@@ -34,7 +34,6 @@ layout(location = 5) in vec4 in_color;
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
float gl_ClipDistance[nb_clipping];
|
||||
};
|
||||
|
||||
void main()
|
||||
@@ -59,9 +58,4 @@ void main()
|
||||
frag_pos = mesh.modelview[gl_ViewIndex] * vec4(in_position, 1.0);
|
||||
light_pos = scene.view[gl_ViewIndex] * scene.light_position;
|
||||
vertex_color = in_color;
|
||||
|
||||
for (int i = 0; i < nb_clipping; i++)
|
||||
{
|
||||
gl_ClipDistance[i] = dot(mesh.clipping_plane[i], mesh.model * vec4(in_position, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ layout(location = 7) in vec4 in_weights;
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
float gl_ClipDistance[nb_clipping];
|
||||
};
|
||||
|
||||
void main()
|
||||
@@ -53,8 +52,8 @@ void main()
|
||||
in_weights.z * joints.joint_matrices[int(in_joints.z)] +
|
||||
in_weights.w * joints.joint_matrices[int(in_joints.w)];
|
||||
|
||||
// TODO on CPU?
|
||||
mat3 mv = inverse(transpose(mat3(mesh.modelview[gl_ViewIndex])));
|
||||
|
||||
mat3 mv = inverse(transpose(mat3(mesh.modelview[gl_ViewIndex] * skinMatrix)));
|
||||
|
||||
tangent = vec4(normalize(mv * in_tangent.xyz), in_tangent.w);
|
||||
if (any(isnan(tangent))) // avoid NaNs if no tangent data is provided
|
||||
@@ -62,15 +61,9 @@ void main()
|
||||
|
||||
normal = normalize(mv * in_normal);
|
||||
|
||||
normal = vec3(mesh.modelview[gl_ViewIndex] * skinMatrix * vec4(in_normal, 0.0));
|
||||
gl_Position = mesh.modelviewproj[gl_ViewIndex] * skinMatrix * vec4(in_position, 1.0);
|
||||
|
||||
frag_pos = mesh.modelview[gl_ViewIndex] * skinMatrix * vec4(in_position, 1.0);
|
||||
light_pos = scene.view[gl_ViewIndex] * scene.light_position;
|
||||
vertex_color = in_color;
|
||||
|
||||
for(int i = 0; i < nb_clipping; i++)
|
||||
{
|
||||
gl_ClipDistance[i] = dot(mesh.clipping_plane[i], mesh.model * skinMatrix * vec4(in_position, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,66 +18,6 @@
|
||||
|
||||
#version 450
|
||||
|
||||
const int nb_views = 2;
|
||||
const int nb_clipping = 4;
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
{
|
||||
mat4 model;
|
||||
mat4 modelview[nb_views];
|
||||
mat4 modelviewproj[nb_views];
|
||||
vec4 clipping_plane[nb_clipping];
|
||||
|
||||
// Extra data
|
||||
float emissive_factor;
|
||||
} mesh;
|
||||
|
||||
layout(set = 0, binding = 3) uniform sampler2D base_color_texture;
|
||||
layout(set = 0, binding = 6) uniform sampler2D emissive_texture;
|
||||
|
||||
struct texture_info
|
||||
{
|
||||
int texcoord;
|
||||
float rotation;
|
||||
vec2 offset;
|
||||
vec2 scale;
|
||||
};
|
||||
|
||||
layout(std140, set = 0, binding = 8) uniform material_ubo
|
||||
{
|
||||
vec4 base_color_factor;
|
||||
vec4 base_emissive_factor;
|
||||
float metallic_factor;
|
||||
float roughness_factor;
|
||||
float occlusion_strength;
|
||||
float normal_scale;
|
||||
float alpha_cutoff;
|
||||
|
||||
texture_info base_color;
|
||||
texture_info metallic_roughness;
|
||||
texture_info occlusion;
|
||||
texture_info emissive;
|
||||
texture_info normal;
|
||||
} material;
|
||||
|
||||
|
||||
layout(location = 4) in vec2 texcoord_base_color;
|
||||
layout(location = 7) in vec2 texcoord_emissive;
|
||||
layout(location = 9) in vec4 vertex_color;
|
||||
|
||||
const bool use_pbr = false;
|
||||
|
||||
// Fragment output
|
||||
layout(location = 0) out vec4 out_color;
|
||||
layout(early_fragment_tests) in;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 albedo = vertex_color * material.base_color_factor * texture(base_color_texture, texcoord_base_color);
|
||||
vec3 emissive_color = mesh.emissive_factor * texture(emissive_texture, texcoord_emissive).rgb;
|
||||
|
||||
out_color = vec4(emissive_color, albedo.a);
|
||||
|
||||
if (use_pbr)
|
||||
out_color = vec4(out_color.rgb / (out_color.rgb + 1), out_color.a);
|
||||
}
|
||||
#include "ray_common.glsl.inc"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 450
|
||||
#extension GL_EXT_multiview : require
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#define SKINNED 0
|
||||
|
||||
#include "ray_common.glsl.inc"
|
||||
@@ -0,0 +1,171 @@
|
||||
// kate: hl glsl
|
||||
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const int nb_views = 2;
|
||||
const int nb_texcoords = 2;
|
||||
const int nb_windows = 4;
|
||||
const bool use_pbr = false;
|
||||
|
||||
layout(set = 0, binding = 0) uniform scene_ubo
|
||||
{
|
||||
mat4 view[nb_views];
|
||||
vec4 light_position;
|
||||
vec4 ambient_color;
|
||||
vec4 light_color;
|
||||
} scene;
|
||||
|
||||
layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
{
|
||||
mat4 model;
|
||||
mat4 modelview[nb_views];
|
||||
mat4 modelviewproj[nb_views];
|
||||
|
||||
// Extra data
|
||||
mat4 world_to_window[nb_windows];
|
||||
float emissive_factor;
|
||||
} mesh;
|
||||
|
||||
layout(set = 0, binding = 2) uniform joints_ubo
|
||||
{
|
||||
mat4 joint_matrices[32];
|
||||
} joints;
|
||||
|
||||
layout(set = 0, binding = 3) uniform sampler2D base_color_texture;
|
||||
layout(set = 0, binding = 4) uniform sampler2D metallic_roughness_texture;
|
||||
layout(set = 0, binding = 5) uniform sampler2D occlusion_texture;
|
||||
layout(set = 0, binding = 6) uniform sampler2D emissive_texture;
|
||||
layout(set = 0, binding = 7) uniform sampler2D normal_map_texture;
|
||||
|
||||
struct texture_info
|
||||
{
|
||||
int texcoord;
|
||||
float rotation;
|
||||
vec2 offset;
|
||||
vec2 scale;
|
||||
};
|
||||
|
||||
layout(std140, set = 0, binding = 8) uniform material_ubo
|
||||
{
|
||||
vec4 base_color_factor;
|
||||
vec4 base_emissive_factor;
|
||||
float metallic_factor;
|
||||
float roughness_factor;
|
||||
float occlusion_strength;
|
||||
float normal_scale;
|
||||
float alpha_cutoff;
|
||||
|
||||
texture_info base_color;
|
||||
texture_info metallic_roughness;
|
||||
texture_info occlusion;
|
||||
texture_info emissive;
|
||||
texture_info normal;
|
||||
} material;
|
||||
|
||||
#ifdef VERT_SHADER
|
||||
// Vertex input
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec3 in_normal;
|
||||
layout(location = 2) in vec4 in_tangent;
|
||||
layout(location = 3) in vec2 in_texcoord[2];
|
||||
layout(location = 5) in vec4 in_color;
|
||||
|
||||
#if SKINNED
|
||||
layout(location = 6) in vec4 in_joints;
|
||||
layout(location = 7) in vec4 in_weights;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
#define VS_TO_FS in
|
||||
#else
|
||||
#define VS_TO_FS out
|
||||
#endif
|
||||
|
||||
// Vertex-to-fragment
|
||||
layout(location = 0) VS_TO_FS vec2 texcoord;
|
||||
layout(location = 1) VS_TO_FS vec4 position_wrt_window[nb_windows];
|
||||
layout(location = 1 + nb_windows) VS_TO_FS vec4 base_wrt_window[nb_windows];
|
||||
|
||||
#ifdef VERT_SHADER
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
texcoord = in_texcoord[0];
|
||||
|
||||
#if SKINNED
|
||||
mat4 skinMatrix =
|
||||
in_weights.x * joints.joint_matrices[int(in_joints.x)] +
|
||||
in_weights.y * joints.joint_matrices[int(in_joints.y)] +
|
||||
in_weights.z * joints.joint_matrices[int(in_joints.z)] +
|
||||
in_weights.w * joints.joint_matrices[int(in_joints.w)];
|
||||
|
||||
gl_Position = mesh.modelviewproj[gl_ViewIndex] * skinMatrix * vec4(in_position, 1.0);
|
||||
vec4 world_position = mesh.model * skinMatrix * vec4(in_position, 1.0);
|
||||
vec4 base_position = mesh.model * skinMatrix * vec4(in_position.xy, 0.0, 1.0);
|
||||
#else
|
||||
gl_Position = mesh.modelviewproj[gl_ViewIndex] * vec4(in_position, 1.0);
|
||||
vec4 world_position = mesh.model * vec4(in_position, 1.0);
|
||||
vec4 base_position = mesh.model * vec4(in_position.xy, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
for(uint i = 0; i < nb_windows; i++)
|
||||
{
|
||||
position_wrt_window[i] = mesh.world_to_window[i] * world_position;
|
||||
base_wrt_window[i] = mesh.world_to_window[i] * base_position;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
// Fragment output
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
for (uint i = 0; i < nb_windows; i++)
|
||||
{
|
||||
if (position_wrt_window[i].w < 0.5)
|
||||
continue;
|
||||
|
||||
// TODO check NaN
|
||||
float lambda = -base_wrt_window[i].z / (position_wrt_window[i].z - base_wrt_window[i].z);
|
||||
|
||||
if (lambda < 0 || lambda > 1)
|
||||
continue;
|
||||
|
||||
vec2 intersection = base_wrt_window[i].xy + lambda * (position_wrt_window[i].xy - base_wrt_window[i].xy);
|
||||
if (abs(intersection.x) < 0.5 && abs(intersection.y) < 0.5)
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 albedo = material.base_color_factor * texture(base_color_texture, texcoord);
|
||||
vec3 emissive_color = mesh.emissive_factor * texture(emissive_texture, texcoord).rgb;
|
||||
|
||||
out_color = vec4(emissive_color, albedo.a);
|
||||
|
||||
if (use_pbr)
|
||||
out_color = vec4(out_color.rgb / (out_color.rgb + 1), out_color.a);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 450
|
||||
#extension GL_EXT_multiview : require
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#define SKINNED 1
|
||||
|
||||
#include "ray_common.glsl.inc"
|
||||
Reference in New Issue
Block a user