Work around HTC bugs

This commit is contained in:
Guillaume Meunier
2026-02-13 17:26:53 +01:00
parent 1158afdad5
commit 66a56dac82
6 changed files with 100 additions and 54 deletions
Binary file not shown.
BIN
View File
Binary file not shown.
+23 -54
View File
@@ -19,17 +19,7 @@
*/ */
const int nb_views = 2; const int nb_views = 2;
const int nb_texcoords = 2;
const int nb_windows = 4; 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 layout(set = 0, binding = 1) uniform mesh_ubo
{ {
@@ -47,48 +37,18 @@ layout(set = 0, binding = 2) uniform joints_ubo
mat4 joint_matrices[32]; mat4 joint_matrices[32];
} joints; } 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 = 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 #ifdef VERT_SHADER
// Vertex input // Vertex input
layout(location = 0) in vec3 in_position; layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_normal; layout(location = 1) in vec2 in_texcoord;
layout(location = 2) in vec4 in_tangent;
layout(location = 3) in vec2 in_texcoord[2];
layout(location = 5) in vec4 in_color;
#if SKINNED #if SKINNED
layout(location = 6) in vec4 in_joints; layout(location = 2) in vec4 in_joints;
layout(location = 7) in vec4 in_weights; layout(location = 3) in vec4 in_weights;
#endif #endif
#endif #endif
@@ -101,18 +61,23 @@ layout(location = 7) in vec4 in_weights;
// Vertex-to-fragment // Vertex-to-fragment
layout(location = 0) VS_TO_FS vec2 texcoord; layout(location = 0) VS_TO_FS vec2 texcoord;
#ifndef HTC_WORKAROUND
layout(location = 1) VS_TO_FS vec4 position_wrt_window[nb_windows]; 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]; layout(location = 1 + nb_windows) VS_TO_FS vec4 base_wrt_window[nb_windows];
#endif // HTC_WORKAROUND
#ifdef VERT_SHADER #ifdef VERT_SHADER
out gl_PerVertex out gl_PerVertex
{ {
vec4 gl_Position; vec4 gl_Position;
#ifdef HTC_WORKAROUND
float gl_ClipDistance[nb_windows];
#endif
}; };
void main() void main()
{ {
texcoord = in_texcoord[0]; texcoord = in_texcoord;
#if SKINNED #if SKINNED
mat4 skinMatrix = mat4 skinMatrix =
@@ -124,19 +89,24 @@ void main()
gl_Position = mesh.modelviewproj[gl_ViewIndex] * skinMatrix * vec4(in_position, 1.0); gl_Position = mesh.modelviewproj[gl_ViewIndex] * skinMatrix * vec4(in_position, 1.0);
vec4 world_position = mesh.model * 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); vec4 base_position = mesh.model * skinMatrix * vec4(in_position.xy, 0.0, 1.0);
#else #else // SKINNED
gl_Position = mesh.modelviewproj[gl_ViewIndex] * vec4(in_position, 1.0); gl_Position = mesh.modelviewproj[gl_ViewIndex] * vec4(in_position, 1.0);
vec4 world_position = mesh.model * 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); vec4 base_position = mesh.model * vec4(in_position.xy, 0.0, 1.0);
#endif #endif // SKINNED
for(uint i = 0; i < nb_windows; i++) for(uint i = 0; i < nb_windows; i++)
{ {
#ifdef HTC_WORKAROUND
vec4 tmp = mesh.world_to_window[i] * world_position;
gl_ClipDistance[i] = tmp.z;
#else // HTC_WORKAROUND
position_wrt_window[i] = mesh.world_to_window[i] * world_position; position_wrt_window[i] = mesh.world_to_window[i] * world_position;
base_wrt_window[i] = mesh.world_to_window[i] * base_position; base_wrt_window[i] = mesh.world_to_window[i] * base_position;
#endif // HTC_WORKAROUND
} }
} }
#endif #endif // VERT_SHADER
#ifdef FRAG_SHADER #ifdef FRAG_SHADER
// Fragment output // Fragment output
@@ -144,6 +114,9 @@ layout(location = 0) out vec4 out_color;
void main() void main()
{ {
#ifdef HTC_WORKAROUND
out_color = vec4(mesh.emissive_factor * texture(emissive_texture, texcoord).rgb, 1.0 / 255.0);
#else // HTC_WORKAROUND
for (uint i = 0; i < nb_windows; i++) for (uint i = 0; i < nb_windows; i++)
{ {
if (position_wrt_window[i].w < 0.5) if (position_wrt_window[i].w < 0.5)
@@ -160,12 +133,8 @@ void main()
discard; discard;
} }
vec4 albedo = material.base_color_factor * texture(base_color_texture, texcoord); out_color = vec4(mesh.emissive_factor * texture(emissive_texture, texcoord).rgb, 0);
vec3 emissive_color = mesh.emissive_factor * texture(emissive_texture, texcoord).rgb; #endif // HTC_WORKAROUND
out_color = vec4(emissive_color, albedo.a);
if (use_pbr)
out_color = vec4(out_color.rgb / (out_color.rgb + 1), out_color.a);
} }
#endif #endif // FRAG_SHADER
+25
View File
@@ -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_GOOGLE_include_directive : require
#define HTC_WORKAROUND
#include "ray_common.glsl.inc"
+26
View File
@@ -0,0 +1,26 @@
/*
* 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
#define HTC_WORKAROUND
#include "ray_common.glsl.inc"
+26
View File
@@ -0,0 +1,26 @@
/*
* 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
#define HTC_WORKAROUND
#include "ray_common.glsl.inc"