ViewportFrame Release

Have you heard of the glass material bug with transparency? You can replicate that effect with that as well, but it’s a matter of preference. I think the glass alternative looks better but it’s also going to be patched according to Roblox, so.

I don’t believe that’s a bug, but just something due to the way SurfaceGuis and BillboardGuis function when in PlayerGui

I have recently noticed an issue with Viewport Frames, It will not set the ViewportSize property of a Camera.

This is especially annoying since you are unable to use WorldToScreenPoint or WorldToViewportPoint as it will always return 0

That’s because multiple ViewportFrames can use the same camera. Since ViewportFrames can have different sizes, there’s no way to decide which size to use.

Is there a way to work around this?

I am using this as a Minimap and I am wanting to be able to mark where people are on the map.

You’re going to have to calculate the positions yourself. Sorry if I can’t tell you how exactly, since I don’t how to, either.

I will probably just end up making a 3D Marker for players in the minimap to save time

Have you tried the AbsoluteSize of a ViewportFrame?

1 Like

Even with me knowing the AbsoluteSize, that would not allow the function WorldtoScreenPoint to work.

1 Like

Here’s some code from a module I wrote, which was borrowed from another module by someone else:

local function pointToScreenSpace(cframe, fieldOfView, point, viewportSize)
	-- borrowed from https://devforum.roblox.com/t/3d-gui-module/5183 ( http://www.roblox.com/Roblox-3D-GUI-Module-item?id=159576724 )
	-- used for transforming points from GetCameraParams into a size
	-- no need to rewrite what's already written!
	local screenSize = viewportSize
	local relative = cframe:pointToObjectSpace(point)
	local ratio = screenSize.x/screenSize.y
	local yFactor = math.tan(math.rad(fieldOfView/2))
	local xFactor = ratio*yFactor
	local y = (relative.y/relative.z) / yFactor
	local x = (relative.x/relative.z) / -xFactor
	return Vector2.new(screenSize.x*(0.5 + 0.5*x), screenSize.y*(0.5 + 0.5*y))
end
5 Likes

I have created a function that will allow you to mimic the function WorldToScreenPoint in a ViewportFrame

    ScreenSpace.ViewportAspectRatio = function(viewport)
	return viewport.AbsoluteSize.X / viewport.AbsoluteSize.Y
end

ScreenSpace.ViewportWorldToScreen = function(viewport,at)
	local point = viewport.CurrentCamera.CoordinateFrame:pointToObjectSpace(at)
	local aspectRatio = ScreenSpace.ViewportAspectRatio(viewport)
	local hfactor = math.tan(math.rad(viewport.CurrentCamera.FieldOfView) / 2)
	local wfactor = aspectRatio * hfactor
	local x = point.x / point.z / -wfactor
	local y = point.y / point.z / hfactor
	return Vector2.new(viewport.AbsoluteSize.X * (0.5 + 0.5 * x), viewport.AbsoluteSize.Y * (0.5 + 0.5 *y)), point.z
end
6 Likes

Thanks for this, I haven’t tested my code so I’m glad I can have something to fall back on!

You could do it with camera CFrame trickery.

It’d be neat to see but impractical.

ViewportFrames are brilliant!

A way for multiple ViewportFrames to render the same model/parts (at the same time) without having to clone them would be appreciated though; managing all of the separate models can become quite a pain.

1 Like


its already possible but it does not use the ViewportFrame :smile:

5 Likes

I’m guessing the sky we see is fake and the real sky box is the galaxy?

1 Like

Yea the HD Skybox is fake and the Space skybox is real

You can’t though, that what my earlier post was all about: ViewportFrame Release And mirrors have the additional problem of not being able to do a reflection without everything turning inside out.

Inside out? Adjusting the camera CFrame shouldn’t be impossible; esp. if you use Object space. Flip X and Y, leave Z alone, boom you have your reflection CFrame. Then you just make the camera’s LookVector point towards that?

Flipping X and Y just gets you a 180-degree rotation. That’s not a mirror reflection. Getting the perspective right can be done with a BillboardGui set to always face the camera, but you have to resort to the hack of cropping it with large blocks if you want to hide that it’s a UI that is facing your camera (because it definitely breaks the illusion). There’s no amount of CFrame magic that will get the correct perspective onto a SurfaceGui,