Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 18, 2023
1 parent cb2d9ad commit f38d821
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 88 deletions.
31 changes: 22 additions & 9 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ 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(
Expand All @@ -131,20 +149,15 @@ export material cesium_material(
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;

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_factor: final_base_color_factor,
base_color_texture: final_base_color_texture,
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,
base_alpha: base_alpha,
alpha_cutoff: alpha_cutoff
alpha_cutoff: alpha_cutoff,
vertex_color_name: string("vertexColor")
);

} in material(
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 @@ -18,7 +18,6 @@ class FabricGeometry {
FabricGeometry(
const omni::fabric::Path& path,
const FabricGeometryDefinition& geometryDefinition,
bool debugRandomColors,
long stageId);
~FabricGeometry();

Expand Down Expand Up @@ -48,7 +47,6 @@ class FabricGeometry {

const omni::fabric::Path _path;
const FabricGeometryDefinition _geometryDefinition;
const bool _debugRandomColors;
const long _stageId;
};

Expand Down
2 changes: 0 additions & 2 deletions src/core/include/cesium/omniverse/FabricGeometryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class FabricGeometryPool final : public ObjectPool<FabricGeometry> {
int64_t poolId,
const FabricGeometryDefinition& geometryDefinition,
uint64_t initialCapacity,
bool debugRandomColors,
long stageId);

[[nodiscard]] const FabricGeometryDefinition& getGeometryDefinition() const;
Expand All @@ -24,7 +23,6 @@ class FabricGeometryPool final : public ObjectPool<FabricGeometry> {
private:
const int64_t _poolId;
const FabricGeometryDefinition _geometryDefinition;
const bool _debugRandomColors;
const long _stageId;
};

Expand Down
6 changes: 4 additions & 2 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class FabricMaterial {
const FabricMaterialDefinition& materialDefinition,
const pxr::TfToken& defaultTextureAssetPathToken,
const pxr::TfToken& defaultTransparentTextureAssetPathToken,
bool debugRandomColors,
long stageId);
~FabricMaterial();

Expand All @@ -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);
Expand Down Expand Up @@ -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<omni::fabric::Path> _shaderPaths;
Expand Down
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 @@ -16,6 +16,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
uint64_t initialCapacity,
const pxr::TfToken& defaultTextureAssetPathToken,
const pxr::TfToken& defaultTransparentTextureAssetPathToken,
bool debugRandomColors,
long stageId);

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

Expand Down
3 changes: 2 additions & 1 deletion src/core/include/cesium/omniverse/OmniTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class OmniTileset {

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

Expand Down
6 changes: 2 additions & 4 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")) \
Expand Down Expand Up @@ -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")) \
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
33 changes: 0 additions & 33 deletions src/core/src/FabricGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#endif

#include <CesiumGltf/Model.h>
#include <glm/gtc/random.hpp>
#include <omni/fabric/FabricUSD.h>

namespace cesium::omniverse {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<uint64_t> primvarIndexStArray;
primvarIndexStArray.reserve(texcoordSetCount);

Expand All @@ -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<omni::fabric::TokenC>(_path, FabricTokens::primvars);
auto primvarInterpolationsFabric = srw.getArrayAttributeWr<omni::fabric::TokenC>(_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;
Expand Down Expand Up @@ -241,8 +225,6 @@ void FabricGeometry::reset() {
auto worldPositionFabric = srw.getAttributeWr<pxr::GfVec3d>(_path, FabricTokens::_worldPosition);
auto worldOrientationFabric = srw.getAttributeWr<pxr::GfQuatf>(_path, FabricTokens::_worldOrientation);
auto worldScaleFabric = srw.getAttributeWr<pxr::GfVec3f>(_path, FabricTokens::_worldScale);
auto displayColorFabric = srw.getArrayAttributeWr<pxr::GfVec3f>(_path, FabricTokens::primvars_displayColor);
auto displayOpacityFabric = srw.getArrayAttributeWr<float>(_path, FabricTokens::primvars_displayOpacity);
// clang-format on

*extentFabric = DEFAULT_EXTENT;
Expand All @@ -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);

Expand Down Expand Up @@ -462,8 +442,6 @@ void FabricGeometry::setGeometry(
auto worldPositionFabric = srw.getAttributeWr<pxr::GfVec3d>(_path, FabricTokens::_worldPosition);
auto worldOrientationFabric = srw.getAttributeWr<pxr::GfQuatf>(_path, FabricTokens::_worldOrientation);
auto worldScaleFabric = srw.getAttributeWr<pxr::GfVec3f>(_path, FabricTokens::_worldScale);
auto displayColorFabric = srw.getArrayAttributeWr<pxr::GfVec3f>(_path, FabricTokens::primvars_displayColor);
auto displayOpacityFabric = srw.getArrayAttributeWr<float>(_path, FabricTokens::primvars_displayOpacity);
// clang-format on

*extentFabric = localExtent;
Expand All @@ -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);
}

Expand Down
4 changes: 1 addition & 3 deletions src/core/src/FabricGeometryPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ FabricGeometryPool::FabricGeometryPool(
int64_t poolId,
const FabricGeometryDefinition& geometryDefinition,
uint64_t initialCapacity,
bool debugRandomColors,
long stageId)
: ObjectPool<FabricGeometry>()
, _poolId(poolId)
, _geometryDefinition(geometryDefinition)
, _debugRandomColors(debugRandomColors)
, _stageId(stageId) {
setCapacity(initialCapacity);
}
Expand All @@ -25,7 +23,7 @@ const FabricGeometryDefinition& FabricGeometryPool::getGeometryDefinition() cons
std::shared_ptr<FabricGeometry> 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<FabricGeometry>(path, _geometryDefinition, _debugRandomColors, _stageId);
return std::make_shared<FabricGeometry>(path, _geometryDefinition, _stageId);
}

void FabricGeometryPool::setActive(std::shared_ptr<FabricGeometry> geometry, bool active) {
Expand Down
Loading

0 comments on commit f38d821

Please sign in to comment.