Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up FabricMaterial #540

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ float4 alpha_blend(float4 src, float4 dst) {
}

float4 compute_base_color(
gltf_texture_lookup_value imagery_layers_texture,
gltf_texture_lookup_value imagery_layer,
float4 tile_color,
gltf_texture_lookup_value base_color_texture,
color base_color_factor,
Expand All @@ -214,7 +214,7 @@ float4 compute_base_color(
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 *= ::scene::data_lookup_float4("COLOR_0", float4(1.0));
base_color = alpha_blend(imagery_layers_texture.value, base_color);
base_color = alpha_blend(imagery_layer.value, base_color);
base_color *= tile_color;

return base_color;
Expand Down Expand Up @@ -251,7 +251,7 @@ export gltf_texture_lookup_value cesium_internal_imagery_layer_lookup(
}

export material cesium_internal_material(
gltf_texture_lookup_value imagery_layers_texture = gltf_texture_lookup_value(true, float4(0.0)),
gltf_texture_lookup_value imagery_layer = gltf_texture_lookup_value(true, float4(0.0)),
uniform float4 tile_color = float4(1.0),
// gltf_material inputs below
gltf_texture_lookup_value base_color_texture = gltf_texture_lookup_value(),
Expand All @@ -263,7 +263,7 @@ export material cesium_internal_material(
uniform float base_alpha = 1.0,
uniform float alpha_cutoff = 0.5
) [[ anno::hidden() ]] = let {
auto base_color = compute_base_color(imagery_layers_texture, tile_color, base_color_texture, base_color_factor, base_alpha);
auto base_color = compute_base_color(imagery_layer, tile_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,
Expand Down
82 changes: 39 additions & 43 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "cesium/omniverse/FabricMaterialDefinition.h"
#include "cesium/omniverse/GltfUtil.h"

#ifdef CESIUM_OMNI_MSVC
#pragma push_macro("OPAQUE")
#undef OPAQUE
corybarr marked this conversation as resolved.
Show resolved Hide resolved
#endif

#include <omni/fabric/IPath.h>
#include <omni/fabric/Type.h>
#include <pxr/usd/sdf/assetPath.h>
Expand All @@ -14,6 +19,8 @@ class DynamicTextureProvider;

namespace cesium::omniverse {

class FabricTexture;

class FabricMaterial {
public:
FabricMaterial(
Expand All @@ -28,80 +35,66 @@ class FabricMaterial {
void setMaterial(
int64_t tilesetId,
const MaterialInfo& materialInfo,
const std::shared_ptr<FabricTexture>& baseColorTexture,
const glm::dvec3& displayColor,
double displayOpacity);
void setBaseColorTexture(
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo,
uint64_t texcoordIndex);
double displayOpacity,
const std::unordered_map<uint64_t, uint64_t>& texcoordIndexMapping);

void setImageryLayer(
const pxr::TfToken& textureAssetPathToken,
const std::shared_ptr<FabricTexture>& texture,
const TextureInfo& textureInfo,
uint64_t texcoordIndex,
uint64_t imageryLayerIndex,
double alpha);
double alpha,
const std::unordered_map<uint64_t, uint64_t>& imageryTexcoordIndexMapping);

void setImageryLayerAlpha(uint64_t imageryLayerIndex, double alpha);
void setDisplayColorAndOpacity(const glm::dvec3& displayColor, double displayOpacity);
void updateShaderInput(const omni::fabric::Path& shaderPath, const omni::fabric::Token& attributeName);

void clearMaterial();
void clearBaseColorTexture();
void clearImageryLayer(uint64_t imageryLayerIndex);
void clearImageryLayers();

void setActive(bool active);

[[nodiscard]] const omni::fabric::Path& getPath() const;
[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;

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

void createMaterial(const omni::fabric::Path& materialPath);
void createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath);
void createMaterial(const omni::fabric::Path& path);
void createShader(const omni::fabric::Path& path);
void createTextureCommon(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput,
const omni::fabric::Path& path,
const omni::fabric::Token& subIdentifier,
const std::vector<std::pair<omni::fabric::Type, omni::fabric::Token>>& additionalAttributes = {});
void createTexture(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput);
void createImageryLayer(
const omni::fabric::Path& imageryLayerPath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput);
void createImageryLayerResolver(
const omni::fabric::Path& imageryLayerResolverPath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput,
uint64_t textureCount);
void createTexture(const omni::fabric::Path& path);
void createImageryLayer(const omni::fabric::Path& path);
void createImageryLayerResolver(const omni::fabric::Path& path, uint64_t textureCount);

void reset();

void setShaderValues(
const omni::fabric::Path& shaderPath,
const omni::fabric::Path& path,
const MaterialInfo& materialInfo,
const glm::dvec3& displayColor,
double displayOpacity);
void setTextureValuesCommon(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& path,
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo,
uint64_t texcoordIndex);
void setTextureValues(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& path,
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo,
uint64_t texcoordIndex);
void setImageryLayerValues(
const omni::fabric::Path& imageryLayerPath,
const omni::fabric::Path& path,
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo,
uint64_t texcoordIndex,
double alpha);
void setImageryLayerAlphaValue(const omni::fabric::Path& imageryLayerPath, double alpha);
void setImageryLayerAlphaValue(const omni::fabric::Path& path, double alpha);

bool stageDestroyed();

Expand All @@ -112,12 +105,15 @@ class FabricMaterial {
const bool _debugRandomColors;
const long _stageId;

AlphaMode _alphaMode;
glm::dvec3 _debugColor;
bool _usesDefaultMaterial;

AlphaMode _alphaMode{AlphaMode::OPAQUE};
glm::dvec3 _debugColor{1.0, 1.0, 1.0};

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

std::vector<omni::fabric::Path> _allPaths;
};
Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/FabricTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct ImageCesium;
} // namespace CesiumGltf

namespace cesium::omniverse {

class FabricTexture {
public:
FabricTexture(const std::string& name);
Expand Down
3 changes: 0 additions & 3 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
((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")) \
((inputs_wrap_t, "inputs:wrap_t")) \
((material_binding, "material:binding")) \
Expand Down Expand Up @@ -238,7 +236,6 @@ const omni::fabric::Type inputs_scale(omni::fabric::BaseDataType::eFloat, 2, 0,
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_imagery_layers_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);
const omni::fabric::Type Material(omni::fabric::BaseDataType::eTag, 1, 0, omni::fabric::AttributeRole::ePrimTypeName);
Expand Down
Loading