Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Info from near plane clipping?

Author
Message
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 10th Feb 2023 22:31
I want to be able to get info such as XYZ co-ordinates of where it is clipped on the near camera plane.
Is this accessible? I can get info such as distance from camera (XYZ) to object any time, but is there any way to know it has been clipped by the near plane?
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 10th Feb 2023 23:26 Edited at: 10th Feb 2023 23:29
If I understand your objective correctly, you can cast a ray from behind the camera in the direction it is facing to the point you want to check ahead of the camera and if the intersect point is less than the clipping distance from the camera location, keep and use the GetObjectRayCastX/Y/Z() values as needed.

Shape and size could have a significant impact on the method though. Usually, if an object clips the near plane, it often does so across a range of intersection points. So you may need to increase the tolerance for detection and/or apply a few rays to account for an object's size, depending on its shape and placement.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 11th Feb 2023 00:53
Yea, the problem here is that the clipped object is a cylinder directly facing the camera, so any rays would just pass down the cylinder and not collide.
The geometry of any clipped shape kind of makes ray traces redundant, as the slice on the near plane removes any geometry you need to intersect. I was hoping for something more elegant than a hacky approach though, but I could do something like move a child object along the Z until it's not "in screen" or something which still seems dirty.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Feb 2023 01:41 Edited at: 11th Feb 2023 02:22
fix a shallow box to the camera (depth = near range + offset?) and check for collision? is it a single cylinder ur checking against or ?

not 100% on what ur trying to do, otherwise. got a visual?

edit:
Quote: "I was hoping for something more elegant than a hacky approach"

ack! i read that as hoping for a hacky approach

nmd

Attachments

Login to view attachments
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 11th Feb 2023 04:27
nz0 wrote: "Yea, the problem here is that the clipped object is a cylinder directly facing the camera, so any rays would just pass down the cylinder and not collide."


Sounds like the cylinder you're working with is open at the ends then. If so and you can't change it, you will likely need the kind of approach Virtual Nomad is referring to. You probably don't have to use ray collision if you don't want to, but mathematical sphere collision that encompasses the entire structure of the object out to the edges would likely be a minimum requirement. Something that just analyzes the rough proximity, then take action once it gets too close.

The other option is to import your own custom structure that is enclosed to detect ray collision at a particular distance. It's tough to say for sure though without knowing what your ultimate goal is. That is, if you want to stop the object once it gets to a specific distance from the near plane, make it disappear, or change its shape/size. You can also optionally retrieve the XYZ ray collision point before the object gets too close to the near plane, then decide what you want to do. Lots of option, just depends on what objective you are trying to accomplish.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Feb 2023 04:48
if you do go the hacky route ("attaching" a box/plane to (just in front of) the camera), how do you determine the height and width of the object? i used the vres dimensions but it seemed too big. @ ~1/4 the size seems "right".

btw, i used THIS to check for collision which will fail with FixObjectToCamera() so had to reposition/rotate:
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 11th Feb 2023 04:58
For height/width size, you can either prefab it when creating the object, then just keep the values in variables or use the 'GetObjectSizeMaxX/Y/Z()' command to retrieve them later.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 12th Feb 2023 01:13
The purpose is to apply an additive lens effect on a plane object (facing camera) at the minimum I could get from the camera.
If I wasn't shooting for VR, I'd just use a sprite and all would be well.

However, the near plane intersect is too close to place a <face camera> plane, as it too would be clipped.
I tried attaching child objects to the cylinder and sliding it about on the Z, which kind of gives me a value, but feels "hacky". I was initially asking if there was a mathematical way to get the plane clip co-ords, but it's looking more like it has to be something hacky

SFSW said the cylinder I am working with might have open ends, but the clipping appears to slice the geometry and "open" the end of it. The cylinder passes by the camera purposely by some way, but the near clip seems to alter the geometry there. I did also try to render both sides of the cylinder to make sure the ray check worked on the inside as well.

I think I'll try some stuff which Virtual Nomad suggests, which is attaching something to the camera and see if I can get some meaningful intercepts that way?

nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 12th Feb 2023 01:16
@blink, yea I looked at that, but I'll be opening another can of worms I feel. I don't know enough about ortho vs projection, although I have played with it a bit and got some interesting effects.
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 12th Feb 2023 03:01 Edited at: 12th Feb 2023 03:04
OK nz0, now I better understand what you're trying to do. My advice for a lens flare effect is to drop the near plane clipping approach entirely and just use depth write/read. I have a lot of lens flare effects in my games (the Evochron link in my signature is one) and I basically use this technique:

- Create lens flare plane surfaces for each segment of the effect.
- Apply the blend mode and transparency needed to apply it additive/mixed on top of anything else in the scene.
- Depending on requirements, apply SetObjectDepthWrite(obj,0) or SetObjectDepthReadMode(obj,7) to remove depth sorting.

I use a column of lens flares that stack out toward the light source with elements on each side of the central viewing angle of the camera. So my placement setup looks something like this:

- Place a hidden guide object at camera, point in the direct of the camera, move out to the minimum near plane distance I need/want.
- Point the hidden guide object at the light source and move forward/backward along the column angle needed for placing each flare.
- Place flares at required points, adjust spacing from camera to stay close the near plane.
- Scale and fade as needed based on angle to light source from camera center position.
- Realign all flares with the camera's angle, rotate on local Z for angle to light source.

Some of that is optional and can be done in different ways, so it's a flexible method. Here are a couple of helper functions that I use to align objects with each other and objects to the camera for such operations:

janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Feb 2023 17:37 Edited at: 13th Feb 2023 17:37
Else if you really want the near plane you could take a look into my Shadow shader code, i reconstruct the entire Projection Matrix there.
This is how i retrieved the camera boundary from AGK:
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 13th Feb 2023 22:32
@sfsw I didn't think about removing the depth sorting - I'll give that a try. I've done that with lens glare for the e.g. the sun, but was too preoccupied with the clipped polys in this case.
@janbo I'll have a look at that also (for other possible reasons if the depth method meets my needs).
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 15th Feb 2023 00:27
@sfsw After some experiments, I think this is going to work as you suggested. I've only just switched in VR for this and it also appears I'll have to create a sphere for the "eyes" in VR and do a ray check on that, or I'll see the effect when I look side on to the point, which isn't right.
@blinkOK yea, I was using a lower range, but looking for the clip point wasn't about how far from the camera it was, it was more the problem with how to position a plane that can face the camera at (or a relative position) from the clip point that didn't clip the plane itself.

As for not being able to bloom in VR, I forgot that it's kind of bloomy as it is already, so not really a big deal.

I just dug out my old VR sandbox which I was staggered to see that I made in 2017 (!) Where has the time gone!? I'm embarrassed to see that I use the DepthReadMode(Obj,7) on the lens flare I made all the way back then... I remember having to convert my old sprite based lens flare effect to planes because of VR.

SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 15th Feb 2023 02:37
Glad that's working. It does indeed work with VR pretty well and provides a nice bloom effect also as you noted. Depending on what kind of free viewing capabilities you are going for in VR, you may want the effect visible when they turn to look to the side and keep things aligned to the center of the player's viewing angle. That is, the lens flare follows the player's eyes/perspective in relation to the light source rather than only when they look forward. Shouldn't require any ray casts on a sphere that way. In VR, I do the placement and angle checks based on the player's viewing angle after VR input is applied and center everything to that perspective. But it can certainly apply in different ways. That kind of flexibility is one of the nice aspects of rendering everything as scene elements without employing full screen shaders/post processing effects.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 1st May 2023 00:34
This project has moved along quite a bit and getting some nice results.
The lack of VR bloom isn't a problem and I did solve the issue with local Z shifting a faker child object along the cylinder and finding a "magic number" for the eye range in VR (just basically moving the billboard plane on -z until it doesn't clip from kinda -60 to +60 degrees. I also had to scale the cylinder down accordingly to avoid "actual" clipping being seen.

The final effect is a lens bloom when a laser happens to shine right in your eye and it works pretty good. It's funny how much effort can go into something that happens for a split second (rarely or never even).

I managed to use vector3dot for the first time in a slightly related issue regarding working out the relative "look at" - e.g. x1/y1/z1 looking at x2/y2/z2 represented by -1.0 ->1.0 which was a game changer.

(every day's a school day!)

Login to post a reply

Server time is: 2024-04-24 23:47:25
Your offset time is: 2024-04-24 23:47:25