Skip to content

Commit 39fa916

Browse files
Merge pull request #337 from vsg-dev/MultiLayerTileDatabase
Added tests for vsg::TileDatabase detail and elevation layers
2 parents 7dce30e + 8fed7e6 commit 39fa916

File tree

20 files changed

+256
-192
lines changed

20 files changed

+256
-192
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.7)
22

33
project(vsgExamples
4-
VERSION 1.1.7
4+
VERSION 1.1.8
55
DESCRIPTION "Set of example programs that test and illustrate how to use the VulkanSceneGraph"
66
LANGUAGES CXX C
77
)

data/shaders/standard.vert

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ layout(push_constant) uniform PushConstants {
1111
mat4 modelView;
1212
} pc;
1313

14-
#ifdef VSG_DISPLACEMENT_MAP
15-
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 6) uniform sampler2D displacementMap;
16-
#endif
17-
1814
layout(location = 0) in vec3 vsg_Vertex;
1915
layout(location = 1) in vec3 vsg_Normal;
2016
layout(location = 2) in vec2 vsg_TexCoord0;
2117
layout(location = 3) in vec4 vsg_Color;
2218

19+
#ifdef VSG_DISPLACEMENT_MAP
20+
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 7) uniform sampler2D displacementMap;
21+
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 8) uniform DisplacementMapScale
22+
{
23+
vec3 value;
24+
} displacementMapScale;
25+
#endif
2326

2427
#ifdef VSG_BILLBOARD
2528
layout(location = 4) in vec4 vsg_position_scaleDistance;
@@ -71,8 +74,11 @@ void main()
7174
vec4 normal = vec4(vsg_Normal, 0.0);
7275

7376
#ifdef VSG_DISPLACEMENT_MAP
74-
// TODO need to pass as as uniform or per instance attributes
77+
#if 0
7578
vec3 scale = vec3(1.0, 1.0, 1.0);
79+
#else
80+
vec3 scale = displacementMapScale.value;
81+
#endif
7682

7783
vertex.xyz = vertex.xyz + vsg_Normal * (texture(displacementMap, vsg_TexCoord0.st).s * scale.z);
7884

data/shaders/standard_flat_shaded.frag

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#version 450
22
#extension GL_ARB_separate_shader_objects : enable
3-
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_ALPHA_TEST)
3+
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_DETAIL_MAP, VSG_ALPHA_TEST)
44

55
#define VIEW_DESCRIPTOR_SET 0
66
#define MATERIAL_DESCRIPTOR_SET 1
@@ -9,6 +9,10 @@
99
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 0) uniform sampler2D diffuseMap;
1010
#endif
1111

12+
#ifdef VSG_DETAIL_MAP
13+
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 1) uniform sampler2D detailMap;
14+
#endif
15+
1216
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 10) uniform MaterialData
1317
{
1418
vec4 ambientColor;
@@ -44,6 +48,12 @@ void main()
4448
#endif
4549
#endif
4650

51+
#ifdef VSG_DETAIL_MAP
52+
vec4 detailColor = texture(detailMap, texCoord0.st);
53+
diffuseColor.rgb = mix(diffuseColor.rgb, detailColor.rgb, detailColor.a);
54+
#endif
55+
56+
4757
#ifdef VSG_ALPHA_TEST
4858
if (material.alphaMask == 1.0f && diffuseColor.a < material.alphaMaskCutoff) discard;
4959
#endif

data/shaders/standard_pbr.frag

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#version 450
22
#extension GL_ARB_separate_shader_objects : enable
3-
#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, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG, VSG_ALPHA_TEST)
3+
#pragma import_defines (VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_DETAIL_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_METALLROUGHNESS_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_WORKFLOW_SPECGLOSS, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG, VSG_ALPHA_TEST)
44

55
// define by default for backwards compatibility
66
#define VSG_SHADOWS_HARD
@@ -18,8 +18,8 @@ const float c_MinRoughness = 0.04;
1818
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 0) uniform sampler2D diffuseMap;
1919
#endif
2020

21-
#ifdef VSG_METALLROUGHNESS_MAP
22-
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 1) uniform sampler2D mrMap;
21+
#ifdef VSG_DETAIL_MAP
22+
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 1) uniform sampler2D detailMap;
2323
#endif
2424

2525
#ifdef VSG_NORMAL_MAP
@@ -38,6 +38,10 @@ layout(set = MATERIAL_DESCRIPTOR_SET, binding = 4) uniform sampler2D emissiveMap
3838
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 5) uniform sampler2D specularMap;
3939
#endif
4040

41+
#ifdef VSG_METALLROUGHNESS_MAP
42+
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 6) uniform sampler2D mrMap;
43+
#endif
44+
4145
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 10) uniform PbrData
4246
{
4347
vec4 baseColorFactor;
@@ -335,6 +339,13 @@ void main()
335339
baseColor = vertexColor * pbr.baseColorFactor;
336340
#endif
337341

342+
343+
#ifdef VSG_DETAIL_MAP
344+
vec4 detailColor = texture(detailMap, texCoord0.st);
345+
baseColor.rgb = mix(baseColor.rgb, detailColor.rgb, detailColor.a);
346+
#endif
347+
348+
338349
#ifdef VSG_ALPHA_TEST
339350
if (pbr.alphaMask == 1.0f && baseColor.a < pbr.alphaMaskCutoff) discard;
340351
#endif

data/shaders/standard_phong.frag

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#version 450
22
#extension GL_ARB_separate_shader_objects : enable
3-
#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, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG, VSG_ALPHA_TEST)
3+
#pragma import_defines (VSG_POINT_SPRITE, VSG_DIFFUSE_MAP, VSG_GREYSCALE_DIFFUSE_MAP, VSG_DETAIL_MAP, VSG_EMISSIVE_MAP, VSG_LIGHTMAP_MAP, VSG_NORMAL_MAP, VSG_SPECULAR_MAP, VSG_TWO_SIDED_LIGHTING, VSG_SHADOWS_PCSS, VSG_SHADOWS_SOFT, VSG_SHADOWS_HARD, SHADOWMAP_DEBUG, VSG_ALPHA_TEST)
44

55
// define by default for backwards compatibility
66
#define VSG_SHADOWS_HARD
@@ -14,6 +14,10 @@ const float PI = radians(180);
1414
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 0) uniform sampler2D diffuseMap;
1515
#endif
1616

17+
#ifdef VSG_DETAIL_MAP
18+
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 1) uniform sampler2D detailMap;
19+
#endif
20+
1721
#ifdef VSG_NORMAL_MAP
1822
layout(set = MATERIAL_DESCRIPTOR_SET, binding = 2) uniform sampler2D normalMap;
1923
#endif
@@ -131,6 +135,11 @@ void main()
131135
#endif
132136
#endif
133137

138+
#ifdef VSG_DETAIL_MAP
139+
vec4 detailColor = texture(detailMap, texCoord0.st);
140+
diffuseColor.rgb = mix(diffuseColor.rgb, detailColor.rgb, detailColor.a);
141+
#endif
142+
134143
vec4 ambientColor = diffuseColor * material.ambientColor * material.ambientColor.a;
135144
vec4 specularColor = material.specularColor;
136145
vec4 emissiveColor = material.emissiveColor;

examples/app/vsgaxes/vsgaxes.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,28 @@
99

1010
// A rotation tracking view matrix. It returns the rotation component
1111
// of another viewMatrix.
12-
class RotationTrackingMatrix : public vsg::Inherit<vsg::ViewMatrix, RotationTrackingMatrix> {
13-
public:
12+
class RotationTrackingMatrix : public vsg::Inherit<vsg::ViewMatrix, RotationTrackingMatrix>
13+
{
14+
public:
1415
RotationTrackingMatrix(vsg::ref_ptr<vsg::ViewMatrix> parentTransform) :
1516
parentTransform_(parentTransform) {}
16-
17+
1718
// The transform() returns the rotation part of the tracked matrix
18-
vsg::dmat4 transform(const vsg::dvec3&) const override {
19+
vsg::dmat4 transform(const vsg::dvec3&) const override
20+
{
1921

2022
vsg::dvec3 translation, scale;
21-
vsg::dquat rotation;
23+
vsg::dquat rotation;
2224
vsg::decompose(parentTransform_->transform(),
2325
// output
2426
translation,
2527
rotation,
2628
scale);
27-
29+
2830
return vsg::rotate(rotation);
2931
}
30-
31-
private:
32+
33+
private:
3234
vsg::ref_ptr<vsg::ViewMatrix> parentTransform_;
3335
};
3436

@@ -42,29 +44,29 @@ vsg::ref_ptr<vsg::Node> createArrow(vsg::vec3 pos, vsg::vec3 dir, vsg::vec4 colo
4244
vsg::GeometryInfo geomInfo;
4345
vsg::StateInfo stateInfo;
4446

45-
geomInfo.color = vsg::vec4{1,1,1,1};
47+
geomInfo.color = vsg::vec4{1, 1, 1, 1};
4648
geomInfo.position = pos;
4749
geomInfo.transform = vsg::translate(0.0f, 0.0f, 0.5f);
4850

4951
// If we don't point in the z-direction, then rotate the arrow
50-
if (vsg::length(vsg::cross(vsg::vec3{0,0,1}, dir)) > 0.0001)
52+
if (vsg::length(vsg::cross(vsg::vec3{0, 0, 1}, dir)) > 0.0001)
5153
{
52-
vsg::vec3 axis = vsg::cross(vsg::vec3{0,0,1}, dir);
53-
float angle = acos(vsg::dot(vsg::vec3{0,0,1}, dir));
54+
vsg::vec3 axis = vsg::cross(vsg::vec3{0, 0, 1}, dir);
55+
float angle = acos(vsg::dot(vsg::vec3{0, 0, 1}, dir));
5456
geomInfo.transform = vsg::rotate(angle, axis) * geomInfo.transform;
5557
}
5658

5759
auto axisTransform = geomInfo.transform;
5860
geomInfo.transform = geomInfo.transform * vsg::scale(0.1f, 0.1f, 1.0f);
59-
61+
6062
// Rotate geomInfo from pos in the direction of dir
6163
auto node = builder.createCylinder(geomInfo, stateInfo);
6264
arrow->addChild(node);
6365

6466
// The cone
6567
geomInfo.color = color;
6668
// This would have been cleaner with a pre_translate transform
67-
geomInfo.transform = vsg::scale(0.3f, 0.3f, 0.3f) * axisTransform * vsg::translate(0.0f, 0.0f, 1.0f/0.3f);
69+
geomInfo.transform = vsg::scale(0.3f, 0.3f, 0.3f) * axisTransform * vsg::translate(0.0f, 0.0f, 1.0f / 0.3f);
6870
node = builder.createCone(geomInfo, stateInfo);
6971
arrow->addChild(node);
7072

@@ -76,14 +78,14 @@ vsg::ref_ptr<vsg::Node> createGizmo()
7678
{
7779
vsg::ref_ptr<vsg::Group> gizmo = vsg::Group::create();
7880

79-
gizmo->addChild(createArrow(vsg::vec3{0,0,0}, vsg::vec3{1,0,0}, vsg::vec4{1,0,0,1}));
80-
gizmo->addChild(createArrow(vsg::vec3{0,0,0}, vsg::vec3{0,1,0}, vsg::vec4{0,1,0,1}));
81-
gizmo->addChild(createArrow(vsg::vec3{0,0,0}, vsg::vec3{0,0,1}, vsg::vec4{0,0,1,1}));
81+
gizmo->addChild(createArrow(vsg::vec3{0, 0, 0}, vsg::vec3{1, 0, 0}, vsg::vec4{1, 0, 0, 1}));
82+
gizmo->addChild(createArrow(vsg::vec3{0, 0, 0}, vsg::vec3{0, 1, 0}, vsg::vec4{0, 1, 0, 1}));
83+
gizmo->addChild(createArrow(vsg::vec3{0, 0, 0}, vsg::vec3{0, 0, 1}, vsg::vec4{0, 0, 1, 1}));
8284

8385
vsg::Builder builder;
8486
vsg::GeometryInfo geomInfo;
8587
vsg::StateInfo stateInfo;
86-
geomInfo.color = vsg::vec4{1,1,1,1};
88+
geomInfo.color = vsg::vec4{1, 1, 1, 1};
8789
geomInfo.transform = vsg::scale(0.1f, 0.1f, 0.1f);
8890

8991
auto sphere = builder.createSphere(geomInfo, stateInfo);
@@ -95,7 +97,7 @@ vsg::ref_ptr<vsg::Node> createGizmo()
9597
// Create a tracking overlay with a axes view that shows the orientation
9698
// of the main camera view matrix
9799
vsg::ref_ptr<vsg::View> createAxesView(vsg::ref_ptr<vsg::Camera> camera,
98-
double aspectRatio)
100+
double aspectRatio)
99101
{
100102
auto viewMat = RotationTrackingMatrix::create(camera->viewMatrix);
101103

@@ -104,14 +106,14 @@ vsg::ref_ptr<vsg::View> createAxesView(vsg::ref_ptr<vsg::Camera> camera,
104106
double camWidth = 10;
105107
double camXOffs = -8;
106108
double camYOffs = -8;
107-
auto ortho = vsg::Orthographic::create(camXOffs,camXOffs+camWidth, // left, right
108-
camYOffs/aspectRatio,(camYOffs+camWidth)/aspectRatio, // bottom, top
109-
-1000,1000); // near, far
109+
auto ortho = vsg::Orthographic::create(camXOffs, camXOffs + camWidth, // left, right
110+
camYOffs / aspectRatio, (camYOffs + camWidth) / aspectRatio, // bottom, top
111+
-1000, 1000); // near, far
110112

111113
auto gizmoCamera = vsg::Camera::create(
112-
ortho,
113-
viewMat,
114-
camera->viewportState);
114+
ortho,
115+
viewMat,
116+
camera->viewportState);
115117

116118
auto scene = vsg::Group::create();
117119
scene->addChild(createGizmo());
@@ -194,7 +196,7 @@ int main(int argc, char** argv)
194196

195197
uint32_t width = window->extent2D().width;
196198
uint32_t height = window->extent2D().height;
197-
double aspectRatio = (double)width/height;
199+
double aspectRatio = (double)width / height;
198200

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

examples/app/vsgmultigpu/vsgmultigpu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ int main(int argc, char** argv)
323323
else if (affinity)
324324
{
325325
std::cout << "vsg::setAffinity(";
326-
for(auto cpu_num : affinity.cpus)
326+
for (auto cpu_num : affinity.cpus)
327327
{
328-
std::cout<<" "<<cpu_num;
328+
std::cout << " " << cpu_num;
329329
}
330-
std::cout<<" )"<< std::endl;
330+
std::cout << " )" << std::endl;
331331

332332
vsg::setAffinity(affinity);
333333
}

examples/app/vsgviewer/vsgviewer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ int main(int argc, char** argv)
180180
affinity.cpus.insert(cpu);
181181
}
182182

183-
184183
// should animations be automatically played
185184
auto autoPlay = !arguments.read({"--no-auto-play", "--nop"});
186185

@@ -327,11 +326,11 @@ int main(int argc, char** argv)
327326
else if (affinity)
328327
{
329328
std::cout << "vsg::setAffinity(";
330-
for(auto cpu_num : affinity.cpus)
329+
for (auto cpu_num : affinity.cpus)
331330
{
332-
std::cout<<" "<<cpu_num;
331+
std::cout << " " << cpu_num;
333332
}
334-
std::cout<<" )"<< std::endl;
333+
std::cout << " )" << std::endl;
335334

336335
vsg::setAffinity(affinity);
337336
}

examples/core/vsgallocator/vsgallocator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ class StdAllocator : public vsg::Allocator
2828

2929
void* allocate(std::size_t size, vsg::AllocatorAffinity) override
3030
{
31-
return operator new (size); //, std::align_val_t{default_alignment});
31+
return operator new(size); //, std::align_val_t{default_alignment});
3232
}
3333

3434
bool deallocate(void* ptr, std::size_t size) override
3535
{
3636
if (nestedAllocator && nestedAllocator->deallocate(ptr, size)) return true;
3737

38-
operator delete (ptr);//, std::align_val_t{default_alignment});
38+
operator delete(ptr); //, std::align_val_t{default_alignment});
3939
return true;
4040
}
4141

@@ -46,7 +46,6 @@ class StdAllocator : public vsg::Allocator
4646
void setBlockSize(vsg::AllocatorAffinity, size_t) {}
4747
};
4848

49-
5049
struct SceneStatistics : public vsg::Inherit<vsg::ConstVisitor, SceneStatistics>
5150
{
5251
std::map<const char*, size_t> objectCounts;

0 commit comments

Comments
 (0)