-
Notifications
You must be signed in to change notification settings - Fork 283
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
Unlit Materials #1017
Unlit Materials #1017
Conversation
joseph-kaile
commented
Dec 12, 2022
Thanks for the pull request @joseph-kaile!
Reviewers, don't forget to make sure that:
|
static void computeFakeNormals( | ||
const TArray<uint32_t>& indices, | ||
TArray<FStaticMeshBuildVertex>& vertices) { | ||
// Compute flat normals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect comment.
|
||
v0.TangentX = v1.TangentX = v2.TangentX = TMeshVector3(0.0f); | ||
v0.TangentY = v1.TangentY = v2.TangentY = TMeshVector3(0.0f); | ||
v0.TangentZ = v1.TangentZ = v2.TangentZ = TMeshVector3(0.0f, 0.0f, 1.0f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe using +Z as the normal isn't quite right. It's fine when the tileset is located near the georeference origin. But what if the origin is on one side of the globe, and the tileset is on the other? Then the tileset would only be lit when the sun is below the horizon, which is likely to surprise users.
So I think instead of +Z, the normal at each point should be set to the ellipsoid surface normal at that point, transformed to the mesh's coordinate system.
Basically you need to get each vertex position, transform it to ECEF using the transform
passed into this method, and then call Ellipsoid::WGS84.geodeticSurfaceNormal
to get the surface normal at that point. Then that surface normal has to be transformed from ECEF back to Unreal coordinates using the inverse of that passed-in transform
(don't forget to construct the vector to transform as glm::dvec4(ecefNormal, 0.0)
before multiplying it with the inverse of the transform, because it's a direction not a position).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHANGES.md
Outdated
|
||
##### Fixes :wrench: | ||
|
||
- Disable normals for unlit materials, which caused photogrammetry to appear too dark. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention the extension name here.
@joseph-kaile Sorry if I'm missing context, but a couple of comments:
|
computeFlatNormals(indices, StaticMeshBuildVertices); | ||
if (material.hasExtension<ExtensionKhrMaterialsUnlit>()) { | ||
glm::dvec3 ecefCenter = glm::dvec3( | ||
transform * CesiumTransforms::unrealToOrFromCesium * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the unrealToOrFromCesium
here and below are needed. I tested by using Buffer Visualization -> World Normal and comparing the color of Melbourne with Cesium World Terrain. Cesium World Terrain will have some undulations in its normals, while Melbourne will be a solid color, but the overall color of them should be the same because the normals should point in basically up in both cases. With the unrealToOrFromCesium
in place, they were quite different, but once I removed it they were the same. This makes sense because there's no need to use the Unreal coordinate system at all. The Origin is expressed in model coordinates, then we transform to ECEF, compute the normal, and transform the ECEF normal back to model coordinates.
There seems to be something weird with normals in Cesium for Unreal in general, though. Everything is good near the georeference origin, but on the back side of the globe something is wonky. For example, in this screenshot, both CWT and Melbourne are dark even though the sun is high in the sky:
This doesn't necessarily need to be fixed as part of this PR, but maybe you have an idea what's wrong? I'm at a bit of a loss at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I assumed that there was code I couldn't find that automatically transformed the coordinates in the position view accessor.
I did see something like that. I think when the georeference was so far away everything was sky blue. I just thought that this was from floating point precision cause its too far away from the origin it gets messed up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be precision related, but in theory the directional light should just be a direction, so the large coordinate values shouldn't matter too much. But who knows. I'll write an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! I think it's just this issue again:
#527
And there's a workaround listed in there.
Thanks @joseph-kaile! |