Skip to content
Draft
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
7 changes: 5 additions & 2 deletions 31_HLSLPathTracer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
include(common RESULT_VARIABLE RES)

if(NOT RES)
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
endif()

if(NBL_BUILD_IMGUI)
set(NBL_INCLUDE_SERACH_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)

list(APPEND NBL_LIBRARIES
list(APPEND NBL_LIBRARIES
imtestengine
imguizmo
"${NBL_EXT_IMGUI_UI_LIB}"
)

Expand All @@ -24,6 +26,7 @@ if(NBL_BUILD_IMGUI)
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)

file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*")

foreach(RES_FILE ${BUILTIN_RESOURCE_FILES})
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}")
endforeach()
Expand Down
42 changes: 42 additions & 0 deletions 31_HLSLPathTracer/app_resources/hlsl/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ struct Shape<PST_SPHERE>
return create(position, radius * radius, bsdfLightIDs);
}

void updateTransform(NBL_CONST_REF_ARG(float32_t3x4) generalPurposeLightMatrix)
{
position = float32_t3(
generalPurposeLightMatrix[0][3],
generalPurposeLightMatrix[1][3],
generalPurposeLightMatrix[2][3]
);
radius2 = generalPurposeLightMatrix[0][0] * generalPurposeLightMatrix[0][0];
}

// return intersection distance if found, nan otherwise
float intersect(NBL_CONST_REF_ARG(float32_t3) origin, NBL_CONST_REF_ARG(float32_t3) direction)
{
Expand Down Expand Up @@ -257,6 +267,26 @@ struct Shape<PST_TRIANGLE>
return create(vertex0, vertex1, vertex2, bsdfLightIDs);
}

void updateTransform(NBL_CONST_REF_ARG(float32_t3x4) generalPurposeLightMatrix)
{
vertex0 = float32_t3(
generalPurposeLightMatrix[0][3],
generalPurposeLightMatrix[1][3],
generalPurposeLightMatrix[2][3]
);

float3 edge0 = generalPurposeLightMatrix[0].xyz;
float3 edge1 = generalPurposeLightMatrix[1].xyz;
// float3 edge2 = generalPurposeLightMatrix[2].xyz;

// Compute triangle vertices relative to v0
vertex1 = vertex0 + edge0;
vertex2 = vertex0 + edge1;

// If you want a fully general triangle using all three columns:
// vertex2 = vertex0 + edge2;
}

float intersect(NBL_CONST_REF_ARG(float32_t3) origin, NBL_CONST_REF_ARG(float32_t3) direction)
{
const float32_t3 edges[2] = { vertex1 - vertex0, vertex2 - vertex0 };
Expand Down Expand Up @@ -310,6 +340,18 @@ struct Shape<PST_RECTANGLE>
return create(offset, edge0, edge1, bsdfLightIDs);
}

void updateTransform(float3x4 generalPurposeLightMatrix)
{
offset = float3(
generalPurposeLightMatrix[0][3],
generalPurposeLightMatrix[1][3],
generalPurposeLightMatrix[2][3]
);
edge0 = generalPurposeLightMatrix[0].xyz;
edge1 = generalPurposeLightMatrix[1].xyz;
}


float intersect(NBL_CONST_REF_ARG(float32_t3) origin, NBL_CONST_REF_ARG(float32_t3) direction)
{
const float32_t3 h = hlsl::cross<float32_t3>(direction, edge1);
Expand Down
8 changes: 5 additions & 3 deletions 31_HLSLPathTracer/app_resources/hlsl/render.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ static const ext::Shape<ext::PST_SPHERE> spheres[SPHERE_COUNT] = {
ext::Shape<ext::PST_SPHERE>::create(float3(-2.0, 0.0, 1.0), 0.5, 5u, light_type::INVALID_ID),
ext::Shape<ext::PST_SPHERE>::create(float3(0.5, 1.0, 0.5), 0.5, 6u, light_type::INVALID_ID)
#ifdef SPHERE_LIGHT
,ext::Shape<ext::PST_SPHERE>::create(float3(-1.5, 1.5, 0.0), 0.3, bxdfnode_type::INVALID_ID, 0u)
,ext::Shape<ext::PST_SPHERE>::create(float3(-1.5, 1.5, 0.0), 0.3, bxdfnode_type::INVALID_ID, 0u) // dummy/old placement, set from push constant
#endif
};

#ifdef TRIANGLE_LIGHT
static const ext::Shape<ext::PST_TRIANGLE> triangles[TRIANGLE_COUNT] = {
ext::Shape<ext::PST_TRIANGLE>::create(float3(-1.8,0.35,0.3) * 10.0, float3(-1.2,0.35,0.0) * 10.0, float3(-1.5,0.8,-0.3) * 10.0, bxdfnode_type::INVALID_ID, 0u)
ext::Shape<ext::PST_TRIANGLE>::create(float3(-1.8,0.35,0.3) * 10.0, float3(-1.2,0.35,0.0) * 10.0, float3(-1.5,0.8,-0.3) * 10.0, bxdfnode_type::INVALID_ID, 0u) // dummy/old placement, set from push constant
};
#else
static const ext::Shape<ext::PST_TRIANGLE> triangles[1];
#endif

#ifdef RECTANGLE_LIGHT
static const ext::Shape<ext::PST_RECTANGLE> rectangles[RECTANGLE_COUNT] = {
ext::Shape<ext::PST_RECTANGLE>::create(float3(-3.8,0.35,1.3), normalize(float3(2,0,-1))*7.0, normalize(float3(2,-5,4))*0.1, bxdfnode_type::INVALID_ID, 0u)
ext::Shape<ext::PST_RECTANGLE>::create(float3(-3.8,0.35,1.3), normalize(float3(2,0,-1))*7.0, normalize(float3(2,-5,4))*0.1, bxdfnode_type::INVALID_ID, 0u) // dummy/old placement, set from push constant
};
#else
static const ext::Shape<ext::PST_RECTANGLE> rectangles[1];
Expand Down Expand Up @@ -248,6 +248,8 @@ void main(uint32_t3 threadID : SV_DispatchThreadID)
ptCreateParams.conductorParams = bxdfs[3].params;
ptCreateParams.dielectricParams = bxdfs[6].params;

scene.updateLight(pc.generalPurposeLightMatrix);

pathtracer_type pathtracer = pathtracer_type::create(ptCreateParams);

#ifdef RWMC_ENABLED
Expand Down
11 changes: 7 additions & 4 deletions 31_HLSLPathTracer/app_resources/hlsl/render_common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
struct RenderPushConstants
{
#ifdef __HLSL_VERSION
float32_t4x4 invMVP;
float32_t4x4 invMVP;
float32_t3x4 generalPurposeLightMatrix;
#else
nbl::core::matrix4SIMD invMVP;
nbl::core::matrix4SIMD invMVP;
nbl::core::matrix3x4SIMD generalPurposeLightMatrix;
#endif
int sampleCount;
int depth;

int sampleCount;
int depth;
};

NBL_CONSTEXPR nbl::hlsl::float32_t3 LightEminence = nbl::hlsl::float32_t3(30.0f, 25.0f, 15.0f);
Expand Down
3 changes: 3 additions & 0 deletions 31_HLSLPathTracer/app_resources/hlsl/render_rwmc_common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ struct RenderRWMCPushConstants
{
#ifdef __HLSL_VERSION
float32_t4x4 invMVP;
float32_t3x4 generalPurposeLightMatrix;
#else
nbl::core::matrix4SIMD invMVP;
nbl::core::matrix3x4SIMD generalPurposeLightMatrix;
#endif

int sampleCount;
int depth;
float start;
Expand Down
13 changes: 13 additions & 0 deletions 31_HLSLPathTracer/app_resources/hlsl/scene.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ struct Scene
return retval;
}

void updateLight(float32_t3x4 generalPurposeLightMatrix)
{
#ifdef SPHERE_LIGHT
spheres[SCENE_SPHERE_COUNT - 1].updateTransform(generalPurposeLightMatrix);
#endif
#ifdef TRIANGLE_LIGHT
triangles[SCENE_TRIANGLE_COUNT - 1].updateTransform(generalPurposeLightMatrix);
#endif
#ifdef RECTANGLE_LIGHT
rectangles[SCENE_RECTANGLE_COUNT - 1].updateTransform(generalPurposeLightMatrix);
#endif
}

#undef SCENE_SPHERE_COUNT
#undef SCENE_TRIANGLE_COUNT
#undef SCENE_RECTANGLE_COUNT
Expand Down
133 changes: 133 additions & 0 deletions 31_HLSLPathTracer/include/nbl/this_example/transform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#ifndef __NBL_THIS_EXAMPLE_TRANSFORM_H_INCLUDED__
#define __NBL_THIS_EXAMPLE_TRANSFORM_H_INCLUDED__

#include "nbl/ext/ImGui/ImGui.h"
#include <cstdint>
#include <imgui.h>
#include <nabla_imconfig.h>
#include <ImGuizmo.h>

static constexpr inline auto OfflineSceneTextureIx = 1u;

struct TransformRequestParams
{
bool useWindow = false, editTransformDecomposition = false, enableViewManipulate = false;
float camDistance = 8.f;
};

nbl::hlsl::uint16_t2 EditTransform(float* cameraView, const float* cameraProjection, float* matrix, const TransformRequestParams& params)
{
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::TRANSLATE);
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::LOCAL);
static bool useSnap = false;
static float snap[3] = { 1.f, 1.f, 1.f };
static float bounds[] = { -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f };
static float boundsSnap[] = { 0.1f, 0.1f, 0.1f };
static bool boundSizing = false;
static bool boundSizingSnap = false;

if (params.editTransformDecomposition)
{
if (ImGui::IsKeyPressed(ImGuiKey_T))
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
if (ImGui::IsKeyPressed(ImGuiKey_R))
mCurrentGizmoOperation = ImGuizmo::ROTATE;
if (ImGui::IsKeyPressed(ImGuiKey_S))
mCurrentGizmoOperation = ImGuizmo::SCALE;

#if 0
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
ImGui::SameLine();
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
mCurrentGizmoOperation = ImGuizmo::ROTATE;
ImGui::SameLine();
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
mCurrentGizmoOperation = ImGuizmo::SCALE;
if (ImGui::RadioButton("Universal", mCurrentGizmoOperation == ImGuizmo::UNIVERSAL))
mCurrentGizmoOperation = ImGuizmo::UNIVERSAL;
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
ImGuizmo::DecomposeMatrixToComponents(matrix, matrixTranslation, matrixRotation, matrixScale);
ImGui::InputFloat3("Tr", matrixTranslation);
ImGui::InputFloat3("Rt", matrixRotation);
ImGui::InputFloat3("Sc", matrixScale);
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix);

if (mCurrentGizmoOperation != ImGuizmo::SCALE)
{
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
mCurrentGizmoMode = ImGuizmo::LOCAL;
ImGui::SameLine();
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
mCurrentGizmoMode = ImGuizmo::WORLD;
}
if (ImGui::IsKeyPressed(ImGuiKey_S) && ImGui::IsKeyPressed(ImGuiKey_LeftShift))
useSnap = !useSnap;
ImGui::Checkbox("##UseSnap", &useSnap);
ImGui::SameLine();

switch (mCurrentGizmoOperation)
{
case ImGuizmo::TRANSLATE:
ImGui::InputFloat3("Snap", &snap[0]);
break;
case ImGuizmo::ROTATE:
ImGui::InputFloat("Angle Snap", &snap[0]);
break;
case ImGuizmo::SCALE:
ImGui::InputFloat("Scale Snap", &snap[0]);
break;
}
ImGui::Checkbox("Bound Sizing", &boundSizing);
if (boundSizing)
{
ImGui::PushID(3);
ImGui::Checkbox("##BoundSizing", &boundSizingSnap);
ImGui::SameLine();
ImGui::InputFloat3("Snap", boundsSnap);
ImGui::PopID();
}
#endif
}

ImGuiIO& io = ImGui::GetIO();
float viewManipulateRight = io.DisplaySize.x;
float viewManipulateTop = 0;
static ImGuiWindowFlags gizmoWindowFlags = 0;


// TODO: this shouldn't be handled here I think
SImResourceInfo info;
info.textureID = OfflineSceneTextureIx;
info.samplerIx = (uint16_t)nbl::ext::imgui::UI::DefaultSamplerIx::USER;

nbl::hlsl::uint16_t2 retval;

ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(io.DisplaySize);
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); // fully transparent fake window
ImGui::Begin("FullScreenWindow", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs);
ImGuizmo::SetDrawlist();
ImVec2 contentRegionSize = ImGui::GetContentRegionAvail();
ImVec2 cursorPos = ImGui::GetCursorScreenPos();

ImGui::Image(info, contentRegionSize);
ImGuizmo::SetRect(cursorPos.x, cursorPos.y, contentRegionSize.x, contentRegionSize.y);
retval = { contentRegionSize.x,contentRegionSize.y };

viewManipulateRight = cursorPos.x + contentRegionSize.x;
viewManipulateTop = cursorPos.y;

ImGuizmo::Manipulate(cameraView, cameraProjection, mCurrentGizmoOperation, mCurrentGizmoMode, matrix, NULL, useSnap ? &snap[0] : NULL, boundSizing ? bounds : NULL, boundSizingSnap ? boundsSnap : NULL);

if (params.enableViewManipulate)
ImGuizmo::ViewManipulate(cameraView, params.camDistance, ImVec2(viewManipulateRight - 128, viewManipulateTop), ImVec2(128, 128), 0x10101010);

ImGui::End();
ImGui::PopStyleColor();

return retval;
}


#endif // __NBL_THIS_EXAMPLE_TRANSFORM_H_INCLUDED__
Loading