Search Unity

Discussion Line frustum intersection

Discussion in 'Scripting' started by Meaningless-Trinket, Aug 19, 2022.

  1. Meaningless-Trinket

    Meaningless-Trinket

    Joined:
    Apr 25, 2020
    Posts:
    83
    I was thinking how a frustum line intersection inside a big portal would work.

    Get the points from lines intersecting plane when the origin of the line is greater than zero.

    One line is tested by all the planes then it goes to the next line.

    The next lines origin gets replaced by the last line intersection point.

    Then a fifth line is made and four points are inside the frustum.

    I made a picture to explain what I'm trying to say.

    Line portal.png
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,116
    I'm not sure if I understand you correctly.

    #1 part: Finding intersections between frustum (4 rays) and some plane P
    You find the camera rays (via ViewportPointToRay), then you find 4 points that lie on P (through ray-plane intersection).

    #2 part: If we imagine that plane P was a surface of an in-portal, we extend the rays from the out-portal
    First you find 4 out-corners according to some portal-to-portal transformation, then you reproject the original rays to extend from these corners further into the destination space. This is akin to UV mapping (and you should normalize your offsets based on the portal rectangle). If your portals are of the same size, then you can simply mirror the local U coordinate (because they behave like mirrors if you think about it, what's going in on the top-left, will come out at the top-right).

    Portal-to-portal transformation is simply a matrix that encapsulates what happens to the plane normal. Consider source plane's normal as antiparallel to the destination plane's normal (see below). Even though this might not be true in the actual world space, it must be true when it comes to portals.

    If there is no space-scaling (along local Z), then you have a simpler job:
    1) find a translation component for each of the 4 corners (by subtracting) and,
    2) find a singular rotation via
    Quaternion.FromToRotation(-source.normal, destination.normal)
    .

    You now have a quaternion which you can apply to the 4 rays.
     
    Last edited: Aug 19, 2022
  3. Meaningless-Trinket

    Meaningless-Trinket

    Joined:
    Apr 25, 2020
    Posts:
    83
    The rays go around the portal and the frustum intersects the rays one ray at a time.

    The top line is 0 to 1 and 0 is the origin.

    I want it to intersect the plane that the origin of the ray is on the positive side.

    The intersection makes a new point then that point is the origin for the next line.

    The lines get trimmed down until there are four points inside the frustum.

    I'm using portals to test for visibility instead of the portals that teleport.

    It's like portals you walk through without teleporting and the portal clips the area behind it to the opening.
     
    Last edited: Aug 19, 2022
  4. Meaningless-Trinket

    Meaningless-Trinket

    Joined:
    Apr 25, 2020
    Posts:
    83
    I think I have a better idea of how to do frustum line intersection.

    Line portal 2.png