Skip to content

Commit

Permalink
Add imagery layer support
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 18, 2023
1 parent 6afb3c0 commit cb2d9ad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
21 changes: 21 additions & 0 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ export color cesium_base_color_texture(
return base_color_texture.valid ? color(base_color_texture.value.x, base_color_texture.value.y, base_color_texture.value.z) : color(0.0);
}

export color cesium_imagery_layer(
gltf_texture_lookup_value imagery_layer
[[
anno::hidden()
]],
int imagery_layer_index
[[
anno::unused()
]]
)
[[
anno::display_name("Imagery layer lookup color"),
anno::description("Returns the color of the imagery layer at the given index. Returns [0, 0, 0] if the imagery layer does not exist."),
anno::author("Cesium GS Inc."),
anno::in_group("Cesium functions"),
anno::ui_order(300)
]]
{
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);
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
(extent) \
(faceVertexCounts) \
(faceVertexIndices) \
(imagery_layer) \
(imagery_layer_0) \
(imagery_layer_1) \
(imagery_layer_2) \
Expand Down Expand Up @@ -81,6 +82,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
((inputs_scale, "inputs:scale")) \
((inputs_tex_coord_index, "inputs:tex_coord_index")) \
((inputs_texture, "inputs:texture")) \
((inputs_imagery_layer, "inputs:imagery_layer")) \
((inputs_imagery_layer_0, "inputs:imagery_layer_0")) \
((inputs_imagery_layer_1, "inputs:imagery_layer_1")) \
((inputs_imagery_layer_2, "inputs:imagery_layer_2")) \
Expand All @@ -98,6 +100,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
((inputs_imagery_layer_14, "inputs:imagery_layer_14")) \
((inputs_imagery_layer_15, "inputs:imagery_layer_15")) \
((inputs_imagery_layers_count, "inputs:imagery_layers_count")) \
((inputs_imagery_layer_index, "inputs:imagery_layer_index")) \
((inputs_imagery_layers_texture, "inputs:imagery_layers_texture")) \
((inputs_vertex_color_name, "inputs:vertex_color_name")) \
((inputs_wrap_s, "inputs:wrap_s")) \
Expand Down
27 changes: 20 additions & 7 deletions src/core/src/FabricMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,23 @@ void FabricMaterial::initialize() {
}

const auto imageryLayerCount = getImageryLayerCount(_materialDefinition);
_imageryLayerPaths.resize(imageryLayerCount);

if (imageryLayerCount == 1) {
const auto imageryLayerPath = FabricUtil::joinPaths(materialPath, FabricTokens::imagery_layer_n[0]);
createTexture(imageryLayerPath, shaderPath, FabricTokens::inputs_imagery_layers_texture);
_imageryLayerPaths.push_back({imageryLayerPath});
_imageryLayerPaths[0].push_back(imageryLayerPath);
_allPaths.push_back(imageryLayerPath);
} else if (imageryLayerCount > 1) {
const auto imageryLayerResolverPath = FabricUtil::joinPaths(materialPath, FabricTokens::imagery_layer_resolver);
createImageryLayerResolver(
imageryLayerResolverPath, shaderPath, FabricTokens::inputs_imagery_layers_texture, imageryLayerCount);
_allPaths.push_back(imageryLayerResolverPath);

_imageryLayerPaths.reserve(imageryLayerCount);
for (uint64_t i = 0; i < imageryLayerCount; i++) {
const auto imageryLayerPath = FabricUtil::joinPaths(materialPath, FabricTokens::imagery_layer_n[i]);
createTexture(imageryLayerPath, imageryLayerResolverPath, FabricTokens::inputs_imagery_layer_n[i]);
_imageryLayerPaths.push_back({imageryLayerPath});
_imageryLayerPaths[i].push_back(imageryLayerPath);
_allPaths.push_back(imageryLayerPath);
}
}
Expand All @@ -138,6 +138,9 @@ void FabricMaterial::initializeFromExistingMaterial(const omni::fabric::Path& sr

const auto dstPaths = FabricUtil::copyMaterial(srcMaterialPath, dstMaterialPath);

const auto imageryLayerCount = getImageryLayerCount(_materialDefinition);
_imageryLayerPaths.resize(imageryLayerCount);

for (const auto& dstPath : dstPaths) {
srw.createAttribute(dstPath, FabricTokens::_cesium_tilesetId, FabricTypes::_cesium_tilesetId);
_allPaths.push_back(dstPath);
Expand All @@ -147,12 +150,22 @@ void FabricMaterial::initializeFromExistingMaterial(const omni::fabric::Path& sr
if (mdlIdentifier == FabricTokens::cesium_base_color_texture) {
if (_materialDefinition.hasBaseColorTexture()) {
// Create a base color texture node to fill the empty slot
const auto baseColorTexturePath =
FabricUtil::joinPaths(dstMaterialPath, FabricTokens::base_color_texture);
const auto baseColorTexturePath = FabricUtil::joinPaths(dstPath, FabricTokens::base_color_texture);
createTexture(baseColorTexturePath, dstPath, FabricTokens::inputs_base_color_texture);
_allPaths.push_back(baseColorTexturePath);
_baseColorTexturePaths.push_back(baseColorTexturePath);
FabricResourceManager::getInstance().retainPath(baseColorTexturePath);
_allPaths.push_back(baseColorTexturePath);
}
} else if (mdlIdentifier == FabricTokens::cesium_imagery_layer) {
const auto imageryLayerIndexFabric =
srw.getAttributeRd<int>(dstPath, FabricTokens::inputs_imagery_layer_index);
const auto imageryLayerIndex =
static_cast<uint64_t>(imageryLayerIndexFabric == nullptr ? 0 : *imageryLayerIndexFabric);

if (imageryLayerIndex < imageryLayerCount) {
const auto imageryLayerPath = FabricUtil::joinPaths(dstPath, FabricTokens::imagery_layer);
createTexture(imageryLayerPath, dstPath, FabricTokens::inputs_imagery_layer);
_imageryLayerPaths[imageryLayerIndex].push_back(imageryLayerPath);
_allPaths.push_back(imageryLayerPath);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/FabricUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,8 @@ bool materialHasCesiumNodes(const omni::fabric::Path& path) {
}

bool isCesiumNode(const omni::fabric::Token& mdlIdentifier) {
return mdlIdentifier == FabricTokens::cesium_base_color_texture;
return mdlIdentifier == FabricTokens::cesium_base_color_texture ||
mdlIdentifier == FabricTokens::cesium_imagery_layer;
}

omni::fabric::Token getMdlIdentifier(const omni::fabric::Path& path) {
Expand Down

0 comments on commit cb2d9ad

Please sign in to comment.