[Lighting] Sunray Intensity Compensation

This version of my system has been discontinued as of its last released version (1.3.0). I have moved on to version 2.0 of this system, which as of June 22nd, 2023, is still being worked on and updated. It has more features, and overall looks more appealing in my opinion.

It can be found here.

Hello! This is an ongoing script I’ve been working on that adds a slight bit of realism to your experience! Allow me to introduce you to Sunray Intensity Compensation:

This script adjusts the intensity of the SunRaysEffect in game.Lighting based on the player’s CurrentCamera angle relative to the sun’s position in the sky.

In other words, the more you look towards the sun, the less intense sunrays are.

As of April 25th, 2023, I have updated the script to version 1.3.0

The script can be found through the link located in the Script dropdown section below.

Check the Changelog section below for any changes made, I will continue to keep this updated.


•There is a config/settings section in the script. Feel free to change whatever you’d like.

If there are any better ways to code sections of this script or the entirety of it, do feel free to post a comment. I will gladly adjust the script to add the necessary changes and give credit where credit is due.

This also applies to bugs and any instances of lag being caused by this script. Please let me know if you encounter either of these!

•Renamed this post to “[Lighting] Sunray Intensity Compensation” from “[Minor Effect] Sunray Intensity Smoothing”


Uncopylocked Experience, free to test and/or download
Sunray Intensity Compensation System - Roblox

Without sunray updates

With sunray updates


Sunray Intensity Compensation - Roblox
This will be updated if comments are made that lead to improvements


V1.3.0 - April 25th, 2023
•Increased NearSunRays’ intensity from 0.01 to 0.06 – There should really be some sunrays when looking at the sun directly

•Removed “BackTurned”. I realized this wasn’t at all necessary, since everything that needs to be calculated when looking behind the “HorizonLine” can be done with just the horizon line, no other radius is required for a good effect.

•Replaced the “ForgivenessRadius” customizable number value with the Lighting.Sky’s SunAngularSize. You can consider this the new method of customizing the ForgivenessRadius!

•There is now a “fake sun” that appears in the sky. It is always a fixed distance from the camera, sitting 500 studs away & is always in the position of the sun.
-This is used specifically used for checking if any objects are obstructing the players view of the sun. And to set the sunray intensity to a fixed value if view is obstructed. (Tweening the intensity is also a slight bit slower in this state, for increased immersion.)

V1.2.0 - April 23rd, 2023
•Added the creation of “FarSunRays” and “NearSunRays” - NearSunRays will be static values for immersion, whereas FarSunRays will be what is adjusted. This SunRaysEffect “reaches” further, for lack of a better term. FarSunRays is what will be affected from the “Settings” module.

•Added a “HorizonRadius” variable that dictates where the horizon is in the sky relative to camera angle

•Added a new “BackTurned” setting in the “Settings” module. This setting really doesn’t need to be adjusted, it is mainly just for the script to know when the player is facing away from the sun. Which is more or less always at the same value.

•Added a function to double check that the correct sunrays were created

•Adjusted the methods used to calculate what intensity the sunrays [being adjusted] need to be set to

•Opened a testing place for this script. It can be found on @WoahItsJeebus’ Roblox profile
-This testing place has a ScreenGui that shows your current angle, intensity, as well as other information.
-Feel free to check it out!

V1.1.0 - March 25th, 2023
•Added presets for easy setup and for those who don’t feel safe messing with scripts

Default || Default preset is fast, near instantaneous. Use this if you don’t want a (visibly) smooth transition

Realism || Realism is faster than default, but slower than cinematic. Use this if you want to add a smoother adjustment feel to sun rays.

Cinematic || Cinematic adjusts the slowest of all presets. This is best used for cutscenes with fairly sluggish camera movements. (Spinning your camera quickly can cause a flash of light. More with slower transition times)

Custom || Custom is completely up to you to do as you want with. Set the transition time, style, and direction to your liking with ease.

•Added Settings and Presets ModuleScripts. Presets was not meant for tampering with, but you are more than welcome to! The Presets module includes Default, Realism, and Cinematic TweenInfo configuration tables. Settings has the Custom preset.

•Adjusted the forgiveness radius to feel more realistic. (This is still subject to change, just as the default)

•Renamed the main LocalScript to “SunrayIntensityController”

•Removed some unnecessary/unused variables in the RunService.Heartbeat:Wait() loop

•Changed code location for checking Lighting.ClockTime on the client to prevent false fires when night time

•Added more comments to detail specific sections of scripts


•Thanks to @Katrist for the script “How to detect when player looks at sun” example code. Though not the original poster of the baseline code used, that post is where I found the code. Further credit & thanks to @Eestlane771 for providing the baseline code and explanation to Katrist and further me. Eestlane’s post can be found here.


Looks nice

(model is offsale by the way)

1 Like

Lol, fixed. Thank you. Had changes to make earlier. Should be good now.

Thank you! The days of blinding sun rays are now gone! [roblox chezburg emoji]
I’ll certainly be using this!

1 Like

Thats one of the most usefull thing i have ever seen in my life


Nice lighting effect! Perhaps you can also slow down the compensation, like a camera trying to focus on a bright object.

While this sounds nice for some added cinematic effect, I wanted to showcase the effect as if it were being seen through the naked eye. Or at the very least, simulate something similar so I could show off the effect.

Our eyes typically adjust to the sunlight exposure (when looking at and away from the sun, like shown in my showcase video) within mere fractions of a second. And like you suggested, cameras tend to adjust a lot more slowly (slow enough to where we notice it with our eyes). I picked a bit of an in-between.

But, that’s why I added a little configuration section for people to use and play with. They can make the adjustment time faster for realism or longer for cinematic footage.

I may add presets for people to choose from if they can’t figure out a good adjustment time and presets become a wanted feature.

(Spinning your camera quickly can cause a flash of light. More with slower transition times)

As I stated in the first changelog update, spinning your camera rapidly/quickly could cause a fairly blinding effect momentarily. This has been reduced significantly, and is a lot more realistic [in my opinion]. I will continue to work on improving this even further.

Updated to 1.2.0, this update should make this system feel a lot more immersive than the previous update; mostly due to formula balances, function changes, removal of some unnecessary code, and tweening alterations. Feel free to read through the changelog in this post or in the “Information” script.

Edit: My apologies for bumping, I was unaware deleting this post would’ve done that. Originally meant to delete since this info was added into the changelog section I added in the initial post.