Wojtek Sterna's Avatar

Wojtek Sterna

@wojtsterna.bsky.social

Principal Engine Programmer at Flying Wild Hog ๐Ÿ– Formerly: NVIDIA, id Software, CD PROJEKT RED, Saxo Bank Professional ๐Ÿฑ petter

28 Followers  |  3 Following  |  37 Posts  |  Joined: 27.10.2024  |  2.1131

Latest posts by wojtsterna.bsky.social on Bluesky

Post image

UE5. If you are writing a plugin which you want to work ONLY in non-shipping game/editor builds (think of a helper plugin used only during development) you can configure the uplugin file like in the screenshot below.

16.10.2025 16:21 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0
https://youtu.be/vgsZGZ0csVQ?t=987

t.co/7QUI33zwGY

30.09.2025 20:28 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0

UE5: So there are these comps for dealing with dynamic geometry:
- ProceduralMeshComponent
- CustomMeshComponent
- DynamicMeshComponent

Apparently starting with UE5 we should be using DynamicMeshComponent. The other two are legacy.

30.09.2025 20:28 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0
Rotate About Axis Node | Shader Graph | 6.9.2

References:
[1] docs.unity3d.com/Packages/com...
[2] en.wikipedia.org/wiki/Rodrigu...

29.07.2025 08:55 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0

๐Ÿฐ. Unreal uses an even different algorithm with projecting the point to rotate onto the rotation axis. If you make a material using the image below and in the UE material editor go to ๐—ช๐—ถ๐—ป๐—ฑ๐—ผ๐˜„ -> ๐—ฆ๐—ต๐—ฎ๐—ฑ๐—ฒ๐—ฟ ๐—–๐—ผ๐—ฑ๐—ฒ -> ๐—›๐—Ÿ๐—ฆ๐—Ÿ ๐—–๐—ผ๐—ฑ๐—ฒ you can look up implementation of ๐—ฅ๐—ผ๐˜๐—ฎ๐˜๐—ฒ๐—”๐—ฏ๐—ผ๐˜‚๐˜๐—”๐˜…๐—ถ๐˜€ function.

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

๐Ÿฏ. Use Rodrigues' rotation formula (minding the pivot point). This is a pretty neat and fairly short formula that can be used if you don't feel like using matrices or quaternions [2].

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

๐Ÿฎ. Use a quaternion. Construct a rotation quaternion and transform by it the point we want to rotate (minding the pivot point).

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

And how can such a rotation be implemented? There are at a least a few ways:
๐Ÿญ. Use a 3x3 rotation matrix. Build a rotation matrix and transform by it the point we want to rotate (minding the pivot point). Unity seems to be using that approach [1].

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

In Unity's shader graph (Unity's counterpart of Unreal's material editor) we set the position of the vertex directly, and that is reflected in its ๐—ฅ๐—ผ๐˜๐—ฎ๐˜๐—ฒ ๐—”๐—ฏ๐—ผ๐˜‚๐˜ ๐—”๐˜…๐—ถ๐˜€ node, which contrary to Unreal does not return the offset but returns the absolute rotated point position.

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

So it returns the difference between the rotated point and the input point. This is very much likely due to the fact that in UE5 materials one of the output pins is ๐—ช๐—ผ๐—ฟ๐—น๐—ฑ ๐—ฃ๐—ผ๐˜€๐—ถ๐˜๐—ถ๐—ผ๐—ป ๐—ข๐—ณ๐—ณ๐˜€๐—ฒ๐˜, where we put an ๐—ผ๐—ณ๐—ณ๐˜€๐—ฒ๐˜ to the vertex position, instead of setting direct value for the vertex position.

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

It is important to realize what is the output of that node because ๐—ถ๐˜ ๐—ถ๐˜€ ๐—ป๐—ผ๐˜ the rotated position/point! It actually returns the value of:
๐—ฅ๐—ผ๐˜๐—ฎ๐˜๐—ฒ๐—ฑ๐—ฃ๐—ผ๐˜€๐—ถ๐˜๐—ถ๐—ผ๐—ป - ๐—ฃ๐—ผ๐˜€๐—ถ๐˜๐—ถ๐—ผ๐—ป

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

- ๐—ฃ๐—ถ๐˜ƒ๐—ผ๐˜๐—ฃ๐—ผ๐—ถ๐—ป๐˜ - That is the center of rotation, a point around which the rotation will occur.
- ๐—ฃ๐—ผ๐˜€๐—ถ๐˜๐—ถ๐—ผ๐—ป - This is the point/vector that we want to rotate.

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

- ๐—ก๐—ผ๐—ฟ๐—บ๐—ฎ๐—น๐—ถ๐˜‡๐—ฒ๐—ฑ๐—ฅ๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐—”๐˜…๐—ถ๐˜€ - That is our axis of rotation.
- ๐—ฅ๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐—”๐—ป๐—ด๐—น๐—ฒ - That is the angle of rotation. It is quite quirky, because this angle is not expressed in radians or degrees, but in normalized units. A value of 1.0, 2.0, 3.0, ... is a full revolution. 0.5 is 180 degrees rotation, etc.

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0
Post image

3D engines, like Unreal or Unity, usually expose some functionality that makes such rotations easy. In UE5, in the material editor, as shown in the image below, there is a node called ๐—ฅ๐—ผ๐˜๐—ฎ๐˜๐—ฒ๐—”๐—ฏ๐—ผ๐˜‚๐˜๐—”๐˜…๐—ถ๐˜€. It takes four inputs:

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

Rotation of points and/or vectors is an extremely important geometrical operation. In 2D it's quite simple because there is only one axis of rotation (the axis perpendicular to the XY plane) but in 3D we have an infinite number of axes that we could rotate about.

29.07.2025 08:49 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0
Post image

This is how you can inspect HLSL code of a material authored in UE material editor:

27.07.2025 16:00 โ€” ๐Ÿ‘ 1    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0
27.07.2025 15:55 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0
Post image

In Unreal Engine, in the material editor there is this node called RotateAboutAxis for rotating points/vectors about a given axis and angle. Here's how it is implemented:

27.07.2025 15:55 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0
Preview
Advanced Graphics Programming in Unreal, part 1 This is a seven-part article series.

If you do custom rendering in UE5, here's a pretty good series of articles

medium.com/@manning.w27...

11.07.2025 21:43 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0
Post image

Here's C# implementation:

29.06.2025 14:07 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0
Rodrigues' rotation formula - Wikipedia

For axis-angle rotation in 3D we usually use either a matrix or a quaternion. But if for some reason you do not want to involve either of these "math objects" you can use this neat formula directly: en.wikipedia.org/wiki/Rodrigu...

29.06.2025 14:07 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0
What Every Programmer Should Know about How CPUs Work โ€ข Matt Godbolt โ€ข GOTO 2024
YouTube video by GOTO Conferences What Every Programmer Should Know about How CPUs Work โ€ข Matt Godbolt โ€ข GOTO 2024

Pretty cool presentation

www.youtube.com/watch?v=-HNp...

17.06.2025 16:23 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0

The bolded part is crucial. Nanite, for each pixel has to evaluate 3 vertex positions (of the triangle the pixel belongs to). For that evaluation WPO for each vertex is needed, hence WPO is calculated 3x per pixel.

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 0    ๐Ÿ“Œ 0

โ€ข ๐˜œ๐˜ด๐˜ฆ๐˜ด ๐˜ต๐˜ฉ๐˜ฐ๐˜ด๐˜ฆ ๐˜ต๐˜ฐ ๐˜ฅ๐˜ฆ๐˜ณ๐˜ช๐˜ท๐˜ฆ ๐˜ต๐˜ฉ๐˜ฆ ๐˜ฃ๐˜ข๐˜ณ๐˜บ๐˜ค๐˜ฆ๐˜ฏ๐˜ต๐˜ณ๐˜ช๐˜ค ๐˜ค๐˜ฐ๐˜ฐ๐˜ณ๐˜ฅ๐˜ช๐˜ฏ๐˜ข๐˜ต๐˜ฆ๐˜ด ๐˜ง๐˜ฐ๐˜ณ ๐˜ต๐˜ฉ๐˜ช๐˜ด ๐˜ฑ๐˜ช๐˜น๐˜ฆ๐˜ญ
โ€ข ๐˜ˆ๐˜ฏ๐˜ฅ ๐˜ธ๐˜ช๐˜ต๐˜ฉ ๐˜ต๐˜ฉ๐˜ฐ๐˜ด๐˜ฆ, ๐˜ญ๐˜ฐ๐˜ข๐˜ฅ๐˜ด ๐˜ข๐˜ฏ๐˜ฅ ๐˜ช๐˜ฏ๐˜ต๐˜ฆ๐˜ณ๐˜ฑ๐˜ฐ๐˜ญ๐˜ข๐˜ต๐˜ฆ๐˜ด ๐˜ต๐˜ฉ๐˜ฆ ๐˜ท๐˜ฆ๐˜ณ๐˜ต๐˜ฆ๐˜น ๐˜ข๐˜ต๐˜ต๐˜ณ๐˜ช๐˜ฃ๐˜ถ๐˜ต๐˜ฆ๐˜ด."

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

Reference [2] is a link to a presentation from Epic on Nanite, where on slide 23 it says:
"๐˜›๐˜ฉ๐˜ฆ๐˜ฏ ๐˜ข ๐˜ฎ๐˜ข๐˜ต๐˜ฆ๐˜ณ๐˜ช๐˜ข๐˜ญ ๐˜ด๐˜ฉ๐˜ข๐˜ฅ๐˜ฆ๐˜ณ ๐˜ฑ๐˜ฆ๐˜ณ ๐˜ฑ๐˜ช๐˜น๐˜ฆ๐˜ญ:
โ€ข ๐˜“๐˜ฐ๐˜ข๐˜ฅ๐˜ด ๐˜ต๐˜ฉ๐˜ฆ ๐˜ท๐˜ช๐˜ด ๐˜ฃ๐˜ถ๐˜ง๐˜ง๐˜ฆ๐˜ณ
โ€ข ๐˜“๐˜ฐ๐˜ข๐˜ฅ๐˜ด ๐˜ต๐˜ฉ๐˜ฆ ๐˜ต๐˜ณ๐˜ช๐˜ข๐˜ฏ๐˜จ๐˜ญ๐˜ฆ ๐˜ฅ๐˜ข๐˜ต๐˜ข
โ€ข ๐™๐™ง๐™–๐™ฃ๐™จ๐™›๐™ค๐™ง๐™ข๐™จ ๐™ฉ๐™๐™š 3 ๐™ซ๐™š๐™ง๐™ฉ๐™š๐™ญ ๐™ฅ๐™ค๐™จ๐™ž๐™ฉ๐™ž๐™ค๐™ฃ๐™จ ๐™ฉ๐™ค ๐™ฉ๐™๐™š ๐™จ๐™˜๐™ง๐™š๐™š๐™ฃ

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

In the ๐—ก๐—ฎ๐—ป๐—ถ๐˜๐—ฒ scenario the cost of WPO is dependent on the number of pixels that the mesh occupies on the screen. For that particular mesh here, covering ~120 000 pixels, WPO would be calculated ~360 000 times (!). That is WPO is calculated 3x per pixel.

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

In ๐˜€๐˜๐—ฎ๐—ป๐—ฑ๐—ฎ๐—ฟ๐—ฑ (๐—ป๐—ผ๐—ป-๐—ก๐—ฎ๐—ป๐—ถ๐˜๐—ฒ) scenario, when rendering that mesh, WPO in the material would have to be calculated 54 times, as that is the number of vertices of the cube. But with Nanite it's different.

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0
Post image

But why is WPO expensive with Nanite in the first place? Have a look at the image attached. It depicts a simple cube that is made of just 54 vertices (it is an Unreal's built-in mesh). This cube occupies roughly 120 000 pixels on the screen.

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

Long story short: they pre-computed the animation offline and pass it to WPO instead of calculating it all in the material every frame.

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

Epic even wrote an article where they explain how they dealt with that problem when they ported Fortnite to UE5/Nanite - section "Wind animation" in reference [1] (links are in the comments).

17.06.2025 09:11 โ€” ๐Ÿ‘ 0    ๐Ÿ” 0    ๐Ÿ’ฌ 1    ๐Ÿ“Œ 0

@wojtsterna is following 3 prominent accounts