Skip to content

Commit 90dba5f

Browse files
committed
Merge branch 'animation' into erfan_vulkan_as
# Conflicts: # examples_tests/06.MeshLoaders/main.cpp # examples_tests/54.Transformations/main.cpp # examples_tests/common/Camera.hpp # include/nbl/scene/ITransformTree.h # include/nbl/scene/ITransformTreeManager.h
2 parents 531350d + 17c6ef8 commit 90dba5f

39 files changed

+2066
-866
lines changed

examples_tests/11.LoDSystem/assets/mesh.vert

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
#include "common.glsl"
88

99
#define NBL_GLSL_TRANSFORM_TREE_POOL_DESCRIPTOR_SET 0
10-
// disable what we dont use
11-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_DECLARED
12-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_RELATIVE_TRANSFORM_DESCRIPTOR_DECLARED
13-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_MODIFIED_TIMESTAMP_DESCRIPTOR_DECLARED
14-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_GLOBAL_TRANSFORM_DESCRIPTOR_DECLARED
15-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_RECOMPUTED_TIMESTAMP_DESCRIPTOR_DECLARED
16-
#include <nbl/builtin/glsl/transform_tree/pool_descriptor_set.glsl>
10+
#include <nbl/builtin/glsl/transform_tree/render_descriptor_set.glsl>
1711

1812
layout(set = 1, binding = 0, std430, row_major) restrict readonly buffer PerViewPerInstance
1913
{

examples_tests/11.LoDSystem/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class LoDSystemApp : public ApplicationBase
395395
{
396396
scene::ILevelOfDetailLibrary::createDescriptorSetLayout(logicalDevice.get()),
397397
culling_system_t::createInputDescriptorSetLayout(logicalDevice.get()),
398-
culling_system_t::createOutputDescriptorSetLayout(logicalDevice.get(),true),
398+
culling_system_t::createOutputDescriptorSetLayout(logicalDevice.get()),
399399
[&]() -> core::smart_refctd_ptr<video::IGPUDescriptorSetLayout>
400400
{
401401
// TODO: figure out what should be here
@@ -541,28 +541,28 @@ class LoDSystemApp : public ApplicationBase
541541
int a = 0;// logger->log("%s", ILogger::ELL_ERROR, "Couldn't load cache.");
542542

543543
//
544-
core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout> cpuTransformTreeDSLayout = scene::ITransformTreeWithNormalMatrices::createDescriptorSetLayout();
544+
core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout> cpuTransformTreeDSLayout = scene::ITransformTreeWithNormalMatrices::createRenderDescriptorSetLayout();
545545

546546
// populating `lodTables` is a bit messy, I know
547547
size_t lodTableIx = lodLibraryData.lodTableDstUvec4s.size();
548548
addLoDTable<EGT_CUBE, 1>(
549549
assetManager.get(), cpuTransformTreeDSLayout, cpuPerViewDSLayout, shaders, cpu2gpuParams,
550550
lodLibraryData, drawIndirectAllocator.get(), lodLibrary.get(), kiln.getDrawcallMetadataVector(),
551-
cullingParams.perInstanceRedirectAttribs, renderpass, ctt->getNodePropertyDescriptorSet(), perViewDS
551+
cullingParams.perInstanceRedirectAttribs, renderpass, ctt->getRenderDescriptorSet(), perViewDS
552552
);
553553
lodTables[EGT_CUBE] = lodLibraryData.lodTableDstUvec4s[lodTableIx];
554554
lodTableIx = lodLibraryData.lodTableDstUvec4s.size();
555555
addLoDTable<EGT_SPHERE, 7>(
556556
assetManager.get(), cpuTransformTreeDSLayout, cpuPerViewDSLayout, shaders, cpu2gpuParams,
557557
lodLibraryData, drawIndirectAllocator.get(), lodLibrary.get(), kiln.getDrawcallMetadataVector(),
558-
cullingParams.perInstanceRedirectAttribs, renderpass, ctt->getNodePropertyDescriptorSet(), perViewDS
558+
cullingParams.perInstanceRedirectAttribs, renderpass, ctt->getRenderDescriptorSet(), perViewDS
559559
);
560560
lodTables[EGT_SPHERE] = lodLibraryData.lodTableDstUvec4s[lodTableIx];
561561
lodTableIx = lodLibraryData.lodTableDstUvec4s.size();
562562
addLoDTable<EGT_CYLINDER, 6>(
563563
assetManager.get(), cpuTransformTreeDSLayout, cpuPerViewDSLayout, shaders, cpu2gpuParams,
564564
lodLibraryData, drawIndirectAllocator.get(), lodLibrary.get(), kiln.getDrawcallMetadataVector(),
565-
cullingParams.perInstanceRedirectAttribs, renderpass, ctt->getNodePropertyDescriptorSet(), perViewDS
565+
cullingParams.perInstanceRedirectAttribs, renderpass, ctt->getRenderDescriptorSet(), perViewDS
566566
);
567567
lodTables[EGT_CYLINDER] = lodLibraryData.lodTableDstUvec4s[lodTableIx];
568568

examples_tests/12.glTF/main.cpp

Lines changed: 486 additions & 97 deletions
Large diffs are not rendered by default.

examples_tests/54.Transformations/main.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ using namespace core;
1414
const char* vertexSource = R"===(
1515
#version 430 core
1616
17-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_PARENT_DESCRIPTOR_DECLARED
18-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_RELATIVE_TRANSFORM_DESCRIPTOR_DECLARED
19-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_MODIFIED_TIMESTAMP_DESCRIPTOR_DECLARED
20-
#define NBL_GLSL_TRANSFORM_TREE_POOL_NODE_RECOMPUTED_TIMESTAMP_DESCRIPTOR_DECLARED
21-
#include "nbl/builtin/glsl/transform_tree/pool_descriptor_set.glsl"
17+
#include "nbl/builtin/glsl/transform_tree/render_descriptor_set.glsl"
2218
2319
layout(location = 0) in vec3 vPos;
2420
layout(location = 3) in vec3 vNormal;
@@ -274,7 +270,8 @@ class TransformationApp : public ApplicationBase
274270
if (!ttm.get())
275271
return;
276272

277-
ttDS = tt->getNodePropertyDescriptorSet();
273+
debugDrawPipeline = ttm->createDebugPipeline<transform_tree_t>(renderpass);
274+
ttRenderDS = tt->getRenderDescriptorSet();
278275

279276
auto ppHandler = core::make_smart_refctd_ptr<video::CPropertyPoolHandler>(core::smart_refctd_ptr(device));
280277

@@ -547,7 +544,7 @@ class TransformationApp : public ApplicationBase
547544
}
548545

549546
asset::SPushConstantRange range[1] = { asset::IShader::ESS_VERTEX,0u,sizeof(core::matrix4SIMD) };
550-
auto gfxLayout = core::make_smart_refctd_ptr<asset::ICPUPipelineLayout>(range,range+1u,scene::ITransformTreeWithNormalMatrices::createDescriptorSetLayout());
547+
auto gfxLayout = core::make_smart_refctd_ptr<asset::ICPUPipelineLayout>(range,range+1u,scene::ITransformTreeWithNormalMatrices::createRenderDescriptorSetLayout());
551548
pipeline->setLayout(core::smart_refctd_ptr(gfxLayout));
552549

553550
core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline> rpIndependentPipeline = CPU2GPU.getGPUObjectsFromAssets(&pipeline, &pipeline + 1, cpu2gpuParams)->front();
@@ -611,7 +608,15 @@ class TransformationApp : public ApplicationBase
611608
ttmDescriptorSets = ttm->createAllDescriptorSets(device.get());
612609
ttm->updateUpdateLocalTransformsDescriptorSet(device.get(),ttmDescriptorSets.updateLocal.get(),{0ull,modRangesBuf},{0ull,relTformModsBuf});
613610
ttm->updateRecomputeGlobalTransformsDescriptorSet(device.get(),ttmDescriptorSets.recomputeGlobal.get(),{0ull,nodeIdsBuf});
614-
//ttm->updateDebugDrawDescriptorSet(device.get(),ttmDescriptorSets.debugDraw.get(),{}); // TODO
611+
core::vector<CompressedAABB> aabbs;
612+
for (auto obj : solarSystemObjectsData)
613+
{
614+
auto aabb = cpuMeshPlanets->getBoundingBox();
615+
aabb.MinEdge *= obj.scale;
616+
aabb.MaxEdge *= obj.scale;
617+
aabbs.emplace_back() = aabb;
618+
}
619+
ttm->updateDebugDrawDescriptorSet(device.get(),ttmDescriptorSets.debugDraw.get(),{0ull,utils->createFilledDeviceLocalGPUBufferOnDedMem(device->getQueue(0,0),sizeof(core::CompressedAABB)*aabbs.size(),aabbs.data())});
615620
}
616621

617622
void onAppTerminated_impl() override
@@ -819,9 +824,17 @@ class TransformationApp : public ApplicationBase
819824

820825
cb->bindGraphicsPipeline(gpuObject.graphicsPipeline.get());
821826
cb->pushConstants(gpuObject.graphicsPipeline->getRenderpassIndependentPipeline()->getLayout(), asset::IShader::ESS_VERTEX, 0u, sizeof(core::matrix4SIMD), viewProj.pointer());
822-
cb->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuObject.graphicsPipeline->getRenderpassIndependentPipeline()->getLayout(), 0u, 1u, &ttDS);
827+
cb->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuObject.graphicsPipeline->getRenderpassIndependentPipeline()->getLayout(), 0u, 1u, &ttRenderDS);
823828
cb->drawMeshBuffer(gpuObject.gpuMesh.get());
824829
}
830+
{
831+
asset::SBufferBinding<video::IGPUBuffer> nodeAndAABBList = {sizeof(uint32_t),nodeIdsBuf};
832+
scene::ITransformTreeManager::DebugPushConstants pushConstants;
833+
pushConstants.viewProjectionMatrix = viewProj;
834+
pushConstants.lineColor = core::vectorSIMDf(1.f,0.f,0.f,1.f);
835+
pushConstants.aabbColor = core::vectorSIMDf(0.f,1.f,0.f,1.f);
836+
ttm->debugDraw(cb.get(),debugDrawPipeline.get(),tt.get(),ttmDescriptorSets.debugDraw.get(),nodeAndAABBList,nodeAndAABBList,pushConstants,ObjectCount);
837+
}
825838
}
826839
// TODO: debug draw
827840
cb->endRenderPass();
@@ -830,8 +843,8 @@ class TransformationApp : public ApplicationBase
830843
// acquires and presents
831844
uint32_t imgnum = 0u;
832845
swapchain->acquireNextImage(MAX_TIMEOUT, imageAcquire[resourceIx].get(), nullptr, &imgnum);
833-
CommonAPI::Submit(device.get(), swapchain.get(), cb.get(), queues[decltype(initOutput)::EQT_GRAPHICS], imageAcquire[resourceIx].get(), renderFinished[resourceIx].get(), fence.get());
834-
CommonAPI::Present(device.get(), swapchain.get(), queues[decltype(initOutput)::EQT_GRAPHICS], renderFinished[resourceIx].get(), imgnum);
846+
CommonAPI::Submit(device.get(), swapchain.get(), cb.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], imageAcquire[resourceIx].get(), renderFinished[resourceIx].get(), fence.get());
847+
CommonAPI::Present(device.get(), swapchain.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], renderFinished[resourceIx].get(), imgnum);
835848
}
836849

837850
bool keepRunning() override
@@ -865,8 +878,9 @@ class TransformationApp : public ApplicationBase
865878
core::smart_refctd_ptr<video::IGPUBuffer> modRangesBuf;
866879
core::smart_refctd_ptr<video::IGPUBuffer> relTformModsBuf;
867880
core::smart_refctd_ptr<video::IGPUBuffer> nodeIdsBuf;
868-
const video::IGPUDescriptorSet* ttDS;
881+
const video::IGPUDescriptorSet* ttRenderDS;
869882
scene::ITransformTreeManager::DescriptorSets ttmDescriptorSets;
883+
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> debugDrawPipeline;
870884

871885
core::smart_refctd_ptr<nbl::video::IGPUCommandBuffer> cmdbuf[FRAMES_IN_FLIGHT];
872886
core::smart_refctd_ptr<video::IGPUFence> frameComplete[FRAMES_IN_FLIGHT] = { nullptr };

examples_tests/common/Camera.hpp

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ class Camera {
4242
inline const nbl::core::matrix3x4SIMD & getViewMatrix() const { return viewMatrix; }
4343
inline const nbl::core::matrix4SIMD & getConcatenatedMatrix() const { return concatMatrix; }
4444

45-
inline void setProjectionMatrix(const nbl::core::matrix4SIMD& projection) {
45+
inline void setProjectionMatrix(const nbl::core::matrix4SIMD& projection)
46+
{
4647
projMatrix = projection;
4748
leftHanded = nbl::core::determinant(projMatrix) < 0.f;
4849
concatMatrix = nbl::core::matrix4SIMD::concatenateBFollowedByAPrecisely(projMatrix, nbl::core::matrix4SIMD(viewMatrix));
4950
}
5051

51-
inline void setPosition(const nbl::core::vectorSIMDf& pos) {
52+
inline void setPosition(const nbl::core::vectorSIMDf& pos)
53+
{
5254
position.set(pos);
5355
recomputeViewMatrix();
5456
}
@@ -238,59 +240,58 @@ class Camera {
238240
}
239241
}
240242

241-
void beginInputProcessing(std::chrono::microseconds _nextPresentationTimeStamp) {
243+
void beginInputProcessing(std::chrono::microseconds _nextPresentationTimeStamp)
244+
{
242245
nextPresentationTimeStamp = _nextPresentationTimeStamp;
243-
244-
if(firstUpdate) {
245-
lastVirtualUpTimeStamp = nextPresentationTimeStamp;
246-
// Set Cursor to middle of the screen
247-
firstUpdate = false;
248-
}
249-
250246
return;
251247
}
252248

253-
void endInputProcessing(std::chrono::microseconds _nextPresentationTimeStamp) {
249+
void endInputProcessing(std::chrono::microseconds _nextPresentationTimeStamp)
250+
{
254251
nbl::core::vectorSIMDf pos = getPosition();
255252
nbl::core::vectorSIMDf localTarget = getTarget() - pos;
256253

257-
nbl::core::vectorSIMDf movedir = localTarget;
258-
movedir.makeSafe3D();
259-
movedir = nbl::core::normalize(movedir);
254+
if (!firstUpdate)
255+
{
256+
nbl::core::vectorSIMDf movedir = localTarget;
257+
movedir.makeSafe3D();
258+
movedir = nbl::core::normalize(movedir);
260259

261-
constexpr float MoveSpeedScale = 0.02f;
260+
constexpr float MoveSpeedScale = 0.02f;
262261

263-
pos += movedir * perActionDt[Keys::EKA_MOVE_FORWARD] * moveSpeed * MoveSpeedScale;
262+
pos += movedir * perActionDt[Keys::EKA_MOVE_FORWARD] * moveSpeed * MoveSpeedScale;
264263

265-
pos -= movedir * perActionDt[Keys::EKA_MOVE_BACKWARD] * moveSpeed * MoveSpeedScale;
264+
pos -= movedir * perActionDt[Keys::EKA_MOVE_BACKWARD] * moveSpeed * MoveSpeedScale;
266265

267-
// strafing
266+
// strafing
268267

269-
// if upvector and vector to the target are the same, we have a
270-
// problem. so solve this problem:
271-
nbl::core::vectorSIMDf up = nbl::core::normalize(upVector);
272-
nbl::core::vectorSIMDf cross = nbl::core::cross(localTarget, up);
273-
bool upVectorNeedsChange = nbl::core::lengthsquared(cross)[0] == 0;
274-
if (upVectorNeedsChange)
275-
{
276-
up = nbl::core::normalize(backupUpVector);
277-
}
268+
// if upvector and vector to the target are the same, we have a
269+
// problem. so solve this problem:
270+
nbl::core::vectorSIMDf up = nbl::core::normalize(upVector);
271+
nbl::core::vectorSIMDf cross = nbl::core::cross(localTarget, up);
272+
bool upVectorNeedsChange = nbl::core::lengthsquared(cross)[0] == 0;
273+
if (upVectorNeedsChange)
274+
{
275+
up = nbl::core::normalize(backupUpVector);
276+
}
278277

279-
nbl::core::vectorSIMDf strafevect = localTarget;
280-
if (leftHanded)
281-
strafevect = nbl::core::cross(strafevect, up);
282-
else
283-
strafevect = nbl::core::cross(up, strafevect);
278+
nbl::core::vectorSIMDf strafevect = localTarget;
279+
if (leftHanded)
280+
strafevect = nbl::core::cross(strafevect, up);
281+
else
282+
strafevect = nbl::core::cross(up, strafevect);
284283

285-
strafevect = nbl::core::normalize(strafevect);
284+
strafevect = nbl::core::normalize(strafevect);
286285

287-
pos += strafevect * perActionDt[Keys::EKA_MOVE_LEFT] * moveSpeed * MoveSpeedScale;
286+
pos += strafevect * perActionDt[Keys::EKA_MOVE_LEFT] * moveSpeed * MoveSpeedScale;
288287

289-
pos -= strafevect * perActionDt[Keys::EKA_MOVE_RIGHT] * moveSpeed * MoveSpeedScale;
288+
pos -= strafevect * perActionDt[Keys::EKA_MOVE_RIGHT] * moveSpeed * MoveSpeedScale;
289+
}
290+
else
291+
firstUpdate = false;
290292

291293
setPosition(pos);
292-
293-
setTarget(localTarget + pos);
294+
setTarget(localTarget+pos);
294295

295296
lastVirtualUpTimeStamp = nextPresentationTimeStamp;
296297
}

0 commit comments

Comments
 (0)