Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c0b2078
Default to sRGB surface format
AnyOldName3 Oct 14, 2024
fc7ee72
Fix sRGB_to_linear and linear_to_sRGB
AnyOldName3 Oct 14, 2024
eea9d2e
Use precise sRGB conversion by default
AnyOldName3 Dec 4, 2024
94a2bf2
Typo fix
AnyOldName3 Dec 19, 2024
7b40dee
Keep the same relative ambient/diffuse intensity with correct gamma
AnyOldName3 Dec 4, 2024
3999c1d
Updated ShaderSets
robertosfield Jan 16, 2025
4189141
Added ColorSpace header and source to assist with conversions between…
robertosfield Jan 17, 2025
7fbb176
Added remapping of image formats to be consistent to sRGB conversions.
robertosfield Jan 17, 2025
1ff39e5
Added vec3 variants and removed approx functions.
robertosfield Jan 17, 2025
2839c67
Bumped version to 1.1.10 for ColorSpace work.
robertosfield Jan 17, 2025
5a44470
Removed debug message
robertosfield Jan 19, 2025
2edaa37
Commented out hardwired format conversions to sRGB as we should now b…
robertosfield Jan 19, 2025
133a17c
Added install of xcb to Linux automated build.
robertosfield Jan 20, 2025
f810efa
Deleted inappropriate copy constructors
robertosfield Jan 20, 2025
296c368
Restructued constructor to avoid need for include Options.h
robertosfield Jan 20, 2025
df3eb17
Merge branch 'master' into ColorSpace3
robertosfield Jan 20, 2025
3154ea1
Rand clang-format
robertosfield Jan 20, 2025
b91a2f9
Renamed ColorSpace to CoordinateSpace and added support for specifyin…
robertosfield Jan 21, 2025
35bc5fe
Wired up initial use of coordinateSpace and updated ShaderSets.
robertosfield Jan 21, 2025
0c95acd
Updated ShaderSets.
robertosfield Jan 21, 2025
1c8b32d
Ran clang-format
robertosfield Jan 22, 2025
9f31f4e
Warning fixes
robertosfield Jan 22, 2025
dec5846
Merge branch 'master' into ColorSpace3
robertosfield Jan 23, 2025
6e31fa6
Removed commented out code and combined if statements.
robertosfield Jan 23, 2025
1104b7c
Renamed local variable to fix cppcheck reporting shadowing of function
robertosfield Jan 24, 2025
7423381
Fixed incomplete name change.
robertosfield Jan 24, 2025
c9829de
Added handling of CoordinateSpace to DescriptorConfigurator::assignTe…
robertosfield Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.7)

project(vsg
VERSION 1.1.9
VERSION 1.1.10
DESCRIPTION "VulkanSceneGraph library"
LANGUAGES CXX
)
Expand Down
1 change: 1 addition & 0 deletions include/vsg/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/utils/Builder.h>
#include <vsg/utils/CommandLine.h>
#include <vsg/utils/ComputeBounds.h>
#include <vsg/utils/CoordinateSpace.h>
#include <vsg/utils/FindDynamicObjects.h>
#include <vsg/utils/GpuAnnotation.h>
#include <vsg/utils/GraphicsPipelineConfigurator.h>
Expand Down
28 changes: 0 additions & 28 deletions include/vsg/maths/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,4 @@ namespace vsg
}
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB(const t_vec4<T>& src)
{
const T exponent = static_cast<T>(2.2);
return t_vec4<T>(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a);
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB(T r, T g, T b, T a)
{
const T exponent = static_cast<T>(2.2);
return t_vec4<T>(std::pow(r, exponent), std::pow(g, exponent), std::pow(b, exponent), a);
}

template<typename T>
constexpr t_vec4<T> sRGB_to_linear(const t_vec4<T>& src)
{
const T exponent = static_cast<T>(1.0 / 2.2);
return t_vec4<T>(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a);
}

template<typename T>
constexpr t_vec4<T> sRGB_to_linear(T r, T g, T b, T a)
{
const T exponent = static_cast<T>(1.0 / 2.2);
return t_vec4<T>(std::pow(r, exponent), std::pow(g, exponent), std::pow(b, exponent), a);
}

} // namespace vsg
112 changes: 112 additions & 0 deletions include/vsg/utils/CoordinateSpace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#pragma once

/* <editor-fold desc="MIT License">

Copyright(c) 2024 Chris Djali

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

</editor-fold> */

#include <vsg/core/Array.h>
#include <vsg/core/Inherit.h>
#include <vsg/maths/color.h>

namespace vsg
{

enum class CoordinateSpace
{
NO_PREFERENCE = 0,
LINEAR = (1 << 0),
sRGB = (1 << 1)
};

template<typename T>
constexpr T linear_to_sRGB_component(T c)
{
constexpr T cutoff = static_cast<T>(0.04045 / 12.92);
constexpr T linearFactor = static_cast<T>(12.92);
constexpr T nonlinearFactor = static_cast<T>(1.055);
constexpr T exponent = static_cast<T>(1.0 / 2.4);
if (c <= cutoff)
return c * linearFactor;
else
return std::pow(c, exponent) * nonlinearFactor - static_cast<T>(0.055);
}

template<typename T>
constexpr T sRGB_to_linear_component(T c)
{
constexpr T cutoff = static_cast<T>(0.04045);
constexpr T linearFactor = static_cast<T>(1.0 / 12.92);
constexpr T nonlinearFactor = static_cast<T>(1.0 / 1.055);
constexpr T exponent = static_cast<T>(2.4);
if (c <= cutoff)
return c * linearFactor;
else
return std::pow((c + static_cast<T>(0.055)) * nonlinearFactor, exponent);
}

template<typename T>
constexpr t_vec3<T> linear_to_sRGB(const t_vec3<T>& src)
{
return t_vec3<T>(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b));
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB(const t_vec4<T>& src)
{
return t_vec4<T>(linear_to_sRGB_component(src.r), linear_to_sRGB_component(src.g), linear_to_sRGB_component(src.b), src.a);
}

template<typename T>
constexpr t_vec4<T> linear_to_sRGB(T r, T g, T b, T a)
{
return t_vec4<T>(linear_to_sRGB_component(r), linear_to_sRGB_component(g), linear_to_sRGB_component(b), a);
}

template<typename T>
constexpr t_vec3<T> sRGB_to_linear(const t_vec3<T>& src)
{
return t_vec3<T>(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b));
}

template<typename T>
constexpr t_vec4<T> sRGB_to_linear(const t_vec4<T>& src)
{
return t_vec4<T>(sRGB_to_linear_component(src.r), sRGB_to_linear_component(src.g), sRGB_to_linear_component(src.b), src.a);
}

template<typename T>
constexpr t_vec4<T> sRGB_to_linear(T r, T g, T b, T a)
{
return t_vec4<T>(sRGB_to_linear_component(r), sRGB_to_linear_component(g), sRGB_to_linear_component(b), a);
}

template<typename T>
void convert(T& data, CoordinateSpace source, CoordinateSpace target)
{
if (source == CoordinateSpace::sRGB && target == CoordinateSpace::LINEAR)
data = sRGB_to_linear(data);
else if (source == CoordinateSpace::LINEAR && target == CoordinateSpace::sRGB)
data = linear_to_sRGB(data);
}

template<typename T>
void convert(size_t num, T* data, CoordinateSpace source, CoordinateSpace target)
{
if (source == CoordinateSpace::sRGB && target == CoordinateSpace::LINEAR)
for (size_t i = 0; i < num; ++i) data[i] = sRGB_to_linear(data[i]);
else if (source == CoordinateSpace::LINEAR && target == CoordinateSpace::sRGB)
for (size_t i = 0; i < num; ++i) data[i] = linear_to_sRGB(data[i]);
}

extern VSG_DECLSPEC VkFormat uNorm_to_sRGB(VkFormat format);
extern VSG_DECLSPEC VkFormat sRGB_to_uNorm(VkFormat format);

} // namespace vsg
7 changes: 5 additions & 2 deletions include/vsg/utils/ShaderSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/state/GraphicsPipeline.h>
#include <vsg/state/Sampler.h>
#include <vsg/state/ShaderStage.h>
#include <vsg/utils/CoordinateSpace.h>

namespace vsg
{
Expand All @@ -27,6 +28,7 @@ namespace vsg
std::string define;
uint32_t location = 0;
VkFormat format = VK_FORMAT_UNDEFINED;
CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE;
ref_ptr<Data> data;

int compare(const AttributeBinding& rhs) const;
Expand All @@ -44,6 +46,7 @@ namespace vsg
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
uint32_t descriptorCount = 0;
VkShaderStageFlags stageFlags = 0;
CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE;
ref_ptr<Data> data;

int compare(const DescriptorBinding& rhs) const;
Expand Down Expand Up @@ -133,10 +136,10 @@ namespace vsg
std::mutex mutex;

/// add an attribute binding, Not thread safe, should only be called when initially setting up the ShaderSet
void addAttributeBinding(const std::string& name, const std::string& define, uint32_t location, VkFormat format, ref_ptr<Data> data);
void addAttributeBinding(const std::string& name, const std::string& define, uint32_t location, VkFormat format, ref_ptr<Data> data, CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE);

/// add an uniform binding. Not thread safe, should only be called when initially setting up the ShaderSet
void addDescriptorBinding(const std::string& name, const std::string& define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Data> data);
void addDescriptorBinding(const std::string& name, const std::string& define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Data> data, CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE);

[[deprecated("use addDescriptorBinding(..)")]] void addUniformBinding(const std::string& name, const std::string& define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Data> data) { addDescriptorBinding(name, define, set, binding, descriptorType, descriptorCount, stageFlags, data); }

Expand Down
4 changes: 2 additions & 2 deletions include/vsg/vk/Swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ namespace vsg
};

extern VSG_DECLSPEC SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface);
extern VSG_DECLSPEC VkSurfaceFormatKHR selectSwapSurfaceFormat(const SwapChainSupportDetails& details, VkSurfaceFormatKHR preferredSurfaceFormat = {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR});
extern VSG_DECLSPEC VkSurfaceFormatKHR selectSwapSurfaceFormat(const SwapChainSupportDetails& details, VkSurfaceFormatKHR preferredSurfaceFormat = {VK_FORMAT_B8G8R8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR});
extern VSG_DECLSPEC VkExtent2D selectSwapExtent(const SwapChainSupportDetails& details, uint32_t width, uint32_t height);
extern VSG_DECLSPEC VkPresentModeKHR selectSwapPresentMode(const SwapChainSupportDetails& details, VkPresentModeKHR preferredPresentMode = VK_PRESENT_MODE_MAILBOX_KHR);

/// Swapchain preferences passed via WindowTraits::swapchainPreferences to guide swapchain creation associated with Window creation.
struct SwapchainPreferences
{
uint32_t imageCount = 3; // default to triple buffering
VkSurfaceFormatKHR surfaceFormat = {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
VkSurfaceFormatKHR surfaceFormat = {VK_FORMAT_B8G8R8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
VkImageUsageFlags imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
};
Expand Down
1 change: 1 addition & 0 deletions src/vsg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ set(SOURCES
vk/ResourceRequirements.cpp

utils/CommandLine.cpp
utils/CoordinateSpace.cpp
utils/Builder.cpp
utils/SharedObjects.cpp
utils/ShaderSet.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/vsg/app/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/maths/color.h>
#include <vsg/maths/vec4.h>
#include <vsg/ui/ApplicationEvent.h>
#include <vsg/utils/CoordinateSpace.h>
#include <vsg/vk/SubmitCommands.h>

#include <array>
Expand All @@ -40,8 +41,7 @@ Window::Window(ref_ptr<WindowTraits> traits) :
{
if (_traits && (_traits->swapchainPreferences.surfaceFormat.format == VK_FORMAT_B8G8R8A8_SRGB || _traits->swapchainPreferences.surfaceFormat.format == VK_FORMAT_B8G8R8_SRGB))
{
_clearColor = linear_to_sRGB(_clearColor);
info("Selected sRGB window ", _clearColor);
_clearColor = sRGB_to_linear(_clearColor);
}
}

Expand Down
34 changes: 27 additions & 7 deletions src/vsg/io/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/state/material.h>
#include <vsg/ui/UIEvent.h>
#include <vsg/utils/ComputeBounds.h>
#include <vsg/utils/CoordinateSpace.h>
#include <vsg/vk/ResourceRequirements.h>

using namespace vsg;
Expand Down Expand Up @@ -164,21 +165,30 @@ vsg::ref_ptr<vsg::Object> tile::read_root(vsg::ref_ptr<const vsg::Options> optio
{
auto imagePath = getTilePath(settings->imageLayer, x, y, lod);
imageData = vsg::read_cast<vsg::Data>(imagePath, options);
if (imageData && settings->imageLayerCallback) imageData = settings->imageLayerCallback(imageData);
if (imageData && settings->imageLayerCallback)
{
imageData = settings->imageLayerCallback(imageData);
}
}

if (settings->detailLayer)
{
auto detailPath = getTilePath(settings->detailLayer, x, y, lod);
detailData = vsg::read_cast<vsg::Data>(detailPath, options);
if (detailData && settings->detailLayerCallback) detailData = settings->detailLayerCallback(detailData);
if (detailData && settings->detailLayerCallback)
{
detailData = settings->detailLayerCallback(detailData);
}
}

if (settings->elevationLayer)
{
auto terrainPath = getTilePath(settings->elevationLayer, x, y, lod);
elevationData = vsg::read_cast<vsg::Data>(terrainPath, options);
if (elevationData && settings->elevationLayerCallback) elevationData = settings->elevationLayerCallback(elevationData);
if (elevationData && settings->elevationLayerCallback)
{
elevationData = settings->elevationLayerCallback(elevationData);
}
}

auto tile_extents = computeTileExtents(x, y, lod);
Expand Down Expand Up @@ -594,14 +604,14 @@ vsg::ref_ptr<vsg::Node> tile::createECEFTile(const vsg::dbox& tile_extents, ref_
auto scenegraph = vsg::StateGroup::create();

double tileReferenceSize = vsg::radians(tile_extents.max.y - tile_extents.min.y) * settings->ellipsoidModel->radiusEquator();
vec3 displacementMapScale(tileReferenceSize, tileReferenceSize, settings->elevationScale);
vec3 displacementMapScale(static_cast<float>(tileReferenceSize), static_cast<float>(tileReferenceSize), static_cast<float>(settings->elevationScale));

if (elevationData)
{
switch (elevationData->properties.format)
{
case (VK_FORMAT_R16_SFLOAT): displacementMapScale.z = 1.0; break;
case (VK_FORMAT_R32_SFLOAT): displacementMapScale.z = 1.0; break;
case (VK_FORMAT_R16_SFLOAT): displacementMapScale.z = 1.0f; break;
case (VK_FORMAT_R32_SFLOAT): displacementMapScale.z = 1.0f; break;
default: break;
}
}
Expand Down Expand Up @@ -829,7 +839,17 @@ vsg::ref_ptr<vsg::Node> tile::createTextureQuad(const vsg::dbox& tile_extents, r
Origin origin = vsg::TOP_LEFT;

double tileReferenceSize = tile_extents.max.y - tile_extents.min.y;
vec3 displacementMapScale(tileReferenceSize, tileReferenceSize, settings->elevationScale);
vec3 displacementMapScale(static_cast<float>(tileReferenceSize), static_cast<float>(tileReferenceSize), static_cast<float>(settings->elevationScale));

if (elevationData)
{
switch (elevationData->properties.format)
{
case (VK_FORMAT_R16_SFLOAT): displacementMapScale.z = 1.0f; break;
case (VK_FORMAT_R32_SFLOAT): displacementMapScale.z = 1.0f; break;
default: break;
}
}

// create StateGroup to bind any texture state
auto scenegraph = vsg::StateGroup::create();
Expand Down
4 changes: 2 additions & 2 deletions src/vsg/lighting/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ ref_ptr<vsg::Node> vsg::createHeadlight()
auto ambientLight = vsg::AmbientLight::create();
ambientLight->name = "ambient";
ambientLight->color.set(1.0f, 1.0f, 1.0f);
ambientLight->intensity = 0.05f;
ambientLight->intensity = 0.0044f;

auto directionalLight = vsg::DirectionalLight::create();
directionalLight->name = "headlight";
directionalLight->color.set(1.0f, 1.0f, 1.0f);
directionalLight->intensity = 0.95f;
directionalLight->intensity = 0.9956f;
directionalLight->direction.set(0.0, 0.0, -1.0);

auto absoluteTransform = vsg::AbsoluteTransform::create();
Expand Down
8 changes: 4 additions & 4 deletions src/vsg/text/GpuLayoutTechnique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ void GpuLayoutTechnique::setup(Text* text, uint32_t minimumAllocation, ref_ptr<c
}
};

ConvertString convert(*(text->font), textArray, textArrayUpdated, minimumAllocation);
text->text->accept(convert);
ConvertString converter(*(text->font), textArray, textArrayUpdated, minimumAllocation);
text->text->accept(converter);

if (convert.allocatedSize == 0) return;
if (converter.allocatedSize == 0) return;

uint32_t num_quads = convert.size;
uint32_t num_quads = converter.size;

// set up the layout data in a form digestible by the GPU.
if (!layoutValue)
Expand Down
Loading
Loading