Boost X-Plane 12 Graphics Performance Now with Simple LUA Scripts.

Boost X-Plane 12 Graphics Performance Now with Simple LUA Scripts.

Boost X-Plane 12 Graphics Performance Now with Simple LUA Scripts.

Fly with Lua
DOWNLOAD FLYWITH LUA HERE

I was stunned yesterday when I learned that I could instantly boost X-Plane 12 graphics performance with simple LUA scripts. We all know how incredibly demanding flight simulation can be on PC hardware. Achieving smooth performance in X-Plane 12 is a challenge, especially when transitioning between different environments, weather conditions, or resolutions like 1080p, 1440p, and 4K.

Thankfully, the LUA scripts below take the headaches out of achieving amazing performance with minimal effort! These two powerful yet simple LUA scripts, which I am using personally as I write this blog post, have proven to be amazing. Powered by the FlyWithLua plugin, they offer a dynamic solution to optimize your settings in real-time.

In this blog post, we’ll explore two powerful LUA scripts designed for X-Plane 12: one for standard monitors (1080p, 1440p, and 4K) and another specifically tailored for Virtual Reality (VR). We’ll also cover what LUA scripts are, how to install them, how to create LUA files, and how they can transform your flying experience by automatically adjusting settings to maintain optimal performance.

Again, I want to emphasize that I’m using these LUA scripts exactly as they are right now, and I’m truly gobsmacked by how well they work in a variety of resolutions as well as in Virtual Reality. Yes, there’s one script for each situation: VR or monitor use.

What is a Lua Script, and How Does It Work in X-Plane 12?

Lua is a lightweight scripting language that allows users to automate tasks and create custom behaviors. In X-Plane 12, Lua scripts can dynamically adjust graphics settings, improving performance without requiring constant manual tweaks.

To use Lua scripts in X-Plane 12, you’ll need the FlyWithLua plugin, which acts as a framework for running these scripts.

How to Install FlyWithLua and Lua Scripts

X Plane 12
  1. Download FlyWithLua: Visit the X-Plane.org Forums and download the latest version of FlyWithLua (compatible with X-Plane 12).
  2. Install FlyWithLua: Extract the downloaded file and place the FlyWithLua folder into the X-Plane 12/Resources/plugins directory.
  3. Create Lua Script Files:
    • Open a text editor such as Notepad (Windows) or TextEdit (Mac, in plain text mode).
    • Copy and paste the script code (provided below) into the text editor.
    • Save the file with a .lua extension, such as dynamic_graphics.lua.
  4. Add Lua Scripts: Place your saved .lua files into the FlyWithLua/Scripts folder.
  5. Launch X-Plane: The scripts will automatically activate upon starting the simulator.

Lua Script 1: Dynamic Graphics Adjustment for Monitors (1080p, 1440p, 4K)

This script dynamically adjusts world objects and other graphics settings based on your FPS, ensuring smooth performance while flying in different scenarios. It’s ideal for maintaining optimal visuals across resolutions like 1080p, 1440p, and 4K.

The Script

-- Dynamic Graphics Adjustment Script for X-Plane 12
-- Place in FlyWithLua/Scripts folder

-- Settings and thresholds
local target_fps = 60
local fps_buffer = 5  -- FPS buffer before adjustments are triggered
local min_world_objects = 1
local max_world_objects = 4

-- Function to monitor FPS and adjust settings
function dynamic_graphics_adjustment()
    local fps = SASL.getFPS()  -- Get current FPS
    local world_objects = get("sim/private/controls/reno/draw_fft_plan")

    -- If FPS drops below target and buffer, reduce world objects
    if fps < (target_fps - fps_buffer) and world_objects > min_world_objects then
        set("sim/private/controls/reno/draw_fft_plan", world_objects - 1)
        logMsg(string.format("[FlyWithLua] FPS low: Reduced world objects to %d", world_objects - 1))
    -- If FPS is above target and buffer, increase world objects
    elseif fps > (target_fps + fps_buffer) and world_objects < max_world_objects then
        set("sim/private/controls/reno/draw_fft_plan", world_objects + 1)
        logMsg(string.format("[FlyWithLua] FPS stable: Increased world objects to %d", world_objects + 1))
    end
end

-- Register the function to run every frame
do_every_frame("dynamic_graphics_adjustment()")

Use Case

  • 1080p: The RTX 3070 can easily handle higher settings, so this script will make fewer adjustments.
  • 1440p: The script balances performance by adjusting world objects dynamically, especially in dense urban areas.
  • 4K: At this resolution, maintaining 60 FPS is challenging. The script reduces settings like world objects to prevent FPS drops.

Lua Script 2: Dynamic Graphics Adjustment for Virtual Reality (VR)

Virtual Reality requires precise optimization to ensure smooth performance and avoid discomfort caused by low FPS. This script is tailored for VR, focusing on FPS stability by adjusting world objects and antialiasing settings.

The Script

-- Dynamic Graphics Adjustment Script for VR in X-Plane 12
-- Place in FlyWithLua/Scripts folder

-- Settings and thresholds
local target_fps = 45   -- Target FPS for VR (can adjust based on your headset)
local fps_buffer = 5    -- FPS buffer before adjustments are triggered
local min_world_objects = 0  -- Minimum world objects for VR
local max_world_objects = 3  -- Maximum world objects for VR (reduce for VR stability)

-- Additional settings for VR
local min_antialiasing = 0  -- Minimum antialiasing setting for VR (Off)
local max_antialiasing = 2  -- Maximum antialiasing for VR (2x SSAA+FXAA)

-- Function to monitor FPS and adjust settings dynamically for VR
function dynamic_vr_graphics_adjustment()
    local fps = SASL.getFPS()  -- Get current FPS
    local world_objects = get("sim/private/controls/reno/draw_fft_plan")
    local antialiasing = get("sim/private/controls/reno/draw_flight_sim_object_detail")

    -- Adjust world objects based on FPS
    if fps < (target_fps - fps_buffer) and world_objects > min_world_objects then
        set("sim/private/controls/reno/draw_fft_plan", world_objects - 1)
        logMsg(string.format("[FlyWithLua] VR FPS low: Reduced world objects to %d", world_objects - 1))
    elseif fps > (target_fps + fps_buffer) and world_objects < max_world_objects then
        set("sim/private/controls/reno/draw_fft_plan", world_objects + 1)
        logMsg(string.format("[FlyWithLua] VR FPS stable: Increased world objects to %d", world_objects + 1))
    end

    -- Adjust antialiasing based on FPS
    if fps < (target_fps - fps_buffer) and antialiasing > min_antialiasing then
        set("sim/private/controls/reno/draw_flight_sim_object_detail", antialiasing - 1)
        logMsg(string.format("[FlyWithLua] VR FPS low: Reduced antialiasing to %d", antialiasing - 1))
    elseif fps > (target_fps + fps_buffer) and antialiasing < max_antialiasing then
        set("sim/private/controls/reno/draw_flight_sim_object_detail", antialiasing + 1)
        logMsg(string.format("[FlyWithLua] VR FPS stable: Increased antialiasing to %d", antialiasing + 1))
    end
end

-- Register the function to run every frame
do_every_frame("dynamic_vr_graphics_adjustment()")
X Plane 12

Use Case

  • VR Headsets: This script ensures that your VR experience remains smooth by targeting 45 FPS and dynamically adjusting settings like world objects and antialiasing. You can change the FPS figure in the script to suit yourself and the LUA script will do its best to maintain it. Its not magic though! It can only deliver the performance your system is capable of and not more. THis is not like Lossless Scaling giving you pre rendered frames boosting performance. I would think using Lossless Scaling and these scripts could be really amazing,

Why Use These Lua Scripts?

Oculus Tray Tool
  1. Dynamic Adjustments: No need to manually tweak settings mid-flight.
  2. Performance Stability: Prevents sudden FPS drops, ensuring a consistent flying experience.
  3. Customizable: Easily modify thresholds and targets to suit your hardware and preferences.
  4. Maximized Visuals: Balances performance and graphics quality automatically.

Im sure you will be impressed by the quality and performance these two scripts enable. My System which is a Ryzen 5 5600X with Nvidia RTX 3070 has just been made incredibly good as it was struggling with clarity.

OCULUS TRAY TOOL

Boost X-Plane 12 Graphics Performance Now with Simple LUA Scripts has allowed me to push my OCULUS TRAY TOOL settings up considerably. THe performance was really smooth but adding ASW at 30fps and pushing the quality slider up to 1.3 times has really made a huge difference to my X Plane 12 Experience which I have to say was somewhat underwhelming with a lack of visual clarity where other sims like DCS World are crystal clear even in my Rift S.


Conclusion

By implementing these Lua scripts, you can significantly enhance your X-Plane 12 experience, whether you’re flying on a monitor or in Virtual Reality. With FlyWithLua, these scripts dynamically adjust settings to maintain optimal performance, allowing you to focus on the skies.

Brendon McAliece - Gunnie and a Jabiru 170
Brendon McAliece Jabiru 170

Download FlyWithLua, create your scripts, and take your flight simulation to new heights!

Author

Brendon McAliece (Aka Gunnie) is a military veteran with 23 years working on Jet Fighters, their weapons systems and ejection seat/module systems as well as munitions and R&D. Involved with flight simulation since the 1980s, he has flown all the major flight simulators over the years.

He is an Australian expat who has lived in Malaysia, UK, Saudi Arabia and more recently Thailand. He is a multi-lingual blogger who loves to share his life experiences here on LetsFlyVFR.com and DreamingGuitar.com, with his lifestyle and Travel experiences Blog plus his Dreaming Coffee website.

Learn More @ DreamingGuitar.com – DreamingCoffee.com – LetsFlyVFR.com

HOME – BLOG – SHOP – ABOUT )

As an Amazon affiliate I may benefit from qualifying sales.

Leave a Reply

Your email address will not be published. Required fields are marked *