Skip to content

Commit

Permalink
Add support for multiple raster overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 16, 2023
1 parent e0e3b34 commit 13bdca1
Show file tree
Hide file tree
Showing 20 changed files with 611 additions and 144 deletions.
60 changes: 59 additions & 1 deletion exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,64 @@ module [[
anno::display_name("Cesium MDL functions")
]];

// For internal use only. See note in FabricMaterial.cpp
// For internal use only
export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup();
export material cesium_material(*) [[ anno::hidden() ]] = gltf_material();

export gltf_texture_lookup_value cesium_texture_array_lookup(
uniform int texture_count = 0,
gltf_texture_lookup_value texture_0 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_1 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_2 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_3 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_4 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_5 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_6 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_7 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_8 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_9 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_10 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_11 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_12 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_13 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_14 = gltf_texture_lookup(),
gltf_texture_lookup_value texture_15 = gltf_texture_lookup()
) [[ anno::hidden() ]]
{
// The array length should match MAX_TEXTURE_LAYER_COUNT in Tokens.h
gltf_texture_lookup_value[16] texture_values(
texture_0,
texture_1,
texture_2,
texture_3,
texture_4,
texture_5,
texture_6,
texture_7,
texture_8,
texture_9,
texture_10,
texture_11,
texture_12,
texture_13,
texture_14,
texture_15,
);

float3 final = float3(1.0, 1.0, 1.0);

for (int i = 0; i < texture_count; i++) {
gltf_texture_lookup_value value = texture_values[i];
if (value.valid) {
float3 rgb = float3(value.value[0], value.value[1], value.value[2]);
float alpha = value.value[3];
final = alpha * rgb + (1.0 - alpha) * final;
}
}

gltf_texture_lookup_value tex_ret;
tex_ret.value = float4(final[0], final[1], final[2], 1.0);
tex_ret.valid = true;

return tex_ret;
}
3 changes: 2 additions & 1 deletion src/core/include/cesium/omniverse/FabricGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class FabricGeometry {
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
bool hasImagery);
const std::unordered_map<uint64_t, uint64_t>& texcoordIndexMapping,
const std::unordered_map<uint64_t, uint64_t>& imageryTexcoordIndexMapping);

void setActive(bool active);
void setVisibility(bool visible);
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/FabricGeometryDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class FabricGeometryDefinition {
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals);

[[nodiscard]] bool hasTexcoords() const;
[[nodiscard]] bool hasNormals() const;
[[nodiscard]] bool hasVertexColors() const;
[[nodiscard]] bool getDoubleSided() const;
[[nodiscard]] uint64_t getTexcoordSetCount() const;

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

private:
bool _hasTexcoords{false};
bool _hasNormals{false};
bool _hasVertexColors{false};
bool _doubleSided{false};
uint64_t _texcoordSetCount{0};
};

} // namespace cesium::omniverse
21 changes: 17 additions & 4 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ class FabricMaterial {
const omni::fabric::Path& path,
const FabricMaterialDefinition& materialDefinition,
const pxr::TfToken& defaultTextureAssetPathToken,
const pxr::TfToken& defaultTransparentTextureAssetPathToken,
long stageId);
~FabricMaterial();

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

void clearMaterial();
void clearBaseColorTexture();
void clearBaseColorTexture(uint64_t textureIndex);

void setActive(bool active);

Expand All @@ -43,23 +48,31 @@ class FabricMaterial {
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput);

void createTextureArray(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput,
uint64_t textureCount);
void reset();
void setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo);
void setTextureValues(
const omni::fabric::Path& texturePath,
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo);
const TextureInfo& textureInfo,
uint64_t texcoordIndex);
void setTilesetId(int64_t tilesetId);
bool stageDestroyed();
void clearBaseColorTextures();

omni::fabric::Path _materialPath;
const FabricMaterialDefinition _materialDefinition;
const pxr::TfToken _defaultTextureAssetPathToken;
const pxr::TfToken _defaultTransparentTextureAssetPathToken;
const long _stageId;

omni::fabric::Path _shaderPath;
omni::fabric::Path _baseColorTexturePath;
std::vector<omni::fabric::Path> _baseColorTextureLayerPaths;
};

} // namespace cesium::omniverse
7 changes: 4 additions & 3 deletions src/core/include/cesium/omniverse/FabricMaterialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ struct MaterialInfo;

class FabricMaterialDefinition {
public:
FabricMaterialDefinition(const MaterialInfo& materialInfo, bool hasImagery, bool disableTextures);
FabricMaterialDefinition(const MaterialInfo& materialInfo, uint64_t imageryLayerCount, bool disableTextures);

[[nodiscard]] bool hasBaseColorTexture() const;
[[nodiscard]] bool hasVertexColors() const;
[[nodiscard]] uint64_t getBaseColorTextureCount() const;
[[nodiscard]] bool hasBaseColorTextures() const;

// Make sure to update this function when adding new fields to the class
bool operator==(const FabricMaterialDefinition& other) const;

private:
bool _hasBaseColorTexture;
bool _hasVertexColors;
uint64_t _baseColorTextureCount;
};

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

[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;
Expand All @@ -27,6 +28,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
const int64_t _poolId;
const FabricMaterialDefinition _materialDefinition;
const pxr::TfToken _defaultTextureAssetPathToken;
const pxr::TfToken _defaultTransparentTextureAssetPathToken;
const long _stageId;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct FabricMesh {
std::shared_ptr<FabricMaterial> material;
std::shared_ptr<FabricTexture> baseColorTexture;
MaterialInfo materialInfo;
std::unordered_map<uint64_t, uint64_t> texcoordIndexMapping;
std::unordered_map<uint64_t, uint64_t> imageryTexcoordIndexMapping;
};

struct TileRenderResources {
Expand Down
4 changes: 3 additions & 1 deletion src/core/include/cesium/omniverse/FabricResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class FabricResourceManager {
long stageId);

std::shared_ptr<FabricMaterial>
acquireMaterial(const MaterialInfo& materialInfo, bool hasImagery, long stageId, int64_t tilesetId);
acquireMaterial(const MaterialInfo& materialInfo, uint64_t imageryLayerCount, long stageId, int64_t tilesetId);

std::shared_ptr<FabricTexture> acquireTexture();

Expand Down Expand Up @@ -140,7 +140,9 @@ class FabricResourceManager {
std::mutex _poolMutex;

std::unique_ptr<omni::ui::DynamicTextureProvider> _defaultTexture;
std::unique_ptr<omni::ui::DynamicTextureProvider> _defaultTransparentTexture;
pxr::TfToken _defaultTextureAssetPathToken;
pxr::TfToken _defaultTransparentTextureAssetPathToken;

std::vector<omni::fabric::Path> _retainedPaths;

Expand Down
4 changes: 4 additions & 0 deletions src/core/include/cesium/omniverse/GltfUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ bool hasImageryTexcoords(const CesiumGltf::Model& model, const CesiumGltf::MeshP
bool hasVertexColors(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive, uint64_t setIndex);
bool hasMaterial(const CesiumGltf::MeshPrimitive& primitive);

std::vector<uint64_t> getTexcoordSetIndexes(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive);
std::vector<uint64_t>
getImageryTexcoordSetIndexes(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive);

} // namespace cesium::omniverse::GltfUtil
3 changes: 3 additions & 0 deletions src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>

namespace Cesium3DTilesSelection {
class RasterOverlay;
class Tileset;
class ViewState;
class ViewUpdateResult;
Expand Down Expand Up @@ -72,6 +73,8 @@ class OmniTileset {

void reload();
void addImageryIon(const pxr::SdfPath& imageryPath);
[[nodiscard]] std::optional<uint64_t> findImageryIndex(const Cesium3DTilesSelection::RasterOverlay& overlay) const;
[[nodiscard]] uint64_t getImageryLayerCount() const;
void onUpdateFrame(const std::vector<Viewport>& viewports);

private:
Expand Down
104 changes: 102 additions & 2 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,27 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
// Note: variable names should match the USD token names as closely as possible, with special characters converted to underscores

#define USD_TOKENS \
(baseColorTexture) \
(base_color_texture) \
(base_color_texture_0) \
(base_color_texture_1) \
(base_color_texture_2) \
(base_color_texture_3) \
(base_color_texture_4) \
(base_color_texture_5) \
(base_color_texture_6) \
(base_color_texture_7) \
(base_color_texture_8) \
(base_color_texture_9) \
(base_color_texture_10) \
(base_color_texture_11) \
(base_color_texture_12) \
(base_color_texture_13) \
(base_color_texture_14) \
(base_color_texture_15) \
(base_color_texture_array) \
(cesium) \
(cesium_material) \
(cesium_texture_array_lookup) \
(cesium_texture_lookup) \
(constant) \
(doubleSided) \
Expand Down Expand Up @@ -61,6 +79,23 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
((inputs_scale, "inputs:scale")) \
((inputs_tex_coord_index, "inputs:tex_coord_index")) \
((inputs_texture, "inputs:texture")) \
((inputs_texture_0, "inputs:texture_0")) \
((inputs_texture_1, "inputs:texture_1")) \
((inputs_texture_2, "inputs:texture_2")) \
((inputs_texture_3, "inputs:texture_3")) \
((inputs_texture_4, "inputs:texture_4")) \
((inputs_texture_5, "inputs:texture_5")) \
((inputs_texture_6, "inputs:texture_6")) \
((inputs_texture_7, "inputs:texture_7")) \
((inputs_texture_8, "inputs:texture_8")) \
((inputs_texture_9, "inputs:texture_9")) \
((inputs_texture_10, "inputs:texture_10")) \
((inputs_texture_11, "inputs:texture_11")) \
((inputs_texture_12, "inputs:texture_12")) \
((inputs_texture_13, "inputs:texture_13")) \
((inputs_texture_14, "inputs:texture_14")) \
((inputs_texture_15, "inputs:texture_15")) \
((inputs_texture_count, "inputs:texture_count")) \
((inputs_vertex_color_name, "inputs:vertex_color_name")) \
((inputs_wrap_s, "inputs:wrap_s")) \
((inputs_wrap_t, "inputs:wrap_t")) \
Expand All @@ -72,7 +107,16 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
((primvars_displayColor, "primvars:displayColor")) \
((primvars_displayOpacity, "primvars:displayOpacity")) \
((primvars_normals, "primvars:normals")) \
((primvars_st, "primvars:st")) \
((primvars_st_0, "primvars:st_0")) \
((primvars_st_1, "primvars:st_1")) \
((primvars_st_2, "primvars:st_2")) \
((primvars_st_3, "primvars:st_3")) \
((primvars_st_4, "primvars:st_4")) \
((primvars_st_5, "primvars:st_5")) \
((primvars_st_6, "primvars:st_6")) \
((primvars_st_7, "primvars:st_7")) \
((primvars_st_8, "primvars:st_8")) \
((primvars_st_9, "primvars:st_9")) \
((primvars_vertexColor, "primvars:vertexColor")) \
((xformOp_transform_cesium, "xformOp:transform:cesium"))

Expand Down Expand Up @@ -104,6 +148,61 @@ __pragma(warning(pop))

namespace cesium::omniverse::FabricTokens {
FABRIC_DECLARE_TOKENS(USD_TOKENS);

const uint64_t MAX_PRIMVAR_ST_COUNT = 10;
const uint64_t MAX_TEXTURE_LAYER_COUNT = 16;

const std::array<const omni::fabric::TokenC, MAX_PRIMVAR_ST_COUNT> primvars_st_n = {{
primvars_st_0,
primvars_st_1,
primvars_st_2,
primvars_st_3,
primvars_st_4,
primvars_st_5,
primvars_st_6,
primvars_st_7,
primvars_st_8,
primvars_st_9,
}};

const std::array<const omni::fabric::TokenC, MAX_TEXTURE_LAYER_COUNT> base_color_texture_n = {{
base_color_texture_0,
base_color_texture_1,
base_color_texture_2,
base_color_texture_3,
base_color_texture_4,
base_color_texture_5,
base_color_texture_6,
base_color_texture_7,
base_color_texture_8,
base_color_texture_9,
base_color_texture_10,
base_color_texture_11,
base_color_texture_12,
base_color_texture_13,
base_color_texture_14,
base_color_texture_15,
}};

const std::array<const omni::fabric::TokenC, MAX_TEXTURE_LAYER_COUNT> inputs_texture_n = {{
inputs_texture_0,
inputs_texture_1,
inputs_texture_2,
inputs_texture_3,
inputs_texture_4,
inputs_texture_5,
inputs_texture_6,
inputs_texture_7,
inputs_texture_8,
inputs_texture_9,
inputs_texture_10,
inputs_texture_11,
inputs_texture_12,
inputs_texture_13,
inputs_texture_14,
inputs_texture_15,
}};

}

namespace cesium::omniverse::FabricTypes {
Expand All @@ -128,6 +227,7 @@ const omni::fabric::Type inputs_roughness_factor(omni::fabric::BaseDataType::eFl
const omni::fabric::Type inputs_scale(omni::fabric::BaseDataType::eFloat, 2, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_tex_coord_index(omni::fabric::BaseDataType::eInt, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_texture(omni::fabric::BaseDataType::eAsset, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_texture_count(omni::fabric::BaseDataType::eInt, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_vertex_color_name(omni::fabric::BaseDataType::eUChar, 1, 1, omni::fabric::AttributeRole::eText);
const omni::fabric::Type inputs_wrap_s(omni::fabric::BaseDataType::eInt, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_wrap_t(omni::fabric::BaseDataType::eInt, 1, 0, omni::fabric::AttributeRole::eNone);
Expand Down
Loading

0 comments on commit 13bdca1

Please sign in to comment.