diff --git a/exts/cesium.omniverse/mdl/cesium.mdl b/exts/cesium.omniverse/mdl/cesium.mdl index 2357263f3..f98f6579e 100644 --- a/exts/cesium.omniverse/mdl/cesium.mdl +++ b/exts/cesium.omniverse/mdl/cesium.mdl @@ -11,6 +11,113 @@ module [[ anno::display_name("Cesium MDL functions") ]]; +float4 alpha_blend(float4 src, float4 dst) { + return src * float4(src.w, src.w, src.w, 1.0) + dst * (1.0 - src.w); +} + +float4 compute_base_color( + gltf_texture_lookup_value imagery_layers_texture, + color debug_color, + gltf_texture_lookup_value base_color_texture, + color base_color_factor, + float base_alpha) { + + auto debug_color_float3 = float3(debug_color); + auto base_color_factor_float3 = float3(base_color_factor); + + auto base_color = base_color_texture.valid ? base_color_texture.value : float4(1.0); + base_color *= float4(base_color_factor_float3.x, base_color_factor_float3.y, base_color_factor_float3.z, base_alpha); + base_color = alpha_blend(imagery_layers_texture.value, base_color); + base_color *= float4(debug_color_float3.x, debug_color_float3.y, debug_color_float3.z, 1.0); + + return base_color; +} + +export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup(); + +export material cesium_material( + gltf_texture_lookup_value imagery_layers_texture = gltf_texture_lookup_value(true, float4(0.0)), + uniform color debug_color = color(1.0), + // gltf_material inputs below + gltf_texture_lookup_value base_color_texture = gltf_texture_lookup_value(), + uniform color base_color_factor = color(1.0), + uniform float metallic_factor = 1.0, + uniform float roughness_factor = 1.0, + uniform color emissive_factor = color(0.0), + uniform gltf_alpha_mode alpha_mode = opaque, + uniform float base_alpha = 1.0, + uniform float alpha_cutoff = 0.5 +) [[ anno::hidden() ]] = let { + auto base_color = compute_base_color(imagery_layers_texture, debug_color, base_color_texture, base_color_factor, base_alpha); + material base = gltf_material( + base_color_texture: gltf_texture_lookup_value(true, base_color), + metallic_factor: metallic_factor, + roughness_factor: roughness_factor, + emissive_factor: emissive_factor, + alpha_mode: alpha_mode, + alpha_cutoff: alpha_cutoff, + vertex_color_name: string("vertexColor") + ); + +} in material( + thin_walled: base.thin_walled, + surface: base.surface, + volume: base.volume, + ior: base.ior, + geometry: base.geometry +); + +export gltf_texture_lookup_value cesium_imagery_layer_resolver( + uniform int imagery_layers_count = 0, + gltf_texture_lookup_value imagery_layer_0 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_1 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_2 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_3 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_4 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_5 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_6 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_7 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_8 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_9 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_10 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_11 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_12 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_13 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_14 = gltf_texture_lookup(), + gltf_texture_lookup_value imagery_layer_15 = gltf_texture_lookup() +) [[ anno::hidden() ]] { + // The array length should match MAX_IMAGERY_LAYERS_COUNT in Tokens.h + gltf_texture_lookup_value[16] imagery_layers( + imagery_layer_0, + imagery_layer_1, + imagery_layer_2, + imagery_layer_3, + imagery_layer_4, + imagery_layer_5, + imagery_layer_6, + imagery_layer_7, + imagery_layer_8, + imagery_layer_9, + imagery_layer_10, + imagery_layer_11, + imagery_layer_12, + imagery_layer_13, + imagery_layer_14, + imagery_layer_15, + ); + + auto resolved_value = float4(0.0); + + for (int i = 0; i < imagery_layers_count; i++) { + auto imagery_layer = imagery_layers[i]; + if (imagery_layer.valid) { + resolved_value = alpha_blend(imagery_layer.value, resolved_value); + } + } + + return gltf_texture_lookup_value(true, resolved_value); +} + export enum up_axis_mode { Y, Z @@ -111,97 +218,3 @@ export color cesium_imagery_layer( { return imagery_layer.valid ? color(imagery_layer.value.x, imagery_layer.value.y, imagery_layer.value.z) : color(0.0); } - -float4 alpha_blend(float4 src, float4 dst) { - return src * float4(src.w, src.w, src.w, 1.0) + dst * (1.0 - src.w); -} - -export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup(); - -export material cesium_material( - gltf_texture_lookup_value imagery_layers_texture = gltf_texture_lookup_value(true, float4(0.0)), - uniform color debug_color = color(1.0), - // gltf_material inputs below - gltf_texture_lookup_value base_color_texture = gltf_texture_lookup_value(), - uniform color base_color_factor = color(1.0), - uniform float metallic_factor = 1.0, - uniform float roughness_factor = 1.0, - uniform color emissive_factor = color(0.0), - uniform gltf_alpha_mode alpha_mode = opaque, - uniform float base_alpha = 1.0, - uniform float alpha_cutoff = 0.5 -) [[ anno::hidden() ]] = let { - auto base_color_texture_value = base_color_texture.valid ? base_color_texture.value : float4(1.0); - auto final_base_color_texture_value = alpha_blend(imagery_layers_texture.value, base_color_texture_value); - auto final_base_color_texture = gltf_texture_lookup_value(true, final_base_color_texture_value); - auto final_base_color_factor = base_color_factor * debug_color; - - material base = gltf_material( - base_color_factor: final_base_color_factor, - base_color_texture: final_base_color_texture, - metallic_factor: metallic_factor, - roughness_factor: roughness_factor, - emissive_factor: emissive_factor, - alpha_mode: alpha_mode, - base_alpha: base_alpha, - alpha_cutoff: alpha_cutoff - ); - -} in material( - thin_walled: base.thin_walled, - surface: base.surface, - volume: base.volume, - ior: base.ior, - geometry: base.geometry -); - -export gltf_texture_lookup_value cesium_imagery_layer_resolver( - uniform int imagery_layers_count = 0, - gltf_texture_lookup_value imagery_layer_0 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_1 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_2 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_3 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_4 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_5 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_6 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_7 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_8 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_9 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_10 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_11 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_12 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_13 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_14 = gltf_texture_lookup(), - gltf_texture_lookup_value imagery_layer_15 = gltf_texture_lookup() -) [[ anno::hidden() ]] { - // The array length should match MAX_IMAGERY_LAYERS_COUNT in Tokens.h - gltf_texture_lookup_value[16] imagery_layers( - imagery_layer_0, - imagery_layer_1, - imagery_layer_2, - imagery_layer_3, - imagery_layer_4, - imagery_layer_5, - imagery_layer_6, - imagery_layer_7, - imagery_layer_8, - imagery_layer_9, - imagery_layer_10, - imagery_layer_11, - imagery_layer_12, - imagery_layer_13, - imagery_layer_14, - imagery_layer_15, - ); - - auto resolved_value = float4(0.0); - - for (int i = 0; i < imagery_layers_count; i++) { - auto imagery_layer = imagery_layers[i]; - if (imagery_layer.valid) { - resolved_value = alpha_blend(imagery_layer.value, resolved_value); - } - } - - return gltf_texture_lookup_value(true, resolved_value); -} diff --git a/src/core/include/cesium/omniverse/FabricGeometry.h b/src/core/include/cesium/omniverse/FabricGeometry.h index cf572d14b..bb804f2bc 100644 --- a/src/core/include/cesium/omniverse/FabricGeometry.h +++ b/src/core/include/cesium/omniverse/FabricGeometry.h @@ -18,7 +18,6 @@ class FabricGeometry { FabricGeometry( const omni::fabric::Path& path, const FabricGeometryDefinition& geometryDefinition, - bool debugRandomColors, long stageId); ~FabricGeometry(); @@ -48,7 +47,6 @@ class FabricGeometry { const omni::fabric::Path _path; const FabricGeometryDefinition _geometryDefinition; - const bool _debugRandomColors; const long _stageId; }; diff --git a/src/core/include/cesium/omniverse/FabricGeometryPool.h b/src/core/include/cesium/omniverse/FabricGeometryPool.h index baf4cb075..a710c4b73 100644 --- a/src/core/include/cesium/omniverse/FabricGeometryPool.h +++ b/src/core/include/cesium/omniverse/FabricGeometryPool.h @@ -12,7 +12,6 @@ class FabricGeometryPool final : public ObjectPool { int64_t poolId, const FabricGeometryDefinition& geometryDefinition, uint64_t initialCapacity, - bool debugRandomColors, long stageId); [[nodiscard]] const FabricGeometryDefinition& getGeometryDefinition() const; @@ -24,7 +23,6 @@ class FabricGeometryPool final : public ObjectPool { private: const int64_t _poolId; const FabricGeometryDefinition _geometryDefinition; - const bool _debugRandomColors; const long _stageId; }; diff --git a/src/core/include/cesium/omniverse/FabricMaterial.h b/src/core/include/cesium/omniverse/FabricMaterial.h index 08b95c9d0..e83e71b99 100644 --- a/src/core/include/cesium/omniverse/FabricMaterial.h +++ b/src/core/include/cesium/omniverse/FabricMaterial.h @@ -21,6 +21,7 @@ class FabricMaterial { const FabricMaterialDefinition& materialDefinition, const pxr::TfToken& defaultTextureAssetPathToken, const pxr::TfToken& defaultTransparentTextureAssetPathToken, + bool debugRandomColors, long stageId); ~FabricMaterial(); @@ -33,11 +34,11 @@ class FabricMaterial { const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo, uint64_t texcoordIndex, - uint64_t imageryIndex); + uint64_t imageryLayerIndex); void clearMaterial(); void clearBaseColorTexture(); - void clearImageryLayer(uint64_t imageryIndex); + void clearImageryLayer(uint64_t imageryLayerIndex); void clearImageryLayers(); void setActive(bool active); @@ -73,6 +74,7 @@ class FabricMaterial { const FabricMaterialDefinition _materialDefinition; const pxr::TfToken _defaultTextureAssetPathToken; const pxr::TfToken _defaultTransparentTextureAssetPathToken; + const bool _debugRandomColors; const long _stageId; std::vector _shaderPaths; diff --git a/src/core/include/cesium/omniverse/FabricMaterialPool.h b/src/core/include/cesium/omniverse/FabricMaterialPool.h index a93c25a6b..a324d3109 100644 --- a/src/core/include/cesium/omniverse/FabricMaterialPool.h +++ b/src/core/include/cesium/omniverse/FabricMaterialPool.h @@ -16,6 +16,7 @@ class FabricMaterialPool final : public ObjectPool { uint64_t initialCapacity, const pxr::TfToken& defaultTextureAssetPathToken, const pxr::TfToken& defaultTransparentTextureAssetPathToken, + bool debugRandomColors, long stageId); [[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const; @@ -29,6 +30,7 @@ class FabricMaterialPool final : public ObjectPool { const FabricMaterialDefinition _materialDefinition; const pxr::TfToken _defaultTextureAssetPathToken; const pxr::TfToken _defaultTransparentTextureAssetPathToken; + const bool _debugRandomColors; const long _stageId; }; diff --git a/src/core/include/cesium/omniverse/OmniTileset.h b/src/core/include/cesium/omniverse/OmniTileset.h index c3e0bcac3..8ba34fa53 100644 --- a/src/core/include/cesium/omniverse/OmniTileset.h +++ b/src/core/include/cesium/omniverse/OmniTileset.h @@ -73,7 +73,8 @@ class OmniTileset { void reload(); void addImageryIon(const pxr::SdfPath& imageryPath); - [[nodiscard]] std::optional findImageryIndex(const Cesium3DTilesSelection::RasterOverlay& overlay) const; + [[nodiscard]] std::optional + findImageryLayerIndex(const Cesium3DTilesSelection::RasterOverlay& overlay) const; [[nodiscard]] uint64_t getImageryLayerCount() const; void onUpdateFrame(const std::vector& viewports); diff --git a/src/core/include/cesium/omniverse/Tokens.h b/src/core/include/cesium/omniverse/Tokens.h index 059921983..0ce4de13a 100644 --- a/src/core/include/cesium/omniverse/Tokens.h +++ b/src/core/include/cesium/omniverse/Tokens.h @@ -73,6 +73,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003)) ((inputs_base_alpha, "inputs:base_alpha")) \ ((inputs_base_color_factor, "inputs:base_color_factor")) \ ((inputs_base_color_texture, "inputs:base_color_texture")) \ + ((inputs_debug_color, "inputs:debug_color")) \ ((inputs_emissive_factor, "inputs:emissive_factor")) \ ((inputs_excludeFromWhiteMode, "inputs:excludeFromWhiteMode")) \ ((inputs_metallic_factor, "inputs:metallic_factor")) \ @@ -110,8 +111,6 @@ __pragma(warning(push)) __pragma(warning(disable : 4003)) ((outputs_mdl_surface, "outputs:mdl:surface")) \ ((outputs_mdl_volume, "outputs:mdl:volume")) \ ((outputs_out, "outputs:out")) \ - ((primvars_displayColor, "primvars:displayColor")) \ - ((primvars_displayOpacity, "primvars:displayOpacity")) \ ((primvars_normals, "primvars:normals")) \ ((primvars_st_0, "primvars:st_0")) \ ((primvars_st_1, "primvars:st_1")) \ @@ -224,6 +223,7 @@ const omni::fabric::Type inputs_alpha_cutoff(omni::fabric::BaseDataType::eFloat, const omni::fabric::Type inputs_alpha_mode(omni::fabric::BaseDataType::eInt, 1, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_base_alpha(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_base_color_factor(omni::fabric::BaseDataType::eFloat, 3, 0, omni::fabric::AttributeRole::eColor); +const omni::fabric::Type inputs_debug_color(omni::fabric::BaseDataType::eFloat, 3, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_emissive_factor(omni::fabric::BaseDataType::eFloat, 3, 0, omni::fabric::AttributeRole::eColor); const omni::fabric::Type inputs_excludeFromWhiteMode(omni::fabric::BaseDataType::eBool, 1, 0, omni::fabric::AttributeRole::eNone); const omni::fabric::Type inputs_metallic_factor(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone); @@ -244,8 +244,6 @@ const omni::fabric::Type outputs_out(omni::fabric::BaseDataType::eToken, 1, 0, o const omni::fabric::Type points(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::ePosition); const omni::fabric::Type primvarInterpolations(omni::fabric::BaseDataType::eToken, 1, 1, omni::fabric::AttributeRole::eNone); const omni::fabric::Type primvars(omni::fabric::BaseDataType::eToken, 1, 1, omni::fabric::AttributeRole::eNone); -const omni::fabric::Type primvars_displayColor(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::eColor); -const omni::fabric::Type primvars_displayOpacity(omni::fabric::BaseDataType::eFloat, 1, 1, omni::fabric::AttributeRole::eNone); const omni::fabric::Type primvars_normals(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::eNormal); const omni::fabric::Type primvars_st(omni::fabric::BaseDataType::eFloat, 2, 1, omni::fabric::AttributeRole::eTexCoord); const omni::fabric::Type primvars_vertexColor(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::eColor); diff --git a/src/core/src/FabricGeometry.cpp b/src/core/src/FabricGeometry.cpp index f22a8eb6e..3ef1a7b10 100644 --- a/src/core/src/FabricGeometry.cpp +++ b/src/core/src/FabricGeometry.cpp @@ -17,7 +17,6 @@ #endif #include -#include #include namespace cesium::omniverse { @@ -54,11 +53,9 @@ uint64_t getTexcoordSetCount(const FabricGeometryDefinition& geometryDefinition) FabricGeometry::FabricGeometry( const omni::fabric::Path& path, const FabricGeometryDefinition& geometryDefinition, - bool debugRandomColors, long stageId) : _path(path) , _geometryDefinition(geometryDefinition) - , _debugRandomColors(debugRandomColors) , _stageId(stageId) { if (stageDestroyed()) { return; @@ -137,8 +134,6 @@ void FabricGeometry::initialize() { attributes.addAttribute(FabricTypes::_worldVisibility, FabricTokens::_worldVisibility); attributes.addAttribute(FabricTypes::primvars, FabricTokens::primvars); attributes.addAttribute(FabricTypes::primvarInterpolations, FabricTokens::primvarInterpolations); - attributes.addAttribute(FabricTypes::primvars_displayColor, FabricTokens::primvars_displayColor); - attributes.addAttribute(FabricTypes::primvars_displayOpacity, FabricTokens::primvars_displayOpacity); attributes.addAttribute(FabricTypes::Mesh, FabricTokens::Mesh); attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); attributes.addAttribute(FabricTypes::_cesium_localToEcefTransform, FabricTokens::_cesium_localToEcefTransform); @@ -176,9 +171,6 @@ void FabricGeometry::initialize() { size_t primvarIndexNormal = 0; size_t primvarIndexVertexColor = 0; - const size_t primvarIndexDisplayColor = primvarsCount++; - const size_t primvarIndexDisplayOpacity = primvarsCount++; - std::vector primvarIndexStArray; primvarIndexStArray.reserve(texcoordSetCount); @@ -196,20 +188,12 @@ void FabricGeometry::initialize() { srw.setArrayAttributeSize(_path, FabricTokens::primvars, primvarsCount); srw.setArrayAttributeSize(_path, FabricTokens::primvarInterpolations, primvarsCount); - srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayColor, 1); - srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayOpacity, 1); // clang-format off auto primvarsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars); auto primvarInterpolationsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvarInterpolations); // clang-format on - primvarsFabric[primvarIndexDisplayColor] = FabricTokens::primvars_displayColor; - primvarsFabric[primvarIndexDisplayOpacity] = FabricTokens::primvars_displayOpacity; - - primvarInterpolationsFabric[primvarIndexDisplayColor] = FabricTokens::constant; - primvarInterpolationsFabric[primvarIndexDisplayOpacity] = FabricTokens::constant; - for (uint64_t i = 0; i < texcoordSetCount; i++) { primvarsFabric[primvarIndexStArray[i]] = FabricTokens::primvars_st_n[i]; primvarInterpolationsFabric[primvarIndexStArray[i]] = FabricTokens::vertex; @@ -241,8 +225,6 @@ void FabricGeometry::reset() { auto worldPositionFabric = srw.getAttributeWr(_path, FabricTokens::_worldPosition); auto worldOrientationFabric = srw.getAttributeWr(_path, FabricTokens::_worldOrientation); auto worldScaleFabric = srw.getAttributeWr(_path, FabricTokens::_worldScale); - auto displayColorFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayColor); - auto displayOpacityFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayOpacity); // clang-format on *extentFabric = DEFAULT_EXTENT; @@ -252,8 +234,6 @@ void FabricGeometry::reset() { *worldPositionFabric = DEFAULT_POSITION; *worldOrientationFabric = DEFAULT_ORIENTATION; *worldScaleFabric = DEFAULT_SCALE; - displayColorFabric[0] = DEFAULT_VERTEX_COLOR; - displayOpacityFabric[0] = DEFAULT_VERTEX_OPACITY; FabricUtil::setTilesetId(_path, NO_TILESET_ID); @@ -462,8 +442,6 @@ void FabricGeometry::setGeometry( auto worldPositionFabric = srw.getAttributeWr(_path, FabricTokens::_worldPosition); auto worldOrientationFabric = srw.getAttributeWr(_path, FabricTokens::_worldOrientation); auto worldScaleFabric = srw.getAttributeWr(_path, FabricTokens::_worldScale); - auto displayColorFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayColor); - auto displayOpacityFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_displayOpacity); // clang-format on *extentFabric = localExtent; @@ -473,17 +451,6 @@ void FabricGeometry::setGeometry( *worldOrientationFabric = worldOrientation; *worldScaleFabric = worldScale; - if (_debugRandomColors) { - const auto r = glm::linearRand(0.0f, 1.0f); - const auto g = glm::linearRand(0.0f, 1.0f); - const auto b = glm::linearRand(0.0f, 1.0f); - displayColorFabric[0] = pxr::GfVec3f(r, g, b); - } else { - displayColorFabric[0] = DEFAULT_VERTEX_COLOR; - } - - displayOpacityFabric[0] = DEFAULT_VERTEX_OPACITY; - FabricUtil::setTilesetId(_path, tilesetId); } diff --git a/src/core/src/FabricGeometryPool.cpp b/src/core/src/FabricGeometryPool.cpp index eed6d7aea..4514620b9 100644 --- a/src/core/src/FabricGeometryPool.cpp +++ b/src/core/src/FabricGeometryPool.cpp @@ -8,12 +8,10 @@ FabricGeometryPool::FabricGeometryPool( int64_t poolId, const FabricGeometryDefinition& geometryDefinition, uint64_t initialCapacity, - bool debugRandomColors, long stageId) : ObjectPool() , _poolId(poolId) , _geometryDefinition(geometryDefinition) - , _debugRandomColors(debugRandomColors) , _stageId(stageId) { setCapacity(initialCapacity); } @@ -25,7 +23,7 @@ const FabricGeometryDefinition& FabricGeometryPool::getGeometryDefinition() cons std::shared_ptr FabricGeometryPool::createObject(uint64_t objectId) { const auto pathStr = fmt::format("/fabric_geometry_pool_{}_object_{}", _poolId, objectId); const auto path = omni::fabric::Path(pathStr.c_str()); - return std::make_shared(path, _geometryDefinition, _debugRandomColors, _stageId); + return std::make_shared(path, _geometryDefinition, _stageId); } void FabricGeometryPool::setActive(std::shared_ptr geometry, bool active) { diff --git a/src/core/src/FabricMaterial.cpp b/src/core/src/FabricMaterial.cpp index dfd77f51d..14aba483e 100644 --- a/src/core/src/FabricMaterial.cpp +++ b/src/core/src/FabricMaterial.cpp @@ -10,14 +10,18 @@ #include "cesium/omniverse/Tokens.h" #include "cesium/omniverse/UsdUtil.h" +#include #include #include namespace cesium::omniverse { namespace { + +const auto DEFAULT_DEBUG_COLOR = pxr::GfVec3f(1.0f, 1.0f, 1.0f); + uint64_t getImageryLayerCount(const FabricMaterialDefinition& materialDefinition) { - uint64_t imageryLayerCount = materialDefinition.getImageryLayerCount(); + auto imageryLayerCount = materialDefinition.getImageryLayerCount(); if (imageryLayerCount > FabricTokens::MAX_IMAGERY_LAYERS_COUNT) { CESIUM_LOG_WARN( @@ -31,6 +35,7 @@ uint64_t getImageryLayerCount(const FabricMaterialDefinition& materialDefinition return imageryLayerCount; } + } // namespace FabricMaterial::FabricMaterial( @@ -38,11 +43,13 @@ FabricMaterial::FabricMaterial( const FabricMaterialDefinition& materialDefinition, const pxr::TfToken& defaultTextureAssetPathToken, const pxr::TfToken& defaultTransparentTextureAssetPathToken, + bool debugRandomColors, long stageId) : _materialPath(path) , _materialDefinition(materialDefinition) , _defaultTextureAssetPathToken(defaultTextureAssetPathToken) , _defaultTransparentTextureAssetPathToken(defaultTransparentTextureAssetPathToken) + , _debugRandomColors(debugRandomColors) , _stageId(stageId) { if (stageDestroyed()) { @@ -188,8 +195,6 @@ void FabricMaterial::createMaterial(const omni::fabric::Path& materialPath) { } void FabricMaterial::createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath) { - const auto hasVertexColors = _materialDefinition.hasVertexColors(); - auto srw = UsdUtil::getFabricStageReaderWriter(); srw.createPrim(shaderPath); @@ -197,7 +202,7 @@ void FabricMaterial::createShader(const omni::fabric::Path& shaderPath, const om FabricAttributesBuilder attributes; // clang-format off - // TODO: add debug_color + attributes.addAttribute(FabricTypes::inputs_debug_color, FabricTokens::inputs_debug_color); attributes.addAttribute(FabricTypes::inputs_alpha_cutoff, FabricTokens::inputs_alpha_cutoff); attributes.addAttribute(FabricTypes::inputs_alpha_mode, FabricTokens::inputs_alpha_mode); attributes.addAttribute(FabricTypes::inputs_base_alpha, FabricTokens::inputs_base_alpha); @@ -216,10 +221,6 @@ void FabricMaterial::createShader(const omni::fabric::Path& shaderPath, const om attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); // clang-format on - if (hasVertexColors) { - attributes.addAttribute(FabricTypes::inputs_vertex_color_name, FabricTokens::inputs_vertex_color_name); - } - attributes.createAttributes(shaderPath); srw.setArrayAttributeSize(shaderPath, FabricTokens::_paramColorSpace, 0); @@ -238,14 +239,6 @@ void FabricMaterial::createShader(const omni::fabric::Path& shaderPath, const om infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::cesium_material; - if (hasVertexColors) { - const auto vertexColorPrimvarNameSize = pxr::UsdTokens->vertexColor.GetString().size(); - srw.setArrayAttributeSize(shaderPath, FabricTokens::inputs_vertex_color_name, vertexColorPrimvarNameSize); - auto vertexColorNameFabric = - srw.getArrayAttributeWr(shaderPath, FabricTokens::inputs_vertex_color_name); - memcpy(vertexColorNameFabric.data(), pxr::UsdTokens->vertexColor.GetText(), vertexColorPrimvarNameSize); - } - // Connect the material terminals to the shader. srw.createConnection( materialPath, @@ -400,16 +393,16 @@ void FabricMaterial::setImageryLayer( const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo, uint64_t texcoordIndex, - uint64_t imageryIndex) { + uint64_t imageryLayerIndex) { if (stageDestroyed()) { return; } - if (imageryIndex >= _imageryLayerPaths.size()) { + if (imageryLayerIndex >= _imageryLayerPaths.size()) { return; } - for (auto& imageryLayerPath : _imageryLayerPaths[imageryIndex]) { + for (auto& imageryLayerPath : _imageryLayerPaths[imageryLayerIndex]) { setTextureValues(imageryLayerPath, textureAssetPathToken, textureInfo, texcoordIndex); } } @@ -422,8 +415,8 @@ void FabricMaterial::clearBaseColorTexture() { setBaseColorTexture(_defaultTextureAssetPathToken, GltfUtil::getDefaultTextureInfo(), 0); } -void FabricMaterial::clearImageryLayer(uint64_t imageryIndex) { - setImageryLayer(_defaultTransparentTextureAssetPathToken, GltfUtil::getDefaultTextureInfo(), 0, imageryIndex); +void FabricMaterial::clearImageryLayer(uint64_t imageryLayerIndex) { + setImageryLayer(_defaultTransparentTextureAssetPathToken, GltfUtil::getDefaultTextureInfo(), 0, imageryLayerIndex); } void FabricMaterial::clearImageryLayers() { @@ -435,6 +428,7 @@ void FabricMaterial::clearImageryLayers() { void FabricMaterial::setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo) { auto srw = UsdUtil::getFabricStageReaderWriter(); + auto debugColorFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_debug_color); auto alphaCutoffFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_alpha_cutoff); auto alphaModeFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_alpha_mode); auto baseAlphaFabric = srw.getAttributeWr(shaderPath, FabricTokens::inputs_base_alpha); @@ -450,6 +444,15 @@ void FabricMaterial::setShaderValues(const omni::fabric::Path& shaderPath, const *emissiveFactorFabric = UsdUtil::glmToUsdVector(glm::fvec3(materialInfo.emissiveFactor)); *metallicFactorFabric = static_cast(materialInfo.metallicFactor); *roughnessFactorFabric = static_cast(materialInfo.roughnessFactor); + + if (_debugRandomColors) { + const auto r = glm::linearRand(0.0f, 1.0f); + const auto g = glm::linearRand(0.0f, 1.0f); + const auto b = glm::linearRand(0.0f, 1.0f); + *debugColorFabric = pxr::GfVec3f(r, g, b); + } else { + *debugColorFabric = DEFAULT_DEBUG_COLOR; + } } void FabricMaterial::setTextureValues( diff --git a/src/core/src/FabricMaterialPool.cpp b/src/core/src/FabricMaterialPool.cpp index 34e0ff682..e860efd4f 100644 --- a/src/core/src/FabricMaterialPool.cpp +++ b/src/core/src/FabricMaterialPool.cpp @@ -10,12 +10,14 @@ FabricMaterialPool::FabricMaterialPool( uint64_t initialCapacity, const pxr::TfToken& defaultTextureAssetPathToken, const pxr::TfToken& defaultTransparentTextureAssetPathToken, + bool debugRandomColors, long stageId) : ObjectPool() , _poolId(poolId) , _materialDefinition(materialDefinition) , _defaultTextureAssetPathToken(defaultTextureAssetPathToken) , _defaultTransparentTextureAssetPathToken(defaultTransparentTextureAssetPathToken) + , _debugRandomColors(debugRandomColors) , _stageId(stageId) { setCapacity(initialCapacity); } @@ -28,7 +30,12 @@ std::shared_ptr FabricMaterialPool::createObject(uint64_t object const auto pathStr = fmt::format("/fabric_material_pool_{}_object_{}", _poolId, objectId); const auto path = omni::fabric::Path(pathStr.c_str()); return std::make_shared( - path, _materialDefinition, _defaultTextureAssetPathToken, _defaultTransparentTextureAssetPathToken, _stageId); + path, + _materialDefinition, + _defaultTextureAssetPathToken, + _defaultTransparentTextureAssetPathToken, + _debugRandomColors, + _stageId); } void FabricMaterialPool::setActive(std::shared_ptr material, bool active) { diff --git a/src/core/src/FabricPrepareRenderResources.cpp b/src/core/src/FabricPrepareRenderResources.cpp index 48aec0fff..c8de2f768 100644 --- a/src/core/src/FabricPrepareRenderResources.cpp +++ b/src/core/src/FabricPrepareRenderResources.cpp @@ -446,8 +446,8 @@ void FabricPrepareRenderResources::attachRasterInMainThread( return; } - auto imageryIndex = _tileset->findImageryIndex(rasterTile.getOverlay()); - if (!imageryIndex.has_value()) { + auto imageryLayerIndex = _tileset->findImageryLayerIndex(rasterTile.getOverlay()); + if (!imageryLayerIndex.has_value()) { return; } @@ -467,7 +467,7 @@ void FabricPrepareRenderResources::attachRasterInMainThread( const auto texcoordIndex = mesh.imageryTexcoordIndexMapping.at(gltfSetIndex); const auto& textureAssetPath = texture->getAssetPathToken(); - material->setImageryLayer(textureAssetPath, textureInfo, texcoordIndex, imageryIndex.value()); + material->setImageryLayer(textureAssetPath, textureInfo, texcoordIndex, imageryLayerIndex.value()); } } } @@ -493,15 +493,15 @@ void FabricPrepareRenderResources::detachRasterInMainThread( return; } - auto imageryIndex = _tileset->findImageryIndex(rasterTile.getOverlay()); - if (!imageryIndex.has_value()) { + auto imageryLayerIndex = _tileset->findImageryLayerIndex(rasterTile.getOverlay()); + if (!imageryLayerIndex.has_value()) { return; } for (const auto& mesh : pTileRenderResources->fabricMeshes) { auto& material = mesh.material; if (material != nullptr) { - material->clearImageryLayer(imageryIndex.value()); + material->clearImageryLayer(imageryLayerIndex.value()); } } } diff --git a/src/core/src/FabricResourceManager.cpp b/src/core/src/FabricResourceManager.cpp index bfea28984..86d700eb4 100644 --- a/src/core/src/FabricResourceManager.cpp +++ b/src/core/src/FabricResourceManager.cpp @@ -73,7 +73,7 @@ std::shared_ptr FabricResourceManager::acquireGeometry( if (_disableGeometryPool) { const auto pathStr = fmt::format("/fabric_geometry_{}", getNextGeometryId()); const auto path = omni::fabric::Path(pathStr.c_str()); - return std::make_shared(path, geometryDefinition, _debugRandomColors, stageId); + return std::make_shared(path, geometryDefinition, stageId); } std::scoped_lock lock(_poolMutex); @@ -102,7 +102,12 @@ FabricResourceManager::createMaterial(const FabricMaterialDefinition& materialDe const auto pathStr = fmt::format("/fabric_material_{}", getNextMaterialId()); const auto path = omni::fabric::Path(pathStr.c_str()); return std::make_shared( - path, materialDefinition, _defaultTextureAssetPathToken, _defaultTransparentTextureAssetPathToken, stageId); + path, + materialDefinition, + _defaultTextureAssetPathToken, + _defaultTransparentTextureAssetPathToken, + _debugRandomColors, + stageId); } void FabricResourceManager::removeSharedMaterial(const SharedMaterial& sharedMaterial) { @@ -347,7 +352,7 @@ std::shared_ptr FabricResourceManager::getTexturePool() { std::shared_ptr FabricResourceManager::createGeometryPool(const FabricGeometryDefinition& geometryDefinition, long stageId) { return _geometryPools.emplace_back(std::make_shared( - getNextPoolId(), geometryDefinition, _geometryPoolInitialCapacity, _debugRandomColors, stageId)); + getNextPoolId(), geometryDefinition, _geometryPoolInitialCapacity, stageId)); } std::shared_ptr @@ -358,6 +363,7 @@ FabricResourceManager::createMaterialPool(const FabricMaterialDefinition& materi _materialPoolInitialCapacity, _defaultTextureAssetPathToken, _defaultTransparentTextureAssetPathToken, + _debugRandomColors, stageId)); } diff --git a/src/core/src/OmniTileset.cpp b/src/core/src/OmniTileset.cpp index ba137a757..ca2742d66 100644 --- a/src/core/src/OmniTileset.cpp +++ b/src/core/src/OmniTileset.cpp @@ -411,7 +411,7 @@ void OmniTileset::addImageryIon(const pxr::SdfPath& imageryPath) { _tileset->getOverlays().add(ionRasterOverlay); } -std::optional OmniTileset::findImageryIndex(const Cesium3DTilesSelection::RasterOverlay& overlay) const { +std::optional OmniTileset::findImageryLayerIndex(const Cesium3DTilesSelection::RasterOverlay& overlay) const { uint64_t overlayIndex = 0; for (const auto& pOverlay : _tileset->getOverlays()) { if (&overlay == pOverlay.get()) {