Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge vsgExamples master into 1.0 branch in prep for a release candidate #254

Merged
merged 48 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f196aad
Fixed timestamp multiplier
robertosfield Aug 1, 2023
02b3e4e
Added lighting to dynamically created view
robertosfield Aug 4, 2023
00d1e6b
Added vsgdynamicwindows example to illustrate multi-thread load and W…
robertosfield Aug 7, 2023
bcdc694
Merge pull request #237 from vsg-dev/DynamicWindows
robertosfield Aug 7, 2023
a221541
Update vsgmultiviews.cpp
lufriem Aug 10, 2023
2f1a01b
Merge pull request #239 from LeeRiva/master
robertosfield Aug 10, 2023
98d5ea9
Fixed nullptr acces if the required input could not be loaded.
lufriem Aug 10, 2023
2f00eca
Merge pull request #240 from LeeRiva/specific_commit
robertosfield Aug 11, 2023
45718d1
Fixed misspellings, reworded some comments
lufriem Aug 10, 2023
3ba5f3e
Removed link to 'traversals' example folder since that seems to have …
lufriem Aug 11, 2023
1e0652a
Merge pull request #241 from LeeRiva/specific_commit
robertosfield Aug 11, 2023
f0fb327
[UPDATED] vsgraytracing uniform to use dataVariance
Aug 11, 2023
36595ca
[FIXED] VSG_GREYSCALE_DIFFUSE_MAP typo
Aug 11, 2023
2a8bfdd
Merge pull request #243 from siystar/vsgraytracing
robertosfield Aug 11, 2023
e95ca96
Merge pull request #244 from siystar/greyscale
robertosfield Aug 11, 2023
3a3b438
[FIXED] typos
Aug 12, 2023
112ce41
Merge pull request #242 from siystar/typos
robertosfield Aug 13, 2023
921e12e
Updated PipelineState mask
robertosfield Aug 15, 2023
4a6cd37
Revert "Updated PipelineState mask"
robertosfield Aug 15, 2023
4fe3a47
Changed to use new GraphicsPipelineState::mask.
robertosfield Aug 15, 2023
1dca84b
Added experimental ShaderSet replacement
robertosfield Aug 15, 2023
1228b76
Updates to work with GraphicsPipelineMask branch
robertosfield Aug 16, 2023
3e0a84e
Simplified code
robertosfield Aug 16, 2023
8593001
Merge pull request #245 from vsg-dev/GraphicsPipelineMask
robertosfield Aug 16, 2023
a69735e
Updated required VSG version to 1.0.9 to work with latest changes
robertosfield Aug 16, 2023
11eb3cb
Added check for valud font.
robertosfield Aug 18, 2023
4e74b20
Added check for valid font file
robertosfield Aug 18, 2023
798625b
Added test for CommandGraph nesting and setting of the CommandGraph::…
robertosfield Aug 18, 2023
e91a2c1
[FIXED] typo
Aug 18, 2023
172874d
Merge pull request #246 from siystar/typos
robertosfield Aug 18, 2023
6f45c13
Fixed incorrect check for the Ctrl modifier - the vsg::KeyPressEvent:…
lufriem Aug 19, 2023
7d5a0b3
Merge pull request #248 from LeeRiva/lrdev
robertosfield Aug 20, 2023
f934c19
Updated vsgcameras example so that the 'extra' mouse buttons (X1/X2 o…
lufriem Aug 21, 2023
892449b
Fixed reference positioning to be consistent with the rest of the VSG.
robertosfield Aug 21, 2023
0513d83
Merge pull request #249 from LeeRiva/lrdev
robertosfield Aug 21, 2023
6d66f0b
Simplified method used
robertosfield Aug 21, 2023
72b9eda
Merge branch 'master' of https://github.com/vsg-dev/vsgExamples
robertosfield Aug 21, 2023
4a299a4
Fixed barrier settings
robertosfield Aug 22, 2023
2047629
Merge branch 'master' into NestedCommandGraph
robertosfield Aug 22, 2023
4ada88c
Added -n command line option to select a nested compute CommandGraph
robertosfield Aug 22, 2023
fe9b2f5
Added fullstop
robertosfield Aug 22, 2023
ffac706
Merge pull request #250 from vsg-dev/NestedCommandGraph
robertosfield Aug 23, 2023
c966fc6
[FIXED] typos
lufriem Aug 23, 2023
0bc5448
Merge pull request #252 from LeeRiva/lrdev2
robertosfield Aug 23, 2023
01dc356
Ignore more MSVC/VS-specific intermediate files
AnyOldName3 Aug 23, 2023
3a70f95
Merge pull request #253 from AnyOldName3/more-gitignore
robertosfield Aug 24, 2023
384999e
Updated vsgXchange version
robertosfield Aug 24, 2023
9de6cbe
Merge branch 'master' of https://github.com/vsg-dev/vsgExamples
robertosfield Aug 24, 2023
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ src/vsg/vsg.dir/
*.pdb
*.tlog
*.log
*.ilk
*.dll.recipe
*.exe.recipe
*.lib.recipe

# Xcode
DerivedData/
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ if (VULKAN_SDK)
set(ENV{VULKAN_SDK} ${VULKAN_SDK})
endif()

find_package(vsg 1.0.8)
find_package(vsg 1.0.9)

vsg_setup_dir_vars()
vsg_setup_build_vars()

# find the optional vsgExamples that can be used for reading and range of image and 3d model formats and shader compilation
find_package(vsgXchange 1.0.2 QUIET)
# find the optional vsgXchange that can be used for reading a range of image and 3d model formats and shader compilation
find_package(vsgXchange 1.0.5 QUIET)

# find the optional vsgImGui that can be used for GUI elements added into graphics window.
# find the optional vsgImGui that can be used for GUI elements added into graphics windows.
find_package(vsgImGui QUIET)

# set the use of C++17 globally as all examples require it
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# vsgExamples
Example programs that test and illustrate how to use the [VulkanSceneGraph](https://github.com/vsg-dev/VulkanSceneGraphPrototype/) and optional add-on libraries. The example programs are grouped according to the type of features they illustrate their dependencies.
Example programs that test and illustrate how to use the [VulkanSceneGraph](https://github.com/vsg-dev/VulkanSceneGraph/) and optional add-on libraries. The example programs are grouped according to the type of features they illustrate and their dependencies.

* [core](examples/core/) examples
* [nodes](examples/nodes/) examples
* [maths](examples/maths/) examples
* [app](examples/app/) examples
* [vk](examples/vk/) examples
* [text](examples/text/) examples
* [ray tracing](examples/raytracing/) examples
* [raytracing](examples/raytracing/) examples
* [state](examples/state/) examples
* [commands](examples/commands/) examples
* [io](examples/io/) examples
* [ui](examples/ui/) examples
* [traversals](examples/traversals/) examples
* [platform](examples/platform/) examples
* [utils](examples/utils/) examples
* [threading](examples/threading/) examples
* [volume](examples/volume/) examples
* [meshshaders](examples/meshshaders/) examples

## Quick Guide to Building the vsgExamples

Expand All @@ -35,7 +38,7 @@ To build and install in source, with all dependencies installed in standard syst
cmake .
make -j 8

Full details on how to build of the VSG can be found in the [INSTALL.md](INSTALL.md) file.
Full details on how to build the vsgExamples can be found in the [INSTALL.md](INSTALL.md) file.

## Running examples

Expand Down
4 changes: 2 additions & 2 deletions data/shaders/standard_flat_shaded.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSACLE_DIFFUSE_MAP)
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP)

#ifdef VSG_DIFFUSE_MAP
layout(binding = 0) uniform sampler2D diffuseMap;
Expand Down Expand Up @@ -34,7 +34,7 @@ void main()
vec4 diffuseColor = vertexColor * material.diffuseColor;

#ifdef VSG_DIFFUSE_MAP
#ifdef VSG_GREYSACLE_DIFFUSE_MAP
#ifdef VSG_GREYSCALE_DIFFUSE_MAP
float v = texture(diffuseMap, texCoord0.st).s;
diffuseColor *= vec4(v, v, v, 1.0);
#else
Expand Down
4 changes: 2 additions & 2 deletions data/shaders/standard_pbr.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#pragma import_defines (VSG_DIFFUSE_MAP, VSG_GREYSACLE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_METALLROUGHNESS_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_WORKFLOW_SPECGLOSS)
#pragma import_defines (VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_METALLROUGHNESS_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_WORKFLOW_SPECGLOSS)

const float PI = 3.14159265359;
const float RECIPROCAL_PI = 0.31830988618;
Expand Down Expand Up @@ -312,7 +312,7 @@ void main()
vec3 f0 = vec3(0.04);

#ifdef VSG_DIFFUSE_MAP
#ifdef VSG_GREYSACLE_DIFFUSE_MAP
#ifdef VSG_GREYSCALE_DIFFUSE_MAP
float v = texture(diffuseMap, texCoord0.st).s * pbr.baseColorFactor;
baseColor = vertexColor * vec4(v, v, v, 1.0);
#else
Expand Down
4 changes: 2 additions & 2 deletions data/shaders/standard_phong.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSACLE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING)
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING)

#ifdef VSG_DIFFUSE_MAP
layout(set = 0, binding = 0) uniform sampler2D diffuseMap;
Expand Down Expand Up @@ -108,7 +108,7 @@ void main()

vec4 diffuseColor = vertexColor * material.diffuseColor;
#ifdef VSG_DIFFUSE_MAP
#ifdef VSG_GREYSACLE_DIFFUSE_MAP
#ifdef VSG_GREYSCALE_DIFFUSE_MAP
float v = texture(diffuseMap, texCoord0.st).s;
diffuseColor *= vec4(v, v, v, 1.0);
#else
Expand Down
128 changes: 70 additions & 58 deletions examples/app/vsganaglyphicstereo/vsganaglyphicstereo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,16 @@
# include <vsgXchange/all.h>
#endif

namespace vsg
{
class PerViewGraphicsPipelineState : public Inherit<GraphicsPipelineState, PerViewGraphicsPipelineState>
{
public:
PerViewGraphicsPipelineState() {}

std::vector<ref_ptr<GraphicsPipelineState>> graphicsPipesStates;

virtual void apply(Context& context, VkGraphicsPipelineCreateInfo& pipelineInfo) const
{
auto viewID = context.viewID;
if (viewID < graphicsPipesStates.size()) graphicsPipesStates[viewID]->apply(context, pipelineInfo);
}

protected:
virtual ~PerViewGraphicsPipelineState() {}
};
VSG_type_name(vsg::PerViewGraphicsPipelineState);
} // namespace vsg

class ReplaceColorBlendState : public vsg::Visitor
{
public:

ReplaceColorBlendState(vsg::Mask in_leftMask, vsg::Mask in_rightMask) :
leftMask(in_leftMask),
rightMask(in_rightMask) {}

vsg::Mask leftMask;
vsg::Mask rightMask;
std::set<vsg::GraphicsPipeline*> visited;

void apply(vsg::Node& node) override
Expand Down Expand Up @@ -60,41 +46,24 @@ class ReplaceColorBlendState : public vsg::Visitor
{
if ((*itr)->is_compatible(typeid(vsg::ColorBlendState)))
{
auto colorBlendState = (*itr)->cast<vsg::ColorBlendState>();
auto perViewGraphicsPipelineState = vsg::PerViewGraphicsPipelineState::create();

VkPipelineColorBlendAttachmentState left_colorBlendAttachment = {
VK_FALSE, // blendEnable
VK_BLEND_FACTOR_ZERO, // srcColorBlendFactor
VK_BLEND_FACTOR_ZERO, // dstColorBlendFactor
VK_BLEND_OP_ADD, // colorBlendOp
VK_BLEND_FACTOR_ZERO, // srcAlphaBlendFactor
VK_BLEND_FACTOR_ZERO, // dstAlphaBlendFactor
VK_BLEND_OP_ADD, // alphaBlendOp
VK_COLOR_COMPONENT_R_BIT /*| VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT*/ | VK_COLOR_COMPONENT_A_BIT // colorWriteMask
};

VkPipelineColorBlendAttachmentState right_colorBlendAttachment = {
VK_FALSE, // blendEnable
VK_BLEND_FACTOR_ZERO, // srcColorBlendFactor
VK_BLEND_FACTOR_ZERO, // dstColorBlendFactor
VK_BLEND_OP_ADD, // colorBlendOp
VK_BLEND_FACTOR_ZERO, // srcAlphaBlendFactor
VK_BLEND_FACTOR_ZERO, // dstAlphaBlendFactor
VK_BLEND_OP_ADD, // alphaBlendOp
/*VK_COLOR_COMPONENT_R_BIT | */ VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT // colorWriteMask
};
auto colorBlendState = itr->cast<vsg::ColorBlendState>();

// remove original ColorBlendState
gp->pipelineStates.erase(itr);

auto left_colorBlendState = vsg::ColorBlendState::create(*colorBlendState);
left_colorBlendState->attachments = {left_colorBlendAttachment};
left_colorBlendState->mask = leftMask;
left_colorBlendState->attachments[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_A_BIT;

auto right_colorBlendState = vsg::ColorBlendState::create(*colorBlendState);
right_colorBlendState->attachments = {right_colorBlendAttachment};
right_colorBlendState->mask = rightMask;
right_colorBlendState->attachments[0].colorWriteMask = VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;

perViewGraphicsPipelineState->graphicsPipesStates.push_back(left_colorBlendState);
perViewGraphicsPipelineState->graphicsPipesStates.push_back(right_colorBlendState);
gp->pipelineStates.push_back(left_colorBlendState);
gp->pipelineStates.push_back(right_colorBlendState);

*itr = perViewGraphicsPipelineState;
// finish loop
return;
}
}
}
Expand All @@ -117,13 +86,13 @@ vsg::ref_ptr<vsg::Node> createTextureQuad(const vsg::vec3& origin, const vsg::ve

// set up graphics pipeline
vsg::DescriptorSetLayoutBindings descriptorBindings{
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr} // { binding, descriptorTpe, descriptorCount, stageFlags, pImmutableSamplers}
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr} // { binding, descriptorType, descriptorCount, stageFlags, pImmutableSamplers}
};

auto descriptorSetLayout = vsg::DescriptorSetLayout::create(descriptorBindings);

vsg::PushConstantRanges pushConstantRanges{
{VK_SHADER_STAGE_VERTEX_BIT, 0, 128} // projection view, and model matrices, actual push constant calls automatically provided by the VSG's DispatchTraversal
{VK_SHADER_STAGE_VERTEX_BIT, 0, 128} // projection, view, and model matrices, actual push constant calls automatically provided by the VSG's RecordTraversal
};

vsg::VertexInputState::Bindings vertexBindingsDescriptions{
Expand Down Expand Up @@ -158,7 +127,7 @@ vsg::ref_ptr<vsg::Node> createTextureQuad(const vsg::vec3& origin, const vsg::ve
auto descriptorSet = vsg::DescriptorSet::create(descriptorSetLayout, vsg::Descriptors{texture});
auto bindDescriptorSets = vsg::BindDescriptorSets::create(VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, vsg::DescriptorSets{descriptorSet});

// create StateGroup as the root of the scene/command graph to hold the GraphicsProgram, and binding of Descriptors to decorate the whole graph
// create StateGroup as the root of the scene/command graph to hold the GraphicsPipeline, and binding of Descriptors to decorate the whole graph
auto scenegraph = vsg::StateGroup::create();
scenegraph->add(bindGraphicsPipeline);
scenegraph->add(bindDescriptorSets);
Expand Down Expand Up @@ -202,6 +171,31 @@ vsg::ref_ptr<vsg::Node> createTextureQuad(const vsg::vec3& origin, const vsg::ve
return scenegraph;
}

void enableCustomShaderSets(vsg::Mask leftMask, vsg::Mask rightMask, vsg::ref_ptr<vsg::Options> options)
{
auto left_colorBlendState = vsg::ColorBlendState::create();
left_colorBlendState->mask = leftMask;
left_colorBlendState->attachments[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_A_BIT;

auto right_colorBlendState = vsg::ColorBlendState::create();
right_colorBlendState->mask = rightMask;
right_colorBlendState->attachments[0].colorWriteMask = VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;

vsg::GraphicsPipelineStates pipelineStates{left_colorBlendState, right_colorBlendState};

auto& text = options->shaderSets["text"] = vsg::createTextShaderSet(options);
text->defaultGraphicsPipelineStates = pipelineStates;

auto& flat = options->shaderSets["flat"] = vsg::createFlatShadedShaderSet(options);
flat->defaultGraphicsPipelineStates = pipelineStates;

auto& phong = options->shaderSets["phong"] = vsg::createPhongShaderSet(options);
phong->defaultGraphicsPipelineStates = pipelineStates;

auto& pbr = options->shaderSets["pbr"] = vsg::createPhysicsBasedRenderingShaderSet(options);
pbr->defaultGraphicsPipelineStates = pipelineStates;
}

int main(int argc, char** argv)
{
// set up defaults and read command line arguments to override them
Expand All @@ -220,6 +214,9 @@ int main(int argc, char** argv)
if (arguments.read({"--window", "-w"}, windowTraits->width, windowTraits->height)) { windowTraits->fullscreen = false; }
arguments.read("--screen", windowTraits->screenNum);
arguments.read("--display", windowTraits->display);
auto outputFile = arguments.value<vsg::Path>("", "-o");

bool replacePipelineStates = !arguments.value<bool>(false, "--no-replace");

vsg::vec3 offset(0.0f, 0.0f, 0.0f);
arguments.read("--offset", offset.x, offset.z);
Expand All @@ -240,6 +237,8 @@ int main(int argc, char** argv)
vsg::Mask leftMask = 0x1;
vsg::Mask rightMask = 0x2;

if (!replacePipelineStates) enableCustomShaderSets(leftMask, rightMask, options);

vsg::ref_ptr<vsg::Node> vsg_scene;
if (leftImageFilename && rightImageFilename)
{
Expand Down Expand Up @@ -277,8 +276,17 @@ int main(int argc, char** argv)
}

// ColorBlendState needs to be overridden per View, so remove existing instances in the scene graph
ReplaceColorBlendState removeColorBlendState;
vsg_scene->accept(removeColorBlendState);
if (replacePipelineStates)
{
ReplaceColorBlendState replaceColorBlendState(leftMask, rightMask);
vsg_scene->accept(replaceColorBlendState);
}

if (outputFile)
{
vsg::write(vsg_scene, outputFile, options);
return 1;
}

// create the viewer and assign window(s) to it
auto viewer = vsg::Viewer::create();
Expand Down Expand Up @@ -321,21 +329,24 @@ int main(int argc, char** argv)
auto left_relative_view = vsg::RelativeViewMatrix::create(vsg::translate(-0.5 * eyeSeperation, 0.0, 0.0), lookAt);
auto left_camera = vsg::Camera::create(left_relative_perspective, left_relative_view, vsg::ViewportState::create(window->extent2D()));

// create the left eye camera
// create the right eye camera
auto right_relative_perspective = vsg::RelativeProjection::create(vsg::translate(shear, 0.0, 0.0), perspective);
auto right_relative_view = vsg::RelativeViewMatrix::create(vsg::translate(0.5 * eyeSeperation, 0.0, 0.0), lookAt);
auto right_camera = vsg::Camera::create(right_relative_perspective, right_relative_view, vsg::ViewportState::create(window->extent2D()));

// add close handler to respond the close window button and pressing escape
// add close handler to respond to close window button and pressing escape
viewer->addEventHandler(vsg::CloseHandler::create(viewer));

// add event handlers, in the order we wish event to be handled.
// add event handlers, in the order we wish events to be handled.
viewer->addEventHandler(vsg::Trackball::create(master_camera, ellipsoidModel));

auto renderGraph = vsg::RenderGraph::create(window);

auto headlight = vsg::createHeadlight();

auto left_view = vsg::View::create(left_camera, vsg_scene);
left_view->mask = leftMask;
left_view->addChild(headlight);
renderGraph->addChild(left_view);

// clear the depth buffer before view2 gets rendered
Expand All @@ -348,6 +359,7 @@ int main(int argc, char** argv)

auto right_view = vsg::View::create(right_camera, vsg_scene);
right_view->mask = rightMask;
right_view->addChild(headlight);
renderGraph->addChild(right_view);

auto commandGraph = vsg::CommandGraph::create(window);
Expand Down
Loading