[Release] ViewportFrame limited-rendering

Based on the title, I hope there’s a good idea of what this thread is. We all know the beta release on ViewportFrame is out, but many people wanting to use it as security cameras think of replicating the entire workspace every second. While that may seem like a good idea to some people, it’s not the best way to handle this.

EDIT: There must be a model with a PrimaryPart visible in order to be replicated! If anything is obstructing view of the PrimaryPart to the camera, it will not replicate!

CREDITS: Credits to @Corecii (:WorldToScreenPoint() - #4 by Corecii) for his corners function!

NEWER/IMPROVED: (ViewportFrame Camera System) Credits to @boatbomber for a much better system for the community to use!

For my first release, I’m hoping to give insight on how you should be using ViewportFrame as a security camera. While this may not be near to as efficient as some people think, I’m hoping you can look at it and improve on it. If there’s any improvements made and you wish to share with the community, I’ll gladly post it on here with credits given to you! Anyways, hope you enjoy and hopefully learn!
Viewport_Demo.rbxl (126.1 KB)

29 Likes

I think to solve the problem of performance, you should instead designate a specific folder or model in the workspace to be copied, instead of removing parts or objects that are being obstructed. I feel like a while loop this complex could result in performance hits, but I could be wrong.

Also should be noted that I don’t drop 15 frames in studio by making “IsVisible” always return true. Could be a micro optimization problem on your part, or my computer’s just weird.

Something to think about!

2 Likes

I’ve been messing around with this, and decided to make my own version based on it. You guys may pick it apart here:
CameraViewPort.rbxl (29.0 KB)

I didn’t really keep my code clean, but I did try to sorta comment it for you!

It’s worth noting that I get a solid 60 FPS with it there, but when you add far more models to the workspace it slows very quickly.

If you don’t want to try out the file, here’s the main features:

  • Supports transparent parts!
  • If the Camera part CFrame changes, it updates the camera (instead of updating every refresh)
  • I wanted to stop models from flickering out just cuz a small primary part got covered.
    Therefore-
    If any part of the model is visible, it renders the whole model. I found this to be faster than rendering any visible part of the model, because I only have to check the first few at most rather than 5 raycasts per part.

Edit:
Slightly cooler version:
CameraViewPort (1).rbxl (37.9 KB)

I plan on remaking the entire system to update part positions rather than delete and remake each frame.

9 Likes

I really like this!! Much better than mine, great work!

1 Like

If you thought that was good, I can’t wait to show you the new one I’m working on :yum:

I plan on remaking the entire system to update part positions rather than delete and remake each frame.

2 Likes

Little side note:

The GetCorners function is neat, but the sides can be visible while corners aren’t, so I added to it. I get better “visibility” results with the function below:

local function PartPositions(part)
	local cframe,size = part.CFrame,part.Size
	return {
		--Center
		part.Position,
		--Corners
		cframe * v3(-size.x/2, -size.y/2, -size.z/2),
		cframe * v3(-size.x/2, -size.y/2,  size.z/2),
		cframe * v3( size.x/2, -size.y/2,  size.z/2),
		cframe * v3( size.x/2, -size.y/2, -size.z/2),
		cframe * v3(-size.x/2,  size.y/2, -size.z/2),
		cframe * v3(-size.x/2,  size.y/2,  size.z/2),
		cframe * v3( size.x/2,  size.y/2,  size.z/2),
		cframe * v3( size.x/2,  size.y/2, -size.z/2),
		--Sides
		cframe * v3(0,		-size.y/2, 0),
		cframe * v3(0,		size.y/2,  0),
		cframe * v3(-size.x/2,	0,	   0),
		cframe * v3(size.x/2,	0,	   0),
		cframe * v3(0,		0,	   -size.z/2),
		cframe * v3(0,		0,	   size.z/2),
		
	}
end

The positions will look like this:
(On every face, every corner, and the center)

Edit: I considered making it a 3D grid(aka nearly filled), but doing that many checks per part would be ridiculous even if it gave me perfect results.

Edit 2: It’s worth mentioning that if the first check finds that it’s visible, it doesn’t bother with the others. The maximum checks per part is 15 but it doesn’t always do them all.

8 Likes

This is really neat! Maybe Roblox should implement automatic occlusion culling for viewport frames.

4 Likes

What would be the fun in that :stuck_out_tongue_winking_eye:

2 Likes

I plan on remaking the entire system to update part positions rather than delete and remake each frame.

I made a working prototype, and posted it, if you’d like to check it out!

HELP! the camera does not recognize or cannot see the structure I put in, does anyone know why? only recognize the ground HELP ME PLS

1 Like

When I use this I have 2 FPS ‘-’

Just now noticing this was replied to, but if you’re referring to using my release it’d be much better to use boat’s as it has better efficiency and is easier to mess around with. My release wasn’t intended for production without modifications as it’s not the best.