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

Handle unlit materials #36

Open
lilleyse opened this issue Nov 3, 2022 · 1 comment
Open

Handle unlit materials #36

lilleyse opened this issue Nov 3, 2022 · 1 comment

Comments

@lilleyse
Copy link
Contributor

lilleyse commented Nov 3, 2022

If a glTF uses the KHR_materials_unlit extension we should render with an unlit material and not generate normals.

We could also give some control to the user. There could be a drop-down list to override the default behavior. The options would be UNLIT, LIT, or AUTO.

@lilleyse
Copy link
Contributor Author

Cesium for Unreal supports unlit materials by disabling shadows and making all normals point up (along the ellipsoid surface normal: CesiumGS/cesium-unreal#1017

I tried experimenting with the same idea in Omniverse and the results don't look great. Aside from ray self-intersections which show up as black, there's this flat shading type of look regardless of the normal direction. It reminds me of some of the issues in #59.

Smooth normals Flat normals Up normals
smooth-normals flat-normals wgs84-normals

unlit-normals-test.usda.zip

Here's the code:

pxr::VtArray<pxr::GfVec3f> getNormalsGlobe(
    const pxr::VtArray<pxr::GfVec3f>& positions,
    const glm::dmat4& localToEcefTransform) {

    const auto ecefToLocalTransform = glm::dmat3(glm::inverse(localToEcefTransform));

    pxr::VtArray<pxr::GfVec3f> normalsUsd(positions.size(), pxr::GfVec3f(0.0f));

    for (size_t i = 0; i < positions.size(); i++) {
        const auto position = UsdUtil::usdToGlmVector(positions[i]);
        const auto positionEcef = glm::dvec3(localToEcefTransform * glm::dvec4(position, 1.0));
        const auto normalEcef = glm::normalize(positionEcef); // geocentric normal, should be geodetic
        const auto normal = ecefToLocalTransform * normalEcef;
        normalsUsd[i] = pxr::GfVec3f(static_cast<float>(normal.x), static_cast<float>(normal.y), static_cast<float>(normal.z));
    }

    return normalsUsd;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant