Looking for a Camera API that regards the near clipping plane

I’m looking for a function that allows you to project a 3D position onto the near clipping plane as a Vector3.
To be specific:

Vector3 Camera:ToNearClippingPlane(Vector3 pos)

It’s hard to explain why I need this, but the method I’m using currently to do this is costly, and I’m wondering if a C++ implementation would make it faster.

I’m using it to create very small holograms that project themselves close to the camera to give an X-Ray illusion.
It works really well. However, it gets expensive with several holograms at once.

Here’s a place that demonstrates exactly what I’m doing:

Can’t you use something like:

local function ToNearClippingPlane(pos)
	local Camera = workspace.CurrentCamera
	local clip = Camera:WorldToViewportPoint(pos)
	return Camera:ViewportPointToRay(clip.X,clip.Y,0.001)
end

I’m using depth 0.001, but using 0 (the default) you would get the actual plane.

(You might be using this and thinking/knowing it’s expensive. could be, idk)

1 Like

That is what I’m doing.
However I don’t know if I could be doing this in a more efficient matter.

Can’t you calculate 2 (or 4?) corners of the plane, and use math to position all stuff on there?
I assume that ToNearClippingPlane is the expensive part if used for every part/model.
If you only have to use it a few times and then can use math… might be better?

That’s probably as efficient as you can get since it’s a C-side method.

Doesn’t work in VR. :wink:

I can imagine why.
I’ll switch over to GetRenderCFrame lol.

That’d be cool, let me know. It might look pretty crazy.

Just updated to GetRenderCFrame.
Hopefully the calculations I’m doing on every renderstep doesn’t grind down your frame-rate.

Hmm, weird stuff happens when I tilt my head, and they don’t line up right. Not entirely sure if it’s your side or not, but I guess it’s something you’d just have to see yourself.

EDIT: Discovered it’s a side-effect of not having a real “2D” in VR