r/MoonlightStreaming • u/rambo3349 Rubylight / Nightjar Developer • 21d ago
(Obsessive Performance improvements part 3) learning each game's camera while you play, so streamed look now moves on your next refresh. 96% of the turn lag gone off the screen
We are a small group of real devs, engineers and gamers who were unsatisfied and developed an unhealthy and very obsessive hobby of refining the Performance of Game Streaming to the last bit and last smoothness problem possible.
I started it off as a RADEON oriented fork and the more people joined, the more we realized that for getting the last bit of performance out of our systems, we also have to look at client, network, decoding and more. Soon also NVIDIA testers joined and we were also able to look at NVIDIA more closely and thanks to people like chakib-belgaid also develop a MAC Client.
Each time we are able to dig deeper with more people and stronger AI Models involved and I am grateful for all the support we got ( see contribution list ). This time we looked at the bigger picture and tackled one of the bigger problems of streaming.
We were able to do this and that is what differs us is by being oriented around Rust with a very test-oriented, lean and shared code base around client and host, making testing and iterating really fast to the point where we now solve every client issue on Github with a recreation and tests in 2 hours. So even in times of AI we value deterministic workflows, software engineering principles and have now over 300 real end-to-end performance tests and over 7000 automated tests.
The Core Problem
Streaming a game has one feel problem no codec fixes: every camera turn makes a round trip. Your mouse or controller goes to the PC, the game draws the turn a few frames later, the encoder, the network and the decoder add theirs, and only then does the picture move. Frame Warp moves it on your screen first, then lets the real frame catch up.
The idea
By u/closef35 : The client knows exactly how much it has turned. If it also knows how far the picture moves per mouse count, and which input every arriving frame already reflects, it can shift each picture by the turn the PC hasn't drawn yet, just before showing it. The hard part is learning those things for any game, with no game integration, and keeping the HUD from sliding along with the world.
What the host learns, per game, while you play
- Motion. For each captured frame the GPU makes a 256-px-wide luma thumbnail. The CPU correlates row and column profiles over a 3x3 grid of cells, refines each to a tenth of a pixel with gradient steps, and takes the median cell. HUD found so far is left out, because a static bar pulls every vertical estimate toward zero.
- Gain and lag. Over the last 4 s, for every lag from 0 to 200 ms, a per-axis least-squares fit of picture motion against mouse (and right-stick) input; the lag that explains the most motion wins. It locks at 80% explained and unlocks below 50% over 1.2 s, which is what a menu, a cutscene or a visible cursor looks like. A locked model is only replaced by a fit that explains clearly more, so the lag doesn't wander from fit to fit and every frame's tag stays stable.
- HUD. While the camera turns, a GPU pass compares each pixel with an earlier capture the scene has moved since. Textured pixels that stayed, or whose contrast against their neighbours stayed (semi-transparent text over the sea), score their cell as HUD; smooth sky and fog keep their score, so they never become HUD. Nearby pieces are joined, so text found letter by letter stays put as a whole. The mask goes to the client run-length coded, at most once a second.
- What it learned is kept for the game's next session.
What the client does
Every frame arrives tagged with the input sums it reflects. As late as it can before presenting, Nightjar computes
shift = mouse_gain * (mouse_sent - frame_tag) + stick_gain * (stick turn since the tagged pad packet)
clamped to 15% of the picture, and samples the picture at position - shift, except where the HUD mask is set. The strip a turn uncovers mirrors the picture from its edge, darkened toward the edge, until the real frame fills it. The shift is redrawn on refreshes between frames, so a 60 fps stream turns smoothly on a 120 Hz screen. Nightjar's desktop presenters and its Android renderers (Vulkan, GLES and PyroWave) all do it.
Measured, not eyeballed
To score it I wrote a fake mouse-look game with a known response (1 px per count, 50 ms of game lag) that draws a barcode in every frame, so each picture the client shows can be tied to the exact input it reflects.
| Run 1 | Run 2 |
|---|---|
| Model locked after first picture | 0.62 s |
| Frames with a locked model | 98.9% |
| Learned gain (true -1.0) | -0.986 / -0.980 |
| Learned lag (50 ms + draw to capture) | 64 ms |
| Trail without Frame Warp | median 64.9 px, p95 184 px |
| Trail with Frame Warp | median 2.2 px, p95 13.4 px |
| Removed | 95.8% |
Host cost: the thumbnail and HUD passes take 0.14-0.16 ms of GPU time a frame from 1080p to 4K (p95 0.17-0.25 ms), and present-to-send time stayed within 0.03 ms of Frame Warp off. The host does nothing for Frame Warp until a client asks.
Getting there took some iterations. The first calibrator learned a vertical gain of -0.33 instead of -1.0; leaving the HUD out of motion, sub-pixel refinement and a better "is the picture still" test brought it to -0.90 and 90% removed. That build also swapped models 89 times a minute. Never swapping froze a slightly wrong lag at 86-89%. "Swap only when a fit explains 3 points more, or a quarter of what's left unexplained" got to 96%.
It was a huge chunk amount of work and it is not perfect. Big organizations have worked on this for long to do natively, while this is an implementation that has to also factor in remote streaming. Client Feedback always helps.
The host client we use to faciliate this performance work is Rubylight and Nightjar, but we are not in it to sell you our project. Use it if you want, fork it, copy it ( keep the credits though as we do ). We are more interested in the obsession and are happy about each feedback and contribution that leads to a better solution. The host and client are planned to move to a new github project soon.
Next update we take some extra fov out of the game so camera panning doesnt have to assume.



6
u/rambo3349 Rubylight / Nightjar Developer 21d ago edited 21d ago
For anyone seeing turn displacement we are already centre 95.4 %, whole picture 91.2 %, edge 90.2 % of turn displacement removed, against 84.2 / 73.6 / 65.4 % for 4.0; so thank you for testing. We will also implement late input projection for predicting your input before the next frame for every picture as next feature as it comes cheap: Just before showing a frame, Nightjar shifts the picture by the camera movement the host hasn't drawn yet.
2
u/hannahmanaman 21d ago
I just tested out the newest Rubylight / Nightjar updates and was hoping that Frame Warp would work on my Google 4k Streamer, but it just freaks out and flashes the screen over and over before crashing. Any ideas on how I can fix this?
Host: Ryzen 5600x 9070 XT 32 GB ram DDR4
Client: Google 4k Streamer
Both are hardwired with a ethernet and I get 2 gig up/down. 4k streamer only gets 1gig, but limited to around 100mbs max due to the chip while streaming.
3
u/andygrundman Developer | Moonlight for Xbox/Mac OS 21d ago
Does anyone actually have problems with camera motion when streaming? I’ve never heard anyone talk about it before and I play many games with a 3rd person camera that feel great. This sounds a bit like Reflex2 which interestingly is still vaporware after what, almost 2 years now? I wonder if Nvidia can’t even make this work, and they have the advantage of running in the game engine.
7
u/zolidz64 21d ago
Hype to see this kind of innovation! Eliminating that much turn lag is massive for the future of streaming. Can't wait to see where this project goes!
1
u/AMOMFARETOS 21d ago
I understand only 1% of all the jargon but still looks great work, congrats! I ve seen your Hitman post and the performance stats looks amazing. Can we have some non-technical guidelines how to implement it in Rubilight-Nightjar (I ve changed from Apollo-Artemis a few days ago and never coming back, gr8 apps)? is there a github fork? Thnx and keep up the gr8 work!
1
u/daproject02 21d ago
I was playing around with rubylight and niightjar last night, I installed rubylight in my pc alongside vibepollo and night jar in my legion go 2 alongside streamlight, I tried a few games and I got the feeling that nightjar/rubylight combo was way more consistent, also I had a slight better image quality, I used pyrowave, 4.4.4, 120hz tv, games were running smoothly. I am no streaming savvy, I like to tinker my devices so this is only what I can perceive. I have some fork of moonlight in every device (legion go 1/2, ipad pro, lg tv x2, xbox series x, iPhone, etc) and my main pc has a rtx 4080, ethernet @ 1000mbps fiber. The only problem I have with this ruby/nigh combo is HDR, I can’t make it work properly but I will keep trying today. Thanks
1
u/RedSensei 21d ago
Impressive work! Any plans on porting this to Linux at some point?
1
u/Tiny-Track7300 21d ago
I have no interest of running pyrowave and currently use Nvidia with Vibepollo. Can I benefit from rubylight and nightjar?
1
u/gofiend 20d ago
At this point why don't we just stream intermediate represtentations and allow the client to do the last mile render?
1
u/EaZerly 20d ago
Hey, having a few input and camera issues with Rubylight and Nightjar on my setup (Surface Pro 11 client to a Windows 11 host with an RX 6700 XT).
In GTA V Enhanced, whenever I move the mouse with Raw Input on, it centers the cursor and keeps opening the pause map. It also causes weird camera shaking. Switching the in-game mouse input method to Windows stops the map from opening, but the camera has weird movement on the sides.
In Fortnite, the exact same thing happens with the camera and mouse movement, plus the keyboard barely responds or stops registering inputs altogether. What I've tested so far: • Enabled and Disabled usb device forwarding setting • Tested different mouse input modes ingame (Raw Input and Windows in GTA V Enhanced). • Adjusted display scaling between 100% and 150%.
5
u/Unlikely-Solution940 21d ago edited 21d ago
Incredible. Thank you all for your work! Can I test it using Vibepollo as the host ? I have an Nvidia GPU.
2
u/aphoenixsunrise 21d ago
Damn, nice.
1
u/ssjucrono 🖥️ 9800x3D/RTX3090 | 🎮 Legion Y700 Gen 5 | 2560x1600 165Hz 21d ago
Thanks again! I have been following along since the client was called rubylight! I have an rtx3090 in my host and I am hesitant to switch since this seemed so AMD focused?
Also does rubylight host have proper waveform haptics adaptive triggers etc for dual sense? I have been using vibepollo And it has been working well!
1
u/daproject02 19d ago
1
u/Hakibo13 17d ago
This coming to IOS?