├── .clang-format ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE.txt ├── PACKAGE-LICENSES ├── MikkTSpace-LICENSE.md ├── OpenEXR-LICENSE.md ├── Turbo_Colormap_Polynomial_Approximation_in_GLSL-LICENSE.md ├── dlib-LICENSE.md ├── libpng-LICENSE.md ├── miniz-LICENSE.md ├── pcg-c-basic-LICENSE.md └── tinyexr-LICENSE.md ├── README.md ├── SECURITY.md ├── automation └── link_heightmaps.py ├── common ├── debug_util.h └── vulkan_nv │ ├── vk_nv_micromesh.h │ ├── vk_nv_micromesh_prototypes.c │ └── vk_nv_micromesh_prototypes.h ├── docs ├── Displacement.png ├── asset_pipeline.md ├── bake_high_low.png ├── bake_high_low_result.jpg ├── data_structures.md ├── displacement_bounds.svg ├── examples.md ├── failure_anisotropy.jpg ├── failure_bounds.jpg ├── failure_bounds2.jpg ├── failure_bounds3.jpg ├── failure_cracks.jpg ├── failure_cracks2.png ├── failure_overlap.jpg ├── failure_overlap2.jpg ├── failure_quantization.jpg ├── failure_spike.jpg ├── micromesh_reefcrab.png ├── resample_before_after.jpg ├── trace_miss.svg ├── trace_overhang.svg ├── trace_spike.svg ├── visualize_anisotropy.jpg ├── visualize_directions.jpg ├── visualize_heightmaptexfreq.jpg ├── visualize_sharedpos.jpg ├── visualize_shell.jpg └── visualize_subdivlevel.jpg ├── external └── tinyexr │ ├── CMakeLists.txt │ ├── miniz.c │ ├── miniz.h │ └── tinyexr.h ├── meshops_bake ├── CMakeLists.txt ├── README.md ├── meshops_bake.cpp ├── meshops_bake_batch.cpp ├── meshops_bake_batch.hpp ├── meshops_bake_vk.cpp ├── meshops_bake_vk.hpp └── shaders │ ├── bary_trace.comp │ ├── host_device.h │ ├── resample.frag │ ├── resample.vert │ ├── trace_utils.glsl │ └── vertex_types.h ├── meshops_core ├── CMakeLists.txt ├── README.md ├── include │ ├── imageio │ │ └── imageio.hpp │ ├── meshops │ │ ├── bias_scale.hpp │ │ ├── meshops_api.h │ │ ├── meshops_array_view.h │ │ ├── meshops_array_view.natvis │ │ ├── meshops_mesh_data.h │ │ ├── meshops_mesh_view.h │ │ ├── meshops_operations.h │ │ ├── meshops_types.h │ │ └── meshops_vk.h │ ├── meshops_internal │ │ ├── heightmap.hpp │ │ ├── mesh_view.hpp │ │ ├── meshops_context.h │ │ ├── meshops_device_mesh.h │ │ ├── meshops_texture.h │ │ ├── meshops_vertexattribs.h │ │ ├── octant_encoding.h │ │ ├── pn_triangles.hpp │ │ └── umesh_util.hpp │ ├── microutils │ │ ├── microutils.hpp │ │ └── microutils_compression.hpp │ └── mikktspace │ │ └── mikktspace.h └── src │ ├── heightmap.cpp │ ├── imageio.cpp │ ├── meshops_compression.cpp │ ├── meshops_context.cpp │ ├── meshops_device_mesh.cpp │ ├── meshops_operations.cpp │ ├── meshops_tangents_lengyel.cpp │ ├── meshops_tangents_lengyel.hpp │ ├── meshops_tangents_liani.cpp │ ├── meshops_tangents_liani.hpp │ ├── meshops_tessellation.cpp │ ├── meshops_texture.cpp │ ├── meshops_types.cpp │ ├── meshops_vertexattribs.cpp │ ├── microutils.cpp │ ├── microutils_compression.cpp │ ├── mikktspace.c │ └── umesh_util.cpp ├── meshops_remesher ├── CMakeLists.txt ├── README.md ├── docs │ ├── curvature_power_10.png │ ├── curvature_power_5.png │ ├── curvature_power_50.png │ ├── dragon_head_1k_1k.png │ ├── dragon_head_500k_355k.png │ ├── dragon_head_50k_40k.png │ ├── dragon_head_5k_4k.png │ ├── dragon_head_original.png │ ├── importance_map.png │ ├── importance_map_decimated.png │ ├── importance_map_preview.png │ ├── importance_weight_10.png │ ├── importance_weight_20.png │ ├── importance_weight_5.png │ ├── max_importance_off.png │ ├── max_importance_on.png │ ├── max_importance_original.png │ ├── micromesh_bounds.png │ ├── micromesh_decimated_wireframe.png │ ├── micromesh_original.png │ ├── micromesh_original_wireframe.png │ ├── micromesh_subd_level.png │ ├── remesher_intro_decimated.png │ ├── remesher_intro_full.png │ ├── seams_decimated.png │ ├── seams_decimated_wireframe.png │ ├── seams_original.png │ ├── seams_original_wireframe.png │ ├── seams_texture.jpg │ ├── trace_distance_10.png │ ├── trace_distance_20.png │ ├── trace_distance_5.png │ ├── valence_11.png │ ├── valence_original.png │ └── valence_unlimited.png ├── generate_importance_operator.cpp ├── generate_importance_operator.hpp ├── meshops_generate_importance.cpp ├── meshops_remesher.cpp ├── meshops_remesher_internal.hpp ├── remeshing_operator.cpp ├── remeshing_operator.hpp └── shaders │ ├── generate_importance.comp │ ├── generate_importance_host_device.h │ ├── hash_functions.h │ ├── octant_encoding.h │ ├── remeshing_host_device.h │ ├── vertex_copy.comp │ └── vertex_merge.comp ├── micromesh_python ├── CMakeLists.txt ├── README.md ├── all-deps.packman.xml ├── install_jupyterlab.cmd.in ├── notebook │ ├── crab.jpg │ ├── microdisplacement.png │ ├── micromesh.ipynb │ └── utils │ │ ├── __init__.py │ │ ├── assets.py │ │ └── mesh.py ├── package.py.in ├── py_conversions.hpp ├── py_enums.hpp ├── py_micromesh.cpp ├── py_operations.hpp ├── py_types.hpp ├── python.cmd.in ├── schema │ ├── api.h │ ├── displacementMicromapAPI.cpp │ ├── displacementMicromapAPI.h │ ├── generatedSchema.usda │ ├── module.cpp │ ├── nvMicromesh │ │ ├── __init__.py │ │ └── resources │ │ │ ├── plugInfo_linux-x86_64.json │ │ │ └── plugInfo_windows-x86_64.json │ ├── plugInfo.json │ ├── schema.usda │ ├── tokens.cpp │ ├── tokens.h │ ├── wrapDisplacementMicromapAPI.cpp │ └── wrapTokens.cpp ├── start_jupyterlab.cmd.in └── test.py ├── micromesh_tool ├── CMakeLists.txt ├── README.md ├── include │ ├── tool_bake.hpp │ ├── tool_bary.hpp │ ├── tool_context.hpp │ ├── tool_displacedtessellate.hpp │ ├── tool_generate.hpp │ ├── tool_image.hpp │ ├── tool_merge.hpp │ ├── tool_merge_args.hpp │ ├── tool_mesh.cpp │ ├── tool_mesh.hpp │ ├── tool_optimize.hpp │ ├── tool_pretessellate.hpp │ ├── tool_remesh.hpp │ └── tool_scene.hpp ├── shaders │ └── pullpush.comp └── src │ ├── baker_manager.cpp │ ├── baker_manager.hpp │ ├── dlib_url.h │ ├── gltf.cpp │ ├── gltf.hpp │ ├── gltf │ ├── NV_micromesh_extension_types.hpp │ ├── micromesh_util.cpp │ └── micromesh_util.hpp │ ├── inputparser.hpp │ ├── main.cpp │ ├── mesh_view_conv.cpp │ ├── mesh_view_conv.hpp │ ├── pullpush_filter.cpp │ ├── pullpush_filter.hpp │ ├── tinygltf_impl.cpp │ ├── tool_bake.cpp │ ├── tool_bake_args.cpp │ ├── tool_bary.cpp │ ├── tool_context.cpp │ ├── tool_displacedtessellate.cpp │ ├── tool_generate.cpp │ ├── tool_image.cpp │ ├── tool_merge.cpp │ ├── tool_merge_args.cpp │ ├── tool_meshops_objects.hpp │ ├── tool_optimize.cpp │ ├── tool_pretessellate.cpp │ ├── tool_remesh.cpp │ ├── tool_scene.cpp │ └── tool_version.h.in ├── micromesh_toolbox ├── .gitignore ├── CMakeLists.txt ├── README.md ├── cmake │ └── FindNsightAftermath.cmake ├── resources │ ├── micromesh_ico_256.h │ ├── micromesh_ico_256.png │ ├── micromesh_ico_32.h │ ├── micromesh_ico_32.png │ ├── micromesh_ico_64.h │ └── micromesh_ico_64.png ├── shaders │ ├── colormap.glsl │ ├── common.h │ ├── common_barymap.h │ ├── common_micromesh.h │ ├── common_micromesh_compressed.h │ ├── config.h │ ├── device_host.h │ ├── dh_bindings.h │ ├── dh_scn_desc.h │ ├── draw_compressed_basic.frag.glsl │ ├── draw_compressed_basic.mesh.glsl │ ├── draw_compressed_basic.task.glsl │ ├── draw_heightmap.frag.glsl │ ├── draw_heightmap.mesh.glsl │ ├── draw_heightmap.task.glsl │ ├── get_hit.glsl │ ├── hbao.h │ ├── hbao_blur.comp │ ├── hbao_blur.glsl │ ├── hbao_blur_apply.comp │ ├── hbao_calc.comp │ ├── hbao_deinterleave.comp │ ├── hbao_depthlinearize.comp │ ├── hbao_reinterleave.comp │ ├── hbao_viewnormal.comp │ ├── hit_state.h │ ├── lighting.glsl │ ├── mat_eval.glsl │ ├── micromesh_decoder.glsl │ ├── micromesh_decoder_api.glsl │ ├── micromesh_decoder_config.glsl │ ├── micromesh_decoder_subtri.glsl │ ├── micromesh_loader.glsl │ ├── micromesh_utils.glsl │ ├── octant_encoding.h │ ├── pathtrace.rahit │ ├── pathtrace.rchit │ ├── pathtrace.rgen │ ├── pathtrace.rmiss │ ├── payload.glsl │ ├── pbr_eval.glsl │ ├── pbr_mat_struct.h │ ├── raster.frag │ ├── raster.vert │ ├── raster_anisotropy.glsl │ ├── raster_common.glsl │ ├── raster_overlay.frag │ ├── raster_shell.frag │ ├── raster_shell.vert │ ├── raster_simple_phong.glsl │ ├── raster_vectors.frag │ ├── raster_vectors.vert │ └── utility.h ├── src │ ├── aftermath │ │ ├── nsight_aftermath_gpu_crash_tracker.cpp │ │ ├── nsight_aftermath_gpu_crash_tracker.h │ │ └── nsight_aftermath_helpers.h │ ├── elements │ │ ├── element_nvml.hpp │ │ ├── element_testing.hpp │ │ └── nvml_monitor.hpp │ ├── hbao │ │ ├── hbao_pass.cpp │ │ └── hbao_pass.hpp │ ├── main.cpp │ ├── micromap │ │ ├── device_micromap.cpp │ │ ├── device_micromap.hpp │ │ ├── microdisp_shim.hpp │ │ ├── micromesh_compressed_vk.cpp │ │ ├── micromesh_compressed_vk.hpp │ │ ├── micromesh_decoder_subtri_vk.cpp │ │ ├── micromesh_decoder_subtri_vk.hpp │ │ ├── micromesh_decoder_utils_vk.cpp │ │ └── micromesh_decoder_utils_vk.hpp │ ├── settings.hpp │ ├── tinygltf_impl.cpp │ ├── toolbox_scene.cpp │ ├── toolbox_scene.hpp │ ├── toolbox_scene_rtx.cpp │ ├── toolbox_scene_rtx.hpp │ ├── toolbox_scene_vk.cpp │ ├── toolbox_scene_vk.hpp │ ├── toolbox_version.h.in │ ├── toolbox_viewer.cpp │ ├── toolbox_viewer.hpp │ ├── ui │ │ ├── ui_about.cpp │ │ ├── ui_about.hpp │ │ ├── ui_axis.cpp │ │ ├── ui_axis.hpp │ │ ├── ui_baker.cpp │ │ ├── ui_busy_window.hpp │ │ ├── ui_color_picker.hpp │ │ ├── ui_displace_tessellate.cpp │ │ ├── ui_environment.cpp │ │ ├── ui_environment.hpp │ │ ├── ui_micromesh_process.cpp │ │ ├── ui_micromesh_process.hpp │ │ ├── ui_micromesh_tools.hpp │ │ ├── ui_optimizer.cpp │ │ ├── ui_pretess.cpp │ │ ├── ui_raster.cpp │ │ ├── ui_raster.hpp │ │ ├── ui_raytracing.hpp │ │ ├── ui_remesher.cpp │ │ ├── ui_rendering.cpp │ │ ├── ui_rendering.hpp │ │ ├── ui_statistics.cpp │ │ ├── ui_statistics.hpp │ │ ├── ui_utilities.cpp │ │ ├── ui_utilities.hpp │ │ ├── ui_widgets.cpp │ │ └── ui_widgets.hpp │ ├── vulkan_mutex.cpp │ └── vulkan_mutex.h └── thirdparty │ └── aftermath_sdk │ ├── .gitignore │ └── _readme.txt └── mini_samples ├── CMakeLists.txt └── dmm_displacement ├── CMakeLists.txt ├── README.md ├── docs ├── DisplacementPrismoidInputs.jpg ├── EdgeDecimation.jpg ├── SubdivisionSchemeExamples.jpg ├── micromesh.png └── micromesh_th.jpg ├── shaders ├── device_host.h ├── dh_bindings.h ├── pathtrace.rchit ├── pathtrace.rgen ├── pathtrace.rmiss └── payload.h └── src ├── dmm_process.cpp ├── dmm_process.hpp ├── dmm_raytrace.cpp ├── nesting_scoped_timer.cpp └── nesting_scoped_timer.hpp /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | AccessModifierOffset: '-2' 3 | AlignAfterOpenBracket: Align 4 | AlignConsecutiveAssignments: 'true' 5 | AlignConsecutiveDeclarations: 'true' 6 | AlignOperands: 'true' 7 | AlignTrailingComments: 'true' 8 | AllowAllParametersOfDeclarationOnNextLine: 'false' 9 | AllowShortBlocksOnASingleLine: 'false' 10 | AllowShortCaseLabelsOnASingleLine: 'false' 11 | AllowShortFunctionsOnASingleLine: Inline 12 | AllowShortIfStatementsOnASingleLine: 'false' 13 | AllowShortLoopsOnASingleLine: 'false' 14 | AlwaysBreakAfterReturnType: None 15 | AlwaysBreakBeforeMultilineStrings: 'true' 16 | AlwaysBreakTemplateDeclarations: 'true' 17 | BinPackArguments: 'true' 18 | BinPackParameters: 'false' 19 | ExperimentalAutoDetectBinPacking: 'false' 20 | BreakBeforeBinaryOperators: NonAssignment 21 | BreakBeforeBraces: Custom 22 | BreakBeforeTernaryOperators: 'false' 23 | BreakConstructorInitializersBeforeComma: 'true' 24 | ColumnLimit: '120' 25 | ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' 26 | Cpp11BracedListStyle: 'true' 27 | IndentCaseLabels: 'true' 28 | IndentWidth: '2' 29 | KeepEmptyLinesAtTheStartOfBlocks: 'true' 30 | Language: Cpp 31 | MaxEmptyLinesToKeep: '2' 32 | NamespaceIndentation: None 33 | ObjCSpaceBeforeProtocolList: 'true' 34 | PointerAlignment: Left 35 | SpaceAfterCStyleCast: 'false' 36 | SpaceBeforeAssignmentOperators: 'true' 37 | SpaceBeforeParens: Never 38 | SpaceInEmptyParentheses: 'false' 39 | SpacesBeforeTrailingComments: '2' 40 | SpacesInAngles: 'false' 41 | SpacesInCStyleCastParentheses: 'false' 42 | SpacesInParentheses: 'false' 43 | SpacesInSquareBrackets: 'false' 44 | Standard: Cpp11 45 | TabWidth: '2' 46 | UseTab: Never 47 | SortIncludes: 'false' 48 | ReflowComments: 'false' 49 | BraceWrapping: { 50 | AfterClass: 'true', 51 | AfterControlStatement: 'true', 52 | AfterEnum: 'true', 53 | AfterFunction: 'true', 54 | AfterNamespace: 'false', 55 | AfterStruct: 'true', 56 | AfterUnion: 'true', 57 | BeforeCatch: 'true', 58 | BeforeElse: 'true', 59 | IndentBraces: 'false' 60 | } 61 | PenaltyExcessCharacter: 1 62 | PenaltyBreakBeforeFirstCallParameter: 40 63 | PenaltyBreakFirstLessLess: 1 64 | PenaltyBreakComment: 30 65 | PenaltyBreakString: 30 66 | PenaltyReturnTypeOnItsOwnLine: 9999 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Any folder starting with an `_` 2 | **/_*/* 3 | /external/bin_x64/* 4 | build/ 5 | cmake_build/ 6 | 7 | external/downloaded_resources/ 8 | 9 | ./log_micromesh_viewer.txt 10 | ./micromesh_viewer.ini 11 | ./testing/ 12 | 13 | .cache/ 14 | .vs/ 15 | .vscode/ 16 | 17 | 18 | mini_samples/mm_raytrace/.obsidian/ 19 | testmesh/ 20 | remesher/docs/crop.bat 21 | 22 | remesher/docs/convert.bat 23 | 24 | micromesh_python/notebook/.fuse_hidden000037a800000004 25 | 26 | micromesh_python/notebook/assets/simplewall/.fuse_hidden000037a600000005 27 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | # Submodules that require authentication are listed with relative paths. 2 | # This makes it so that if a developer can clone partner_tools, they can also 3 | # clone the submodules, even if they only have one of HTTPS or SSH 4 | # authentication set up. Since libpng's Git does not require authentication, 5 | # it does not use a relative path. 6 | [submodule "external/nvpro_core"] 7 | path = external/nvpro_core 8 | url = https://github.com/nvpro-samples/nvpro_core.git 9 | [submodule "external/libpng"] 10 | path = external/libpng 11 | url = https://git.code.sf.net/p/libpng/code 12 | shallow = true 13 | [submodule "external/heightmap_rtx"] 14 | path = external/heightmap_rtx 15 | url = https://github.com/NVIDIAGameWorks/heightmap_rtx.git 16 | [submodule "external/Displacement-MicroMap-SDK"] 17 | path = external/Displacement-MicroMap-SDK 18 | url = ../Displacement-MicroMap-SDK.git 19 | [submodule "external/Displacement-MicroMap-BaryFile"] 20 | path = external/Displacement-MicroMap-BaryFile 21 | url = ../Displacement-MicroMap-BaryFile.git 22 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/LICENSE.txt -------------------------------------------------------------------------------- /PACKAGE-LICENSES/MikkTSpace-LICENSE.md: -------------------------------------------------------------------------------- 1 | ``` 2 | * This software is provided 'as-is', without any express or implied 3 | * warranty. In no event will the authors be held liable for any damages 4 | * arising from the use of this software. 5 | * 6 | * Permission is granted to anyone to use this software for any purpose, 7 | * including commercial applications, and to alter it and redistribute it 8 | * freely, subject to the following restrictions: 9 | * 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | ``` -------------------------------------------------------------------------------- /PACKAGE-LICENSES/OpenEXR-LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) Contributors to the OpenEXR Project. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /PACKAGE-LICENSES/Turbo_Colormap_Polynomial_Approximation_in_GLSL-LICENSE.md: -------------------------------------------------------------------------------- 1 | ``` 2 | // Copyright 2019 Google LLC. 3 | // SPDX-License-Identifier: Apache-2.0 4 | 5 | // Polynomial approximation in GLSL for the Turbo colormap 6 | // Original LUT: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f 7 | 8 | // Authors: 9 | // Colormap Design: Anton Mikhailov (mikhailov@google.com) 10 | // GLSL Approximation: Ruofei Du (ruofei@google.com) 11 | ``` -------------------------------------------------------------------------------- /PACKAGE-LICENSES/dlib-LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2003 Davis E. King (davis@dlib.net) 2 | Boost Software License - Version 1.0 - August 17th, 2003 3 | 4 | Permission is hereby granted, free of charge, to any person or organization 5 | obtaining a copy of the software and accompanying documentation covered by 6 | this license (the "Software") to use, reproduce, display, distribute, 7 | execute, and transmit the Software, and to prepare derivative works of the 8 | Software, and to permit third-parties to whom the Software is furnished to 9 | do so, all subject to the following: 10 | 11 | The copyright notices in the Software and this entire statement, including 12 | the above license grant, this restriction and the following disclaimer, 13 | must be included in all copies of the Software, in whole or in part, and 14 | all derivative works of the Software, unless such copies or derivative 15 | works are solely in the form of machine-executable object code generated by 16 | a source language processor. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /PACKAGE-LICENSES/libpng-LICENSE.md: -------------------------------------------------------------------------------- 1 | COPYRIGHT NOTICE, DISCLAIMER, and LICENSE 2 | ========================================= 3 | 4 | PNG Reference Library License version 2 5 | --------------------------------------- 6 | 7 | * Copyright (c) 1995-2022 The PNG Reference Library Authors. 8 | * Copyright (c) 2018-2022 Cosmin Truta. 9 | * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson. 10 | * Copyright (c) 1996-1997 Andreas Dilger. 11 | * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. 12 | 13 | The software is supplied "as is", without warranty of any kind, 14 | express or implied, including, without limitation, the warranties 15 | of merchantability, fitness for a particular purpose, title, and 16 | non-infringement. In no event shall the Copyright owners, or 17 | anyone distributing the software, be liable for any damages or 18 | other liability, whether in contract, tort or otherwise, arising 19 | from, out of, or in connection with the software, or the use or 20 | other dealings in the software, even if advised of the possibility 21 | of such damage. 22 | 23 | Permission is hereby granted to use, copy, modify, and distribute 24 | this software, or portions hereof, for any purpose, without fee, 25 | subject to the following restrictions: 26 | 27 | 1. The origin of this software must not be misrepresented; you 28 | must not claim that you wrote the original software. If you 29 | use this software in a product, an acknowledgment in the product 30 | documentation would be appreciated, but is not required. 31 | 32 | 2. Altered source versions must be plainly marked as such, and must 33 | not be misrepresented as being the original software. 34 | 35 | 3. This Copyright notice may not be removed or altered from any 36 | source or altered source distribution. -------------------------------------------------------------------------------- /PACKAGE-LICENSES/miniz-LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2013-2014 RAD Game Tools and Valve Software 2 | Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC 3 | 4 | All Rights Reserved. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. -------------------------------------------------------------------------------- /PACKAGE-LICENSES/pcg-c-basic-LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2017 Melissa O'Neill and PCG Project contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /PACKAGE-LICENSES/tinyexr-LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 - 2021, Syoyo Fujita and many contributors. 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | * Redistributions of source code must retain the above copyright 6 | notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | * Neither the name of the Syoyo Fujita nor the 11 | names of its contributors may be used to endorse or promote products 12 | derived from this software without specific prior written permission. 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 17 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Security 2 | 3 | NVIDIA is dedicated to the security and trust of our software products and services, including all source code repositories managed through our organization. 4 | 5 | If you need to report a security issue, please use the appropriate contact points outlined below. **Please do not report security vulnerabilities through GitHub/GitLab.** 6 | 7 | ## Reporting Potential Security Vulnerability in an NVIDIA Product 8 | 9 | To report a potential security vulnerability in any NVIDIA product: 10 | - Web: [Security Vulnerability Submission Form](https://www.nvidia.com/object/submit-security-vulnerability.html) 11 | - E-Mail: psirt@nvidia.com 12 | - We encourage you to use the following PGP key for secure email communication: [NVIDIA public PGP Key for communication](https://www.nvidia.com/en-us/security/pgp-key) 13 | - Please include the following information: 14 | - Product and driver version/branch that contains the vulnerability 15 | - Type of vulnerability (code execution, denial of service, buffer overflow, etc.) 16 | - Instructions to reproduce the vulnerability 17 | - Proof-of-concept or exploit code 18 | - Potential impact of the vulnerability, including how an attacker could exploit the vulnerability 19 | 20 | While NVIDIA currently does not have a bug bounty program, we do offer acknowledgement when an externally reported security issue is addressed under our coordinated vulnerability disclosure policy. Please visit our [Product Security Incident Response Team (PSIRT)](https://www.nvidia.com/en-us/security/psirt-policies/) policies page for more information. 21 | 22 | ## NVIDIA Product Security 23 | 24 | For all security-related concerns, please visit NVIDIA's Product Security portal at https://www.nvidia.com/en-us/security -------------------------------------------------------------------------------- /common/debug_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #ifdef _WIN32 16 | 17 | #include 18 | 19 | static int AbortReportHook(int reportType, char* message, int* returnValue) 20 | { 21 | const char* typeStr; 22 | switch(reportType) 23 | { 24 | case _CRT_WARN: 25 | typeStr = "Warning"; 26 | break; 27 | case _CRT_ERROR: 28 | typeStr = "Error"; 29 | break; 30 | case _CRT_ASSERT: 31 | typeStr = "Assertion"; 32 | break; 33 | default: 34 | typeStr = ""; 35 | break; 36 | } 37 | printf("Abort (%s): %s\n", typeStr, message); 38 | fflush(stdout); 39 | *returnValue = 1; 40 | return true; // no popup! 41 | } 42 | 43 | inline void fixAbortOnWindows() 44 | { 45 | // Disable assert popups on windows that can hang automated testing when no debugger is attached 46 | if(!IsDebuggerPresent()) 47 | { 48 | _CrtSetReportHook(AbortReportHook); 49 | } 50 | } 51 | 52 | #endif // _WIN32 53 | -------------------------------------------------------------------------------- /common/vulkan_nv/vk_nv_micromesh_prototypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | ////////////////////////////////////////////////////////////////////////////////////// 14 | ////////////////////////////////////////////////////////////////////////////////////// 15 | // 16 | // WARNING: VK_NV_displacement_micromap is in beta and subject to future changes. 17 | // Do not use these headers in production code. 18 | // 19 | ////////////////////////////////////////////////////////////////////////////////////// 20 | ////////////////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | #include "vk_nv_micromesh.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #ifdef VULKAN_NV_DEFINED_EXT_opacity_micromap 31 | #ifndef VK_NO_PROTOTYPES 32 | void load_VK_EXT_opacity_micromap_prototypes(VkDevice device, PFN_vkGetDeviceProcAddr getDeviceProcAddr); 33 | #else 34 | typedef struct VK_EXT_opacity_micromap_functions 35 | { 36 | PFN_vkCreateMicromapEXT pfn_vkCreateMicromapEXT; 37 | PFN_vkDestroyMicromapEXT pfn_vkDestroyMicromapEXT; 38 | PFN_vkCmdBuildMicromapsEXT pfn_vkCmdBuildMicromapsEXT; 39 | PFN_vkBuildMicromapsEXT pfn_vkBuildMicromapsEXT; 40 | PFN_vkCopyMicromapEXT pfn_vkCopyMicromapEXT; 41 | PFN_vkCopyMicromapToMemoryEXT pfn_vkCopyMicromapToMemoryEXT; 42 | PFN_vkCopyMemoryToMicromapEXT pfn_vkCopyMemoryToMicromapEXT; 43 | PFN_vkWriteMicromapsPropertiesEXT pfn_vkWriteMicromapsPropertiesEXT; 44 | PFN_vkCmdCopyMicromapEXT pfn_vkCmdCopyMicromapEXT; 45 | PFN_vkCmdCopyMicromapToMemoryEXT pfn_vkCmdCopyMicromapToMemoryEXT; 46 | PFN_vkCmdCopyMemoryToMicromapEXT pfn_vkCmdCopyMemoryToMicromapEXT; 47 | PFN_vkCmdWriteMicromapsPropertiesEXT pfn_vkCmdWriteMicromapsPropertiesEXT; 48 | PFN_vkGetDeviceMicromapCompatibilityEXT pfn_vkGetDeviceMicromapCompatibilityEXT; 49 | PFN_vkGetMicromapBuildSizesEXT pfn_vkGetMicromapBuildSizesEXT; 50 | } VK_EXT_opacity_micromap_functions; 51 | 52 | void load_VK_EXT_opacity_micromap_functions(VK_EXT_opacity_micromap_functions* fns, VkDevice device, PFN_vkGetDeviceProcAddr getDeviceProcAddr); 53 | #endif 54 | #else // ^^^ #ifdef VULKAN_NV_DEFINED_EXT_opacity_micromap 55 | // When the Vulkan SDK provides VK_EXT_opacity_micromap, extensions_vk.cpp loads it for us. 56 | inline void load_VK_EXT_opacity_micromap_prototypes(VkDevice device, PFN_vkGetDeviceProcAddr getDeviceProcAddr){}; 57 | #endif // #ifdef VULKAN_NV_DEFINED_EXT_opacity_micromap 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | // there are no extra function prototypes for displacement -------------------------------------------------------------------------------- /docs/Displacement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/Displacement.png -------------------------------------------------------------------------------- /docs/bake_high_low.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/bake_high_low.png -------------------------------------------------------------------------------- /docs/bake_high_low_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/bake_high_low_result.jpg -------------------------------------------------------------------------------- /docs/failure_anisotropy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_anisotropy.jpg -------------------------------------------------------------------------------- /docs/failure_bounds.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_bounds.jpg -------------------------------------------------------------------------------- /docs/failure_bounds2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_bounds2.jpg -------------------------------------------------------------------------------- /docs/failure_bounds3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_bounds3.jpg -------------------------------------------------------------------------------- /docs/failure_cracks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_cracks.jpg -------------------------------------------------------------------------------- /docs/failure_cracks2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_cracks2.png -------------------------------------------------------------------------------- /docs/failure_overlap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_overlap.jpg -------------------------------------------------------------------------------- /docs/failure_overlap2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_overlap2.jpg -------------------------------------------------------------------------------- /docs/failure_quantization.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_quantization.jpg -------------------------------------------------------------------------------- /docs/failure_spike.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/failure_spike.jpg -------------------------------------------------------------------------------- /docs/micromesh_reefcrab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/micromesh_reefcrab.png -------------------------------------------------------------------------------- /docs/resample_before_after.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/resample_before_after.jpg -------------------------------------------------------------------------------- /docs/visualize_anisotropy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/visualize_anisotropy.jpg -------------------------------------------------------------------------------- /docs/visualize_directions.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/visualize_directions.jpg -------------------------------------------------------------------------------- /docs/visualize_heightmaptexfreq.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/visualize_heightmaptexfreq.jpg -------------------------------------------------------------------------------- /docs/visualize_sharedpos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/visualize_sharedpos.jpg -------------------------------------------------------------------------------- /docs/visualize_shell.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/visualize_shell.jpg -------------------------------------------------------------------------------- /docs/visualize_subdivlevel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/docs/visualize_subdivlevel.jpg -------------------------------------------------------------------------------- /external/tinyexr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # All sources and headers 2 | file(GLOB SOURCE_FILES *.*) 3 | 4 | # Make an automatic library - will be static or dynamic based on user setting 5 | add_library(tinyexr ${SOURCE_FILES}) 6 | 7 | # We need this directory, and users of our library will need it too 8 | target_include_directories(tinyexr PUBLIC .) 9 | 10 | # Fix the miniz.c warning about large files with fopen() etc. 11 | if(UNIX) 12 | target_compile_definitions(tinyexr PRIVATE _LARGEFILE64_SOURCE) 13 | endif() -------------------------------------------------------------------------------- /meshops_bake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Library 3 | #------------------------------------------------------------------------- 4 | set(PROJECT_NAME "meshops_bake") 5 | 6 | # Sources and headers for the library 7 | set(SOURCE_FILES 8 | meshops_bake_batch.hpp 9 | meshops_bake_batch.cpp 10 | meshops_bake_vk.hpp 11 | meshops_bake_vk.cpp 12 | meshops_bake.cpp 13 | ) 14 | 15 | # Attempt to match MSVC warnings 16 | if(UNIX) 17 | set_property(SOURCE ${SOURCE_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS -Wconversion) 18 | endif() 19 | 20 | # Add library 21 | add_library(${PROJECT_NAME} ${SOURCE_FILES}) 22 | 23 | # Add thirdparty 24 | target_include_directories(${PROJECT_NAME} PRIVATE ${THIRDPARTY_DIR}) 25 | target_include_directories(${PROJECT_NAME} PRIVATE ${COMMON_DIR}) 26 | 27 | # Dependencies 28 | target_link_libraries (${PROJECT_NAME} meshops_core) 29 | 30 | # We need this directory, and users of our library will need it too 31 | #target_include_directories(${PROJECT_NAME} INTERFACE .) 32 | 33 | #---------------------------------- 34 | # Adding shader files 35 | set(SHD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shaders) 36 | file(GLOB SHD_HDR ${SHD_DIR}/*.glsl ${SHD_DIR}/*.h ${COMMON_DIR}/*.glsl) 37 | file(GLOB SHD_SRC ${SHD_DIR}/*.rchit ${SHD_DIR}/*.rmiss ${SHD_DIR}/*.frag ${SHD_DIR}/*.rahit ${SHD_DIR}/*.rgen ${SHD_DIR}/*.vert ${SHD_DIR}/*.comp) 38 | # Compiling shaders to Spir-V header 39 | compile_glsl( 40 | SOURCE_FILES ${SHD_SRC} 41 | HEADER_FILES ${SHD_HDR} 42 | DST "${CMAKE_CURRENT_SOURCE_DIR}/_autogen" 43 | VULKAN_TARGET "vulkan1.2" 44 | HEADER ON 45 | DEPENDENCY ON 46 | FLAGS "-I${SHD_DIR}" "-I${COMMON_DIR}" -g 47 | ) 48 | target_sources(${PROJECT_NAME} PRIVATE ${SHD_SRC} ${SHD_HDR}) 49 | source_group("Shaders" FILES ${SHD_SRC} ${SHD_HDR}) 50 | #---------------------------------- 51 | 52 | # Extra 53 | install(TARGETS ${PROJECT_NAME}) 54 | set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "meshops_bake") 55 | -------------------------------------------------------------------------------- /meshops_bake/meshops_bake_batch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | #pragma once 13 | 14 | #include "vulkan/vulkan_core.h" 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace meshops { 21 | 22 | bool getMemoryUsageVk(VkPhysicalDevice physicalDevice, VkDeviceSize* budget, VkDeviceSize* usage); 23 | 24 | struct GeometryBatch 25 | { 26 | // Range of triangles in the batch before growing 27 | uint32_t triangleOffset; 28 | uint32_t triangleCount; 29 | 30 | // Batch index for logging 31 | uint32_t batchIndex; 32 | uint32_t totalBatches; 33 | 34 | // The subset of triangle indices for the batch after growing to neighbours 35 | bool allTriangles; 36 | std::vector triangles; 37 | size_t size() const { return allTriangles ? triangleCount : triangles.size(); } 38 | uint32_t triangle(uint32_t i) const { return allTriangles ? i : triangles[i]; } 39 | }; 40 | 41 | std::vector computeBatches(Context context, 42 | uint64_t memLimitBytes, 43 | const micromesh::MeshTopology* topology, 44 | const meshops::MeshView& referenceMeshView); 45 | 46 | } // namespace meshops 47 | -------------------------------------------------------------------------------- /meshops_core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # All sources and headers 3 | file(GLOB SOURCE_FILES src/*.*) 4 | file(GLOB PUBLIC_HEADER_FILES include/imageio/*.* include/meshops/*.* include/microutils/*.* include/mikktspace/*.*) 5 | file(GLOB INTERNAL_HEADER_FILES include/meshops_internal/*.*) 6 | 7 | source_group("public_include" FILES ${PUBLIC_HEADER_FILES}) 8 | source_group("internal_include" FILES ${INTERNAL_HEADER_FILES}) 9 | source_group("source" FILES ${SOURCE_FILES}) 10 | 11 | # Make an automatic library - will be static or dynamic based on user setting 12 | add_library(meshops_core ${SOURCE_FILES} ${PUBLIC_HEADER_FILES} ${INTERNAL_HEADER_FILES}) 13 | 14 | # We need this directory, and users of our library will need it too 15 | target_include_directories(meshops_core PUBLIC include) 16 | 17 | target_include_directories(meshops_core PRIVATE $) 18 | 19 | # This depends on nvpro_core bary_core bary_utils micromesh_core 20 | target_link_libraries(meshops_core PUBLIC nvpro_core bary_core bary_utils micromesh_core micromesh_displacement_compression png_static tinyexr) 21 | 22 | set_target_properties(meshops_core PROPERTIES FOLDER "meshops_core") 23 | 24 | # Add pretty printers for visual studio 25 | # Alt: add_link_options(/NATVIS:file.natvis) if not for https://github.com/microsoft/vscode-cpptools/issues/10175 26 | if (MSVC_IDE) 27 | target_sources(meshops_core INTERFACE 28 | ${CMAKE_CURRENT_SOURCE_DIR}/include/meshops/meshops_array_view.natvis 29 | ) 30 | endif() 31 | -------------------------------------------------------------------------------- /meshops_core/README.md: -------------------------------------------------------------------------------- 1 | # meshops_core 2 | 3 | The `meshops` API is a layer above the `micromesh` SDK, that provides easier usage and higher level operations. 4 | The functions within typically operate on a single mesh provided in memory through an abstraction called [`meshops::MeshView`](include/meshops/meshops_mesh_view.h). 5 | 6 | Basic operations for this library can be found [here](include/meshops/meshops_operations.h). 7 | 8 | While the `micromesh` core is storage agnostic, the `meshops` layer is design around using the `bary` container. As a result the library also hosts the `microutils` namespace and utilities, which handle some `micromesh` related operations on top of the bary file containers provided through `bary` or `baryutils`. The primary usecase are [compression related functions](include/microutils/microutils_compression.hpp). 9 | 10 | This layer makes use of a Vulkan implementation for the various GPU-based operations and leverages `nvpro_core`'s `nvvk` utilities. 11 | It is possible to use this API without explicitly accessing any Vulkan resources, or creating a custom Vulkan context. However, it does also support this to be embedded in an interactive viewer. 12 | 13 | The headers in `include/meshops_internal` are strictly meant for other meshops libraries, and not meant as public interface for this api. 14 | 15 | ## Roadmap 16 | 17 | Currently this library is still a bit more work in progress and subject to changes, until we have migrated all tools into `micromesh_tool` and refactored the `micromesh_viewer`. We might move or hide the microutils layer in future. 18 | 19 | A few upcoming changes for `MeshView`: 20 | 21 | - reduce template nesting, improve debugging 22 | - remove bitangent vector and rely only on 4 component tangents 23 | - add more texcoords and colors in MeshView 24 | -------------------------------------------------------------------------------- /meshops_core/include/meshops/bias_scale.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | // Class to use a bias and scale as a self-contained transformation object 18 | template 19 | struct BiasScale 20 | { 21 | BiasScale() = default; 22 | BiasScale(const BiasScale& other) = default; 23 | BiasScale(const T& bias, const T& scale) 24 | : bias(bias) 25 | , scale(scale) 26 | { 27 | } 28 | template 29 | BiasScale(const Vec& vec) 30 | : bias(vec.x) 31 | , scale(vec.y) 32 | { 33 | } 34 | 35 | // Transform a value by the bias and scale 36 | template 37 | V operator*(const V& value) const 38 | { 39 | return value * scale + bias; 40 | } 41 | 42 | // Combines two BiasScales into one that performs the same transform that they would when chained 43 | BiasScale& operator*=(const BiasScale& other) 44 | { 45 | bias += other.bias * scale; 46 | scale *= other.scale; 47 | return *this; 48 | } 49 | 50 | BiasScale operator*(const BiasScale& other) const 51 | { 52 | BiasScale result(*this); 53 | result *= other; 54 | return result; 55 | } 56 | 57 | // Returns a BiasScale that scales about a point. 58 | static BiasScale centered_scale(const T& center, const T& scale) 59 | { 60 | return BiasScale((static_cast(1) - scale) * center, scale); 61 | } 62 | 63 | // Returns a BiasScale that transforms values in the range min/max into the range 0 to 1. 64 | static BiasScale minmax_unit(const T& min, const T& max) { return BiasScale(min, max - min); } 65 | 66 | template 67 | static BiasScale minmax_unit(const Vec& vec) 68 | { 69 | return BiasScale(vec.x, vec.y - vec.x); 70 | } 71 | 72 | T unit_min() const { return bias; } // BiasScale * 0 = 0 * scale + bias 73 | T unit_max() const { return scale + bias; } // BiasScale * 1 = 1 * scale + bias 74 | 75 | BiasScale inverse() const { return BiasScale(-bias / scale, static_cast(1) / scale); } 76 | 77 | // Avoid singularity transforms by limiting how small scale can get 78 | BiasScale degenerate_clamped(T epsilon = static_cast(1e-6)) const 79 | { 80 | return BiasScale(bias, std::max(epsilon, scale)); 81 | } 82 | 83 | T bias{0}; 84 | T scale{1}; 85 | }; 86 | 87 | using BiasScalef = BiasScale; -------------------------------------------------------------------------------- /meshops_core/include/meshops/meshops_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #if defined(_MSC_VER) 16 | #define MESHOPS_CALL __fastcall 17 | #elif !defined(__aarch64__) && !defined(__x86_64) && (defined(__GNUC__) || defined(__clang__)) 18 | #define MESHOPS_CALL __attribute__((fastcall)) 19 | #else 20 | #define MESHOPS_CALL 21 | #endif 22 | 23 | #ifndef MESHOPS_API 24 | #define MESHOPS_API extern "C" 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /meshops_core/include/meshops/meshops_array_view.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{ size={m_size} }} 5 | 6 | m_ptr 7 | m_size 8 | m_stride 9 | 10 | m_size 11 | *(value_type*)((uint8_t*)m_ptr + $i * m_stride) 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /meshops_core/include/meshops_internal/heightmap.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | 14 | #pragma once 15 | #include 16 | #include 17 | 18 | #include "nvmath/nvmath.h" 19 | 20 | ////////////////////////////////////////////////////////////////////////// 21 | /// Class to hold the height map texture and to fetch the value 22 | struct HeightMap 23 | { 24 | HeightMap() = default; 25 | HeightMap(int width, int height, const float* source) 26 | : width(width) 27 | , height(height) 28 | , data(source) 29 | { 30 | } 31 | 32 | // Load the texture in 16bit 33 | bool load(const std::string& filename); 34 | 35 | // Return the value [0..1] for texture coordinates [0..1] 36 | float texelFetch(const nvmath::vec2f& texcoord) const; 37 | float texelFetch(int x, int y) const; 38 | float bilinearFetch(const nvmath::vec2f& texcoord) const; 39 | const float* raw() const { return data ? data : fileData.data(); } 40 | int width{0}; 41 | int height{0}; 42 | int components{0}; 43 | const float* data = nullptr; 44 | std::vector fileData; 45 | }; 46 | -------------------------------------------------------------------------------- /meshops_core/include/meshops_internal/meshops_texture.h: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | // SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | // 5 | // NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | // property and proprietary rights in and to this material, related 7 | // documentation and any modifications thereto. Any use, reproduction, 8 | // disclosure or distribution of this material and related documentation 9 | // without an express license agreement from NVIDIA CORPORATION or 10 | // its affiliates is strictly prohibited. 11 | // 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | namespace meshops { 18 | 19 | inline bool textureHasReadWriteAccess(TextureUsageFlags flags) 20 | { 21 | return (flags & (eTextureUsageBakerResamplingDestination | eTextureUsageBakerResamplingDistance)) != 0; 22 | } 23 | 24 | inline bool textureNeedsHost(TextureUsageFlags flags) 25 | { 26 | return (flags & (eTextureUsageBakerHeightmapSource)) != 0; 27 | } 28 | 29 | inline bool textureNeedsDevice(TextureUsageFlags flags) 30 | { 31 | return (flags 32 | & (eTextureUsageBakerResamplingDestination | eTextureUsageBakerResamplingDistance 33 | | eTextureUsageBakerResamplingSource | eTextureUsageRemesherImportanceSource)) 34 | != 0; 35 | } 36 | 37 | class Texture_c 38 | { 39 | public: 40 | TextureConfig m_config; 41 | TextureUsageFlags m_usageFlags; 42 | 43 | TextureVK m_vk; 44 | nvvk::Image m_vkData; 45 | 46 | micromesh::MicromapValue m_fillValue; 47 | std::vector m_mipSizes; 48 | std::vector> m_mipData; // only if host data exists 49 | 50 | // returns mip 0 data only if host copy exists 51 | const void* getImageData() const { return m_mipData.size() ? m_mipData[0].data() : nullptr; } 52 | 53 | void initMipSizes() 54 | { 55 | m_mipSizes.resize(m_config.mips); 56 | if(m_config.mips) 57 | { 58 | m_mipSizes[0] = {m_config.width, m_config.height}; 59 | } 60 | 61 | for(uint32_t m = 1; m < m_config.mips; m++) 62 | { 63 | m_mipSizes[m] = {std::max(1u, m_mipSizes[m - 1].x / 2), std::max(1u, m_mipSizes[m - 1].y / 2)}; 64 | } 65 | } 66 | 67 | inline bool hasReadWriteAccess() const { return textureHasReadWriteAccess(m_usageFlags); } 68 | inline bool needsDevice() const { return textureNeedsDevice(m_usageFlags); } 69 | inline bool needsHost() const { return textureNeedsHost(m_usageFlags); } 70 | }; 71 | 72 | } // namespace meshops 73 | -------------------------------------------------------------------------------- /meshops_core/include/meshops_internal/meshops_vertexattribs.h: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | // SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | // 5 | // NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | // property and proprietary rights in and to this material, related 7 | // documentation and any modifications thereto. Any use, reproduction, 8 | // disclosure or distribution of this material and related documentation 9 | // without an express license agreement from NVIDIA CORPORATION or 10 | // its affiliates is strictly prohibited. 11 | // 12 | 13 | #pragma once 14 | 15 | #include "meshops/meshops_api.h" 16 | #include "meshops/meshops_types.h" 17 | 18 | namespace meshops { 19 | 20 | // Generate per-vertex directions by averaging the face normals adjacent to each vertex 21 | MESHOPS_API micromesh::Result MESHOPS_CALL meshopsGenerateVertexDirections(Context context, meshops::ResizableMeshView& meshView); 22 | 23 | // Compute extent of meshView 24 | MESHOPS_API float MESHOPS_CALL meshopsComputeMeshViewExtent(Context context, const meshops::MutableMeshView& meshView); 25 | 26 | } // namespace meshops -------------------------------------------------------------------------------- /meshops_core/src/heightmap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "imageio/imageio.hpp" 18 | 19 | bool HeightMap::load(const std::string& filename) 20 | { 21 | data = nullptr; 22 | fileData.clear(); 23 | size_t loaded_width, loaded_height, components; 24 | imageio::ImageIOData loaded_data = imageio::loadF(filename.c_str(), &loaded_width, &loaded_height, &components, 1); 25 | if(!loaded_data) 26 | { 27 | return false; 28 | } 29 | assert(components == 1); // Double-checking myself 30 | if(loaded_width > std::numeric_limits::max() || loaded_height > std::numeric_limits::max()) 31 | { 32 | // Too large! 33 | return false; 34 | } 35 | width = static_cast(loaded_width); 36 | height = static_cast(loaded_height); 37 | const float* const loaded_data_float = reinterpret_cast(loaded_data); 38 | fileData.insert(fileData.begin(), loaded_data_float, loaded_data_float + (width * height)); 39 | imageio::freeData(&loaded_data); 40 | data = fileData.data(); 41 | return true; 42 | } 43 | 44 | float HeightMap::texelFetch(int x, int y) const 45 | { 46 | // Wrap around; perform modulo so e.g. -3 mod 8 = 5. 47 | x = (x < 0 ? width : 0) + (x % width); 48 | y = (y < 0 ? height : 0) + (y % height); 49 | return data[(y * width) + x]; 50 | } 51 | 52 | float HeightMap::texelFetch(const nvmath::vec2f& texcoord) const 53 | { 54 | const int x = int(texcoord.x * float(width)); 55 | const int y = int(texcoord.y * float(height)); 56 | return texelFetch(x, y); 57 | } 58 | 59 | float HeightMap::bilinearFetch(const nvmath::vec2f& texcoord) const 60 | { 61 | const float tx = texcoord.x - 0.5f / float(width); // Offset so that texels are centered 62 | const float ty = texcoord.y - 0.5f / float(height); // at half-integer coordinates 63 | const float gx = (tx - std::floor(tx)) * float(width); 64 | const float gy = (ty - std::floor(ty)) * float(height); 65 | const int gxi0 = int(gx) % width; 66 | const int gxi1 = (gxi0 + 1) % width; 67 | const int gyi0 = int(gy) % height; 68 | const int gyi1 = (gyi0 + 1) % height; 69 | 70 | const float t00 = data[(gyi0 * width) + gxi0]; 71 | const float t10 = data[(gyi0 * width) + gxi1]; 72 | const float t01 = data[(gyi1 * width) + gxi0]; 73 | const float t11 = data[(gyi1 * width) + gxi1]; 74 | 75 | const float i0 = nvmath::lerp(gx - float(gxi0), t00, t10); 76 | const float i1 = nvmath::lerp(gx - float(gxi0), t01, t11); 77 | const float r = nvmath::lerp(gy - float(gyi0), i0, i1); 78 | return r; 79 | } 80 | -------------------------------------------------------------------------------- /meshops_core/src/meshops_tangents_lengyel.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | // SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | // 5 | // NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | // property and proprietary rights in and to this material, related 7 | // documentation and any modifications thereto. Any use, reproduction, 8 | // disclosure or distribution of this material and related documentation 9 | // without an express license agreement from NVIDIA CORPORATION or 10 | // its affiliates is strictly prohibited. 11 | // 12 | 13 | #pragma once 14 | 15 | #include "meshops/meshops_mesh_view.h" 16 | 17 | namespace meshops { 18 | 19 | void createLengyelTangents(meshops::MutableMeshView& mesh); 20 | 21 | } -------------------------------------------------------------------------------- /meshops_remesher/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Library 3 | #------------------------------------------------------------------------- 4 | set(PROJECT_NAME "meshops_remesher") 5 | 6 | # Sources and headers for the library 7 | set(SOURCE_FILES 8 | remeshing_operator.hpp 9 | generate_importance_operator.hpp 10 | meshops_remesher_internal.hpp 11 | meshops_remesher.cpp 12 | meshops_generate_importance.cpp 13 | remeshing_operator.cpp 14 | generate_importance_operator.cpp 15 | ) 16 | 17 | # Attempt to match MSVC warnings 18 | if(UNIX) 19 | set_property(SOURCE ${SOURCE_FILES} APPEND_STRING PROPERTY COMPILE_FLAGS -Wconversion) 20 | endif() 21 | 22 | # Add library 23 | add_library(${PROJECT_NAME} ${SOURCE_FILES}) 24 | 25 | # Add thirdparty 26 | target_include_directories(${PROJECT_NAME} PRIVATE ${THIRDPARTY_DIR}) 27 | target_include_directories(${PROJECT_NAME} PRIVATE ${COMMON_DIR}) 28 | 29 | # Dependencies 30 | target_link_libraries (${PROJECT_NAME} micromesh_displacement_remeshing meshops_core) 31 | 32 | # We need this directory, and users of our library will need it too 33 | #target_include_directories(${PROJECT_NAME} INTERFACE .) 34 | 35 | #---------------------------------- 36 | # Adding shader files 37 | set(SHD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shaders) 38 | file(GLOB SHD_HDR ${SHD_DIR}/*.glsl ${SHD_DIR}/*.h ${COMMON_DIR}/*.glsl) 39 | file(GLOB SHD_SRC ${SHD_DIR}/*.rchit ${SHD_DIR}/*.rmiss ${SHD_DIR}/*.frag ${SHD_DIR}/*.rahit ${SHD_DIR}/*.rgen ${SHD_DIR}/*.vert ${SHD_DIR}/*.comp) 40 | # Compiling shaders to Spir-V header 41 | compile_glsl( 42 | SOURCE_FILES ${SHD_SRC} 43 | HEADER_FILES ${SHD_HDR} 44 | DST "${CMAKE_CURRENT_SOURCE_DIR}/_autogen" 45 | VULKAN_TARGET "vulkan1.2" 46 | HEADER ON 47 | DEPENDENCY ON 48 | FLAGS "-I${SHD_DIR}" "-I${COMMON_DIR}" -g 49 | ) 50 | target_sources(${PROJECT_NAME} PRIVATE ${SHD_SRC} ${SHD_HDR}) 51 | source_group("Shaders" FILES ${SHD_SRC} ${SHD_HDR}) 52 | #---------------------------------- 53 | 54 | # Extra 55 | install(TARGETS ${PROJECT_NAME}) 56 | set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "meshops_remesher") 57 | -------------------------------------------------------------------------------- /meshops_remesher/docs/curvature_power_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/curvature_power_10.png -------------------------------------------------------------------------------- /meshops_remesher/docs/curvature_power_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/curvature_power_5.png -------------------------------------------------------------------------------- /meshops_remesher/docs/curvature_power_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/curvature_power_50.png -------------------------------------------------------------------------------- /meshops_remesher/docs/dragon_head_1k_1k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/dragon_head_1k_1k.png -------------------------------------------------------------------------------- /meshops_remesher/docs/dragon_head_500k_355k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/dragon_head_500k_355k.png -------------------------------------------------------------------------------- /meshops_remesher/docs/dragon_head_50k_40k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/dragon_head_50k_40k.png -------------------------------------------------------------------------------- /meshops_remesher/docs/dragon_head_5k_4k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/dragon_head_5k_4k.png -------------------------------------------------------------------------------- /meshops_remesher/docs/dragon_head_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/dragon_head_original.png -------------------------------------------------------------------------------- /meshops_remesher/docs/importance_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/importance_map.png -------------------------------------------------------------------------------- /meshops_remesher/docs/importance_map_decimated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/importance_map_decimated.png -------------------------------------------------------------------------------- /meshops_remesher/docs/importance_map_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/importance_map_preview.png -------------------------------------------------------------------------------- /meshops_remesher/docs/importance_weight_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/importance_weight_10.png -------------------------------------------------------------------------------- /meshops_remesher/docs/importance_weight_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/importance_weight_20.png -------------------------------------------------------------------------------- /meshops_remesher/docs/importance_weight_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/importance_weight_5.png -------------------------------------------------------------------------------- /meshops_remesher/docs/max_importance_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/max_importance_off.png -------------------------------------------------------------------------------- /meshops_remesher/docs/max_importance_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/max_importance_on.png -------------------------------------------------------------------------------- /meshops_remesher/docs/max_importance_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/max_importance_original.png -------------------------------------------------------------------------------- /meshops_remesher/docs/micromesh_bounds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/micromesh_bounds.png -------------------------------------------------------------------------------- /meshops_remesher/docs/micromesh_decimated_wireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/micromesh_decimated_wireframe.png -------------------------------------------------------------------------------- /meshops_remesher/docs/micromesh_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/micromesh_original.png -------------------------------------------------------------------------------- /meshops_remesher/docs/micromesh_original_wireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/micromesh_original_wireframe.png -------------------------------------------------------------------------------- /meshops_remesher/docs/micromesh_subd_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/micromesh_subd_level.png -------------------------------------------------------------------------------- /meshops_remesher/docs/remesher_intro_decimated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/remesher_intro_decimated.png -------------------------------------------------------------------------------- /meshops_remesher/docs/remesher_intro_full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/remesher_intro_full.png -------------------------------------------------------------------------------- /meshops_remesher/docs/seams_decimated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/seams_decimated.png -------------------------------------------------------------------------------- /meshops_remesher/docs/seams_decimated_wireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/seams_decimated_wireframe.png -------------------------------------------------------------------------------- /meshops_remesher/docs/seams_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/seams_original.png -------------------------------------------------------------------------------- /meshops_remesher/docs/seams_original_wireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/seams_original_wireframe.png -------------------------------------------------------------------------------- /meshops_remesher/docs/seams_texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/seams_texture.jpg -------------------------------------------------------------------------------- /meshops_remesher/docs/trace_distance_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/trace_distance_10.png -------------------------------------------------------------------------------- /meshops_remesher/docs/trace_distance_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/trace_distance_20.png -------------------------------------------------------------------------------- /meshops_remesher/docs/trace_distance_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/trace_distance_5.png -------------------------------------------------------------------------------- /meshops_remesher/docs/valence_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/valence_11.png -------------------------------------------------------------------------------- /meshops_remesher/docs/valence_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/valence_original.png -------------------------------------------------------------------------------- /meshops_remesher/docs/valence_unlimited.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/meshops_remesher/docs/valence_unlimited.png -------------------------------------------------------------------------------- /meshops_remesher/generate_importance_operator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | 12 | #pragma once 13 | #include 14 | 15 | #ifdef __cplusplus // GLSL Type 16 | #include 17 | using namespace glm; 18 | #endif 19 | #include "shaders/generate_importance_host_device.h" 20 | #include "micromesh/micromesh_gpu.h" 21 | 22 | 23 | #include "nvvk/images_vk.hpp" 24 | #include "nvh/timesampler.hpp" 25 | #include "nvvk/resourceallocator_vk.hpp" 26 | #include "nvh/nvprint.hpp" 27 | #include "nvvk/memallocator_vma_vk.hpp" 28 | #include "vk_mem_alloc.h" 29 | #include "nvvk/descriptorsets_vk.hpp" 30 | 31 | #include "nvvk/compute_vk.hpp" 32 | #include "meshops/meshops_operations.h" 33 | #include 34 | 35 | namespace meshops { 36 | 37 | class GenerateImportanceOperator_c 38 | { 39 | public: 40 | bool create(Context context); 41 | bool destroy(Context context); 42 | 43 | 44 | bool generateImportance(Context context, size_t inputCount, OpGenerateImportance_modified* inputs); 45 | 46 | private: 47 | bool m_isInitialized{false}; 48 | 49 | nvvk::PushComputeDispatcher m_generateImportance; 50 | 51 | nvvk::Image m_dummyMap; 52 | nvvk::Texture m_dummyTex; 53 | 54 | GenerateImportanceConstants m_constants; 55 | }; 56 | } // namespace meshops -------------------------------------------------------------------------------- /meshops_remesher/meshops_generate_importance.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | #include "generate_importance_operator.hpp" 12 | #include "meshops_internal/meshops_device_mesh.h" 13 | 14 | using namespace meshops; 15 | 16 | MESHOPS_API micromesh::Result MESHOPS_CALL meshopsGenerateImportanceOperatorCreate(Context context, GenerateImportanceOperator* pOp) 17 | { 18 | (*pOp) = new GenerateImportanceOperator_c; 19 | if((*pOp)->create(context)) 20 | { 21 | return micromesh::Result::eSuccess; 22 | } 23 | else 24 | { 25 | return micromesh::Result::eFailure; 26 | } 27 | } 28 | MESHOPS_API void MESHOPS_CALL meshopsGenerateImportanceOperatorDestroy(Context context, GenerateImportanceOperator op) 29 | { 30 | op->destroy(context); 31 | } 32 | 33 | MESHOPS_API micromesh::Result MESHOPS_CALL meshopsOpGenerateImportance(Context context, 34 | GenerateImportanceOperator op, 35 | size_t count, 36 | OpGenerateImportance_modified* inputs) 37 | { 38 | if(op->generateImportance(context, count, inputs)) 39 | { 40 | return micromesh::Result::eSuccess; 41 | } 42 | else 43 | { 44 | return micromesh::Result::eFailure; 45 | } 46 | } -------------------------------------------------------------------------------- /meshops_remesher/meshops_remesher_internal.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "nvvk/compute_vk.hpp" -------------------------------------------------------------------------------- /meshops_remesher/shaders/generate_importance_host_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | #ifndef __cplusplus 12 | #include "octant_encoding.h" 13 | #endif 14 | 15 | #define GENERATE_IMPORTANCE_BLOCK_SIZE 256 16 | 17 | // clang-format off 18 | #ifdef __cplusplus // Descriptor binding helper for C++ and GLSL 19 | #define START_BINDING(a) enum a { 20 | #define END_BINDING() } 21 | #define INLINE inline 22 | #else 23 | #define START_BINDING(a) const uint 24 | #define END_BINDING() 25 | #define INLINE 26 | #endif 27 | 28 | #define START_ENUM(a) START_BINDING(a) 29 | #define END_ENUM() END_BINDING() 30 | // clang-format on 31 | 32 | struct GenerateImportanceConstants 33 | { 34 | mat4 worldToObject; 35 | mat4 objectToWorld; 36 | uint vertexCount; 37 | float curvatureMaxDist; 38 | float curvaturePower; 39 | uint hasImportanceMap; 40 | 41 | uint texCoordCount; 42 | uint texCoordIndex; 43 | }; 44 | // clang-format off 45 | START_BINDING(GenerateImportanceBindings) 46 | 47 | // fp32 x 3 + octant normal (snorm16x2) 48 | eModifiedVertexPositionNormalBuffer = 0, 49 | 50 | // 2 x octant normal (snorm16x2) 51 | eModifiedVertexTangentSpaceBuffer = 1, 52 | 53 | // n x fp32 x 2 54 | eModifiedVertexTexcoordBuffer = 2, 55 | 56 | // fp16 x 4 57 | eModifiedVertexDirectionsBuffer = 3, 58 | 59 | // 1 x fp16 60 | // used by remesher 61 | eModifiedVertexImportanceBuffer = 5, 62 | eMeshAccel = 6, 63 | eInputImportanceMap = 7 64 | END_BINDING(); 65 | // clang-format on 66 | -------------------------------------------------------------------------------- /meshops_remesher/shaders/hash_functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | 12 | uint wangHash(uint seed) 13 | { 14 | seed = (seed ^ 61) ^ (seed >> 16); 15 | seed *= 9; 16 | seed = seed ^ (seed >> 4); 17 | seed *= 0x27d4eb2d; 18 | seed = seed ^ (seed >> 15); 19 | return seed; 20 | } 21 | 22 | uint xorshift32(uint x64) 23 | { 24 | x64 ^= x64 << 13; 25 | x64 ^= x64 >> 7; 26 | x64 ^= x64 << 17; 27 | return x64; 28 | } 29 | 30 | 31 | #define ADD_HASH(type_, components_, conversion_) \ 32 | uvec2 addHash(uvec2 h, type_ val) \ 33 | { \ 34 | for(uint i = 0; i < components_; i++) \ 35 | { \ 36 | h = uvec2(wangHash(h.x + conversion_(val[i])), xorshift32(h.y + conversion_(val[i]))); \ 37 | } \ 38 | return h; \ 39 | } 40 | #define ADD_HASH1(type_, conversion_) \ 41 | uvec2 addHash(uvec2 h, type_ val) \ 42 | { \ 43 | return uvec2(wangHash(h.x + conversion_(val)), xorshift32(h.y + conversion_(val))); \ 44 | } 45 | 46 | ADD_HASH(uvec2, 2, uint) 47 | ADD_HASH1(float, floatBitsToUint) 48 | ADD_HASH1(uint, uint) 49 | ADD_HASH(vec2, 2, floatBitsToUint) 50 | ADD_HASH(vec3, 3, floatBitsToUint) 51 | ADD_HASH(vec4, 4, floatBitsToUint) 52 | -------------------------------------------------------------------------------- /meshops_remesher/shaders/remeshing_host_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | #ifndef __cplusplus 12 | #include "octant_encoding.h" 13 | #endif 14 | 15 | #define REMESHER_BLOCK_SIZE 256 16 | 17 | // clang-format off 18 | #ifdef __cplusplus // Descriptor binding helper for C++ and GLSL 19 | #define START_BINDING(a) enum a { 20 | #define END_BINDING() } 21 | #define INLINE inline 22 | #else 23 | #define START_BINDING(a) const uint 24 | #define END_BINDING() 25 | #define INLINE 26 | #endif 27 | 28 | #define START_ENUM(a) START_BINDING(a) 29 | #define END_ENUM() END_BINDING() 30 | 31 | #ifndef __cplusplus 32 | #define CopyDirection uint 33 | #endif 34 | 35 | struct VertexCopyConstants 36 | { 37 | uint itemCount; 38 | 39 | uint useTexCoord; 40 | uint useTangent; 41 | uint useNormal; 42 | uint useDirection; 43 | 44 | uint texcoordCount; 45 | uint texcoordIndex; 46 | 47 | }; 48 | 49 | struct VertexMergeConstants 50 | { 51 | uint useTexCoord; 52 | uint useTangent; 53 | uint useNormal; 54 | uint useDirection; 55 | uint texcoordCount; 56 | uint texcoordIndex; 57 | uint fitToOriginalSurface; 58 | }; 59 | 60 | 61 | START_BINDING(VertexKernelBindings) 62 | 63 | 64 | // fp32 x 3 + octant normal (snorm16x2) 65 | eModifiedVertexPositionNormalBuffer = 0, 66 | 67 | // 2 x octant normal (snorm16x2) 68 | eModifiedVertexTangentSpaceBuffer = 1, 69 | 70 | // n x fp32 x 2 71 | eModifiedVertexTexcoordBuffer = 2, 72 | 73 | // fp16 x 4 74 | eModifiedVertexDirectionsBuffer = 3, 75 | // fp32 x 2 76 | eModifiedVertexDirectionBoundsBuffer = 4, 77 | 78 | // 1 x fp16 79 | // used by remesher 80 | eModifiedVertexImportanceBuffer = 5, 81 | 82 | // 2 x uint per-vertex 83 | eGpuRemeshingMeshVertexHashBuffer = 6, 84 | 85 | eGpuRemeshingMeshVertexMergeBuffer = 7, 86 | eGpuRemeshingCurrentStateBuffer = 8 87 | 88 | END_BINDING(); 89 | 90 | 91 | #define COMPACTION_BLOCK_SIZE 1024 92 | #define COMPACTION_ENTRIES_PER_THREAD_0 4 93 | #define COMPACTION_ENTRIES_PER_THREAD_1 4 94 | #define COMPACTION_ENTRIES_PER_THREAD_2 4 95 | 96 | START_BINDING(CompactionBindings) 97 | eData = 0, 98 | eInvalidEntry = 1, 99 | eBlockState = 2, 100 | eAuxBuffer = 3, 101 | eGlobalCounter = 4 102 | END_BINDING(); 103 | // clang-format on 104 | struct CompactionConstants 105 | { 106 | uint entryCount; 107 | uint entrySize; 108 | uint mode; 109 | }; 110 | struct GlobalCounters 111 | { 112 | uint validEntries; 113 | uint currentInvalidEntry; 114 | uint currentValidEntry; 115 | }; 116 | -------------------------------------------------------------------------------- /micromesh_python/README.md: -------------------------------------------------------------------------------- 1 | # micromesh_python 2 | 3 | `micromesh_python` is a Python module for processing and baking micromeshes. 4 | Uses may include content creation plugins or creating customized asset 5 | pipelines. The GUI, [`micromesh_toolkit`](../README.md#micromesh-toolkit), and 6 | [`micromesh_tool`](../README.md#micromesh-tool) are good for exploring 7 | micromaps visually or in command line environment. 8 | 9 | Building this module requires an active Python 3 environment and Pybind11 -- point cmake variable `PYBIND11_LOCATION` to root of pybind11 header installation while configuring. If both Python3 and Pybind11 are found then CMake will configure the micromesh_python project to build the bindings. 10 | 11 | There is a [`Jupyter Notebook`](/micromesh_python/notebook/micromesh.ipynb) as an example of how to create assets compatible with micro-mesh technology using the `micromesh_python` module. Features briefly covered include: 12 | 13 | - **pretessellate** - Tessellates a mesh to match the heightmap resolution. 14 | - **bake** - Creates an NVIDIA displacement micromap given a low-resolution mesh and high-resolution mesh, heightmap, or both. 15 | - **resample** - Resamples textures to be compatible with resulting micro-mesh. 16 | - **displace** - Tessellates and displaces a mesh with micromap displacement. 17 | - **remesh** - Decimates a triangle mesh, optimizing for micromap friendly 18 | geometry. 19 | - **save** - Save the displacement micromap data out to a .bary file for future use. 20 | 21 | The notebook can be run locally. After building this repository, you can run `/micromesh_python/install_jupyter.cmd` to install Jupyter Lab, and then `/micromesh_python/start_jupyter.cmd` to launch the Jupyter server and automatically load the notebook in a browser. The notebook contains cells to install (and uninstall) dependencies, as well as downloading assets not distributed with this repository. -------------------------------------------------------------------------------- /micromesh_python/all-deps.packman.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /micromesh_python/install_jupyterlab.cmd.in: -------------------------------------------------------------------------------- 1 | @PYTHON_EXE@ -m pip install jupyterlab numpy numba py7zr -------------------------------------------------------------------------------- /micromesh_python/notebook/crab.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/micromesh_python/notebook/crab.jpg -------------------------------------------------------------------------------- /micromesh_python/notebook/microdisplacement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/micromesh_python/notebook/microdisplacement.png -------------------------------------------------------------------------------- /micromesh_python/notebook/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .assets import * 2 | from .mesh import * 3 | -------------------------------------------------------------------------------- /micromesh_python/notebook/utils/assets.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import urllib.parse 3 | from pathlib import Path 4 | import py7zr 5 | 6 | def fetch_url(url : str, filepath : Path, force : bool) -> bool: 7 | if filepath.is_file() and not force: 8 | print(f'{filepath} exists, skipping download') 9 | return True 10 | print(f'Fetching {url}...') 11 | result = requests.get(url) 12 | if result.status_code == 200: 13 | with open(str(filepath), 'wb') as file: 14 | print(f'Writing {filepath}') 15 | file.write(result.content) 16 | return True 17 | print(f'Error fetching remote file') 18 | return False 19 | 20 | def fetch_and_extract(url : str, download_path : str, extract_path : str, force : bool = False): 21 | download_path = Path(download_path) 22 | if not download_path.is_dir(): 23 | download_path.mkdir() 24 | 25 | download_filepath = Path(download_path / Path(urllib.parse.urlparse(url).path).name).resolve() 26 | extract_path = Path(extract_path).resolve() 27 | if fetch_url(url, download_filepath, force): 28 | if extract_path.is_dir() and not force: 29 | print(f'{extract_path} exists, skipping extraction') 30 | return True 31 | with py7zr.SevenZipFile(str(download_filepath), mode='r') as archive: 32 | print(f'Extracting {archive.getnames()}...') 33 | archive.extractall(path=str(extract_path)) 34 | return True 35 | return False 36 | -------------------------------------------------------------------------------- /micromesh_python/package.py.in: -------------------------------------------------------------------------------- 1 | from importlib.machinery import SourceFileLoader 2 | 3 | pm = SourceFileLoader("pm", "@CMAKE_CURRENT_BINARY_DIR@/packman-packager/packman_packager.py").load_module() 4 | 5 | artifacts = [ 6 | pm.PackagedArtifact("@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.@MODULE_EXT@", dest="."), 7 | pm.PackagedArtifact("@CMAKE_CURRENT_BINARY_DIR@/nvMicromesh", dest="./nvMicromesh") 8 | ] 9 | version_list = str("@MICROMESH_PYTHON_VERSION@").split(".", 2) 10 | packager = pm.Packager( 11 | package_name="micromesh-python", 12 | version=pm.Version(version_list[0], version_list[1], version_list[2]), 13 | platform="@PYTHON_VERSION@.@BUILD_PLATFORM@.@BUILD_TYPE@", 14 | artifacts=artifacts 15 | ) 16 | packager.run() 17 | -------------------------------------------------------------------------------- /micromesh_python/python.cmd.in: -------------------------------------------------------------------------------- 1 | @SET_ENV_CMD@ PYTHONPATH=@PYTHON_PATH@ 2 | @SET_ENV_CMD@ @LIBRARY_PATH_SETTING@ 3 | @PYTHON_EXE_ARGS@ -------------------------------------------------------------------------------- /micromesh_python/schema/api.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2017 Pixar 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "Apache License") 5 | // with the following modification; you may not use this file except in 6 | // compliance with the Apache License and the following modification to it: 7 | // Section 6. Trademarks. is deleted and replaced with: 8 | // 9 | // 6. Trademarks. This License does not grant permission to use the trade 10 | // names, trademarks, service marks, or product names of the Licensor 11 | // and its affiliates, except as required to comply with Section 4(c) of 12 | // the License and to reproduce the content of the NOTICE file. 13 | // 14 | // You may obtain a copy of the Apache License at 15 | // 16 | // http://www.apache.org/licenses/LICENSE-2.0 17 | // 18 | // Unless required by applicable law or agreed to in writing, software 19 | // distributed under the Apache License with the above modification is 20 | // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 | // KIND, either express or implied. See the Apache License for the specific 22 | // language governing permissions and limitations under the Apache License. 23 | // 24 | #ifndef NVMICROMESH_API_H 25 | #define NVMICROMESH_API_H 26 | 27 | #include "pxr/base/arch/export.h" 28 | 29 | #if defined(PXR_STATIC) 30 | # define NVMICROMESH_API 31 | # define NVMICROMESH_API_TEMPLATE_CLASS(...) 32 | # define NVMICROMESH_API_TEMPLATE_STRUCT(...) 33 | # define NVMICROMESH_LOCAL 34 | #else 35 | # if defined(NVMICROMESH_EXPORTS) 36 | # define NVMICROMESH_API ARCH_EXPORT 37 | # define NVMICROMESH_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__) 38 | # define NVMICROMESH_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__) 39 | # else 40 | # define NVMICROMESH_API ARCH_IMPORT 41 | # define NVMICROMESH_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__) 42 | # define NVMICROMESH_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__) 43 | # endif 44 | # define NVMICROMESH_LOCAL ARCH_HIDDEN 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /micromesh_python/schema/module.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2016 Pixar 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "Apache License") 5 | // with the following modification; you may not use this file except in 6 | // compliance with the Apache License and the following modification to it: 7 | // Section 6. Trademarks. is deleted and replaced with: 8 | // 9 | // 6. Trademarks. This License does not grant permission to use the trade 10 | // names, trademarks, service marks, or product names of the Licensor 11 | // and its affiliates, except as required to comply with Section 4(c) of 12 | // the License and to reproduce the content of the NOTICE file. 13 | // 14 | // You may obtain a copy of the Apache License at 15 | // 16 | // http://www.apache.org/licenses/LICENSE-2.0 17 | // 18 | // Unless required by applicable law or agreed to in writing, software 19 | // distributed under the Apache License with the above modification is 20 | // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 | // KIND, either express or implied. See the Apache License for the specific 22 | // language governing permissions and limitations under the Apache License. 23 | // 24 | #include "boost/python.hpp" 25 | #include "pxr/base/tf/pyModule.h" 26 | #include "pxr/pxr.h" 27 | 28 | PXR_NAMESPACE_USING_DIRECTIVE 29 | 30 | TF_WRAP_MODULE 31 | { 32 | // wrap any types you want exposed to python here 33 | TF_WRAP(NvMicromeshDisplacementMicromapAPI); 34 | } 35 | -------------------------------------------------------------------------------- /micromesh_python/schema/nvMicromesh/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 NVIDIA CORPORATION 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | import os 15 | 16 | from pxr import Plug, Tf, UsdGeom 17 | 18 | plugin_root = os.path.join(os.path.dirname(__file__), "resources") 19 | Plug.Registry().RegisterPlugins(plugin_root) 20 | 21 | # PreparePythonModule didn't make it's way into USD 22 | # until 21.08 - older versions import the module 23 | # manually and call PrepareModule 24 | if hasattr(Tf, "PreparePythonModule"): 25 | Tf.PreparePythonModule() 26 | else: 27 | from . import _nvMicromesh 28 | Tf.PrepareModule(_nvMicromesh, locals()) 29 | 30 | try: 31 | import __DOC 32 | 33 | __DOC.Execute(locals()) 34 | del __DOC 35 | except Exception: 36 | try: 37 | import __tmpDoc 38 | 39 | __tmpDoc.Execute(locals()) 40 | del __tmpDoc 41 | except: 42 | pass 43 | 44 | del Plug 45 | del Tf 46 | del UsdGeom 47 | -------------------------------------------------------------------------------- /micromesh_python/schema/nvMicromesh/resources/plugInfo_linux-x86_64.json: -------------------------------------------------------------------------------- 1 | { 2 | "Plugins": [ 3 | { 4 | "Info": { 5 | "Types": { 6 | "NvMicromeshDisplacementMicromapAPI": { 7 | "alias": { 8 | "UsdSchemaBase": "DisplacementMicromapAPI" 9 | }, 10 | "autoGenerated": true, 11 | "bases": [ 12 | "UsdAPISchemaBase" 13 | ], 14 | "schemaKind": "singleApplyAPI" 15 | } 16 | } 17 | }, 18 | "LibraryPath": "./libnvMicromesh.so", 19 | "Name": "nvMicromesh", 20 | "ResourcePath": "resources", 21 | "Root": "..", 22 | "Type": "library" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /micromesh_python/schema/nvMicromesh/resources/plugInfo_windows-x86_64.json: -------------------------------------------------------------------------------- 1 | { 2 | "Plugins": [ 3 | { 4 | "Info": { 5 | "Types": { 6 | "NvMicromeshDisplacementMicromapAPI": { 7 | "alias": { 8 | "UsdSchemaBase": "DisplacementMicromapAPI" 9 | }, 10 | "autoGenerated": true, 11 | "bases": [ 12 | "UsdAPISchemaBase" 13 | ], 14 | "schemaKind": "singleApplyAPI" 15 | } 16 | } 17 | }, 18 | "LibraryPath": "./nvMicromesh.dll", 19 | "Name": "nvMicromesh", 20 | "ResourcePath": "resources", 21 | "Root": "..", 22 | "Type": "library" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /micromesh_python/schema/plugInfo.json: -------------------------------------------------------------------------------- 1 | # Portions of this file auto-generated by usdGenSchema. 2 | # Edits will survive regeneration except for comments and 3 | # changes to types with autoGenerated=true. 4 | { 5 | "Plugins": [ 6 | { 7 | "Info": { 8 | "Types": { 9 | "NvMicromeshDisplacementMicromapAPI": { 10 | "alias": { 11 | "UsdSchemaBase": "DisplacementMicromapAPI" 12 | }, 13 | "autoGenerated": true, 14 | "bases": [ 15 | "UsdAPISchemaBase" 16 | ], 17 | "schemaKind": "singleApplyAPI" 18 | } 19 | } 20 | }, 21 | "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@", 22 | "Name": "nvMicromesh", 23 | "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@", 24 | "Root": "@PLUG_INFO_ROOT@", 25 | "Type": "library" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /micromesh_python/schema/schema.usda: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | ( 3 | subLayers = [ 4 | @usd/schema.usda@ 5 | ] 6 | ) 7 | 8 | over "GLOBAL" ( 9 | customData = { 10 | string libraryName = "nvMicromesh" 11 | string libraryPath = "." 12 | string libraryPrefix = "NvMicromesh" 13 | bool skipCodeGeneration = false 14 | } 15 | ) { 16 | } 17 | 18 | class "DisplacementMicromapAPI" ( 19 | inherits = 20 | customData = { 21 | token apiSchemaType = "singleApply" 22 | string className = "DisplacementMicromapAPI" 23 | } 24 | doc = """DisplacementMicromapAPI Schema""" 25 | ) 26 | { 27 | uint primvars:micromesh:version(doc = "") 28 | bool primvars:micromesh:compressed(doc = "true if micromap dat is compressed") 29 | float primvars:micromesh:floatScale(doc = "global scale") 30 | float primvars:micromesh:floatBias(doc = "global bias") 31 | uint primvars:micromesh:minSubdivLevel(doc = "minimum subdivision level in the micromap") 32 | uint primvars:micromesh:maxSubdivLevel(doc = "maximum subdivision level in the micromap") 33 | float3[] primvars:micromesh:directions(doc = "per-vertex displacement directions") 34 | float2[] primvars:micromesh:directionBounds(doc = "per-vertex displacement direction bounds") 35 | 36 | uint primvars:micromesh:triangleMappingsFormat(doc = "") 37 | uint primvars:micromesh:triangleMappingsCount(doc = "") 38 | uint primvars:micromesh:triangleMappingsByteSize(doc = "") 39 | uchar[] primvars:micromesh:triangleMappings(doc = "maps triangle ID to base primitive (unpack per format)") 40 | 41 | uint primvars:micromesh:valueLayout(doc = "") 42 | uint primvars:micromesh:valueFrequency(doc = "") 43 | uint primvars:micromesh:valueFormat(doc = "") 44 | uint primvars:micromesh:valueCount(doc = "") 45 | uint primvars:micromesh:valueByteSize(doc = "") 46 | uchar[] primvars:micromesh:values(doc = "per-vertex displacement values") 47 | 48 | uint primvars:micromesh:triangleFlagsFormat(doc = "") 49 | uint primvars:micromesh:triangleFlagsCount(doc = "") 50 | uint primvars:micromesh:triangleFlagsByteSize(doc = "") 51 | uchar[] primvars:micromesh:triangleFlags(doc = "per-triangle edge flags") 52 | 53 | uint[] primvars:micromesh:triangleValueOffsets(doc = "") 54 | uint[] primvars:micromesh:triangleSubdivLevels(doc = "") 55 | uint[] primvars:micromesh:triangleBlockFormats(doc = "") 56 | 57 | uint[] primvars:micromesh:histogramCounts(doc = "required for compressed data") 58 | uint[] primvars:micromesh:histogramSubdivLevels(doc = "required for compressed data") 59 | uint[] primvars:micromesh:histogramBlockFormats(doc = "required for compressed data") 60 | 61 | uint primvars:micromesh:triangleMinMaxsFormat(doc = "optional") 62 | uint primvars:micromesh:triangleMinMaxsCount(doc = "optional") 63 | uint primvars:micromesh:triangleMinMaxsByteSize(doc = "optional") 64 | uchar[] primvars:micromesh:triangleMinMaxs(doc = "optional") 65 | 66 | asset primvars:micromesh:quaternionMap(doc = "quaternion map texture") 67 | asset primvars:micromesh:offsetMap(doc = "offset map texture") 68 | } 69 | -------------------------------------------------------------------------------- /micromesh_python/start_jupyterlab.cmd.in: -------------------------------------------------------------------------------- 1 | @SET_ENV_CMD@ PYTHONPATH=@PYTHON_PATH@ 2 | @SET_ENV_CMD@ @LIBRARY_PATH_SETTING@ 3 | @PYTHON_EXE@ -m jupyterlab --notebook-dir=@CMAKE_CURRENT_SOURCE_DIR@/notebook @CMAKE_CURRENT_SOURCE_DIR@/notebook/micromesh.ipynb 4 | -------------------------------------------------------------------------------- /micromesh_tool/README.md: -------------------------------------------------------------------------------- 1 | # micromesh_tool 2 | 3 | `micromesh_tool` is a command line utility for processing and baking 4 | micromeshes. The GUI, [`micromesh_toolkit`](../README.md#micromesh-toolkit), is 5 | good for exploring micromaps visually. **glTF** is the only file format 6 | currently supported. Operations can be joined without having to write 7 | intermediate results, by chaining multiple commands wrapped in curly braces, 8 | e.g. `{ operation --args ... }`. 9 | 10 | Input and output top level arguments are required: 11 | 12 | - `--input ` 13 | - `--output ` 14 | 15 | It can be useful to enable `--verbose` to see more context for errors as 16 | operations run. 17 | 18 | The operations are: 19 | 20 | - **generate** - Creates test meshes with textures. Use displacedtessellate to 21 | create real geometry from meshes with heightmaps. `--input` is not required 22 | when using generate. 23 | - **pretessellate** - Tessellates a mesh to match the heightmap resolution plus 24 | a `--subdivLevelBias`. Useful when a mesh is too coarse for baking. 25 | - **bake** - Creates an NVIDIA displacement micromap. Takes a base triangle mesh 26 | and computes distances needed to tessellate and displace it to match a 27 | reference mesh (--high). The result is written to a .bary file, referenced by 28 | the .gltf scene. Baking requires `VK_KHR_acceleration_structure` support. 29 | - **displacedtessellate** - Tessellates and displaces a mesh with bary or 30 | heightmap displacement. 31 | - **remesh** - Decimates a triangle mesh, optimizing for micromap friendly 32 | geometry. 33 | - **optimize** - Trims and compresses displacement data to save space and 34 | improve performance 35 | - **merge** - Merges multiple glTF files into one, with support for micromesh 36 | extensions. 37 | - **print** - Prints a summary of the current scene data. Useful for inspecting 38 | intermediate pipeline state without writing the file to disk. 39 | 40 | The **bake** operation takes two meshes as an argument. The base mesh is the 41 | current scene in the pipeline. The reference mesh (typically with much more 42 | detail) can be referenced with `--high `. If the **remesh** operation 43 | appears before **bake**, a copy of the scene is made before remeshing and passed 44 | to **bake** in place of `--high`. 45 | 46 | If the destination path is different from the source, textures will be copied 47 | there. 48 | -------------------------------------------------------------------------------- /micromesh_tool/include/tool_context.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace micromesh_tool { 20 | 21 | // Class to hold common resources to all tools. This avoids redundant 22 | // construction costs for things such as the vulkan context. 23 | class ToolContext 24 | { 25 | public: 26 | ToolContext(const meshops::ContextConfig& config); 27 | ToolContext(const meshops::ContextConfig& config, const meshops::ContextVK& sharedContextVK); 28 | ~ToolContext() { meshops::meshopsContextDestroy(m_meshopsContext); } 29 | 30 | bool valid() const { return m_createResult == micromesh::Result::eSuccess; } 31 | 32 | meshops::Context& meshopsContext() { return m_meshopsContext; } 33 | meshops::ContextVK* meshopsContextVK() { return meshops::meshopsContextGetVK(m_meshopsContext); } 34 | 35 | // Disable copying 36 | ToolContext(const ToolContext& other) = delete; 37 | ToolContext& operator=(const ToolContext& other) = delete; 38 | 39 | private: 40 | meshops::Context m_meshopsContext; 41 | micromesh::Result m_createResult = micromesh::Result::eFailure; 42 | }; 43 | 44 | } // namespace micromesh_tool 45 | -------------------------------------------------------------------------------- /micromesh_tool/include/tool_displacedtessellate.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | // TODO: use public meshops API for attrib generation 21 | #include 22 | 23 | namespace tinygltf { 24 | class Model; 25 | } 26 | 27 | namespace tool_tessellate { 28 | 29 | struct ToolDisplacedTessellateArgs 30 | { 31 | std::string basePath; // base path for .bary files and heightmaps 32 | bool heightmaps{true}; 33 | int heightmapTessBias{0}; 34 | bool heightmapDirectionsGen = false; 35 | NormalReduceOp heightmapDirectionsOp = NormalReduceOp::eNormalReduceNormalizedLinear; 36 | float heightmapBias{0.0f}; 37 | float heightmapScale{1.0f}; 38 | bool heightmapPNtriangles = false; 39 | }; 40 | 41 | bool toolDisplacedTessellateParse(int argc, char** argv, ToolDisplacedTessellateArgs& args, std::ostream& os = std::cerr); 42 | bool toolDisplacedTessellate(micromesh_tool::ToolContext& context, 43 | const ToolDisplacedTessellateArgs& args, 44 | std::unique_ptr& scene); 45 | 46 | void toolDisplacedTessellateAddRequirements(meshops::ContextConfig& contextConfig); 47 | } // namespace tool_tessellate 48 | -------------------------------------------------------------------------------- /micromesh_tool/include/tool_generate.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace tool_generate { 21 | 22 | struct ToolGenerateArgs 23 | { 24 | enum Geometry 25 | { 26 | GEOMETRY_PLANE, 27 | GEOMETRY_CUBE, 28 | GEOMETRY_TERRAIN, 29 | GEOMETRY_SPHERE, 30 | GEOMETRY_ROCK, 31 | }; 32 | 33 | Geometry geometry = GEOMETRY_CUBE; 34 | uint32_t resolution = 128; 35 | }; 36 | 37 | bool toolGenerateParse(int argc, char** argv, ToolGenerateArgs& args); 38 | void toolGenerateAddRequirements(meshops::ContextConfig& contextConfig); 39 | bool toolGenerate(micromesh_tool::ToolContext& context, const ToolGenerateArgs& args, std::unique_ptr& scene); 40 | 41 | } // namespace tool_generate -------------------------------------------------------------------------------- /micromesh_tool/include/tool_merge.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | // Implementation of the merge tool. 16 | 17 | #include "tool_merge_args.hpp" 18 | #include 19 | 20 | namespace tool_merge { 21 | 22 | // Runs the merge tool. Returns whether it succeeded. 23 | bool toolMerge(const ToolMergeArgs& args, std::unique_ptr& scene); 24 | 25 | } // namespace tool_merge -------------------------------------------------------------------------------- /micromesh_tool/include/tool_merge_args.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | // Parser structures for the merge tool. 12 | #pragma once 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace tool_merge { 19 | 20 | struct ToolMergeArgs 21 | { 22 | std::vector inputs; // List of additional files to merge into the existing ToolScene 23 | }; 24 | 25 | // Parses a command-line into merge tool arguments. Returns true on success. 26 | bool toolMergeParse(int argc, char** argv, ToolMergeArgs& args, std::ostream& os); 27 | 28 | } // namespace tool_merge -------------------------------------------------------------------------------- /micromesh_tool/include/tool_optimize.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace tool_optimize { 21 | struct ToolOptimizeArgs 22 | { 23 | // Reduces the subdivision level of each triangle to at most this number. 24 | int trimSubdiv = 5; 25 | // Minimum Peak Signal-to-Noise Ratio in decibels for lossy compression. 26 | float psnr = 40.0; 27 | // validateEdges is true by default only in debug mode. 28 | bool validateEdges = 29 | #ifdef NDEBUG 30 | false; 31 | #else 32 | true; 33 | #endif 34 | }; 35 | 36 | bool toolOptimizeParse(int argc, char** argv, ToolOptimizeArgs& args, std::ostream& os = std::cerr); 37 | bool toolOptimize(micromesh_tool::ToolContext& context, const ToolOptimizeArgs& args, std::unique_ptr& scene); 38 | 39 | void toolOptimizeAddRequirements(meshops::ContextConfig& contextConfig); 40 | } // namespace tool_optimize 41 | -------------------------------------------------------------------------------- /micromesh_tool/include/tool_pretessellate.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace tool_tessellate { 21 | 22 | struct ToolPreTessellateArgs 23 | { 24 | uint32_t maxSubdivLevel = 0; // 0 == baryutils maximum 25 | int32_t subdivLevelBias = -5; 26 | bool matchUVArea = true; 27 | uint32_t heightmapWidth = 0; 28 | uint32_t heightmapHeight = 0; 29 | }; 30 | 31 | bool toolPreTessellateParse(int argc, char** argv, ToolPreTessellateArgs& args, std::ostream& os = std::cerr); 32 | bool toolPreTessellate(micromesh_tool::ToolContext& context, 33 | const ToolPreTessellateArgs& args, 34 | std::unique_ptr& scene); 35 | 36 | void toolPretessellateAddRequirements(meshops::ContextConfig& contextConfig); 37 | } // namespace tool_tessellate 38 | -------------------------------------------------------------------------------- /micromesh_tool/include/tool_remesh.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace tool_remesh { 21 | 22 | struct ToolRemeshArgs 23 | { 24 | float errorThreshold{100.f}; 25 | float curvaturePower{1.f}; 26 | float importanceWeight{200.f}; 27 | float curvatureMaxDist{0.05f}; 28 | float directionBoundsFactor{1.02f}; 29 | std::string curvatureMaxDistMode{"scenefraction"}; 30 | bool fitToOriginalSurface{true}; 31 | uint32_t maxSubdivLevel{5}; 32 | glm::ivec2 heightmapResolution{-1, -1}; 33 | uint32_t heightmapTexcoord{0}; // Texture coordinates used by the displacement map 34 | 35 | std::string importanceMap; // Input filename of the optional importance map 36 | uint32_t importanceTexcoord{0}; // Texture coordinates to use with the importance map 37 | 38 | float decimationRatio{0.1f}; 39 | uint32_t maxVertexValence{20}; 40 | float importanceThreshold{1.f}; 41 | bool ignoreTexCoords{false}; 42 | bool ignoreNormals{false}; 43 | bool ignoreTangents{false}; 44 | bool ignoreDisplacementDirections{false}; 45 | bool disableMicromeshData{false}; 46 | uint32_t remeshMinTriangles{0}; // Only remesh meshes with at least this many triangles 47 | }; 48 | 49 | bool toolRemeshParse(int argc, char** argv, ToolRemeshArgs& args, std::ostream& os = std::cerr); 50 | void toolRemeshSanitizeArgs(ToolRemeshArgs& args); 51 | void toolRemeshAddRequirements(meshops::ContextConfig& contextConfig); 52 | bool toolRemesh(micromesh_tool::ToolContext& context, const ToolRemeshArgs& args, std::unique_ptr& scene); 53 | 54 | } // namespace tool_remesh 55 | -------------------------------------------------------------------------------- /micromesh_tool/src/tinygltf_impl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #ifdef _MSC_VER 14 | #pragma warning(disable : 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen 15 | #endif 16 | 17 | #define TINYGLTF_IMPLEMENTATION 18 | #define TINYGLTF_NO_EXTERNAL_IMAGE 19 | #define TINYGLTF_NO_INCLUDE_STB_IMAGE // Include nvpro_core's stb_image instead of tinygltf's 20 | #define TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE 21 | #include "third_party/stb/stb_image.h" 22 | #include "third_party/stb/stb_image_write.h" 23 | #include "tiny_gltf.h" 24 | 25 | #define TINYOBJLOADER_IMPLEMENTATION 26 | #include "tiny_obj_loader.h" 27 | 28 | #define VMA_IMPLEMENTATION 29 | #include "nvvk/memallocator_vma_vk.hpp" 30 | -------------------------------------------------------------------------------- /micromesh_tool/src/tool_context.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include 14 | 15 | namespace micromesh_tool { 16 | 17 | ToolContext::ToolContext(const meshops::ContextConfig& config) 18 | { 19 | m_createResult = meshops::meshopsContextCreate(config, &m_meshopsContext); 20 | if(m_createResult != micromesh::Result::eSuccess) 21 | { 22 | LOGE("Error: failed to create meshops context\n"); 23 | assert(!"meshopsContextCreate()"); 24 | } 25 | } 26 | ToolContext::ToolContext(const meshops::ContextConfig& config, const meshops::ContextVK& sharedContextVK) 27 | { 28 | m_createResult = meshops::meshopsContextCreateVK(config, sharedContextVK, &m_meshopsContext); 29 | if(m_createResult != micromesh::Result::eSuccess) 30 | { 31 | LOGE("Error: failed to create meshops context\n"); 32 | assert(!"meshopsContextCreate()"); 33 | } 34 | } 35 | 36 | } // namespace micromesh_tool -------------------------------------------------------------------------------- /micromesh_tool/src/tool_merge_args.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | #include "include/tool_merge_args.hpp" 12 | #include "nvh/nvprint.hpp" 13 | 14 | namespace tool_merge { 15 | 16 | void printHelp(std::ostream& os) 17 | { 18 | os << "merge: merges multiple glTF files into 1, with support for micromesh extensions." << std::endl; 19 | os << "Example usage: micromesh_tool --input input1.gltf --output output.gltf merge input2.gltf ... lastInput.gltf" << std::endl; 20 | } 21 | 22 | bool toolMergeParse(int argc, char** argv, ToolMergeArgs& args, std::ostream& os) 23 | { 24 | for(int i = 0; i < argc; i++) 25 | { 26 | const char* arg = argv[i]; 27 | if(strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) 28 | { 29 | printHelp(os); 30 | // TODO: add a way to gracefully print subcommand help text 31 | return false; 32 | } 33 | else 34 | { 35 | args.inputs.push_back(std::string(arg)); 36 | } 37 | } 38 | return true; 39 | } 40 | 41 | } // namespace tool_merge -------------------------------------------------------------------------------- /micromesh_tool/src/tool_version.h.in: -------------------------------------------------------------------------------- 1 | 2 | #define MICROMESH_TOOL_VERSION_MAJOR @micromesh_toolkit_VERSION_MAJOR@ 3 | #define MICROMESH_TOOL_VERSION_MINOR @micromesh_toolkit_VERSION_MINOR@ 4 | #define MICROMESH_TOOL_VERSION_STRING "@micromesh_toolkit_VERSION_MAJOR@.@micromesh_toolkit_VERSION_MINOR@" -------------------------------------------------------------------------------- /micromesh_toolbox/.gitignore: -------------------------------------------------------------------------------- 1 | /spv/* 2 | /build/* 3 | 4 | .vs/ 5 | */_autogen/ 6 | 7 | .obsidian/ 8 | -------------------------------------------------------------------------------- /micromesh_toolbox/README.md: -------------------------------------------------------------------------------- 1 | # Micromesh ToolBox 2 | 3 | `micromesh_toolbox` is a graphical workbench that allows inspecting micromeshes 4 | as well as interacting with some of the tools. Use it to visually explore mesh 5 | processing operations, bake and view meshes with displacement micromaps (that 6 | are stored in .bary files). glTF is currently the only file format supported. 7 | 8 | This application requires driver support for the `VK_NV_mesh_shader` extension. 9 | The `VK_NV_displacement_micromap` extension is required to see the displacement 10 | in raytracing mode. This extension will first ship with [NVIDIA Vulkan Beta 11 | drivers](https://developer.nvidia.com/vulkan-driver). Check the website's 12 | information for which drivers support it. This extension will be accelerated 13 | through special hardware features of the NVIDIA Ada Generation hardware. 14 | However, the extension will be available to previous hardware generations as 15 | well, albeit having slower ray-tracing performance. 16 | 17 | HDR environment maps are supported for rendering. See 18 | for some examples. 19 | 20 | > The rasterization within this application is primarily for visualization and 21 | not as efficient or feature rich as one that will be part of a future 22 | vk_displacement_micromaps sample. 23 | -------------------------------------------------------------------------------- /micromesh_toolbox/resources/micromesh_ico_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/micromesh_toolbox/resources/micromesh_ico_256.png -------------------------------------------------------------------------------- /micromesh_toolbox/resources/micromesh_ico_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/micromesh_toolbox/resources/micromesh_ico_32.png -------------------------------------------------------------------------------- /micromesh_toolbox/resources/micromesh_ico_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/micromesh_toolbox/resources/micromesh_ico_64.png -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/common_barymap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | // this file is included by C++ and GLSL 12 | 13 | #ifndef _COMMON_BARYMAP_H_ 14 | #define _COMMON_BARYMAP_H_ 15 | 16 | ////////////////////////////////////////////////////////////////////////// 17 | 18 | #ifdef __cplusplus 19 | namespace microdisp { 20 | using namespace nvmath; 21 | #endif 22 | 23 | 24 | //////////////////////////////////////////////////////////////////// 25 | // BaryMapData 26 | 27 | // meshlet configuration for pregenerated meshlets for each level 28 | #define MAX_BARYMAP_VERTICES 64 29 | #define MAX_BARYMAP_PRIMITIVES 64 30 | 31 | // Limit the current app to a sane upper bound. 32 | // Raising this can have consequences in number of bits required for offsets 33 | // in task shader output in dynamic lod scenario. 34 | // But also the data structure required for precalculated uv coords, 35 | // as well as other upper bounds. 36 | #define MAX_BARYMAP_LEVELS 8 37 | // 3 edge bits, up to 8 permutations 38 | #define MAX_BARYMAP_TOPOS 8 39 | 40 | //////////////////////////////////////////////////////////////////// 41 | // BaryMapMeshlet 42 | // 43 | // pre-computed meshlets, we render a single base-triangle 44 | // as sequence of these. 45 | 46 | struct BaryMapMeshlet 47 | { 48 | uint16_t numVertices; 49 | uint16_t numPrimitives; 50 | uint16_t offsetPrims; 51 | uint16_t offsetVertices; 52 | }; 53 | #ifndef __cplusplus 54 | layout(buffer_reference, buffer_reference_align = 4, scalar) restrict readonly buffer BaryMapMeshlet_in 55 | { 56 | BaryMapMeshlet d[]; 57 | }; 58 | #endif 59 | 60 | //////////////////////////////////////////////////////////////////// 61 | // BaryMapLevel 62 | // 63 | // pre-computed data for each subdivision level 64 | 65 | struct BaryMapLevel 66 | { 67 | BUFFER_REF(uints_in) coords; // micro vertex barycentric coords 68 | BUFFER_REF(BaryMapMeshlet_in) meshletHeaders; // micro triangles meshlet headers 69 | BUFFER_REF(uints_in) meshletData; // micro triangles meshlet data 70 | uint meshletCount; 71 | uint triangleCount; 72 | }; 73 | #ifndef __cplusplus 74 | layout(buffer_reference, buffer_reference_align = 16, scalar) restrict readonly buffer BaryMapLevel_in 75 | { 76 | BaryMapLevel d[]; 77 | }; 78 | #endif 79 | 80 | //////////////////////////////////////////////////////////////////// 81 | // BaryMapData 82 | // 83 | // contains multiple BaryMapLevels and accessors for uniform or 84 | // divergent access. 85 | 86 | struct BaryMapData 87 | { 88 | // barycentric lookup maps 89 | BaryMapLevel levelsUni[MAX_BARYMAP_LEVELS * MAX_BARYMAP_TOPOS]; // subgroup-uniform access 90 | BUFFER_REF(BaryMapLevel_in) levels; // divergent access (points to same data as above) 91 | }; 92 | 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | #endif 98 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/common_micromesh.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 4 | * 5 | * NVIDIA CORPORATION and its licensors retain all intellectual property 6 | * and proprietary rights in and to this software, related documentation 7 | * and any modifications thereto. Any use, reproduction, disclosure or 8 | * distribution of this software and related documentation without an express 9 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 10 | */ 11 | 12 | // this file is included by C++ and GLSL 13 | 14 | #ifndef _COMMON_MICROMESH_H_ 15 | #define _COMMON_MICROMESH_H_ 16 | 17 | #define MICRO_GROUP_SIZE SUBGROUP_SIZE 18 | #define MICRO_TRI_PER_TASK SUBGROUP_SIZE 19 | 20 | // how many groups per flat mesh shader invocations 21 | #define MICRO_FLAT_GROUPS 2 22 | 23 | #endif -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/dh_bindings.h: -------------------------------------------------------------------------------- 1 | #ifndef HD_BINDINGS_H 2 | #define HD_BINDINGS_H 3 | 4 | // clang-format off 5 | #ifdef __cplusplus // Descriptor binding helper for C++ and GLSL 6 | #define START_BINDING(a) enum a { 7 | #define END_BINDING() } 8 | #define INLINE inline 9 | #else 10 | #define START_BINDING(a) const uint 11 | #define END_BINDING() 12 | #define INLINE 13 | #endif 14 | 15 | 16 | START_BINDING(SceneBindings) 17 | eFrameInfo = 0, 18 | eSceneDesc = 1, 19 | eSceneDescTools = 2, 20 | eTextures = 3 21 | END_BINDING(); 22 | 23 | START_BINDING(RtxBindings) 24 | eTlas = 0, 25 | eOutImage = 1 26 | END_BINDING(); 27 | 28 | START_BINDING(DeferredBindings) 29 | eDeferredOutImage = 0, 30 | eDeferredData = 1 31 | END_BINDING(); 32 | 33 | START_BINDING(PostBindings) 34 | ePostImage = 0 35 | END_BINDING(); 36 | 37 | 38 | 39 | 40 | #endif // HD_BINDINGS_H 41 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/hbao_blur.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION.All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met : 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and / or other materials provided with the distribution. 12 | * * Neither the name of NVIDIA CORPORATION nor the names of its 13 | * contributors may be used to endorse or promote products derived 14 | * from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | * PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES( INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY 24 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #version 460 30 | #extension GL_GOOGLE_include_directive : enable 31 | #extension GL_EXT_control_flow_attributes : require 32 | 33 | #include "hbao.h" 34 | 35 | layout(binding = NVHBAO_MAIN_IMG_BLUR, rg16f) uniform image2D imgBlur; 36 | layout(binding = NVHBAO_MAIN_TEX_RESULT) uniform sampler2D texSource; 37 | 38 | #include "hbao_blur.glsl" 39 | 40 | //------------------------------------------------------------------------- 41 | 42 | void main() 43 | { 44 | ivec2 intCoord; 45 | vec2 texCoord; 46 | 47 | if(setupCoordFull(intCoord, texCoord)) 48 | return; 49 | 50 | vec2 res = BlurRun(texCoord); 51 | imageStore(imgBlur, intCoord, vec4(res, 0, 0)); 52 | } 53 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/hbao_blur.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION.All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met : 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and / or other materials provided with the distribution. 12 | * * Neither the name of NVIDIA CORPORATION nor the names of its 13 | * contributors may be used to endorse or promote products derived 14 | * from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | * PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES( INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY 24 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | layout(push_constant) uniform pushData 31 | { 32 | NVHBAOBlurPush blur; 33 | }; 34 | 35 | 36 | const float KERNEL_RADIUS = 3; 37 | 38 | //------------------------------------------------------------------------- 39 | 40 | float BlurFunction(vec2 uv, float r, float center_c, float center_d, inout float w_total) 41 | { 42 | vec2 aoz = texture(texSource, uv).xy; 43 | float c = aoz.x; 44 | float d = aoz.y; 45 | 46 | const float BlurSigma = float(KERNEL_RADIUS) * 0.5; 47 | const float BlurFalloff = 1.0 / (2.0 * BlurSigma * BlurSigma); 48 | 49 | float ddiff = (d - center_d) * blur.sharpness; 50 | float w = exp2(-r * r * BlurFalloff - ddiff * ddiff); 51 | w_total += w; 52 | 53 | return c * w; 54 | } 55 | 56 | vec2 BlurRun(vec2 texCoord) 57 | { 58 | vec2 aoz = texture(texSource, texCoord).xy; 59 | float center_c = aoz.x; 60 | float center_d = aoz.y; 61 | 62 | float c_total = center_c; 63 | float w_total = 1.0; 64 | 65 | [[unroll]] for(float r = 1; r <= KERNEL_RADIUS; ++r) 66 | { 67 | vec2 uv = texCoord + blur.invResolutionDirection * r; 68 | c_total += BlurFunction(uv, r, center_c, center_d, w_total); 69 | } 70 | 71 | [[unroll]] for(float r = 1; r <= KERNEL_RADIUS; ++r) 72 | { 73 | vec2 uv = texCoord - blur.invResolutionDirection * r; 74 | c_total += BlurFunction(uv, r, center_c, center_d, w_total); 75 | } 76 | 77 | return vec2(c_total / w_total, center_d); 78 | //return vec2(aoz); 79 | } 80 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/hbao_blur_apply.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION.All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met : 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and / or other materials provided with the distribution. 12 | * * Neither the name of NVIDIA CORPORATION nor the names of its 13 | * contributors may be used to endorse or promote products derived 14 | * from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | * PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES( INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY 24 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #version 460 30 | #extension GL_GOOGLE_include_directive : enable 31 | #extension GL_EXT_control_flow_attributes : require 32 | 33 | #include "hbao.h" 34 | 35 | layout(binding = NVHBAO_MAIN_IMG_OUT, rgba16f) uniform image2D imgOut; 36 | layout(binding = NVHBAO_MAIN_TEX_BLUR) uniform sampler2D texSource; 37 | 38 | #include "hbao_blur.glsl" 39 | 40 | //------------------------------------------------------------------------- 41 | 42 | 43 | void main() 44 | { 45 | ivec2 intCoord; 46 | vec2 texCoord; 47 | 48 | if(setupCoordFull(intCoord, texCoord)) 49 | return; 50 | 51 | vec2 res = BlurRun(texCoord); 52 | vec4 color = imageLoad(imgOut, intCoord); 53 | imageStore(imgOut, intCoord, color * res.x); 54 | } 55 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/hbao_deinterleave.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION.All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met : 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and / or other materials provided with the distribution. 12 | * * Neither the name of NVIDIA CORPORATION nor the names of its 13 | * contributors may be used to endorse or promote products derived 14 | * from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | * PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES( INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY 24 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #version 460 30 | #extension GL_GOOGLE_include_directive : enable 31 | #extension GL_EXT_control_flow_attributes : require 32 | 33 | #include "hbao.h" 34 | 35 | layout(binding = NVHBAO_MAIN_TEX_LINDEPTH) uniform sampler2D texLinearDepth; 36 | layout(binding = NVHBAO_MAIN_IMG_DEPTHARRAY, r32f) uniform image2DArray imgDepthArray; 37 | 38 | //---------------------------------------------------------------------------------- 39 | 40 | void outputColor(ivec2 intCoord, int layer, float value) 41 | { 42 | imageStore(imgDepthArray, ivec3(intCoord, layer), vec4(value, 0, 0, 0)); 43 | } 44 | 45 | void main() 46 | { 47 | ivec2 intCoord; 48 | vec2 texCoord; 49 | 50 | if(setupCoordQuarter(intCoord, texCoord)) 51 | return; 52 | 53 | vec2 uv = vec2(intCoord) * 4.0 + 0.5; 54 | uv *= control.InvFullResolution; 55 | 56 | vec4 S0 = textureGather(texLinearDepth, uv, 0); 57 | vec4 S1 = textureGatherOffset(texLinearDepth, uv, ivec2(2, 0), 0); 58 | vec4 S2 = textureGatherOffset(texLinearDepth, uv, ivec2(0, 2), 0); 59 | vec4 S3 = textureGatherOffset(texLinearDepth, uv, ivec2(2, 2), 0); 60 | 61 | outputColor(intCoord, 0, S0.w); 62 | outputColor(intCoord, 1, S0.z); 63 | outputColor(intCoord, 2, S1.w); 64 | outputColor(intCoord, 3, S1.z); 65 | outputColor(intCoord, 4, S0.x); 66 | outputColor(intCoord, 5, S0.y); 67 | outputColor(intCoord, 6, S1.x); 68 | outputColor(intCoord, 7, S1.y); 69 | 70 | outputColor(intCoord, 0 + 8, S2.w); 71 | outputColor(intCoord, 1 + 8, S2.z); 72 | outputColor(intCoord, 2 + 8, S3.w); 73 | outputColor(intCoord, 3 + 8, S3.z); 74 | outputColor(intCoord, 4 + 8, S2.x); 75 | outputColor(intCoord, 5 + 8, S2.y); 76 | outputColor(intCoord, 6 + 8, S3.x); 77 | outputColor(intCoord, 7 + 8, S3.y); 78 | } 79 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/hbao_reinterleave.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023 NVIDIA CORPORATION.All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met : 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and / or other materials provided with the distribution. 12 | * * Neither the name of NVIDIA CORPORATION nor the names of its 13 | * contributors may be used to endorse or promote products derived 14 | * from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | * PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES( INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY 24 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #version 460 30 | #extension GL_GOOGLE_include_directive : enable 31 | #extension GL_EXT_control_flow_attributes : require 32 | 33 | #include "hbao.h" 34 | 35 | layout(binding = NVHBAO_MAIN_TEX_RESULTARRAY) uniform sampler2DArray texResultsArray; 36 | #if NVHBAO_BLUR 37 | layout(binding = NVHBAO_MAIN_IMG_RESULT, rg16f) uniform image2D imgResult; 38 | #else 39 | layout(binding = NVHBAO_MAIN_IMG_RESULT, r8) uniform image2D imgResult; 40 | #endif 41 | 42 | //---------------------------------------------------------------------------------- 43 | 44 | void main() 45 | { 46 | ivec2 intCoord; 47 | vec2 texCoord; 48 | 49 | if(setupCoordFull(intCoord, texCoord)) 50 | return; 51 | 52 | ivec2 FullResPos = intCoord; 53 | ivec2 Offset = FullResPos & 3; 54 | int SliceId = Offset.y * 4 + Offset.x; 55 | ivec2 QuarterResPos = FullResPos >> 2; 56 | 57 | #if NVHBAO_BLUR 58 | imageStore(imgResult, intCoord, vec4(texelFetch(texResultsArray, ivec3(QuarterResPos, SliceId), 0).xy, 0, 0)); 59 | #else 60 | imageStore(imgResult, intCoord, vec4(texelFetch(texResultsArray, ivec3(QuarterResPos, SliceId), 0).x)); 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/hbao_viewnormal.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2023, NVIDIA CORPORATION.All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met : 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and / or other materials provided with the distribution. 12 | * * Neither the name of NVIDIA CORPORATION nor the names of its 13 | * contributors may be used to endorse or promote products derived 14 | * from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 | * PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES( INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY 24 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #version 460 30 | #extension GL_GOOGLE_include_directive : enable 31 | #extension GL_EXT_control_flow_attributes : require 32 | 33 | #include "hbao.h" 34 | 35 | layout(binding = NVHBAO_MAIN_TEX_LINDEPTH) uniform sampler2D texLinearDepth; 36 | layout(binding = NVHBAO_MAIN_IMG_VIEWNORMAL, rgba8) uniform image2D imgViewNormal; 37 | 38 | //---------------------------------------------------------------------------------- 39 | 40 | vec3 UVToView(vec2 uv, float eye_z) 41 | { 42 | return vec3((uv * control.projInfo.xy + control.projInfo.zw) * (control.projOrtho != 0 ? 1. : eye_z), eye_z); 43 | } 44 | 45 | vec3 FetchViewPos(vec2 UV) 46 | { 47 | float ViewDepth = textureLod(texLinearDepth, UV, 0).x; 48 | return UVToView(UV, ViewDepth); 49 | } 50 | 51 | vec3 MinDiff(vec3 P, vec3 Pr, vec3 Pl) 52 | { 53 | vec3 V1 = Pr - P; 54 | vec3 V2 = P - Pl; 55 | return (dot(V1, V1) < dot(V2, V2)) ? V1 : V2; 56 | } 57 | 58 | vec3 ReconstructNormal(vec2 UV, vec3 P) 59 | { 60 | vec3 Pr = FetchViewPos(UV + vec2(control.InvFullResolution.x, 0)); 61 | vec3 Pl = FetchViewPos(UV + vec2(-control.InvFullResolution.x, 0)); 62 | vec3 Pt = FetchViewPos(UV + vec2(0, control.InvFullResolution.y)); 63 | vec3 Pb = FetchViewPos(UV + vec2(0, -control.InvFullResolution.y)); 64 | return normalize(cross(MinDiff(P, Pr, Pl), MinDiff(P, Pt, Pb))); 65 | } 66 | 67 | //---------------------------------------------------------------------------------- 68 | 69 | void main() 70 | { 71 | ivec2 intCoord; 72 | vec2 texCoord; 73 | 74 | if(setupCoordFull(intCoord, texCoord)) 75 | return; 76 | 77 | vec3 P = FetchViewPos(texCoord); 78 | vec3 N = ReconstructNormal(texCoord, P); 79 | 80 | imageStore(imgViewNormal, intCoord, vec4(N * 0.5 + 0.5, 0)); 81 | } 82 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/hit_state.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HIT_STATE_H 3 | #define HIT_STATE_H 4 | 5 | //----------------------------------------------------------------------- 6 | // Hit state information 7 | struct HitState 8 | { 9 | vec3 pos; 10 | vec3 nrm; 11 | vec3 geonrm; 12 | vec2 uv; 13 | vec3 tangent; 14 | vec3 bitangent; 15 | }; 16 | 17 | #endif // HIT_STATE_H -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/micromesh_decoder_config.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | /* 12 | * NOTE: This file's content is based on older versions of code in 13 | * https://github.com/nvpro-samples/vk_displacement_micromaps. Please 14 | * follow micromesh rasterization examples there instead. 15 | */ 16 | 17 | /////////////////////////////////////////////////////////////// 18 | // public api 19 | 20 | struct MicroDecoderConfig 21 | { 22 | // baseTriID or subTriID 23 | // depending on decoder type 24 | uint microID; 25 | 26 | // only for base-triangle based decoder 27 | uint subTriangleIndex; 28 | 29 | // a micromesh may need multiple parts to be decoded, each part has a maximum of 30 | // MICRO_PART_MAX_PRIMITIVES triangles (64) and 31 | // MICRO_PART_MAX_VERTICES vertices (45) 32 | uint partID; 33 | // subdivision resolution of the part being decoded [0,3] 34 | uint partSubdiv; 35 | 36 | // target subdivision [0, microSubdiv] 37 | uint targetSubdiv; 38 | 39 | // When multiple decoder states are packed within a subgroup 40 | // packID is the unique identifier for each such state. 41 | // Each pack will use packThreads many threads, and packThreadID 42 | // specifies which thread is calling the function. 43 | // packThreads * packID + packThreadID < SUBGROUP_SIZE 44 | 45 | uint packID; 46 | uint packThreads; 47 | uint packThreadID; 48 | 49 | // decoder could be invalid 50 | // if subgroup contains some that are not 51 | // supposed to participate 52 | bool valid; 53 | }; 54 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/micromesh_loader.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | /* 12 | * NOTE: This file's content is based on older versions of code in 13 | * https://github.com/nvpro-samples/vk_displacement_micromaps. Please 14 | * follow micromesh rasterization examples there instead. 15 | */ 16 | 17 | // separated to ease integration with other renderers/apis 18 | 19 | // flat renderers need to pull per-mesh data from local pointers 20 | 21 | #ifndef mesh_microdata 22 | #define mesh_microdata microdata 23 | #endif 24 | 25 | uint microdata_loadDistance(uint idx) 26 | { 27 | return mesh_microdata.distances.d[idx]; 28 | } 29 | 30 | uvec2 microdata_loadDistance2(uint idx) 31 | { 32 | uvec2s_in distances64 = uvec2s_in(mesh_microdata.distances); 33 | return distances64.d[idx]; 34 | } 35 | 36 | uint microdata_loadMipDistance(uint idx) 37 | { 38 | return mesh_microdata.mipDistances.d[idx]; 39 | } 40 | 41 | uint microdata_loadFormatInfo(uint formatIdx, uint decodeSubdiv) 42 | { 43 | return uint(mesh_microdata.formats.d[formatIdx].width_start[decodeSubdiv]); 44 | } 45 | 46 | #if MICRO_DECODER == MICRO_DECODER_BASETRI_MIP_SHUFFLE 47 | MicromeshBTriVertex 48 | #elif MICRO_DECODER == MICRO_DECODER_MICROTRI_THREAD 49 | MicromeshMTriVertex 50 | #else 51 | MicromeshSTriVertex 52 | #endif 53 | microdata_loadMicromeshVertex(uint idx) 54 | { 55 | return mesh_microdata.vertices.d[idx]; 56 | } 57 | #if MICRO_DECODER == MICRO_DECODER_BASETRI_MIP_SHUFFLE 58 | MicromeshBTriDescend 59 | #elif MICRO_DECODER == MICRO_DECODER_MICROTRI_THREAD 60 | MicromeshMTriDescend 61 | #else 62 | MicromeshSTriDescend 63 | #endif 64 | microdata_loadMicromeshDescend(uint idx) 65 | { 66 | return mesh_microdata.descendInfos.d[idx]; 67 | } 68 | 69 | uint microdata_loadTriangleIndices(uint idx) 70 | { 71 | return mesh_microdata.triangleIndices.d[idx]; 72 | } -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/pathtrace.rmiss: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 460 14 | #extension GL_EXT_ray_tracing : require 15 | #extension GL_GOOGLE_include_directive : enable 16 | 17 | #include "payload.glsl" 18 | #include "nvvkhl/shaders/constants.glsl" 19 | 20 | layout(location = 0) rayPayloadInEXT HitPayload payload; 21 | 22 | void main() 23 | { 24 | payload.hitT = INFINITE; 25 | } 26 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/payload.glsl: -------------------------------------------------------------------------------- 1 | #ifndef PAYLOAD_H 2 | #define PAYLOAD_H 3 | 4 | precision highp float; 5 | 6 | #include "hit_state.h" 7 | 8 | struct HitPayload 9 | { 10 | uint seed; 11 | float hitT; 12 | int instanceIndex; 13 | HitState hit; 14 | bool micromesh; 15 | }; 16 | 17 | #endif // PAYLOAD_H -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/pbr_mat_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION 17 | * SPDX-License-Identifier: Apache-2.0 18 | */ 19 | 20 | #ifndef PBR_MAT_STRUCT_H 21 | #define PBR_MAT_STRUCT_H 1 22 | 23 | struct PbrMaterial 24 | { 25 | vec4 albedo; 26 | float roughness; 27 | float metallic; 28 | vec3 normal; 29 | vec3 emissive; 30 | vec3 f0; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/raster.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 450 14 | #extension GL_EXT_nonuniform_qualifier : enable 15 | #extension GL_GOOGLE_include_directive : enable 16 | #extension GL_EXT_scalar_block_layout : enable 17 | #extension GL_EXT_shader_explicit_arithmetic_types_int8 : enable 18 | #extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable 19 | #extension GL_EXT_shader_explicit_arithmetic_types_int64 : require 20 | #extension GL_EXT_shader_explicit_arithmetic_types : enable 21 | #extension GL_EXT_buffer_reference2 : require 22 | #extension GL_NV_fragment_shader_barycentric : enable 23 | #extension GL_EXT_debug_printf : enable 24 | 25 | // clang-format off 26 | // Incoming 27 | layout(location = 0) in Interpolants { 28 | vec3 pos; 29 | } IN; 30 | 31 | // Outgoing 32 | layout(location = 0) out vec4 outColor; 33 | 34 | #include "raster_common.glsl" 35 | 36 | void main() 37 | { 38 | GltfShadeMaterial gltfMat; 39 | DeviceMeshInfo pinfo; 40 | TriangleAttribute triInfo; 41 | HitState hit; // Interpolated Hit from vertex shader 42 | vec3 toEye; 43 | rasterLoad(IN.pos, gl_BaryCoordNV, gl_PrimitiveID, gltfMat, pinfo, triInfo, hit, toEye); 44 | outColor = rasterShade(gl_BaryCoordNV, gltfMat, pinfo, triInfo, hit, toEye, gl_PrimitiveID); 45 | } 46 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/raster.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 450 14 | #extension GL_ARB_separate_shader_objects : enable 15 | #extension GL_EXT_scalar_block_layout : enable 16 | #extension GL_GOOGLE_include_directive : enable 17 | 18 | #extension GL_EXT_shader_explicit_arithmetic_types_int64 : require 19 | #extension GL_EXT_buffer_reference2 : require 20 | 21 | #include "device_host.h" 22 | #include "dh_bindings.h" 23 | #include "octant_encoding.h" 24 | #include "dh_scn_desc.h" 25 | 26 | // clang-format off 27 | layout(buffer_reference, scalar) buffer InstancesInfo { InstanceInfo i[]; }; 28 | 29 | layout(set = 0, binding = eFrameInfo) uniform FrameInfo_ { FrameInfo frameInfo; }; 30 | layout(set = 0, binding = eSceneDescTools) readonly buffer SceneDesc_ { SceneDescription sceneDesc; } ; 31 | // clang-format on 32 | 33 | layout(push_constant) uniform RasterPushConstant_ 34 | { 35 | PushConstant pc; 36 | }; 37 | 38 | layout(location = 0) in vec4 i_pos; 39 | 40 | 41 | layout(location = 0) out Interpolants 42 | { 43 | vec3 pos; 44 | } 45 | OUT; 46 | 47 | out gl_PerVertex 48 | { 49 | vec4 gl_Position; 50 | }; 51 | 52 | 53 | void main() 54 | { 55 | InstancesInfo instances = InstancesInfo(sceneDesc.instInfoAddress); 56 | InstanceInfo instinfo = instances.i[pc.instanceID]; 57 | 58 | vec3 origin = vec3(frameInfo.viewInv * vec4(0, 0, 0, 1)); 59 | vec3 position = i_pos.xyz; 60 | 61 | OUT.pos = vec3(instinfo.objectToWorld * vec4(position, 1.0)); 62 | 63 | gl_Position = frameInfo.proj * frameInfo.view * vec4(OUT.pos, 1.0); 64 | } 65 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/raster_anisotropy.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #ifndef RASTER_ANISOTROPY 14 | #define RASTER_ANISOTROPY 15 | 16 | float anisotropyMetric(vec3 v0, vec3 v1, vec3 v2) 17 | { 18 | // Compute edge vectors between vertices. We'll catch NaNs at the end. 19 | const vec3 e01 = normalize(v0 - v1); 20 | const vec3 e02 = normalize(v0 - v2); 21 | const vec3 e12 = normalize(v1 - v2); 22 | 23 | // Get cosines of angles. This doesn't depend on the triangle's winding order. 24 | const float c0 = abs(dot(e01, e02)); // <-e01, -e02> 25 | const float c1 = abs(dot(e01, e12)); // 26 | const float c2 = abs(dot(e02, e12)); 27 | 28 | // const float bigM = acos(min(min(c0, c1), c2)); 29 | // const float ltlM = acos(max(max(c0, c1), c2)); 30 | 31 | // This denominator should always be at least 2pi/3. 32 | // const float e = (bigM - ltlM) / (bigM + ltlM); 33 | // Catch NaNs in case of undefined normalize behavior. If two vertices were 34 | // equal, the triangle's degenerate, so return 1. 35 | //return isnan(e) ? 1.0 : e; 36 | return smoothstep(0.85f, 1.0f, max(max(c0, c1), c2)); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/raster_overlay.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 450 14 | #extension GL_GOOGLE_include_directive : enable 15 | #extension GL_EXT_shader_explicit_arithmetic_types_int64 : require 16 | 17 | 18 | // Incoming 19 | layout(location = 0) in Interpolants 20 | { 21 | vec3 pos; 22 | } 23 | IN; 24 | 25 | // Outgoing 26 | layout(location = 0) out vec4 outColor; 27 | 28 | #include "device_host.h" 29 | #include "dh_bindings.h" 30 | #include "utility.h" 31 | 32 | layout(set = 0, binding = eFrameInfo) uniform FrameInfo_ 33 | { 34 | FrameInfo frameInfo; 35 | }; 36 | 37 | 38 | void main() 39 | { 40 | outColor = intColorToVec4(frameInfo.overlayColor); 41 | } 42 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/raster_shell.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 450 14 | #extension GL_EXT_nonuniform_qualifier : enable 15 | #extension GL_GOOGLE_include_directive : enable 16 | #extension GL_EXT_scalar_block_layout : enable 17 | #extension GL_EXT_shader_explicit_arithmetic_types_int8 : enable 18 | #extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable 19 | #extension GL_EXT_shader_explicit_arithmetic_types_int64 : require 20 | #extension GL_EXT_buffer_reference2 : require 21 | #extension GL_EXT_debug_printf : enable 22 | #extension GL_NV_fragment_shader_barycentric : enable 23 | 24 | // Outgoing 25 | layout(location = 0) out vec4 outColor; 26 | 27 | #include "device_host.h" 28 | #include "dh_bindings.h" 29 | #include "nvvkhl/shaders/dh_tonemap.h" 30 | 31 | layout(set = 0, binding = eFrameInfo) uniform FrameInfo_ 32 | { 33 | FrameInfo frameInfo; 34 | }; 35 | 36 | 37 | layout(location = 0) in Interpolants 38 | { 39 | float outerShell; 40 | } 41 | IN; 42 | 43 | 44 | void main() 45 | { 46 | outColor = vec4(toLinear(mix(vec3(0, 1, 1), vec3(1, 1, 0), IN.outerShell)), 1); 47 | } 48 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/raster_simple_phong.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #ifndef RASTER_SIMPLE_PHONG 14 | #define RASTER_SIMPLE_PHONG 15 | 16 | vec3 simplePhong(in vec3 toEye, in vec3 normal) 17 | { 18 | vec3 color = vec3(0.8); 19 | vec3 wUpDir = vec3(0, 1, 0); 20 | vec3 lightDir = toEye; 21 | vec3 eyeDir = toEye; 22 | 23 | vec3 reflDir = normalize(-reflect(lightDir, normal)); 24 | float lt = abs(dot(normal, lightDir)) + pow(max(0, dot(reflDir, eyeDir)), 16.0) * 0.3; // Diffuse + Specular 25 | color = color * (lt); 26 | color += mix(vec3(0.1, 0.1, 0.4), vec3(0.8, 0.6, 0.2), dot(normal, wUpDir.xyz) * 0.5 + 0.5) * 0.2; // Ambient term (sky effect) 27 | return toLinear(color); // Gamma correction 28 | } 29 | 30 | //----------------------------------------------------------------------- 31 | // This darkens the color when the normal is facing away 32 | vec4 simpleShade(in vec3 color, in float NdotL) 33 | { 34 | color = mix(color, vec3(1), vec3(0.15)); // makes everything brighter (washed out) 35 | color *= clamp(pow(max(NdotL, 0.2), 1.2) + 0.15, 0, 1); 36 | return vec4(toLinear(color), 1); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/raster_vectors.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 450 14 | #extension GL_EXT_nonuniform_qualifier : enable 15 | #extension GL_GOOGLE_include_directive : enable 16 | #extension GL_EXT_scalar_block_layout : enable 17 | #extension GL_EXT_shader_explicit_arithmetic_types_int8 : enable 18 | #extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable 19 | #extension GL_EXT_shader_explicit_arithmetic_types_int64 : require 20 | #extension GL_EXT_buffer_reference2 : require 21 | #extension GL_EXT_debug_printf : enable 22 | #extension GL_NV_fragment_shader_barycentric : enable 23 | 24 | // Outgoing 25 | layout(location = 0) out vec4 outColor; 26 | 27 | #include "device_host.h" 28 | #include "dh_bindings.h" 29 | #include "utility.h" 30 | 31 | 32 | layout(set = 0, binding = eFrameInfo) uniform FrameInfo_ 33 | { 34 | FrameInfo frameInfo; 35 | }; 36 | 37 | 38 | void main() 39 | { 40 | outColor = intColorToVec4(frameInfo.overlayColor); 41 | } 42 | -------------------------------------------------------------------------------- /micromesh_toolbox/shaders/utility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2019-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | 14 | #ifndef UTILITY_H 15 | #define UTILITY_H 16 | 17 | 18 | #define IM_COL32_R_SHIFT 0 19 | #define IM_COL32_G_SHIFT 8 20 | #define IM_COL32_B_SHIFT 16 21 | #define IM_COL32_A_SHIFT 24 22 | 23 | vec4 intColorToVec4(int rgba) 24 | { 25 | vec4 value; 26 | float sc = 1.0f / 255.0f; 27 | value.x = float((rgba >> IM_COL32_R_SHIFT) & 0xFF) * sc; 28 | value.y = float((rgba >> IM_COL32_G_SHIFT) & 0xFF) * sc; 29 | value.z = float((rgba >> IM_COL32_B_SHIFT) & 0xFF) * sc; 30 | value.w = float((rgba >> IM_COL32_A_SHIFT) & 0xFF) * sc; 31 | return value; 32 | } 33 | 34 | 35 | #endif -------------------------------------------------------------------------------- /micromesh_toolbox/src/micromap/micromesh_compressed_vk.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include "microdisp_shim.hpp" 16 | 17 | namespace microdisp { 18 | 19 | struct MicromeshCombinedData; 20 | 21 | // Meshlet data common between micromesh instances. 22 | struct MicromeshSplitPartsVk 23 | { 24 | RBuffer vertices; 25 | RBuffer descends; 26 | RBuffer triangleIndices; 27 | 28 | // init() with e.g. initSplitPartsSubTri() 29 | 30 | void deinit(ResourcesVK& res); 31 | }; 32 | 33 | struct MicromeshSetCompressedVK 34 | { 35 | RBuffer umajor2bmap; 36 | 37 | struct MeshData 38 | { 39 | // TODO: merge with BaryInfo struct 40 | RBuffer binding; 41 | MicromeshCombinedData* combinedData = nullptr; 42 | 43 | // Either base- or sub-triangle data is used and 44 | // never both. We kept separate variables 45 | // for clarity 46 | 47 | RBuffer baseTriangles; 48 | RBuffer baseSpheres; 49 | 50 | RBuffer subTriangles; 51 | RBuffer subSpheres; 52 | 53 | RBuffer distances; // compressed values buffer 54 | RBuffer mipDistances; 55 | 56 | RBuffer attrNormals; 57 | RBuffer attrTriangles; 58 | 59 | // just for visualization purposes not for rendering 60 | RBuffer baseTriangleMinMaxs; 61 | 62 | // either sub or base triangle count 63 | uint32_t microTriangleCount; 64 | 65 | // TODO: Make another struct, or merge just the following into DeviceMicromap 66 | //RBuffer baseTriangles; 67 | //RBuffer baseSpheres; 68 | //RBuffer baseTriangleMinMaxs; 69 | // Binding struct will also need a ref to 70 | //RBuffer distances; 71 | }; 72 | 73 | MicromeshSplitPartsVk* splitParts; 74 | 75 | std::vector meshDatas; 76 | 77 | bool hasBaseTriangles = false; 78 | bool usedFormats[uint32_t(bary::BlockFormatDispC1::eR11_unorm_lvl5_pack1024) + 1]; 79 | 80 | // creates buffers & uploads typical data that is agnostic of the specific 81 | // rasterization decoder chosen. 82 | // see various `micromesh_decoder_...` files for the full init sequence 83 | 84 | void initBasics(ResourcesVK& res, const bary::ContentView& bary, bool useBaseTriangles, bool useMips); 85 | 86 | // creates buffers & uploads micro vertex attribute normals 87 | void initAttributeNormals(ResourcesVK& res, const bary::ContentView& bary, uint32_t numThreads = 0); 88 | 89 | void deinit(ResourcesVK& res); 90 | 91 | // updates the state of `MeshData::combinedData` to retrieve most buffer addresses and store them 92 | // in the binding buffer 93 | void uploadMeshDatasBinding(nvvk::StagingMemoryManager* staging, VkCommandBuffer cmd, const MicromeshSplitPartsVk* splitParts); 94 | }; 95 | 96 | } // namespace microdisp -------------------------------------------------------------------------------- /micromesh_toolbox/src/micromap/micromesh_decoder_subtri_vk.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 3 | * 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property 5 | * and proprietary rights in and to this software, related documentation 6 | * and any modifications thereto. Any use, reproduction, disclosure or 7 | * distribution of this software and related documentation without an express 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "micromesh_compressed_vk.hpp" 14 | 15 | namespace microdisp { 16 | 17 | class MicroSplitParts; 18 | 19 | void initSplitPartsSubTri(ResourcesVK& res, MicromeshSplitPartsVk& splitParts); 20 | 21 | class MicromeshSubTriangleDecoderVK 22 | { 23 | public: 24 | MicromeshSubTriangleDecoderVK(const MicromeshSplitPartsVk& splitParts, MicromeshSetCompressedVK& microSet) 25 | : m_parts(splitParts) 26 | , m_micro(microSet) 27 | { 28 | } 29 | 30 | void init(ResourcesVK& res, 31 | const bary::ContentView& bary, 32 | const uint8_t* decimateEdgeFlags, 33 | uint32_t maxSubdivLevel, 34 | bool useBaseTriangles, 35 | bool withAttributes, 36 | uint32_t numThreads); 37 | 38 | private: 39 | friend class MicromeshMicroTriangleDecoderVK; 40 | 41 | const MicromeshSplitPartsVk& m_parts; 42 | MicromeshSetCompressedVK& m_micro; 43 | 44 | void uploadMicroSubTriangles(nvvk::StagingMemoryManager* staging, 45 | VkCommandBuffer cmd, 46 | const bary::ContentView& bary, 47 | const uint8_t* decimateEdgeFlags, 48 | uint32_t maxSubdivLevel, 49 | uint32_t numThreads); 50 | 51 | void uploadMicroBaseTriangles(nvvk::StagingMemoryManager* staging, 52 | VkCommandBuffer cmd, 53 | const bary::ContentView& bary, 54 | const uint8_t* decimateEdgeFlags, 55 | uint32_t maxSubdivLevel, 56 | uint32_t numThreads); 57 | }; 58 | 59 | } // namespace microdisp 60 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/tinygltf_impl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | 14 | #ifdef _MSC_VER 15 | #pragma warning(disable : 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen 16 | #endif 17 | 18 | #define TINYGLTF_IMPLEMENTATION 19 | #define TINYGLTF_NO_EXTERNAL_IMAGE 20 | #define TINYGLTF_NO_INCLUDE_STB_IMAGE // Include nvpro_core's stb_image instead of tinygltf's 21 | #define TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE 22 | #include "third_party/stb/stb_image.h" 23 | #include "third_party/stb/stb_image_write.h" 24 | #include "tiny_gltf.h" 25 | 26 | #define TINYOBJLOADER_IMPLEMENTATION 27 | #include "tiny_obj_loader.h" 28 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/toolbox_version.h.in: -------------------------------------------------------------------------------- 1 | 2 | #define MICROMESH_TOOLBOX_VERSION_MAJOR @micromesh_toolkit_VERSION_MAJOR@ 3 | #define MICROMESH_TOOLBOX_VERSION_MINOR @micromesh_toolkit_VERSION_MINOR@ 4 | #define MICROMESH_TOOLBOX_VERSION_STRING "@micromesh_toolkit_VERSION_MAJOR@.@micromesh_toolkit_VERSION_MINOR@" 5 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_about.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "ui_about.hpp" 14 | #include "imgui.h" 15 | #include "toolbox_version.h" 16 | 17 | void uiAbout(bool* p_open) 18 | { 19 | if(!*p_open) 20 | return; 21 | 22 | // Always center this window when appearing 23 | const ImVec2 win_size(500, 300); 24 | ImGui::SetNextWindowSize(win_size, ImGuiCond_Appearing); 25 | ImVec2 center = ImGui::GetMainViewport()->GetCenter(); 26 | ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); 27 | 28 | if(ImGui::Begin("About##NVIDIA", p_open, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse)) 29 | { 30 | ImGui::Text("NVIDIA Micro-Mesh ToolBox v" MICROMESH_TOOLBOX_VERSION_STRING); 31 | ImGui::Spacing(); 32 | ImGui::Text("https://github.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit"); 33 | ImGui::Spacing(); 34 | ImGui::TextWrapped( 35 | "micromesh_toolbox is a graphical workbench that allows inspecting micromeshes as well as interacting with " 36 | "some of the tools. It relies on VK_NV_mesh_shader to allow rasterized display of micromeshes. " 37 | "VK_KHR_acceleration_structure is required for baking micromaps. If available, VK_NV_displacement_micromap is " 38 | "used to render micromeshes with raytracing when choosing Rendering -> RTX. VK_NV_displacement_micromap was " 39 | "introduced with the RTX 40 Series Ada Lovelace architecture based GPUs. Previous RTX cards have support, but " 40 | "performance will be better with Ada. If you see a message about the missing extension, update to the latest " 41 | "driver (note: beta drivers are available at https://developer.nvidia.com/vulkan-driver)."); 42 | ImGui::End(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_about.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | void uiAbout(bool* p_open); 16 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_axis.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "imgui.h" 14 | #include "nvmath/nvmath.h" 15 | 16 | // The API 17 | namespace ImGuiH { 18 | 19 | IMGUI_API void Axis(ImVec2 pos, const nvmath::mat4f& modelView, float size = 20.f); 20 | 21 | }; // namespace ImGuiH 22 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_busy_window.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include "imgui.h" 17 | 18 | 19 | //-------------------------------------------------------------------------------------------------- 20 | // This function place a Popup window in the middle of the screen, blocking all inputs and is 21 | // use to show the application is busy doing something 22 | // 23 | inline void showBusyWindow(const std::string& busyReasonText) 24 | { 25 | static bool state_open = false; 26 | 27 | // Display a modal window when loading assets or other long operation on separated thread 28 | if(!state_open && !busyReasonText.empty()) 29 | { 30 | ImGui::OpenPopup("Busy Info"); 31 | state_open = true; 32 | } 33 | 34 | // Position in the center of the main window when appearing 35 | const ImVec2 win_size(300, 75); 36 | ImGui::SetNextWindowSize(win_size); 37 | const ImVec2 center = ImGui::GetMainViewport()->GetCenter(); 38 | ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5F, 0.5F)); 39 | 40 | // Window without any decoration 41 | ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 15.0); 42 | if(ImGui::BeginPopupModal("Busy Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration)) 43 | { 44 | if(busyReasonText.empty()) 45 | { 46 | ImGui::CloseCurrentPopup(); 47 | state_open = false; 48 | } 49 | else 50 | { 51 | 52 | // Center text in window 53 | const ImVec2 available = ImGui::GetContentRegionAvail(); 54 | const ImVec2 text_size = ImGui::CalcTextSize(busyReasonText.c_str(), nullptr, false, available.x); 55 | 56 | ImVec2 pos; 57 | pos.x = (available.x - text_size.x) * 0.5F; 58 | pos.y = (available.y - text_size.y) * 0.2F; 59 | 60 | ImGui::SetCursorPosX(pos.x); 61 | ImGui::Text("%s", busyReasonText.c_str()); 62 | 63 | // Add animation \ | / - 64 | ImGui::SetCursorPosX(available.x * 0.5F); 65 | ImGui::Text("%c", "|/-\\"[static_cast(ImGui::GetTime() / 0.25F) & 3]); 66 | } 67 | ImGui::EndPopup(); 68 | } 69 | ImGui::PopStyleVar(); 70 | } 71 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_displace_tessellate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "ui_micromesh_tools.hpp" 14 | 15 | 16 | void uiDisplaceTessalate(tool_tessellate::ToolDisplacedTessellateArgs& args, GLFWwindow* glfWin) 17 | { 18 | static const std::array reduce_names = {"Linear", "Normalized Linear", "Tangent"}; 19 | 20 | using PE = ImGuiH::PropertyEditor; 21 | 22 | if(ImGui::SmallButton("Reset##Displace")) 23 | args = {}; 24 | ImGuiH::tooltip("Reset values to default"); 25 | 26 | PE::begin(); 27 | 28 | std::string basePath; // base path for any heightmaps 29 | 30 | // #TODO: Should we expose the parameter to the user? 31 | //{ 32 | // PE::entry( 33 | // "Base Path", [&]() { return ImGuiH::InputText("##T1", &args.basePath, ImGuiInputTextFlags_None); }, 34 | // "Input of the heightmap"); 35 | // ImGuiH::LoadFileButtons(glfWin, args.basePath, "Load Heightmap", ImageFilter); 36 | //} 37 | 38 | // #TODO: This one seems unused 39 | // PE::entry("Heightmaps", [&] { return ImGui::Checkbox("##heightmaps", &args.heightmaps); }); 40 | PE::entry("Tessellation Bias", [&] { return ImGui::InputInt("##TessBias", (int*)&args.heightmapTessBias); }); 41 | PE::entry( 42 | "Generate Directions", [&] { return ImGui::Checkbox("##DirectionsGen", &args.heightmapDirectionsGen); }, 43 | "Computes smooth heightmap displacement direction vectors. Mesh normals are used otherwise."); 44 | ImGui::BeginDisabled(!args.heightmapDirectionsGen); 45 | PE::entry("Direction Generation Method", [&] { 46 | return ImGui::Combo("##Op", (int*)&args.heightmapDirectionsOp, reduce_names.data(), static_cast(reduce_names.size())); 47 | }); 48 | ImGuiH::tooltip( 49 | "Linear = angle-weighted average of adjacent face normals; Normalized Linear = average + normalize to unit " 50 | "length; Tangent = preserve sharp edges"); 51 | ImGui::EndDisabled(); 52 | PE::entry("Bias", [&] { return ImGui::SliderFloat("##heightmapBias", &args.heightmapBias, 0.0F, 1.0F); }); 53 | PE::entry("Scale", [&] { return ImGui::SliderFloat("##heightmapScale", &args.heightmapScale, 0.0F, 1.0F); }); 54 | PE::entry("PN Triangles", [&] { return ImGui::Checkbox("##heightmapPNtriangles", &args.heightmapPNtriangles); }); 55 | PE::end(); 56 | } 57 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_environment.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "ui_environment.hpp" 14 | #include "imgui/imgui_helper.h" 15 | #include "nvvkhl/hdr_env.hpp" 16 | #include "nvvkhl/sky.hpp" 17 | #include "toolbox_viewer.hpp" 18 | 19 | 20 | UiEnvironment::UiEnvironment(ToolboxViewer* v) 21 | : _v(v) 22 | { 23 | } 24 | 25 | bool UiEnvironment::onUI(ViewerSettings& settings) 26 | { 27 | ImGui::PushID("UiEnvironment"); 28 | 29 | using PE = ImGuiH::PropertyEditor; 30 | bool reset = false; 31 | 32 | const bool sky_only = !(_v->m_hdrEnv && _v->m_hdrEnv->isValid()); 33 | reset |= ImGui::RadioButton("Sky", reinterpret_cast(&settings.envSystem), ViewerSettings::eSky); 34 | ImGui::SameLine(); 35 | ImGui::BeginDisabled(sky_only); 36 | reset |= ImGui::RadioButton("Hdr", reinterpret_cast(&settings.envSystem), ViewerSettings::eHdr); 37 | ImGui::EndDisabled(); 38 | PE::begin(); 39 | if(PE::treeNode("Sky")) 40 | { 41 | reset |= _v->m_sky->onUI(); 42 | PE::treePop(); 43 | } 44 | ImGui::BeginDisabled(sky_only); 45 | if(PE::treeNode("Hdr")) 46 | { 47 | reset |= PE::entry( 48 | "Color", [&] { return ImGui::ColorEdit3("##Color", &settings.envColor.x, ImGuiColorEditFlags_Float); }, 49 | "Color multiplier"); 50 | 51 | reset |= PE::entry( 52 | "Rotation", [&] { return ImGui::SliderAngle("Rotation", &settings.envRotation); }, "Rotating the environment"); 53 | PE::treePop(); 54 | } 55 | ImGui::EndDisabled(); 56 | PE::end(); 57 | 58 | ImGui::PopID(); 59 | return reset; 60 | } 61 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_environment.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | class ToolboxViewer; 16 | struct ViewerSettings; 17 | 18 | class UiEnvironment 19 | { 20 | ToolboxViewer* _v; 21 | 22 | public: 23 | UiEnvironment(ToolboxViewer* v); 24 | 25 | bool onUI(ViewerSettings& settings); 26 | }; 27 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_micromesh_process.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | #include "settings.hpp" 15 | #include 16 | 17 | 18 | class ToolboxViewer; 19 | class ToolboxScene; 20 | 21 | 22 | /// 23 | /// Implementation of the UI setting dialog section of for Raster rendering 24 | /// 25 | class UiMicromeshProcess 26 | { 27 | ToolboxViewer* m_toolboxViewer; 28 | std::future m_toolOperation; 29 | std::future m_loadingScene; 30 | 31 | public: 32 | UiMicromeshProcess(ToolboxViewer* v) 33 | : m_toolboxViewer(v) 34 | { 35 | } 36 | bool onUI(); 37 | 38 | private: 39 | int loadSaveDelLine(std::string name, std::unique_ptr& tboxscene, ViewerSettings::RenderViewSlot view, bool& dispbaked); 40 | void runSourceToTarget(); 41 | void attributesOperations(std::unique_ptr& scene_base); 42 | }; 43 | 44 | /// 45 | /// Implementation of the UI setting dialog section of for Raster rendering 46 | /// 47 | class UiMicromeshProcessPipeline 48 | { 49 | ToolboxViewer* m_toolboxViewer; 50 | std::future m_toolOperation; 51 | std::future m_loadingScene; 52 | 53 | public: 54 | UiMicromeshProcessPipeline(ToolboxViewer* v) 55 | : m_toolboxViewer(v) 56 | { 57 | } 58 | bool onUI(); 59 | 60 | private: 61 | void loadLine(std::string name, ViewerSettings::RenderViewSlot view); 62 | bool toolHeader(const char* name, bool& use); 63 | void attributesOperations(std::unique_ptr& scene); 64 | }; 65 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_micromesh_tools.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include "imgui.h" 17 | #include "imgui/imgui_helper.h" 18 | #include "ui_widgets.hpp" 19 | #include "ui_utilities.hpp" 20 | 21 | #include "tool_bake.hpp" 22 | #include "tool_displacedtessellate.hpp" 23 | #include "tool_optimize.hpp" 24 | #include "tool_pretessellate.hpp" 25 | #include "tool_remesh.hpp" 26 | #include "settings.hpp" 27 | 28 | 29 | void uiBaker(tool_bake::ToolBakeArgs& bake_args, ViewerSettings::GlobalToolSettings& toolSettings, GLFWwindow* glfwWindow); 30 | void uiDisplaceTessalate(tool_tessellate::ToolDisplacedTessellateArgs& args, GLFWwindow* glfWin); 31 | void uiOptimizer(bool& use_optimizer, tool_optimize::ToolOptimizeArgs& args); 32 | void uiPretesselator(tool_tessellate::ToolPreTessellateArgs& args, ViewerSettings::GlobalToolSettings& toolSettings, GLFWwindow* glfWin); 33 | void uiRemesher(ViewerSettings::GlobalToolSettings& toolSettings, tool_remesh::ToolRemeshArgs& remesh_args); 34 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_optimizer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "ui_micromesh_tools.hpp" 14 | 15 | 16 | void uiOptimizer(bool& use_optimizer, tool_optimize::ToolOptimizeArgs& args) 17 | { 18 | using PE = ImGuiH::PropertyEditor; 19 | 20 | bool open_optim = ImGui::CollapsingHeader("Optimizer", ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_AllowItemOverlap); 21 | ImGui::SameLine(); 22 | ImGui::TableNextColumn(); 23 | PE::begin(); 24 | ImGuiH::ToggleButton("Optimizer", &use_optimizer); 25 | if(open_optim) 26 | { 27 | ImGui::BeginDisabled(!use_optimizer); 28 | 29 | PE::entry( 30 | "trimSubdiv", [&]() { return ImGui::InputInt("trimSubdiv", &args.trimSubdiv); }, 31 | "Reduces the subdivision level of each triangle to at most this number. Removes unused subdivision levels - " 32 | "like " 33 | "reducing the resolution of an image. (Default: 4)"); 34 | 35 | PE::entry( 36 | "Min PNSR", [&]() { return ImGui::InputFloat("minPNSR", &args.psnr); }, 37 | "Minimum Peak Signal-to-Noise Ratio in decibels for lossy compression. 20 is very low quality; 30 is low " 38 | "quality; 40 is normal quality; 50 is high quality. (Default: 40)"); 39 | 40 | PE::entry( 41 | "Validate Edges", [&]() { return ImGui::Checkbox("validateEdges", &args.validateEdges); }, 42 | "Validates that the input and output displacements are watertight. (Default: false)"); 43 | 44 | ImGui::EndDisabled(); 45 | } 46 | PE::end(); 47 | } 48 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_pretess.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "ui_micromesh_tools.hpp" 14 | 15 | 16 | void uiPretesselator(tool_tessellate::ToolPreTessellateArgs& args, ViewerSettings::GlobalToolSettings& toolSettings, GLFWwindow* glfWin) 17 | { 18 | if(ImGui::SmallButton("Reset##Pretess")) 19 | args = {}; 20 | ImGuiH::tooltip("Reset values to default"); 21 | 22 | using PE = ImGuiH::PropertyEditor; 23 | PE::begin(); 24 | PE::entry("Max Subdiv Level", [&] { return ImGui::SliderInt("##maxSubdivLevel", (int*)&args.maxSubdivLevel, 0, 15); }); 25 | ImGuiH::tooltip("A value of zero will be replaced with the internal maximum"); 26 | PE::entry("Bake Subdiv Bias", 27 | [&] { return ImGui::SliderInt("##subdivLevelBias", &toolSettings.pretessellateBias, -10, 10); }); 28 | ImGuiH::tooltip( 29 | "Use negative values to limit the tessellation. Visualize results with Rendering -> Shading -> Heightmap Texel " 30 | "Frequency."); 31 | PE::entry( 32 | "Pre-tessellate Bias", 33 | [&] { 34 | ImGui::Text("%i", args.subdivLevelBias); 35 | return false; 36 | }, 37 | "Offset from matching heightmap resolution. Typically negative. Driven by Bake Subdiv Level"); 38 | PE::entry("Match UV Area", [&] { return ImGui::Checkbox("##matchUVArea", &args.matchUVArea); }); 39 | PE::entry("Heightmap Width", [&] { return ImGui::InputInt("##heightmapWidth", (int*)&args.heightmapWidth); }); 40 | PE::entry("Heightmap Height", [&] { return ImGui::InputInt("##heightmapWidth", (int*)&args.heightmapHeight); }); 41 | 42 | PE::end(); 43 | } 44 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_raster.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | class ToolboxViewer; 16 | struct ViewerSettings; 17 | 18 | /// 19 | /// Implementation of the UI setting dialog section of for Raster rendering 20 | /// 21 | class UiRaster 22 | { 23 | ToolboxViewer* _v; 24 | 25 | public: 26 | UiRaster(ToolboxViewer* v); 27 | bool onUI(ViewerSettings& settings); 28 | }; 29 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_rendering.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | #include "settings.hpp" 15 | class ToolboxViewer; 16 | 17 | class UiRendering 18 | { 19 | ToolboxViewer* _v; 20 | 21 | public: 22 | UiRendering(ToolboxViewer* v); 23 | 24 | bool onUI(ViewerSettings& settings); 25 | 26 | private: 27 | void sceneWarnings(const ViewerSettings::RenderView& view); 28 | }; 29 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_statistics.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "imgui/imgui_helper.h" 14 | #include "ui_statistics.hpp" 15 | #include "tool_scene.hpp" 16 | 17 | 18 | bool UiStatistics::onUI(const micromesh_tool::ToolScene* scene) 19 | { 20 | using PE = ImGuiH::PropertyEditor; 21 | 22 | if(scene == nullptr) 23 | { 24 | ImGui::Text("No current scene"); 25 | return false; 26 | } 27 | 28 | uint64_t num_tri = 0; 29 | for(const auto& r : scene->meshes()) 30 | { 31 | num_tri += r->view().triangleCount(); 32 | } 33 | 34 | const bool clipboard = ImGui::Button("Copy to Clipboard"); 35 | if(clipboard) 36 | ImGui::LogToClipboard(); 37 | 38 | ImGui::PushID("Stat_Val"); 39 | const tinygltf::Model& tiny = scene->model(); 40 | PE::begin(); 41 | PE::entry("Instances", std::to_string(tiny.nodes.size())); 42 | PE::entry("Mesh", std::to_string(tiny.meshes.size())); 43 | PE::entry("Materials", std::to_string(tiny.materials.size())); 44 | PE::entry("Triangles", std::to_string(num_tri)); 45 | //PE::entry("Lights", std::to_string(gltf.m_lights.size())); 46 | PE::entry("Textures", std::to_string(tiny.textures.size())); 47 | PE::entry("Images", std::to_string(tiny.images.size())); 48 | PE::end(); 49 | ImGui::PopID(); 50 | 51 | if(clipboard) 52 | ImGui::LogFinish(); 53 | 54 | return false; 55 | } 56 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_statistics.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | namespace micromesh_tool { 16 | class ToolScene; 17 | } 18 | 19 | 20 | class UiStatistics 21 | { 22 | public: 23 | bool onUI(const micromesh_tool::ToolScene* scene); 24 | }; 25 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_utilities.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | #include 15 | #include "imgui.h" 16 | 17 | struct GLFWwindow; 18 | 19 | // This file contains ImGUI utility functions added for the toolbox project 20 | 21 | 22 | typedef int ImGuiHCol; // -> enum ImGuiHCol_ // Enum: A color identifier for styling 23 | 24 | enum ImGuiHCol_Button 25 | { 26 | ImGuiHCol_ButtonRed, 27 | ImGuiHCol_ButtonYellow, 28 | ImGuiHCol_ButtonGreen, 29 | ImGuiHCol_ButtonTurquoise, 30 | ImGuiHCol_ButtonBlue, 31 | ImGuiHCol_ButtonPurple, 32 | ImGuiHCol_ButtonPink, 33 | }; 34 | 35 | namespace ImGuiH { 36 | void PushButtonColor(ImGuiHCol c, float s = 1.0F, float v = 1.0F); 37 | void PopButtonColor(); 38 | 39 | bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr); 40 | 41 | bool LoadFileButtons(GLFWwindow* glfwin, std::string& result, const char* title, const char* exts); 42 | 43 | void ErrorMessageShow(const char* message); 44 | void ErrorMessageRender(); 45 | 46 | } // namespace ImGuiH 47 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_widgets.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "ui_widgets.hpp" 14 | 15 | 16 | void ImGuiH::ToggleButton(const char* str_id, bool* v) 17 | { 18 | float height = ImGui::GetFrameHeight(); 19 | float width = height * 1.55F; 20 | float radius = height * 0.50F; 21 | 22 | // Right-align the button 23 | ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - width); 24 | 25 | ImVec2 p = ImGui::GetCursorScreenPos(); 26 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 27 | 28 | ImGui::InvisibleButton(str_id, ImVec2(width, height)); 29 | if(ImGui::IsItemClicked()) 30 | *v = !*v; 31 | ImU32 col_bg; 32 | if(ImGui::IsItemHovered()) 33 | col_bg = *v ? IM_COL32(145 + 20, 211, 68 + 20, 255) : IM_COL32(218 - 20, 145 - 20, 145 - 20, 255); 34 | else 35 | col_bg = *v ? IM_COL32(145, 211, 68, 255) : IM_COL32(218, 145, 145, 255); 36 | 37 | draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.5F); 38 | draw_list->AddCircleFilled(ImVec2(*v ? (p.x + width - radius) : (p.x + radius), p.y + radius), radius - 1.5F, 39 | IM_COL32(255, 255, 255, 255)); 40 | } 41 | 42 | void ImGuiH::DownArrow(ImVec2 size) 43 | { 44 | float width = size.x; 45 | float height = size.y; 46 | 47 | ImGui::SetCursorPosX((ImGui::GetWindowContentRegionMax().x - width) / 2.0F); 48 | 49 | ImVec2 p = ImGui::GetCursorScreenPos(); 50 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 51 | 52 | // Advance the cursor 53 | ImGui::InvisibleButton("DownArrow", ImVec2(width, height * 2.0F)); 54 | 55 | ImU32 col_bg = IM_COL32(200, 200, 200, 255); 56 | draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height / 2.0F), col_bg, 0.0F); 57 | draw_list->AddTriangleFilled(ImVec2(p.x - width / 2.0F, p.y + height / 2.0F), 58 | ImVec2(p.x + width * 3.0F / 2.0F, p.y + height / 2.0F), 59 | ImVec2(p.x + width / 2.0F, p.y + height * 1.5F), col_bg); 60 | } 61 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/ui/ui_widgets.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "imgui.h" 14 | #pragma once 15 | 16 | namespace ImGuiH { 17 | 18 | void ToggleButton(const char* str_id, bool* v); 19 | void DownArrow(ImVec2 size); 20 | 21 | } // namespace ImGuiH 22 | -------------------------------------------------------------------------------- /micromesh_toolbox/src/vulkan_mutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "vulkan_mutex.h" 14 | 15 | static std::recursive_mutex m_vkQueueOrAllocatorMutex; 16 | 17 | std::unique_lock GetVkQueueOrAllocatorLock() noexcept 18 | { 19 | #pragma warning(push) 20 | // It looks like MSVC 16.11.13 doesn't quite figure out the lifetime of the 21 | // unique_lock here: 22 | #pragma warning(disable : 26115) 23 | return std::unique_lock(m_vkQueueOrAllocatorMutex); 24 | #pragma warning(pop) 25 | } -------------------------------------------------------------------------------- /micromesh_toolbox/thirdparty/aftermath_sdk/.gitignore: -------------------------------------------------------------------------------- 1 | include/ 2 | lib/ -------------------------------------------------------------------------------- /micromesh_toolbox/thirdparty/aftermath_sdk/_readme.txt: -------------------------------------------------------------------------------- 1 | Add here the latest Nsight Aftermath SDK 2 | - lib/ 3 | - include/ -------------------------------------------------------------------------------- /mini_samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | function(DefaultBasicMakefile) 3 | 4 | # Executable 5 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) 6 | message(STATUS "-------------------------------") 7 | message(STATUS "Processing Project ${PROJECT_NAME}") 8 | add_executable(${PROJECT_NAME}) 9 | 10 | # Sources for the project 11 | file(GLOB SOURCE_FILES src/*.cpp src/*.hpp src/*.h) 12 | target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES}) 13 | target_sources(${PROJECT_NAME} PRIVATE ${COMMON_SOURCE_FILES}) # Extra source from nvpro-core based on options 14 | target_sources(${PROJECT_NAME} PRIVATE ${PACKAGE_SOURCE_FILES}) # Extra source from nvpro-core based on options 15 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES}) 16 | source_group("Other" FILES ${COMMON_SOURCE_FILES} ${PACKAGE_SOURCE_FILES}) 17 | 18 | # Include paths 19 | target_include_directories(${PROJECT_NAME} PRIVATE ${SAMPLES_COMMON_DIR}) 20 | 21 | # Linking with other libraries 22 | target_link_libraries (${PROJECT_NAME} ${PLATFORM_LIBRARIES} ${LIBRARIES_OPTIMIZED}) 23 | target_link_libraries (${PROJECT_NAME} nvpro_core) 24 | 25 | # Compile definitions 26 | target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_NAME="${PROJECT_NAME}") 27 | 28 | # other properties 29 | set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Samples") 30 | 31 | 32 | # Shaders in project 33 | set(SHD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shaders) 34 | file(GLOB SHD_HDR ${SHD_DIR}/*.glsl ${SHD_DIR}/*.h) 35 | file(GLOB SHD_SRC ${SHD_DIR}/*.vert ${SHD_DIR}/*.frag ${SHD_DIR}/*.rgen ${SHD_DIR}/*.rchit ${SHD_DIR}/*.rmiss) 36 | 37 | # Compiling shaders to Spir-V header 38 | compile_glsl( 39 | SOURCE_FILES ${SHD_SRC} 40 | HEADER_FILES ${SHD_HDR} 41 | DST "${CMAKE_CURRENT_SOURCE_DIR}/_autogen" 42 | VULKAN_TARGET "vulkan1.2" 43 | HEADER ON 44 | DEPENDENCY ${VULKAN_BUILD_DEPENDENCIES} 45 | FLAGS "-I${SHD_DIR}" "-I${NVPRO_CORE_DIR}" -g 46 | ) 47 | 48 | target_sources(${PROJECT_NAME} PRIVATE ${GLSL_SOURCES} ${GLSL_HEADERS}) 49 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${GLSL_SOURCES} ${GLSL_HEADERS}) 50 | 51 | # Copy binary 52 | _finalize_target( ${PROJECT_NAME} ) 53 | 54 | endfunction() 55 | 56 | add_subdirectory(dmm_displacement) 57 | 58 | if(WIN32) 59 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/dx12_dmm_displacement") 60 | add_subdirectory(dx12_dmm_displacement) 61 | endif() 62 | endif() 63 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | DefaultBasicMakefile() 2 | 3 | # Get name 4 | get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) 5 | 6 | # Adding the micromesh prototype 7 | set(VULKAN_NV 8 | ${COMMON_DIR}/vulkan_nv/vk_nv_micromesh_prototypes.c 9 | ${COMMON_DIR}/vulkan_nv/vk_nv_micromesh_prototypes.h 10 | ) 11 | target_sources(${PROJECT_NAME} PRIVATE ${VULKAN_NV}) 12 | source_group(vulkan_nv FILES ${VULKAN_NV}) 13 | 14 | # Adding the dependency libraries 15 | target_link_libraries(${PROJECT_NAME} micromesh_core) 16 | target_link_libraries(${PROJECT_NAME} meshops_core) 17 | target_link_libraries(${PROJECT_NAME} micromesh_displacement_compression) 18 | 19 | # For array_view 20 | target_include_directories(${PROJECT_NAME} PRIVATE ${COMMON_DIR}) 21 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/docs/DisplacementPrismoidInputs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/mini_samples/dmm_displacement/docs/DisplacementPrismoidInputs.jpg -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/docs/EdgeDecimation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/mini_samples/dmm_displacement/docs/EdgeDecimation.jpg -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/docs/SubdivisionSchemeExamples.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/mini_samples/dmm_displacement/docs/SubdivisionSchemeExamples.jpg -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/docs/micromesh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/mini_samples/dmm_displacement/docs/micromesh.png -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/docs/micromesh_th.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NVIDIAGameWorks/Displacement-MicroMap-Toolkit/01e6024ec07d0e6dd51185c16228355236d07e64/mini_samples/dmm_displacement/docs/micromesh_th.jpg -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/shaders/device_host.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #ifndef HOST_DEVICE_H 14 | #define HOST_DEVICE_H 15 | 16 | #ifdef __cplusplus 17 | #include 18 | namespace shaders { 19 | using mat4 = nvmath::mat4f; 20 | using vec4 = nvmath::vec4f; 21 | using vec3 = nvmath::vec3f; 22 | using vec2 = nvmath::vec2f; 23 | #endif // __cplusplus 24 | 25 | 26 | struct PushConstant 27 | { 28 | float metallic; 29 | float roughness; 30 | float intensity; 31 | int maxDepth; 32 | int numBaseTriangles; 33 | }; 34 | 35 | 36 | struct FrameInfo 37 | { 38 | mat4 proj; 39 | mat4 view; 40 | mat4 projInv; 41 | mat4 viewInv; 42 | vec3 camPos; 43 | }; 44 | 45 | 46 | struct Light 47 | { 48 | vec3 position; 49 | float intensity; 50 | vec3 color; 51 | int type; 52 | }; 53 | 54 | // From primitive 55 | struct Vertex 56 | { 57 | vec3 position; 58 | vec3 normal; 59 | vec2 t; 60 | }; 61 | 62 | struct PrimMeshInfo 63 | { 64 | uint64_t vertexAddress; 65 | uint64_t indexAddress; 66 | }; 67 | 68 | struct InstanceInfo 69 | { 70 | mat4 transform; 71 | int materialID; 72 | }; 73 | 74 | struct SceneDescription 75 | { 76 | uint64_t materialAddress; 77 | uint64_t instInfoAddress; 78 | uint64_t primInfoAddress; 79 | }; 80 | 81 | struct GltfShadeMaterial 82 | { 83 | vec4 pbrBaseColorFactor; 84 | vec3 emissiveFactor; 85 | int pbrBaseColorTexture; 86 | 87 | int normalTexture; 88 | float normalTextureScale; 89 | int shadingModel; 90 | float pbrRoughnessFactor; 91 | 92 | float pbrMetallicFactor; 93 | int pbrMetallicRoughnessTexture; 94 | int khrSpecularGlossinessTexture; 95 | int khrDiffuseTexture; 96 | 97 | vec4 khrDiffuseFactor; 98 | vec3 khrSpecularFactor; 99 | float khrGlossinessFactor; 100 | 101 | int emissiveTexture; 102 | int alphaMode; 103 | float alphaCutoff; 104 | }; 105 | 106 | #ifdef __cplusplus 107 | } // namespace shaders 108 | #endif 109 | 110 | #endif // HOST_DEVICE_H 111 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/shaders/dh_bindings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #ifndef BINDINGS_H 14 | #define BINDINGS_H 15 | 16 | const int BRtTlas = 0; 17 | const int BRtOutImage = 1; 18 | const int BRtFrameInfo = 2; 19 | const int BRtSceneDesc = 3; 20 | const int BRtSkyParam = 4; 21 | 22 | #endif // !BINDINGS_H 23 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/shaders/pathtrace.rgen: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 460 14 | #extension GL_EXT_ray_tracing : require 15 | #extension GL_GOOGLE_include_directive : enable 16 | #extension GL_EXT_shader_explicit_arithmetic_types_int64 : require 17 | 18 | #include "device_host.h" 19 | #include "payload.h" 20 | #include "dh_bindings.h" 21 | #include "nvvkhl/shaders/random.glsl" 22 | #include "nvvkhl/shaders/constants.glsl" 23 | 24 | // clang-format off 25 | layout(location = 0) rayPayloadEXT HitPayload payload; 26 | 27 | layout(set = 0, binding = BRtTlas) uniform accelerationStructureEXT topLevelAS; 28 | layout(set = 0, binding = BRtOutImage, rgba32f) uniform image2D image; 29 | layout(set = 0, binding = BRtFrameInfo) uniform FrameInfo_ { FrameInfo frameInfo; }; 30 | // clang-format on 31 | 32 | layout(push_constant) uniform RtxPushConstant_ 33 | { 34 | PushConstant pc; 35 | }; 36 | 37 | 38 | void main() 39 | { 40 | payload = initPayload(); 41 | 42 | const vec2 pixelCenter = vec2(gl_LaunchIDEXT.xy); 43 | const vec2 inUV = pixelCenter / vec2(gl_LaunchSizeEXT.xy); 44 | const vec2 d = inUV * 2.0 - 1.0; 45 | 46 | const vec4 origin = frameInfo.viewInv * vec4(0.0, 0.0, 0.0, 1.0); 47 | const vec4 target = frameInfo.projInv * vec4(d.x, d.y, 0.01, 1.0); 48 | const vec4 direction = frameInfo.viewInv * vec4(normalize(target.xyz), 0.0); 49 | const uint rayFlags = gl_RayFlagsCullBackFacingTrianglesEXT; 50 | const float tMin = 0.001; 51 | const float tMax = INFINITE; 52 | 53 | traceRayEXT(topLevelAS, // acceleration structure 54 | rayFlags, // rayFlags 55 | 0xFF, // cullMask 56 | 0, // sbtRecordOffset 57 | 0, // sbtRecordStride 58 | 0, // missIndex 59 | origin.xyz, // ray origin 60 | tMin, // ray min range 61 | direction.xyz, // ray direction 62 | tMax, // ray max range 63 | 0 // payload (location = 0) 64 | ); 65 | 66 | imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(payload.color, 1.F)); 67 | } 68 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/shaders/pathtrace.rmiss: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #version 460 14 | #extension GL_EXT_ray_tracing : require 15 | #extension GL_GOOGLE_include_directive : enable 16 | #extension GL_EXT_shader_explicit_arithmetic_types_int64 : require 17 | 18 | #include "device_host.h" 19 | #include "payload.h" 20 | #include "dh_bindings.h" 21 | #include "nvvkhl/shaders/dh_sky.h" 22 | 23 | layout(location = 0) rayPayloadInEXT HitPayload payload; 24 | 25 | layout(set = 0, binding = BRtSkyParam) uniform SkyInfo_ 26 | { 27 | ProceduralSkyShaderParameters skyInfo; 28 | }; 29 | 30 | 31 | void main() 32 | { 33 | vec3 sky_color = proceduralSky(skyInfo, gl_WorldRayDirectionEXT, 0); 34 | payload.color += sky_color * payload.weight; 35 | payload.depth = MISS_DEPTH; // Stop 36 | } 37 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/shaders/payload.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #ifndef PAYLOAD_H 14 | #define PAYLOAD_H 15 | 16 | #ifdef __cplusplus 17 | #include 18 | namespace shaders { 19 | using vec3 = nvmath::vec3f; 20 | #endif // __cplusplus 21 | 22 | #define MISS_DEPTH 1000 23 | 24 | struct HitPayload 25 | { 26 | vec3 color; 27 | vec3 weight; 28 | int depth; 29 | }; 30 | 31 | HitPayload initPayload() 32 | { 33 | HitPayload p; 34 | p.color = vec3(0, 0, 0); 35 | p.depth = 0; 36 | p.weight = vec3(1); 37 | return p; 38 | } 39 | 40 | #ifdef __cplusplus 41 | } // namespace shaders 42 | #endif 43 | 44 | #endif // PAYLOAD_H 45 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/src/dmm_process.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include "nvvk/context_vk.hpp" 17 | #include "nvvk/resourceallocator_vk.hpp" 18 | #include "vulkan_nv/vk_nv_micromesh.h" 19 | #include "nvh/primitives.hpp" 20 | 21 | // Setting for the terrain generator 22 | struct Terrain 23 | { 24 | float seed{0.0F}; 25 | float freq{2.0F}; 26 | float power{2.0F}; 27 | int octave{4}; 28 | }; 29 | 30 | 31 | class MicromapProcess 32 | { 33 | 34 | public: 35 | MicromapProcess(nvvk::Context* ctx, nvvk::ResourceAllocator* allocator); 36 | ~MicromapProcess(); 37 | 38 | bool createMicromapData(VkCommandBuffer cmd, const nvh::PrimitiveMesh& mesh, uint16_t subdivLevel, const Terrain& terrain); 39 | void createMicromapBuffers(VkCommandBuffer cmd, const nvh::PrimitiveMesh& mesh, const nvmath::vec2f& biasScale); 40 | void cleanBuildData(); 41 | 42 | const nvvk::Buffer& primitiveFlags() { return m_primitiveFlags; } 43 | const nvvk::Buffer& displacementDirections() { return m_displacementDirections; } 44 | const nvvk::Buffer& displacementBiasAndScale() { return m_displacementBiasAndScale; } 45 | const VkMicromapEXT& micromap() { return m_micromap; } 46 | const std::vector& usages() { return m_usages; } 47 | 48 | private: 49 | struct MicromapData 50 | { 51 | std::vector values; 52 | std::vector triangles; 53 | std::vector usages; 54 | }; 55 | 56 | // Raw values per triangles 57 | struct RawTriangle 58 | { 59 | uint32_t subdivLevel{0}; 60 | std::vector values; 61 | }; 62 | 63 | struct MicroDistances 64 | { 65 | std::vector rawTriangles; 66 | }; 67 | 68 | 69 | bool buildMicromap(VkCommandBuffer cmd); 70 | static void barrier(VkCommandBuffer cmd); 71 | static MicroDistances createDisplacements(const nvh::PrimitiveMesh& mesh, uint16_t subdivLevel, const Terrain& terrain); 72 | static MicromapData prepareData(const nvh::PrimitiveMesh& mesh, uint32_t subdivLevel, const MicroDistances& inputValues); 73 | 74 | VkDevice m_device; 75 | nvvk::ResourceAllocator* m_alloc; 76 | 77 | nvvk::Buffer m_inputData; 78 | nvvk::Buffer m_microData; 79 | nvvk::Buffer m_trianglesBuffer; 80 | nvvk::Buffer m_primitiveFlags; 81 | nvvk::Buffer m_displacementDirections; 82 | nvvk::Buffer m_displacementBiasAndScale; 83 | nvvk::Buffer m_scratchBuffer; 84 | 85 | VkMicromapEXT m_micromap{VK_NULL_HANDLE}; 86 | std::vector m_usages; 87 | }; 88 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/src/nesting_scoped_timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #include "nesting_scoped_timer.hpp" 14 | 15 | 16 | thread_local size_t NestingScopedTimer::s_depth = 0; 17 | 18 | 19 | std::string NestingScopedTimer::indent() 20 | { 21 | size_t num = s_depth; 22 | std::string input = "| "; 23 | 24 | std::string ret; 25 | ret.reserve(input.size() * num); 26 | while(0 < num--) 27 | { 28 | ret += input; 29 | } 30 | 31 | return ret; 32 | } 33 | -------------------------------------------------------------------------------- /mini_samples/dmm_displacement/src/nesting_scoped_timer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 | * SPDX-License-Identifier: LicenseRef-NvidiaProprietary 4 | * 5 | * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual 6 | * property and proprietary rights in and to this material, related 7 | * documentation and any modifications thereto. Any use, reproduction, 8 | * disclosure or distribution of this material and related documentation 9 | * without an express license agreement from NVIDIA CORPORATION or 10 | * its affiliates is strictly prohibited. 11 | */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | #include "nvh/nvprint.hpp" 18 | #include "nvh/timesampler.hpp" 19 | 20 | //-------------------------------------------------------------------------------------------------- 21 | // Print the time a function takes and indent nested functions 22 | // 23 | struct NestingScopedTimer 24 | { 25 | explicit NestingScopedTimer(std::string str) 26 | : m_name(std::move(str)) 27 | { 28 | LOGI("%s%s:\n", indent().c_str(), m_name.c_str()); 29 | ++s_depth; 30 | } 31 | 32 | ~NestingScopedTimer() 33 | { 34 | --s_depth; 35 | LOGI("%s|-> (%.3f ms)\n", indent().c_str(), m_sw.elapsed()); 36 | } 37 | 38 | // Comment indented comments 39 | template 40 | void print(const char* fmt, Args... args) 41 | { 42 | LOGI("%s", indent().c_str()); 43 | nvprintf(fmt, args...); 44 | } 45 | 46 | static std::string indent(); 47 | 48 | std::string m_name; 49 | nvh::Stopwatch m_sw; 50 | static thread_local size_t s_depth; 51 | }; 52 | --------------------------------------------------------------------------------