Guess if sRGB conversion is needed
This commit is contained in:
@@ -132,3 +132,23 @@ XrViewConfigurationView override_view(XrViewConfigurationView view, model m)
|
|||||||
}
|
}
|
||||||
throw std::range_error("invalid model " + std::to_string((int)m));
|
throw std::range_error("invalid model " + std::to_string((int)m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool need_srgb_conversion(model m)
|
||||||
|
{
|
||||||
|
switch (m)
|
||||||
|
{
|
||||||
|
case model::lynx_r1:
|
||||||
|
return false;
|
||||||
|
case model::oculus_quest:
|
||||||
|
case model::oculus_quest_2:
|
||||||
|
case model::meta_quest_pro:
|
||||||
|
case model::meta_quest_3:
|
||||||
|
case model::pico_neo_3:
|
||||||
|
case model::pico_4:
|
||||||
|
case model::htc_vive_focus_3:
|
||||||
|
case model::htc_vive_xr_elite:
|
||||||
|
case model::unknown:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
throw std::range_error("invalid model " + std::to_string((int)m));
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,3 +37,5 @@ enum class model
|
|||||||
model guess_model();
|
model guess_model();
|
||||||
|
|
||||||
XrViewConfigurationView override_view(XrViewConfigurationView, model);
|
XrViewConfigurationView override_view(XrViewConfigurationView, model);
|
||||||
|
|
||||||
|
bool need_srgb_conversion(model);
|
||||||
|
|||||||
@@ -424,9 +424,19 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
|||||||
.size = sizeof(float),
|
.size = sizeof(float),
|
||||||
}};
|
}};
|
||||||
|
|
||||||
vk::SpecializationInfo specialization_info;
|
vk::SpecializationInfo vert_specialization_info;
|
||||||
specialization_info.setMapEntries(specialization_constants_desc);
|
vert_specialization_info.setMapEntries(specialization_constants_desc);
|
||||||
specialization_info.setData<float>(useful_size);
|
vert_specialization_info.setData<float>(useful_size);
|
||||||
|
|
||||||
|
VkBool32 do_srgb = need_srgb_conversion(guess_model());
|
||||||
|
vk::SpecializationMapEntry frag_specialization_constant_desc{
|
||||||
|
.constantID = 0,
|
||||||
|
.offset = 0,
|
||||||
|
.size = sizeof(do_srgb),
|
||||||
|
};
|
||||||
|
vk::SpecializationInfo frag_specialization_info;
|
||||||
|
frag_specialization_info.setMapEntries(frag_specialization_constant_desc);
|
||||||
|
frag_specialization_info.setData<VkBool32>(do_srgb);
|
||||||
|
|
||||||
// Create graphics pipeline
|
// Create graphics pipeline
|
||||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
||||||
@@ -445,12 +455,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
|||||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||||
.module = *vertex_shader,
|
.module = *vertex_shader,
|
||||||
.pName = "main",
|
.pName = "main",
|
||||||
.pSpecializationInfo = &specialization_info,
|
.pSpecializationInfo = &vert_specialization_info,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||||
.module = *fragment_shader,
|
.module = *fragment_shader,
|
||||||
.pName = "main",
|
.pName = "main",
|
||||||
|
.pSpecializationInfo = &frag_specialization_info,
|
||||||
}},
|
}},
|
||||||
.VertexInputState = {.flags = {}},
|
.VertexInputState = {.flags = {}},
|
||||||
.VertexBindingDescriptions = {},
|
.VertexBindingDescriptions = {},
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ void main()
|
|||||||
|
|
||||||
#ifdef FRAG_SHADER
|
#ifdef FRAG_SHADER
|
||||||
layout(binding = 0) uniform sampler2D texSampler;
|
layout(binding = 0) uniform sampler2D texSampler;
|
||||||
|
layout(constant_id = 0) const bool do_srgb = true;
|
||||||
|
|
||||||
layout(location = 0) in vec2 inUV;
|
layout(location = 0) in vec2 inUV;
|
||||||
|
|
||||||
@@ -69,6 +70,13 @@ vec4 sRGB_to_linear_rgba(vec4 x)
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
outColor = sRGB_to_linear_rgba(texture(texSampler, inUV));
|
if (do_srgb)
|
||||||
|
{
|
||||||
|
outColor = sRGB_to_linear_rgba(texture(texSampler, inUV));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outColor = texture(texSampler, inUV);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user