Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 6 additions & 9 deletions 09_GeometryCreator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h

#include <nbl/builtin/hlsl/matrix_utils/transformation_matrix_utils.hlsl>
#include <nbl/builtin/hlsl/projection/projection.hlsl>

#include "common.hpp"

Expand Down Expand Up @@ -73,7 +75,7 @@ class GeometryCreatorApp final : public MonoWindowApplication, public BuiltinRes
{
core::vectorSIMDf cameraPosition(-5.81655884, 2.58630896, -4.23974705);
core::vectorSIMDf cameraTarget(-0.349590302, -0.213266611, 0.317821503);
matrix4SIMD projectionMatrix = matrix4SIMD::buildProjectionMatrixPerspectiveFovLH(core::radians(60.0f), float(m_initialResolution.x)/float(m_initialResolution.y), 0.1, 10000);
float32_t4x4 projectionMatrix = hlsl::buildProjectionMatrixPerspectiveFovLH<float>(core::radians(60.0f), float(m_initialResolution.x) / m_initialResolution.y, 0.1f, 10000.0f);
camera = Camera(cameraPosition, cameraTarget, projectionMatrix, 1.069f, 0.4f);
}

Expand Down Expand Up @@ -139,13 +141,8 @@ class GeometryCreatorApp final : public MonoWindowApplication, public BuiltinRes
cb->beginRenderPass(info, IGPUCommandBuffer::SUBPASS_CONTENTS::INLINE);
}

float32_t3x4 viewMatrix;
float32_t4x4 viewProjMatrix;
// TODO: get rid of legacy matrices
{
memcpy(&viewMatrix,camera.getViewMatrix().pointer(),sizeof(viewMatrix));
memcpy(&viewProjMatrix,camera.getConcatenatedMatrix().pointer(),sizeof(viewProjMatrix));
}
float32_t3x4 viewMatrix = camera.getViewMatrix();
float32_t4x4 viewProjMatrix = camera.getConcatenatedMatrix();
const auto viewParams = CSimpleDebugRenderer::SViewParams(viewMatrix,viewProjMatrix);

// tear down scene every frame
Expand Down Expand Up @@ -251,7 +248,7 @@ class GeometryCreatorApp final : public MonoWindowApplication, public BuiltinRes
InputSystem::ChannelReader<IKeyboardEventChannel> keyboard;

//
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), core::matrix4SIMD());
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), hlsl::float32_t4x4());

uint16_t gcIndex = {};

Expand Down
14 changes: 5 additions & 9 deletions 12_MeshLoaders/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "common.hpp"

#include "../3rdparty/portable-file-dialogs/portable-file-dialogs.h"
#include <nbl/builtin/hlsl/projection/projection.hlsl>

#ifdef NBL_BUILD_MITSUBA_LOADER
#include "nbl/ext/MitsubaLoader/CSerializedLoader.h"
Expand Down Expand Up @@ -161,13 +162,8 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
}
// draw scene
{
float32_t3x4 viewMatrix;
float32_t4x4 viewProjMatrix;
// TODO: get rid of legacy matrices
{
memcpy(&viewMatrix, camera.getViewMatrix().pointer(), sizeof(viewMatrix));
memcpy(&viewProjMatrix, camera.getConcatenatedMatrix().pointer(), sizeof(viewProjMatrix));
}
float32_t3x4 viewMatrix = camera.getViewMatrix();
float32_t4x4 viewProjMatrix = camera.getConcatenatedMatrix();
m_renderer->render(cb, CSimpleDebugRenderer::SViewParams(viewMatrix, viewProjMatrix));
}
cb->endRenderPass();
Expand Down Expand Up @@ -456,7 +452,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
{
const auto measure = hlsl::length(diagonal);
const auto aspectRatio = float(m_window->getWidth()) / float(m_window->getHeight());
camera.setProjectionMatrix(core::matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(1.2f, aspectRatio, distance * measure * 0.1, measure * 4.0));
camera.setProjectionMatrix(hlsl::buildProjectionMatrixPerspectiveFovRH<float>(1.2f, aspectRatio, distance * measure * 0.1, measure * 4.0));
camera.setMoveSpeed(measure * 0.04);
}
const auto pos = bound.maxVx + diagonal * distance;
Expand Down Expand Up @@ -492,7 +488,7 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
InputSystem::ChannelReader<IMouseEventChannel> mouse;
InputSystem::ChannelReader<IKeyboardEventChannel> keyboard;
//
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), core::matrix4SIMD());
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), hlsl::float32_t4x4());
// mutables
std::string m_modelPath;

Expand Down
49 changes: 22 additions & 27 deletions 61_UI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in nabla.h

#include "common.hpp"
#include <nbl/builtin/hlsl/projection/projection.hlsl>

/*
Renders scene texture to an offscreen framebuffer whose color attachment is then sampled into a imgui window.
Expand Down Expand Up @@ -252,14 +253,9 @@ class UISampleApp final : public MonoWindowApplication, public BuiltinResourcesA
}
// draw scene
{
float32_t3x4 viewMatrix;
float32_t4x4 viewProjMatrix;
// TODO: get rid of legacy matrices
{
const auto& camera = interface.camera;
memcpy(&viewMatrix,camera.getViewMatrix().pointer(),sizeof(viewMatrix));
memcpy(&viewProjMatrix,camera.getConcatenatedMatrix().pointer(),sizeof(viewProjMatrix));
}
const auto& camera = interface.camera;
float32_t3x4 viewMatrix = camera.getViewMatrix();
float32_t4x4 viewProjMatrix = camera.getConcatenatedMatrix();
const auto viewParams = CSimpleDebugRenderer::SViewParams(viewMatrix,viewProjMatrix);

// tear down scene every frame
Expand Down Expand Up @@ -570,21 +566,21 @@ class UISampleApp final : public MonoWindowApplication, public BuiltinResourcesA
// TODO: why is this a lambda and not just an assignment in a scope ?
camera.setProjectionMatrix([&]()
{
matrix4SIMD projection;
hlsl::float32_t4x4 projection;

if (isPerspective)
if(isLH)
projection = matrix4SIMD::buildProjectionMatrixPerspectiveFovLH(core::radians(fov), io.DisplaySize.x / io.DisplaySize.y, zNear, zFar);
projection = hlsl::buildProjectionMatrixPerspectiveFovLH<float>(core::radians(fov), io.DisplaySize.x / io.DisplaySize.y, zNear, zFar);
else
projection = matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(core::radians(fov), io.DisplaySize.x / io.DisplaySize.y, zNear, zFar);
projection = hlsl::buildProjectionMatrixPerspectiveFovRH<float>(core::radians(fov), io.DisplaySize.x / io.DisplaySize.y, zNear, zFar);
else
{
float viewHeight = viewWidth * io.DisplaySize.y / io.DisplaySize.x;

if(isLH)
projection = matrix4SIMD::buildProjectionMatrixOrthoLH(viewWidth, viewHeight, zNear, zFar);
projection = hlsl::buildProjectionMatrixOrthoLH<float>(viewWidth, viewHeight, zNear, zFar);
else
projection = matrix4SIMD::buildProjectionMatrixOrthoRH(viewWidth, viewHeight, zNear, zFar);
projection = hlsl::buildProjectionMatrixOrthoRH<float>(viewWidth, viewHeight, zNear, zFar);
}

return projection;
Expand Down Expand Up @@ -720,33 +716,32 @@ class UISampleApp final : public MonoWindowApplication, public BuiltinResourcesA
* note it also modifies input view matrix but projection matrix is immutable
*/

// TODO: do all computation using `hlsl::matrix` and its `hlsl::float32_tNxM` aliases
static struct
{
core::matrix4SIMD view, projection, model;
hlsl::float32_t4x4 view, projection, model;
} imguizmoM16InOut;

ImGuizmo::SetID(0u);

imguizmoM16InOut.view = core::transpose(matrix4SIMD(camera.getViewMatrix()));
imguizmoM16InOut.projection = core::transpose(camera.getProjectionMatrix());
imguizmoM16InOut.model = core::transpose(matrix4SIMD(model));
imguizmoM16InOut.view = hlsl::transpose(hlsl::getMatrix3x4As4x4(camera.getViewMatrix()));
imguizmoM16InOut.projection = hlsl::transpose(camera.getProjectionMatrix());
imguizmoM16InOut.model = hlsl::transpose(hlsl::getMatrix3x4As4x4(model));
{
if (flipGizmoY) // note we allow to flip gizmo just to match our coordinates
imguizmoM16InOut.projection[1][1] *= -1.f; // https://johannesugb.github.io/gpu-programming/why-do-opengl-proj-matrices-fail-in-vulkan/

transformParams.editTransformDecomposition = true;
sceneResolution = EditTransform(imguizmoM16InOut.view.pointer(), imguizmoM16InOut.projection.pointer(), imguizmoM16InOut.model.pointer(), transformParams);
transformParams.editTransformDecomposition = true;
sceneResolution = EditTransform(&imguizmoM16InOut.view[0][0], &imguizmoM16InOut.projection[0][0], &imguizmoM16InOut.model[0][0], transformParams);
}

model = core::transpose(imguizmoM16InOut.model).extractSub3x4();
model = hlsl::extractSub3x4From4x4Matrix(hlsl::transpose(imguizmoM16InOut.model));
// to Nabla + update camera & model matrices
// TODO: make it more nicely, extract:
// - Position by computing inverse of the view matrix and grabbing its translation
// - Target from 3rd row without W component of view matrix multiplied by some arbitrary distance value (can be the length of position from origin) and adding the position
// But then set the view matrix this way anyway, because up-vector may not be compatible
const auto& view = camera.getViewMatrix();
const_cast<core::matrix3x4SIMD&>(view) = core::transpose(imguizmoM16InOut.view).extractSub3x4(); // a hack, correct way would be to use inverse matrix and get position + target because now it will bring you back to last position & target when switching from gizmo move to manual move (but from manual to gizmo is ok)
const_cast<hlsl::float32_t3x4&>(view) = hlsl::extractSub3x4From4x4Matrix(hlsl::transpose(imguizmoM16InOut.view)); // a hack, correct way would be to use inverse matrix and get position + target because now it will bring you back to last position & target when switching from gizmo move to manual move (but from manual to gizmo is ok)
// update concatanated matrix
const auto& projection = camera.getProjectionMatrix();
camera.setProjectionMatrix(projection);
Expand Down Expand Up @@ -783,9 +778,9 @@ class UISampleApp final : public MonoWindowApplication, public BuiltinResourcesA
ImGui::Separator();
};

addMatrixTable("Model Matrix", "ModelMatrixTable", 3, 4, model.pointer());
addMatrixTable("Camera View Matrix", "ViewMatrixTable", 3, 4, view.pointer());
addMatrixTable("Camera View Projection Matrix", "ViewProjectionMatrixTable", 4, 4, projection.pointer(), false);
addMatrixTable("Model Matrix", "ModelMatrixTable", 3, 4, &model[0][0]);
addMatrixTable("Camera View Matrix", "ViewMatrixTable", 3, 4, &view[0][0]);
addMatrixTable("Camera View Projection Matrix", "ViewProjectionMatrixTable", 4, 4, &projection[0][0], false);

ImGui::End();
}
Expand Down Expand Up @@ -867,9 +862,9 @@ class UISampleApp final : public MonoWindowApplication, public BuiltinResourcesA
smart_refctd_ptr<SubAllocatedDescriptorSet> subAllocDS;
SubAllocatedDescriptorSet::value_type renderColorViewDescIndex = SubAllocatedDescriptorSet::invalid_value;
//
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), core::matrix4SIMD());
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), hlsl::float32_t4x4());
// mutables
core::matrix3x4SIMD model;
hlsl::float32_t3x4 model = identity<hlsl::float32_t3x4>();
std::string_view objectName;
TransformRequestParams transformParams;
uint16_t2 sceneResolution = {1280,720};
Expand Down
23 changes: 11 additions & 12 deletions 70_FLIPFluids/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "nbl/examples/examples.hpp"
// TODO: why is it not in nabla.h ?
#include "nbl/asset/metadata/CHLSLMetadata.h"
#include "nbl/builtin/hlsl/projection/projection.hlsl"

using namespace nbl;
using namespace nbl::core;
Expand Down Expand Up @@ -231,7 +232,7 @@ class FLIPFluidsApp final : public SimpleWindowedApplication, public BuiltinReso
float zNear = 0.1f, zFar = 10000.f;
core::vectorSIMDf cameraPosition(14, 8, 12);
core::vectorSIMDf cameraTarget(0, 0, 0);
matrix4SIMD projectionMatrix = matrix4SIMD::buildProjectionMatrixPerspectiveFovLH(core::radians(60.0f), float(WIN_WIDTH) / WIN_HEIGHT, zNear, zFar);
hlsl::float32_t4x4 projectionMatrix = hlsl::buildProjectionMatrixPerspectiveFovLH(core::radians(60.0f), float(WIN_WIDTH) / WIN_HEIGHT, zNear, zFar);
camera = Camera(cameraPosition, cameraTarget, projectionMatrix, 1.069f, 0.4f);

m_pRenderParams.zNear = zNear;
Expand Down Expand Up @@ -884,22 +885,20 @@ class FLIPFluidsApp final : public SimpleWindowedApplication, public BuiltinReso
const auto projectionMatrix = camera.getProjectionMatrix();
const auto viewProjectionMatrix = camera.getConcatenatedMatrix();

core::matrix3x4SIMD modelMatrix;
modelMatrix.setTranslation(nbl::core::vectorSIMDf(0, 0, 0, 0));
modelMatrix.setRotation(quaternion(0, 0, 0));
hlsl::float32_t3x4 modelMatrix = hlsl::identity<float32_t3x4>();

core::matrix3x4SIMD modelViewMatrix = core::concatenateBFollowedByA(viewMatrix, modelMatrix);
core::matrix4SIMD modelViewProjectionMatrix = core::concatenateBFollowedByA(viewProjectionMatrix, modelMatrix);
hlsl::float32_t3x4 modelViewMatrix = viewMatrix;
hlsl::float32_t4x4 modelViewProjectionMatrix = viewProjectionMatrix;

auto modelMat = core::concatenateBFollowedByA(core::matrix4SIMD(), modelMatrix);
auto modelMat = hlsl::getMatrix3x4As4x4(modelMatrix);

const core::vector3df camPos = camera.getPosition().getAsVector3df();

camPos.getAs4Values(camData.cameraPosition);
memcpy(camData.MVP, modelViewProjectionMatrix.pointer(), sizeof(camData.MVP));
memcpy(camData.M, modelMat.pointer(), sizeof(camData.M));
memcpy(camData.V, viewMatrix.pointer(), sizeof(camData.V));
memcpy(camData.P, projectionMatrix.pointer(), sizeof(camData.P));
memcpy(camData.MVP, &modelViewProjectionMatrix[0][0], sizeof(camData.MVP));
memcpy(camData.M, &modelMat[0][0], sizeof(camData.M));
memcpy(camData.V, &viewMatrix[0][0], sizeof(camData.V));
memcpy(camData.P, &projectionMatrix[0][0], sizeof(camData.P));
{
camDataRange.buffer = cameraBuffer;
camDataRange.size = cameraBuffer->getSize();
Expand Down Expand Up @@ -1817,7 +1816,7 @@ class FLIPFluidsApp final : public SimpleWindowedApplication, public BuiltinReso
InputSystem::ChannelReader<IMouseEventChannel> mouse;
InputSystem::ChannelReader<IKeyboardEventChannel> keyboard;

Camera camera = Camera(core::vectorSIMDf(0,0,0), core::vectorSIMDf(0,0,0), core::matrix4SIMD());
Camera camera = Camera(core::vectorSIMDf(0,0,0), core::vectorSIMDf(0,0,0), hlsl::float32_t4x4());
video::CDumbPresentationOracle oracle;

bool m_shouldInitParticles = true;
Expand Down
Loading