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
82 changes: 82 additions & 0 deletions 75_CAD_3D/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
include(common RESULT_VARIABLE RES)
if(NOT RES)
message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory")
endif()

set(EXAMPLE_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/DrawResourcesFiller.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/DrawResourcesFiller.h"
"${CMAKE_CURRENT_SOURCE_DIR}/CTriangleMesh.h"
)
set(EXAMPLE_INCLUDES
"${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/boost/superproject/libs/math/include")
nbl_create_executable_project("${EXAMPLE_SOURCES}" "" "${EXAMPLE_INCLUDES}" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")
target_link_libraries(${EXECUTABLE_NAME} PRIVATE Nabla::ext::FullScreenTriangle)

# if enabled then try use Nabla "Text Rendering" extension
# with an implemented interface using the 3rdparty deps

set(NBL_CAD_EX_USE_TEXT_RENDERING_EXT OFF) # do not enable, for future usage when the extension is written

if(NBL_BUILD_TEXT_RENDERING AND NBL_CAD_EX_USE_TEXT_RENDERING_EXT)
add_dependencies(${EXECUTABLE_NAME} ${NBL_EXT_TEXT_RENDERING_TARGET})
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_EXT_TEXT_RENDERING_TARGET})
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_EXT_TEXT_RENDERING_TARGET},INCLUDE_DIRECTORIES>)
else()
# Freetype
add_dependencies(${EXECUTABLE_NAME} freetype)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE freetype)
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:freetype,INCLUDE_DIRECTORIES>)

# msdfgen
add_dependencies(${EXECUTABLE_NAME} ${NBL_MSDFGEN_TARGETS})
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_MSDFGEN_TARGETS})
foreach(NBL_TARGET IN LISTS NBL_MSDFGEN_TARGETS)
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_TARGET},INCLUDE_DIRECTORIES>)
endforeach()
endif()

set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen")

set(SM 6_8)

set(JSON [=[
[
{
"INPUT": "shaders/main_pipeline/vertex_shader.hlsl",
"KEY": "main_pipeline_vertex_shader",
"CAPS": []
},
{
"INPUT": "shaders/main_pipeline/fragment_shader.hlsl",
"KEY": "main_pipeline_fragment_shader",
"CAPS": []
}
]
]=])
string(CONFIGURE "${JSON}" JSON)

set(COMPILE_OPTIONS
-I "${CMAKE_CURRENT_SOURCE_DIR}"
-T lib_${SM}
)

NBL_CREATE_NSC_COMPILE_RULES(
TARGET ${EXECUTABLE_NAME}SPIRV
LINK_TO ${EXECUTABLE_NAME}
BINARY_DIR ${OUTPUT_DIRECTORY}
MOUNT_POINT_DEFINE NBL_THIS_EXAMPLE_BUILD_MOUNT_POINT
COMMON_OPTIONS ${COMPILE_OPTIONS}
OUTPUT_VAR KEYS
INCLUDE nbl/this_example/builtin/build/spirv/keys.hpp
NAMESPACE nbl::this_example::builtin::build
INPUTS ${JSON}
)

NBL_CREATE_RESOURCE_ARCHIVE(
NAMESPACE nbl::this_example::builtin::build
TARGET ${EXECUTABLE_NAME}_builtinsBuild
LINK_TO ${EXECUTABLE_NAME}
BIND ${OUTPUT_DIRECTORY}
BUILTINS ${KEYS}
)
119 changes: 119 additions & 0 deletions 75_CAD_3D/CTriangleMesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#pragma once

#include <nabla.h>
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include "shaders/globals.hlsl"

using namespace nbl;

struct DTMHeightShadingSettingsInfo
{
// Height Shading Mode
E_HEIGHT_SHADING_MODE heightShadingMode;

// Used as fixed interval length for "DISCRETE_FIXED_LENGTH_INTERVALS" shading mode
float intervalLength;

// Converts an interval index to its corresponding height value
// For example, if this value is 10.0, then an interval index of 2 corresponds to a height of 20.0.
// This computed height is later used to determine the interpolated color for shading.
// It makes sense for this variable to be always equal to `intervalLength` but sometimes it's a different scaling so that last index corresponds to largestHeight
float intervalIndexToHeightMultiplier;

// Used for "DISCRETE_FIXED_LENGTH_INTERVALS" shading mode
// If `isCenteredShading` is true, the intervals are centered around `minHeight`, meaning the
// first interval spans [minHeight - intervalLength / 2.0, minHeight + intervalLength / 2.0].
// Otherwise, intervals are aligned from `minHeight` upward, so the first interval spans
// [minHeight, minHeight + intervalLength].
bool isCenteredShading;

void addHeightColorMapEntry(float height, float32_t4 color)
{
heightColorSet.emplace(height, color);
}

bool fillShaderDTMSettingsHeightColorMap(DTMSettings& dtmSettings) const
{
const uint32_t mapSize = heightColorSet.size();
if (mapSize > DTMHeightShadingSettings::HeightColorMapMaxEntries)
return false;
dtmSettings.heightShadingSettings.heightColorEntryCount = mapSize;

int index = 0;
for (auto it = heightColorSet.begin(); it != heightColorSet.end(); ++it)
{
dtmSettings.heightShadingSettings.heightColorMapHeights[index] = it->height;
dtmSettings.heightShadingSettings.heightColorMapColors[index] = it->color;
++index;
}

return true;
}

private:
struct HeightColor
{
float height;
float32_t4 color;

bool operator<(const HeightColor& other) const
{
return height < other.height;
}
};

std::set<HeightColor> heightColorSet;
};

struct DTMSettingsInfo
{
DTMHeightShadingSettingsInfo heightShadingInfo;
};

class CTriangleMesh final
{
public:
using index_t = uint32_t;
using vertex_t = TriangleMeshVertex;

inline void setVertices(core::vector<vertex_t>&& vertices)
{
m_vertices = std::move(vertices);
}
inline void setIndices(core::vector<uint32_t>&& indices)
{
m_indices = std::move(indices);
}

inline const core::vector<vertex_t>& getVertices() const
{
return m_vertices;
}
inline const core::vector<uint32_t>& getIndices() const
{
return m_indices;
}

inline size_t getVertexBuffByteSize() const
{
return sizeof(vertex_t) * m_vertices.size();
}
inline size_t getIndexBuffByteSize() const
{
return sizeof(index_t) * m_indices.size();
}
inline size_t getIndexCount() const
{
return m_indices.size();
}

inline void clear()
{
m_vertices.clear();
m_indices.clear();
}

private:
core::vector<vertex_t> m_vertices;
core::vector<index_t> m_indices;
};
Loading