Rotate both X and Y in a material (HDR, SkySphere)

Hi,
I am trying to rotate both X and Y in my material (for a skysphere). I have tried many approaches but often resulting in image distortion.

For now my most stable approach is:

At first this seem to work but eventually I realized that at some point my up/down rotation are switched gradually overtime (almost like a slow sinus).

Any idea on how to rotate both x and y without distorting the image?

I have tried another approach where I try to simply use a mesh with a material based on objectOrientation (I use a sphere mesh to do a skysphere). This works well for the sky itself but now all my other actors flickers which was not the case with the dynamic texture (the niagara effects are the most afffected by the flickering).

Help please.

1 Like

You don’t need any of that stuff :wink:

If you want to rotate the sky, you can just add to the UVs in the sky material. Assuming your texture is square

The reason you’re getting distortion, is because the typical sphere has distorted UVs, especially pinched at the top

The other option, is a sort of cube layout, but then the distortion is just somewhere else

In the end, the best option, is to make your own sky dome ( not sphere ), because it is possible to project the UVs down from a plane, and avoid almost all problems

Here I just made a sphere using the modelling tools, and then reprojected the UVs using a plane. Tell me if you need a step by step on that.

As long as you keep the stretchy bit low on the horizon, you’re good.

Hi,
Thx @ClockworkOcean for your quick response.

Regarding
The reason you’re getting distortion, is because the typical sphere has distorted UVs, especially pinched at the top

I get what you mean but in my case the distortion was kind of dynamic (like a deflating or inflating balloon, but now with the screenshot from main post I don’t have any distortion, only up/down rotation degradation). I suspected my pivot point at first but it does not seem to be the issue.

The distortion from the sphere is really not that bad I can see it in the viewport with another non dynamic version of my texture.

Just FYI,
For the sphere itself I mainly followed:
-https://www.youtube.com/watch?v=bXMcZfvB_Ik (For the texture to sphere)
-https://www.youtube.com/watch?v=IQ3wKSzAEG4 (For the rotation of the texture, however he only rotates around one axis).

I also added a screen shot to my original post

That being said, I will try your approach to see if I can manage to obtain interesting results.

I will keep you inform.

1 Like

Ah, it’s an HDR, you didn’t say that :wink:

Then only makes sense to rotate on Z ( or the up ) axis. Rotating on another axis would just tilt the whole thing.

There’s already an HDRI plugin as part of the engine

Once you’ve enabled it, you can just drop an HDR in the map

It has a similar material to yours here, but more complex. You might want to take a look at that.

I haven’t look yet to your HDR plugin. However I have 2 solutions:

Solution#1:
The one mentioned in the initial post (the mesh with object orientiation)


PROS: Fluid rotation of the background at runtime
CONS: High flickering of actors (especially niagara systems)

Solution#2:
Code solution mixed to perform Angles to Quaternions transformation (to mix X axis and Y axis together, thx Bing Copilot) mixed with the solution presented in https://www.youtube.com/watch?v=IQ3wKSzAEG4. (This one use a /Engine/EngineSky/SM_SkySphere.SM_SkySphere instead of /Engine/BasicShapes/Sphere.Sphere)

				f_YBasicRotation = 0 + 0.1 * f_Counter;
				f_XBasicRotation =  0 + 0.1 * f_Counter;
				f_Counter++;

				// Define the rotations
				FRotator RotationX(f_YBasicRotation, 0.0f, 0.0f);
				FRotator RotationY(0.0f, 0.0f , f_XBasicRotation);

				// Convert to quaternions
				FQuat QuatX = FQuat(RotationX);
				FQuat QuatY = FQuat(-1 * RotationY);

				// Combine the quaternions
				FQuat CombinedQuat = QuatY * QuatX;

				// Ensure stability for small angles
				if (CombinedQuat.IsIdentity())
				{
					CombinedQuat = FQuat::Identity;
				}

				// Get the axis and angle from the combined quaternion
				FVector RotationAxis = CombinedQuat.GetRotationAxis();
				float RotationAngle = CombinedQuat.GetAngle();
				RotationAngle = FMath::RadiansToDegrees(RotationAngle); // Convert to degrees

				// Output the axis and angle
				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("N Rotation Axis: %s , Rotation Angle: %f degrees "), *RotationAxis.ToString(), RotationAngle));

				// Create a vector with rotation angle
				FVector MyVector(RotationAngle, 0.0f, 0.0f);

				// Set the material parameters
				UMID_DynamicSkyMaterial->SetVectorParameterValue(TEXT("AxisToSet"), RotationAxis);
				UMID_DynamicSkyMaterial->SetVectorParameterValue(TEXT("XYZMapRotation"), MyVector * 0.001);
				USMC_SkyDomeMesh->SetMaterial(0, UMID_DynamicSkyMaterial);

PROS: Low flickering of actors
CONS: Background rotation is a bit less fluid than option#1

For me option#2 is less annoying than option#1. I will keep option#2 (unless plugin results are nice)

I will try to get a look at your plugin.

Thx for your help!

1 Like

I still have some issue solution#2, I thought I was ok but my rotations axis get messed up. I suppose that with some revisions it will get there.

1 Like

If you want to rotate the sky, why not just rotate the mesh?

Because all the things in my view (within the sphere) (mainly niagara systems) flickers more with the mesh rotation approach than with the dynamic material approach

1 Like

No, I mean actually rotate the mesh, nothing to do with the material.

When I rotate the mesh (stuff in my game (within the sphere) flicker more)
When I rotate the material (stuff in my game (within the sphere) flicker less)

1 Like

Did you mark the sky material as ‘is sky’?

also unlit

It sounds a bit like your sky sphere is getting used for lighting computations.

My hero! so finally Solution#1
(Mesh, material with object rotation) with your sky fix to the material does exactly what I am looking for and I have no more flickering! THX


1 Like

Ha! :star_struck: