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 70cb777
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 173 deletions.
201 changes: 107 additions & 94 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
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
Loading

0 comments on commit 70cb777

Please sign in to comment.