Skip to content

Commit

Permalink
Tileset material nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jul 24, 2023
1 parent f57d02f commit 71a6594
Show file tree
Hide file tree
Showing 27 changed files with 877 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
Checks: "-*,bugprone-*,performance-*,modernize-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-bugprone-exception-escape"
Checks: "-*,bugprone-*,performance-*,modernize-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-bugprone-exception-escape,-modernize-pass-by-value"
WarningsAsErrors: "*"
FormatStyle: none
14 changes: 12 additions & 2 deletions apps/cesium.omniverse.dev.kit
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@ app = true
[dependencies]
# Include basic configuration (that brings most of basic extensions)
"omni.app.dev" = {}
"omni.kit.window.material_graph" = {}
"cesium.omniverse" = {}
"cesium.powertools" = {}
#"omni.example.ui" = {}
#"omni.kit.documentation.ui.style" = {}

[settings]
app.window.title = "Cesium for Omniverse Testing App"
app.useFabricSceneDelegate = true
app.useFabricSceneDelegate = false
app.usdrt.scene_delegate.enableProxyCubes = false
app.usdrt.scene_delegate.geometryStreaming.enabled = false
app.fastShutdown = true
# Both searchPaths settings must be set in order for material graph to find cesium mdl exports
renderer.mdl.searchPaths.custom = "${app}/../exts/cesium.omniverse/mdl"
materialConfig.searchPaths.custom = ["${app}/../exts/cesium.omniverse/mdl"]
materialConfig.materialGraph.userAllowList = ["cesium.mdl"]

[settings.app.exts]
folders.'++' = ["${app}/../exts"] # Make extensions from this repo available.
folders.'++' = [
"${app}", # Find other applications in this folder
"${app}/exts", # Find extensions in this folder
"${app}/../exts", # Find cesium.omniverse and cesium.usd.schemas
"${app}/../extern/nvidia/app/extscache" # Find omni.kit.window.material_graph
]
6 changes: 0 additions & 6 deletions apps/cesium.omniverse.dev.python.debug.kit
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@ app = true

[settings]
app.window.title = "Cesium For Omniverse Python Debugging App"

[settings.app.exts]
folders.'++' = [
"${app}",
"${app}/../exts"
]
6 changes: 0 additions & 6 deletions apps/cesium.omniverse.dev.trace.kit
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ app = true
[settings]
app.window.title = "Cesium For Omniverse Performance Tracing App"
app.fastShutdown = false

[settings.app.exts]
folders.'++' = [
"${app}",
"${app}/../exts"
]
7 changes: 0 additions & 7 deletions apps/cesium.performance.kit
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,3 @@ app = true

[settings]
app.window.title = "Cesium For Omniverse Performance Testing App"

[settings.app.exts]
folders.'++' = [
"${app}",
"${app}/exts",
"${app}/../exts"
]
8 changes: 8 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ if(exit_code AND NOT exit_code EQUAL 0)
endif()
# cmake-format: on

# Add a symlink to USD Composer (create) so that we can use its extensions (e.g. omni.kit.window.material_graph) in our internal applications
# Don't check for errors because we can still proceed with the build
if(UNIX)
execute_process(COMMAND bash "${PROJECT_SOURCE_DIR}/extern/nvidia/link_app.sh --app create")
elseif(WIN32)
execute_process(COMMAND cmd /C "${PROJECT_SOURCE_DIR}/extern/nvidia/link_app.bat --app create")
endif()

if(WIN32)
set(NVIDIA_PLATFORM_NAME "windows-x86_64")
elseif(UNIX AND NOT APPLE)
Expand Down
78 changes: 78 additions & 0 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
mdl 1.8;

import ::anno::*;
import ::state::*;
import ::tex::*;

using ::gltf::pbr import *;

module [[
anno::version( 1, 0, 0),
anno::display_name("Cesium MDL functions")
]];

export float2 world_coordinate_2d(float2 min_world_xy=float2(-5000.0,-5000.0), float2 max_world_xy=float2(5000.0,5000.0))
[[
anno::display_name("World Coordinate 2D"),
anno::description("Returns UV coordinates for mapping rasters to world space positions."),
anno::author("Cesium"),
anno::in_group("Cesium functions"),
anno::ui_order(300)
]]{
// Get the world pos of the pixel
float3 world_pos = state::transform_vector(state::coordinate_internal, state::coordinate_world, state::position());

// Return 0-1 UVs based on the min/max world coordinates provided
return float2(0.0,0.0) + (float2(world_pos.x, world_pos.y) - min_world_xy) * (float2(1.0, 1.0) - float2(0.0, 0.0)) / (max_world_xy - min_world_xy);
}

export float4 lookup_world_texture_float4(uniform texture_2d texture = texture_2d(), float2 min_world_xy=float2(-5000.0,-5000.0), float2 max_world_xy=float2(5000.0,5000.0))
[[
anno::display_name("World-mapped texture lookup float4"),
anno::description("Returns float4 from a texture mapped to world UV coordinates"),
anno::author("Cesium GS Inc."),
anno::in_group("Cesium functions"),
anno::ui_order(300)
]]
{
return tex::lookup_float4(
tex: texture,
coord: world_coordinate_2d(min_world_xy, max_world_xy),
wrap_u: ::tex::wrap_clamp,
wrap_v: ::tex::wrap_clamp);
}

export float3 lookup_world_texture_float3(uniform texture_2d texture = texture_2d(), float2 min_world_xy=float2(-5000.0,-5000.0), float2 max_world_xy=float2(5000.0,5000.0))
[[
anno::display_name("World-mapped texture lookup float3"),
anno::description("Returns float3 from a texture mapped to world UV coordinates"),
anno::author("Cesium GS Inc."),
anno::in_group("Cesium functions"),
anno::ui_order(300)
]]
{
return tex::lookup_float3(
tex: texture,
coord: world_coordinate_2d(min_world_xy, max_world_xy),
wrap_u: ::tex::wrap_clamp,
wrap_v: ::tex::wrap_clamp);
}


// The use of world_coordinate_2d and subsequent call to state::position causes issues when used in this color specific function and I have absolutely no idea why!!
// export color lookup_world_texture_color(uniform texture_2d texture = texture_2d(), float2 min_world_xy=float2(-5000.0,-5000.0), float2 max_world_xy=float2(5000.0,5000.0))
// [[
// anno::display_name("World-mapped texture lookup color"),
// anno::description("Returns color from a texture mapped to world UV coordinates"),
// anno::author("Cesium GS Inc."),
// anno::in_group("Cesium functions"),
// anno::ui_order(300)
// ]]
// {
// return tex::lookup_color(
// tex: texture,
// coord: world_coordinate_2d(min_world_xy, max_world_xy));
// }

export material cesium_gltf_material(*) = gltf_material();
export gltf_texture_lookup_value cesium_gltf_texture_lookup(*) = gltf_texture_lookup();
6 changes: 4 additions & 2 deletions src/core/include/cesium/omniverse/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ class Context {
uint64_t tokenEventId,
uint64_t assetEventId);

std::filesystem::path getCesiumExtensionLocation() const;
std::filesystem::path getCertificatePath() const;
const std::filesystem::path& getCesiumExtensionLocation() const;
const std::filesystem::path& getCertificatePath() const;
const pxr::TfToken& getCesiumMdlPathToken() const;

bool creditsAvailable() const;
std::vector<std::pair<std::string, bool>> getCredits() const;
Expand Down Expand Up @@ -162,6 +163,7 @@ class Context {

std::filesystem::path _cesiumExtensionLocation;
std::filesystem::path _certificatePath;
pxr::TfToken _cesiumMdlPathToken;

glm::dmat4 _ecefToUsdTransform;
};
Expand Down
2 changes: 0 additions & 2 deletions src/core/include/cesium/omniverse/FabricGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ struct Model;

namespace cesium::omniverse {

class FabricMaterial;

class FabricGeometry {
public:
FabricGeometry(
Expand Down
101 changes: 80 additions & 21 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,29 @@
#include "cesium/omniverse/GltfUtil.h"

#include <omni/fabric/IPath.h>
#include <omni/fabric/Type.h>
#include <pxr/usd/sdf/assetPath.h>
#include <pxr/usd/sdf/path.h>

namespace omni::ui {
class DynamicTextureProvider;
}

namespace CesiumGltf {
struct ImageCesium;
struct MeshPrimitive;
struct Model;
} // namespace CesiumGltf

namespace cesium::omniverse {

class FabricTexture;

class FabricMaterial {
public:
FabricMaterial(
pxr::SdfPath path,
const pxr::SdfPath& path,
const FabricMaterialDefinition& materialDefinition,
pxr::SdfAssetPath defaultTextureAssetPath);
const pxr::TfToken& defaultTextureAssetPathToken);

~FabricMaterial();

void setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo);
void setBaseColorTexture(const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo);

void setBaseColorTexture(const std::shared_ptr<FabricTexture>& texture, const TextureInfo& textureInfo);

void clearMaterial();
void clearBaseColorTexture();

void setActive(bool active);
Expand All @@ -41,18 +35,83 @@ class FabricMaterial {
[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;

private:
void initialize(pxr::SdfPath path, const FabricMaterialDefinition& materialDefinition);
void reset();
void setTilesetId(int64_t tilesetId);
void setMaterialValues(const MaterialInfo& materialInfo);
void setBaseColorTextureValues(const pxr::SdfAssetPath& textureAssetPath, const TextureInfo& textureInfo);
struct FabricInput {
omni::fabric::Token name;
omni::fabric::Type type;
bool writable;
};

enum ShaderInput : size_t {
ALPHA_CUTOFF,
ALPHA_MODE,
BASE_ALPHA,
BASE_COLOR_FACTOR,
EMISSIVE_FACTOR,
METALLIC_FACTOR,
ROUGHNESS_FACTOR,
VERTEX_COLOR_NAME,
SHADER_INPUT_COUNT,
};

enum TextureInput : size_t {
OFFSET,
ROTATION,
SCALE,
TEX_COORD_INDEX,
TEXTURE,
WRAP_S,
WRAP_T,
TEXTURE_INPUT_COUNT,
};

void initialize();
void initializeFromExistingMaterial(const omni::fabric::Path& path);

void createMaterial(const omni::fabric::Path& materialPath);
void createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath);
void createTexture(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput);

void reset();
void setShaderValues(
const omni::fabric::Path& shaderPath,
const std::array<FabricInput, SHADER_INPUT_COUNT>& shaderInputs,
const MaterialInfo& materialInfo);
void setTextureValues(
const omni::fabric::Path& texturePath,
const std::array<FabricInput, TEXTURE_INPUT_COUNT>& textureInputs,
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo);

void
setInputValue(const omni::fabric::Path& path, const FabricInput& input, const gsl::span<const std::byte>& value);

std::array<FabricInput, SHADER_INPUT_COUNT>
createShaderInputs(const omni::fabric::Path& shaderPath, bool checkExisting);

std::array<FabricInput, TEXTURE_INPUT_COUNT>
createTextureInputs(const omni::fabric::Path& shaderPath, bool checkExisting);

FabricInput createInput(
const omni::fabric::Path& path,
const omni::fabric::Token& name,
const omni::fabric::Type& type,
bool writable,
bool checkExisting,
uint64_t arraySize);

omni::fabric::Path _materialPath;
const FabricMaterialDefinition _materialDefinition;
const pxr::SdfAssetPath _defaultTextureAssetPath;
const pxr::TfToken _defaultTextureAssetPathToken;

std::vector<omni::fabric::Path> _shaderPaths;
std::vector<omni::fabric::Path> _baseColorTexturePaths;
std::vector<omni::fabric::Path> _allPaths;

omni::fabric::Path _materialPathFabric;
omni::fabric::Path _shaderPathFabric;
omni::fabric::Path _baseColorTexPathFabric;
std::vector<std::array<FabricInput, SHADER_INPUT_COUNT>> _shaderInputs;
std::vector<std::array<FabricInput, TEXTURE_INPUT_COUNT>> _baseColorTextureInputs;
};

} // namespace cesium::omniverse
15 changes: 9 additions & 6 deletions src/core/include/cesium/omniverse/FabricMaterialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@
#include <glm/glm.hpp>
#include <pxr/base/gf/vec2f.h>
#include <pxr/base/gf/vec3f.h>

namespace CesiumGltf {
struct MeshPrimitive;
struct Model;
} // namespace CesiumGltf
#include <pxr/usd/sdf/path.h>

namespace cesium::omniverse {

struct MaterialInfo;

class FabricMaterialDefinition {
public:
FabricMaterialDefinition(const MaterialInfo& materialInfo, bool hasImagery, bool disableTextures);
FabricMaterialDefinition(
const MaterialInfo& materialInfo,
bool hasImagery,
bool disableTextures,
const pxr::SdfPath& tilesetMaterialPath);

[[nodiscard]] bool hasBaseColorTexture() const;
[[nodiscard]] bool hasVertexColors() const;
[[nodiscard]] bool hasTilesetMaterial() const;
[[nodiscard]] const pxr::SdfPath& getTilesetMaterialPath() const;

bool operator==(const FabricMaterialDefinition& other) const;

private:
bool _hasBaseColorTexture;
bool _hasVertexColors;
pxr::SdfPath _tilesetMaterialPath;
};

} // namespace cesium::omniverse
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/FabricMaterialPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
int64_t poolId,
const FabricMaterialDefinition& materialDefinition,
uint64_t initialCapacity,
pxr::SdfAssetPath defaultTextureAssetPath);
const pxr::TfToken& defaultTextureAssetPathToken);

[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;

Expand All @@ -25,7 +25,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
private:
const int64_t _poolId;
const FabricMaterialDefinition _materialDefinition;
const pxr::SdfAssetPath _defaultTextureAssetPath;
const pxr::TfToken _defaultTextureAssetPathToken;
};

} // namespace cesium::omniverse
Loading

0 comments on commit 71a6594

Please sign in to comment.