Skip to content

Commit

Permalink
Merge pull request #406 from CesiumGS/tileset-material-nodes
Browse files Browse the repository at this point in the history
Add base color texture node to tileset materials
  • Loading branch information
lilleyse authored Oct 19, 2023
2 parents 7fc5672 + 67024a8 commit 5ec6e4b
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 49 deletions.
2 changes: 1 addition & 1 deletion apps/cesium.omniverse.dev.kit
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ app = true

[settings]
app.window.title = "Cesium for Omniverse Testing App"
app.useFabricSceneDelegate = true
app.useFabricSceneDelegate = false
app.usdrt.scene_delegate.enableProxyCubes = false
app.usdrt.scene_delegate.geometryStreaming.enabled = false
omnihydra.parallelHydraSprimSync = false
Expand Down
113 changes: 110 additions & 3 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")
]];

annotation annotation_not_connectable();

export float4 cesium_base_color_texture_float4(
gltf_texture_lookup_value base_color_texture = gltf_texture_lookup_value()
[[
anno::hidden(),
annotation_not_connectable()
]]
)
[[
anno::display_name("Cesium base color texture lookup float4"),
anno::description("Returns the base color texture as a float4. Returns [0, 0, 0, 0] if the base color texture does not exist."),
anno::author("Cesium GS Inc."),
anno::in_group("Cesium")
]]
{
return base_color_texture.valid ? base_color_texture.value : float4(0.0);
}

export float4 cesium_imagery_layer_float4(
gltf_texture_lookup_value imagery_layer = gltf_texture_lookup_value()
[[
anno::hidden(),
annotation_not_connectable()
]],
int imagery_layer_index = 0
[[
anno::unused()
]]
)
[[
anno::display_name("Cesium imagery layer lookup float4"),
anno::description("Returns the imagery layer at the given index as a float4. Returns [0, 0, 0, 0] if the imagery layer does not exist."),
anno::author("Cesium GS Inc."),
anno::in_group("Cesium")
]]
{
return imagery_layer.valid ? imagery_layer.value : float4(0.0);
}

export material cesium_material(
uniform color base_color_factor = color(1.0)
[[
anno::display_name("Base Color Factor"),
anno::description("The base color of the material.")
]],
uniform float metallic_factor = 0.0
[[
anno::hard_range(0.0, 1.0),
anno::display_name("Metallic Factor"),
anno::description("The metalness of the material. Select between dielectric (0.0) and metallic (1.0).")
]],

uniform float roughness_factor = 1.0
[[
anno::hard_range(0.0, 1.0),
anno::display_name("Roughness Factor"),
anno::description("The roughness of the material. Select between very glossy (0.0) and dull (1.0).")
]],
uniform color emissive_factor = color(0.0)
[[
anno::display_name("Emissive Factor"),
anno::description("The emissive color of the material.")
]],
uniform gltf_alpha_mode alpha_mode = opaque
[[
anno::display_name("Alpha Mode"),
anno::description("Select how to interpret the alpha value.")
]],
uniform float base_alpha = 1.0
[[
anno::hard_range(0.0, 1.0),
anno::display_name("Base Alpha"),
anno::description("Select between transparent (0.0) and opaque (1.0)."),
anno::enable_if("alpha_mode!=opaque")
]],
uniform float alpha_cutoff = 0.5
[[
anno::hard_range(0.0, 1.0),
anno::display_name("Alpha Cutoff"),
anno::description("Threshold to decide between fully transparent and fully opaque when alpha mode is 'mask'."),
anno::enable_if("alpha_mode==mask")
]]
) [[
anno::display_name("Cesium PBR material"),
anno::description("Cesium metallic-roughness material based off glTF PBR model"),
anno::author("Cesium GS Inc."),
anno::in_group("Cesium")
]] = let {
material base = gltf_material(
base_color_factor: base_color_factor,
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
);

float4 alpha_blend(float4 src, float4 dst) {
return src * float4(src.w, src.w, src.w, 1.0) + dst * (1.0 - src.w);
}
Expand All @@ -33,9 +140,9 @@ float4 compute_base_color(
return base_color;
}

export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup();
export gltf_texture_lookup_value cesium_internal_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup();

export material cesium_material(
export material cesium_internal_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
Expand Down Expand Up @@ -66,7 +173,7 @@ export material cesium_material(
geometry: base.geometry
);

export gltf_texture_lookup_value cesium_imagery_layer_resolver(
export gltf_texture_lookup_value cesium_internal_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(),
Expand Down
7 changes: 4 additions & 3 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FabricMaterial {

private:
void initialize();
void initializeFromExistingMaterial(const omni::fabric::Path& path);

void createMaterial(const omni::fabric::Path& materialPath);
void createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath);
Expand Down Expand Up @@ -76,9 +77,9 @@ class FabricMaterial {
const bool _debugRandomColors;
const long _stageId;

omni::fabric::Path _shaderPath;
omni::fabric::Path _baseColorTexturePath;
std::vector<omni::fabric::Path> _imageryLayerPaths;
std::vector<omni::fabric::Path> _shaderPaths;
std::vector<omni::fabric::Path> _baseColorTexturePaths;
std::vector<std::vector<omni::fabric::Path>> _imageryLayerPaths;

std::vector<omni::fabric::Path> _allPaths;
};
Expand Down
10 changes: 9 additions & 1 deletion src/core/include/cesium/omniverse/FabricMaterialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
#include <glm/glm.hpp>
#include <pxr/base/gf/vec2f.h>
#include <pxr/base/gf/vec3f.h>
#include <pxr/usd/sdf/path.h>

namespace cesium::omniverse {

struct MaterialInfo;

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

[[nodiscard]] bool hasVertexColors() const;
[[nodiscard]] bool hasBaseColorTexture() const;
[[nodiscard]] uint64_t getImageryLayerCount() const;
[[nodiscard]] bool hasTilesetMaterial() const;
[[nodiscard]] const pxr::SdfPath& getTilesetMaterialPath() const;

// Make sure to update this function when adding new fields to the class
bool operator==(const FabricMaterialDefinition& other) const;
Expand All @@ -23,6 +30,7 @@ class FabricMaterialDefinition {
bool _hasVertexColors;
bool _hasBaseColorTexture;
uint64_t _imageryLayerCount;
pxr::SdfPath _tilesetMaterialPath;
};

} // namespace cesium::omniverse
8 changes: 6 additions & 2 deletions src/core/include/cesium/omniverse/FabricResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ class FabricResourceManager {
bool smoothNormals,
long stageId);

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

std::shared_ptr<FabricTexture> acquireTexture();

Expand Down
6 changes: 5 additions & 1 deletion src/core/include/cesium/omniverse/FabricUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void setTilesetTransform(int64_t tilesetId, const glm::dmat4& ecefToUsdTransform
void setTilesetId(const omni::fabric::Path& path, int64_t tilesetId);
omni::fabric::Path toFabricPath(const pxr::SdfPath& path);
omni::fabric::Path joinPaths(const omni::fabric::Path& absolutePath, const omni::fabric::Token& relativePath);
bool isEmpty(const omni::fabric::Path& path);
std::vector<omni::fabric::Path>
copyMaterial(const omni::fabric::Path& srcMaterialPath, const omni::fabric::Path& dstMaterialPath);
bool materialHasCesiumNodes(const omni::fabric::Path& path);
bool isCesiumNode(const omni::fabric::Token& mdlIdentifier);
omni::fabric::Token getMdlIdentifier(const omni::fabric::Path& path);

} // namespace cesium::omniverse::FabricUtil
11 changes: 8 additions & 3 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
#define USD_TOKENS \
(base_color_texture) \
(cesium) \
(cesium_imagery_layer_resolver) \
(cesium_material) \
(cesium_texture_lookup) \
(cesium_base_color_texture_float4) \
(cesium_imagery_layer_float4) \
(cesium_internal_imagery_layer_resolver) \
(cesium_internal_material) \
(cesium_internal_texture_lookup) \
(constant) \
(doubleSided) \
(extent) \
(faceVertexCounts) \
(faceVertexIndices) \
(imagery_layer) \
(imagery_layer_0) \
(imagery_layer_1) \
(imagery_layer_2) \
Expand Down Expand Up @@ -79,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 @@ -96,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
Loading

0 comments on commit 5ec6e4b

Please sign in to comment.