Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Aug 4, 2023
1 parent fe22312 commit affaad9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
43 changes: 27 additions & 16 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export color cesium_lookup_world_texture_color(uniform texture_2d texture = text

// For internal use only. See note in FabricMaterial.cpp
export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup();
export material cesium_material(*) [[ anno::hidden() ]] = gltf_material();

export color cesium_base_color_texture(
gltf_texture_lookup_value base_color_texture
Expand All @@ -95,6 +96,7 @@ export color cesium_base_color_texture(
}

export gltf_texture_lookup_value cesium_read_from_texture_array(
uniform texture_2d texture,
uniform texture_2d[2] textures,
float2 min_world = float2(-5000.0, -5000.0),
float2 max_world = float2(5000.0, 5000.0),
Expand All @@ -110,26 +112,35 @@ export gltf_texture_lookup_value cesium_read_from_texture_array(
{
gltf_texture_lookup_value tex_ret;
tex_ret.valid = true;

int texture_index = 0;//::scene::data_lookup_int("texture_index");

for (int i = 0; i < 2; i++) {
if (i == texture_index) {
tex_ret.value = tex::lookup_float4(
tex: textures[i],
coord: world_coordinate_2d(min_world, max_world, up_axis),
wrap_u: ::tex::wrap_clamp,
wrap_v: ::tex::wrap_clamp);

return tex_ret;
}
}

tex_ret.value = tex::lookup_float4(
tex: textures[1],
tex: texture,
coord: world_coordinate_2d(min_world, max_world, up_axis),
wrap_u: ::tex::wrap_clamp,
wrap_v: ::tex::wrap_clamp);

return tex_ret;



// int texture_index = 0;//::scene::data_lookup_int("texture_index");

// for (int i = 0; i < 2; i++) {
// if (i == texture_index) {
// tex_ret.value = tex::lookup_float4(
// tex: textures[i],
// coord: world_coordinate_2d(min_world, max_world, up_axis),
// wrap_u: ::tex::wrap_clamp,
// wrap_v: ::tex::wrap_clamp);

// return tex_ret;
// }
// }

// tex_ret.value = tex::lookup_float4(
// tex: textures[1],
// coord: world_coordinate_2d(min_world, max_world, up_axis),
// wrap_u: ::tex::wrap_clamp,
// wrap_v: ::tex::wrap_clamp);

// return tex_ret;
}
2 changes: 2 additions & 0 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace cesium::omniverse::FabricTokens {
extern const omni::fabric::TokenC baseColorTex;
extern const omni::fabric::TokenC cesium_base_color_texture;
extern const omni::fabric::TokenC cesium_material;
extern const omni::fabric::TokenC cesium_read_from_texture_array;
extern const omni::fabric::TokenC cesium_texture_lookup;
extern const omni::fabric::TokenC constant;
Expand Down Expand Up @@ -77,6 +78,7 @@ extern const omni::fabric::TokenC _worldVisibility;
namespace cesium::omniverse::UsdTokens {
extern const pxr::TfToken& baseColorTex;
extern const pxr::TfToken& cesium_base_color_texture;
extern const pxr::TfToken& cesium_material;
extern const pxr::TfToken& cesium_read_from_texture_array;
extern const pxr::TfToken& cesium_texture_lookup;
extern const pxr::TfToken& constant;
Expand Down
13 changes: 10 additions & 3 deletions src/core/src/FabricMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ void FabricMaterial::createShader(const omni::fabric::Path& shaderPath, const om
auto infoMdlSourceAssetSubIdentifierFabric = srw.getAttributeWr<omni::fabric::Token>(shaderPath, FabricTokens::info_mdl_sourceAsset_subIdentifier);
// clang-format on

const auto& assetPath = Context::instance().getCesiumMdlPathToken();

*inputsExcludeFromWhiteModeFabric = false;
*infoImplementationSourceFabric = FabricTokens::sourceAsset;
infoMdlSourceAssetFabric->assetPath = UsdTokens::gltf_pbr_mdl;
infoMdlSourceAssetFabric->assetPath = assetPath;
infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken();
*infoMdlSourceAssetSubIdentifierFabric = FabricTokens::gltf_material;
*infoMdlSourceAssetSubIdentifierFabric = FabricTokens::cesium_material;

if (hasVertexColors) {
const auto vertexColorPrimvarNameSize = UsdTokens::vertexColor.GetString().size();
Expand Down Expand Up @@ -194,6 +196,7 @@ void FabricMaterial::createTexture(
FabricAttributesBuilder attributes;

// clang-format off
attributes.addAttribute(FabricTypes::inputs_texture, FabricTokens::inputs_texture);
attributes.addAttribute(FabricTypes::inputs_textures, FabricTokens::inputs_textures);
attributes.addAttribute(FabricTypes::outputs_out, FabricTokens::outputs_out);
attributes.addAttribute(FabricTypes::info_implementationSource, FabricTokens::info_implementationSource);
Expand Down Expand Up @@ -293,11 +296,15 @@ void FabricMaterial::setTextureValues(

auto srw = UsdUtil::getFabricStageReaderWriter();

auto textureFabric = srw.getAttributeWr<omni::fabric::AssetPath>(texturePath, FabricTokens::inputs_texture);
auto texturesFabric = srw.getArrayAttributeWr<omni::fabric::AssetPath>(texturePath, FabricTokens::inputs_textures);

textureFabric->assetPath = _textureAssetPathTokenRed;
textureFabric->resolvedPath = pxr::TfToken();

texturesFabric[0].assetPath = _textureAssetPathTokenRed;
texturesFabric[0].resolvedPath = pxr::TfToken();
texturesFabric[1].assetPath = _textureAssetPathTokenRed;
texturesFabric[1].assetPath = _textureAssetPathTokenBlue;
texturesFabric[1].resolvedPath = pxr::TfToken();
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/src/Tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TF_DEFINE_PRIVATE_TOKENS(
UsdTokens,
(baseColorTex)
(cesium_base_color_texture)
(cesium_material)
(cesium_read_from_texture_array)
(cesium_texture_lookup)
(constant)
Expand Down Expand Up @@ -92,6 +93,7 @@ __pragma(warning(pop))
namespace cesium::omniverse::FabricTokens {
const omni::fabric::TokenC baseColorTex = omni::fabric::asInt(pxr::UsdTokens->baseColorTex);
const omni::fabric::TokenC cesium_base_color_texture = omni::fabric::asInt(pxr::UsdTokens->cesium_base_color_texture);
const omni::fabric::TokenC cesium_material = omni::fabric::asInt(pxr::UsdTokens->cesium_material);
const omni::fabric::TokenC cesium_read_from_texture_array = omni::fabric::asInt(pxr::UsdTokens->cesium_read_from_texture_array);
const omni::fabric::TokenC cesium_texture_lookup = omni::fabric::asInt(pxr::UsdTokens->cesium_texture_lookup);
const omni::fabric::TokenC constant = omni::fabric::asInt(pxr::UsdTokens->constant);
Expand Down Expand Up @@ -161,6 +163,7 @@ const omni::fabric::TokenC _worldVisibility = omni::fabric::asInt(pxr::UsdTokens
namespace cesium::omniverse::UsdTokens {
const pxr::TfToken& baseColorTex = pxr::UsdTokens->baseColorTex;
const pxr::TfToken& cesium_base_color_texture = pxr::UsdTokens->cesium_base_color_texture;
const pxr::TfToken& cesium_material = pxr::UsdTokens->cesium_material;
const pxr::TfToken& cesium_read_from_texture_array = pxr::UsdTokens->cesium_read_from_texture_array;
const pxr::TfToken& cesium_texture_lookup = pxr::UsdTokens->cesium_texture_lookup;
const pxr::TfToken& constant = pxr::UsdTokens->constant;
Expand Down

0 comments on commit affaad9

Please sign in to comment.