Hey.
Semi-recently, I made some UI which emulated the effect of the neon material. Following this, a few people asked me how I did it so I felt like sharing it with the community.
Step 1. Get a part and place it infront of the camera, then with your UI (which should be a SurfaceGui), you can parent it/set the adornee to said part. If you want to calculate how large the part should be, you use this:
local THETA = math.tan(math.rad(camera.FieldOfView) / 2)
local function getAspectRatio(ViewportSize)
return ViewportSize.X / ViewportSize.Y
end
local function getHeight(ViewportSize, theta, depth)
return -1 * 2 * theta * depth
end
local function getWidth(ViewportSize, theta, depth)
local aspectRatio = getAspectRatio(ViewportSize)
local width = aspectRatio * theta
return -1 * 2 * width * depth
end
local ViewSize = camera.ViewportSize
local uiCFrame = Camera.CFrame * CFrame.new(0, 0, -PART_DEPTH - 0.5)
UIPart.Size = Vector3.new(
getWidth(ViewSize.X, -PART_DEPTH),
getHeight(ViewSize.Y, -PART_DEPTH),
1
)
Always remember to update this when the players screen size changes!
The -1 in the code is there because we want to cover the entire screen, if you wanted to cover an entire frame or similar you could replace it with -(ViewportSize.X / FrameXAbsoluteSize)
(or just swap the axis’ depending on the function)
(obviously your code should look a bit prettier than this, I wrote this in the post editor lol, code was devised from AstroCode’s ScreenSpace module)
Step 2. With that part infront of the camera, and the UI parented/adorned, you can put the brightness up to whatever you want. Brighter colours will obviously show up more than darker ones, so use this carefully so you don’t burn the players retinas.
Since you have the part infront of the camera, you can do whatever with it! Personally, I added a subtle shake when the player moves their mouse:
UIPart.CFrame = uiCFrame:Lerp(
CFrame.lookAt(uiCFrame.Position, Mouse.Hit.Position),
UIPART_ALPHA
)
but it’s your game after all.
This is a really nice graphical effect, and it’s limited the the players graphic level so you don’t have to worry about optimisation.
I hope this is helpful, and I hope I remembered the code from earlier properly.
Thanks for reading!