how to rotate reflection vector/ skybox

Hello, I have a skybox using these nodes:

How can I rotate the reflection vector to rotate the skybox on z axis in game? I have tried the different rotate Vector nodes with no luck, some will rotate x and y but I haven’t been able to rotate on z axis.

You need to rotate that vector yes. However standard material nodes do not have required math exposed. So you need to make hlsl custom shader. It is not that hard. And coincidence i made similar shader to what you want about month ago. You can either search forum for NASA skybox texture + nawrot, or wait a bit for me to post that shader again.

Or you can try instead vertex shader and rotate sphere mesh trough material vertex shader.

faster is just giving you link to that post:

shader for rotating is last reply.

However it has a bug i wrongly used X,Y,Z vectors. I copied rotating calculations from system that uses Y as vertical axis (unreal uses Z), so some fiddling with calculating rotations would be required.

Also shader calculates rotation for place on surface of earth and day/year, you may want to remove those calculations. Oh NVM this version does not have that day/year calculation. But i may include updated shader per request.

ps.
for skybox that uses reflection vector you need actual CUBEMAP texture.

Lots of good info here, thank you! I’d like to get this working in UEFN as well so sadly can’t use custom node yet but I’ll take these calculations and see if I can pull it off with nodes!

Uh not sure about UEFN materials, in Unreal those vector calculations are not exposed to normal nodes. You probably can do that calculations using sine, cosine, multiply and so on. But graph will be huge. In UEFN does not have material functions or at least named reroutes, I do not think it will be doable (because those calculations while simple use a lot of multiply and adding)

Edit that math is not complicated, it will be something like:

So this is what HLSL can do, you need this coded with just multiply and add:

// Given three float3 vectors ENU
float3 E = float3(a, b, c);
float3 N = float3(d, e, f);
float3 U = float3(g, h, i);

// Construct rotation matrix (column-major)
float3x3 M = float3x3(E, N, U);

// Transform reflection vector to skybox space
return mul(M, R);

Luckily it is just matrix math.

And it is not that complicated:

// Individual float values representing the matrix
float M00 = a, M01 = d, M02 = g;
float M10 = b, M11 = e, M12 = h;
float M20 = c, M21 = f, M22 = i;

// Reflection vector components
float Rx = R.x;
float Ry = R.y;
float Rz = R.z;

// Perform the matrix-vector multiplication manually
float x = M00 * Rx + M01 * Ry + M02 * Rz;
float y = M10 * Rx + M11 * Ry + M12 * Rz;
float z = M20 * Rx + M21 * Ry + M22 * Rz;

// Return the transformed vector
return float3(x, y, z);

just 9 variables, and then 3 more. Yup this begs for named reroutes.
1 Like

Amazing, thank you! This is making me want to learn hlsl now for other projects, I’d prefer coding to nodes for stuff like this for sure haha

1 Like

This calculation can be done with just basic nodes. I thought it was more complicated, but turns out it is just 3x3 matrix multiply 1x3. And calculating E,N,U vectors you have in first hlsl shader in other topic.

i think UEFN has custom functions and named reroutes (however i did not used those in UEFN myself). With function and named reroutes you can make this whole calculation without going nuts from wires everywhere. :wink:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.