Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/shared-assets' into shared-asset…
Browse files Browse the repository at this point in the history
…s-wip
  • Loading branch information
kring committed Oct 29, 2024
2 parents 2d1ccd8 + d7cda44 commit 71b885b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

### Next Version - Not Released Yet

##### Additions :tada:

- Added `CircumscribedGroundHeight` property to `CesiumSunSky`. It defaults to 0, which is consistent with the previous behavior. It can be set to a larger value (like 40) to avoid dark splotchy artifacts when zoomed out far from the globe in certain tilesets where geometry extends very far beyond the ellipsoid in the low-detail representation, such as Google Photorealistic 3D Tiles.

##### Fixes :wrench:

- Fixed a bug that caused incorrect lighting for tilesets using `KHR_materials_unlit`.
- Reduced the memory used by tiles with `KHR_materials_unlit`.
- `CesiumGlobeAnchor` properties are no longer shown on the main `CesiumSunSky` Details panel, because it is almost never necessary to set these. They can still be set on the component's own Details panel if needed.

### v2.9.0 - 2024-10-01

##### Additions :tada:
Expand Down
49 changes: 28 additions & 21 deletions Source/CesiumRuntime/Private/CesiumGltfComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,23 @@ static void computeTangentSpace(TArray<FStaticMeshBuildVertex>& vertices) {
genTangSpaceDefault(&MikkTContext);
}

static void setUniformNormals(
static void setUnlitNormals(
TArray<FStaticMeshBuildVertex>& vertices,
TMeshVector3 normal) {
const CesiumGeospatial::Ellipsoid& ellipsoid,
const glm::dmat4& vertexToEllipsoidFixed) {
glm::dmat4 ellipsoidFixedToVertex =
glm::affineInverse(vertexToEllipsoidFixed);

for (int i = 0; i < vertices.Num(); i++) {
FStaticMeshBuildVertex& v = vertices[i];
v.TangentX = v.TangentY = TMeshVector3(0.0f);
v.TangentZ = normal;

glm::dvec3 positionFixed = glm::dvec3(
vertexToEllipsoidFixed *
glm::dvec4(VecMath::createVector3D(FVector(v.Position)), 1.0));
glm::dvec3 normal = ellipsoid.geodeticSurfaceNormal(positionFixed);
v.TangentZ = FVector3f(VecMath::createVector(
glm::normalize(ellipsoidFixedToVertex * glm::dvec4(normal, 0.0))));
}
}

Expand Down Expand Up @@ -1349,7 +1359,10 @@ static void loadPrimitive(
// vertices shared by multiple triangles. If we don't have tangents, but
// need them, we need to use a tangent space generation algorithm which
// requires duplicated vertices.
bool duplicateVertices = !hasNormals || (needsTangents && !hasTangents);
bool normalsAreRequired = !primitiveResult.isUnlit;
bool needToGenerateFlatNormals = normalsAreRequired && !hasNormals;
bool needToGenerateTangents = needsTangents && !hasTangents;
bool duplicateVertices = needToGenerateFlatNormals || needToGenerateTangents;
duplicateVertices =
duplicateVertices && primitive.mode != MeshPrimitive::Mode::POINTS;

Expand Down Expand Up @@ -1512,6 +1525,13 @@ static void loadPrimitive(
}
}

double scale = 1.0 / CesiumPrimitiveData::positionScaleFactor;
glm::dmat4 scaleMatrix = glm::dmat4(
glm::dvec4(scale, 0.0, 0.0, 0.0),
glm::dvec4(0.0, scale, 0.0, 0.0),
glm::dvec4(0.0, 0.0, scale, 0.0),
glm::dvec4(0.0, 0.0, 0.0, 1.0));

// TangentX: Tangent
// TangentY: Bi-tangent
// TangentZ: Normal
Expand Down Expand Up @@ -1543,16 +1563,10 @@ static void loadPrimitive(
}
} else {
if (primitiveResult.isUnlit) {
glm::dvec3 ecefCenter = glm::dvec3(
transform *
glm::dvec4(VecMath::createVector3D(RenderData->Bounds.Origin), 1.0));
TMeshVector3 upDir = TMeshVector3(VecMath::createVector(
glm::affineInverse(transform) *
glm::dvec4(
ellipsoid.geodeticSurfaceNormal(glm::dvec3(ecefCenter)),
0.0)));
upDir.Y *= -1;
setUniformNormals(StaticMeshBuildVertices, upDir);
setUnlitNormals(
StaticMeshBuildVertices,
ellipsoid,
transform * yInvertMatrix * scaleMatrix);
} else {
TRACE_CPUPROFILER_EVENT_SCOPE(Cesium::ComputeFlatNormals)
computeFlatNormals(StaticMeshBuildVertices);
Expand Down Expand Up @@ -1687,13 +1701,6 @@ static void loadPrimitive(
primitiveResult.RenderData = std::move(RenderData);
primitiveResult.pCollisionMesh = nullptr;

double scale = 1.0 / CesiumPrimitiveData::positionScaleFactor;
glm::dmat4 scaleMatrix = glm::dmat4(
glm::dvec4(scale, 0.0, 0.0, 0.0),
glm::dvec4(0.0, scale, 0.0, 0.0),
glm::dvec4(0.0, 0.0, scale, 0.0),
glm::dvec4(0.0, 0.0, 0.0, 1.0));

primitiveResult.transform = transform * yInvertMatrix * scaleMatrix;

if (primitive.mode != MeshPrimitive::Mode::POINTS &&
Expand Down
3 changes: 2 additions & 1 deletion Source/CesiumRuntime/Private/CesiumSunSky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ void ACesiumSunSky::UpdateAtmosphereRadius() {
pGeoreference->TransformUnrealPositionToLongitudeLatitudeHeight(location);

// An atmosphere of this radius should circumscribe all Earth terrain.
double maxRadius = pEllipsoid->GetMaximumRadius();
double maxRadius =
pEllipsoid->GetMaximumRadius() + this->CircumscribedGroundHeight * 1000.0;

if (llh.Z / 1000.0 > this->CircumscribedGroundThreshold) {
this->SetSkyAtmosphereGroundRadius(
Expand Down
17 changes: 16 additions & 1 deletion Source/CesiumRuntime/Public/CesiumSunSky.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CESIUMRUNTIME_API ACesiumSunSky : public AActor {
/**
* The Globe Anchor Component that precisely ties this Actor to the Globe.
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Cesium")
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Components)
UCesiumGlobeAnchorComponent* GlobeAnchor;

/**
Expand Down Expand Up @@ -295,6 +295,21 @@ class CESIUMRUNTIME_API ACesiumSunSky : public AActor {
Category = "Cesium|Atmosphere")
double CircumscribedGroundThreshold = 100.0;

/**
* The height at which to place the bottom of the atmosphere when the player
* pawn is above the CircumscribedGroundThreshold. This is expressed as a
* height in kilometers above the maximum radius of the ellipsoid (usually
* WGS84). To avoid dark splotchy artifacts in the atmosphere when zoomed out
* far from the globe, this value must be above the greatest height achieved
* by any part of the tileset.
*/
UPROPERTY(
EditAnywhere,
BlueprintReadWrite,
meta = (EditCondition = "UpdateAtmosphereAtRuntime"),
Category = "Cesium|Atmosphere")
double CircumscribedGroundHeight = 0.0;

/**
* The height of the atmosphere layer above the ground, in kilometers. This
* value is automatically scaled according to the CesiumGeoreference Scale and
Expand Down

0 comments on commit 71b885b

Please sign in to comment.