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

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