Search Unity

Computing horizon height at far-plane for current camera?

Discussion in 'Scripting' started by metaleap, May 30, 2014.

  1. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Anyone know a smart snippet to do this?

    On the CPU/scripting side (not GPU/shading side), we know a camera's far-plane, near-plane, FoV and transform and matrices. We also know it only ever rotates around the Y (look left or right) or X axes (look up or down), but never around Z axis (tilting).

    With this info, I want to compute whether the "horizon" (world ground level y=0) is currently inside the cam's far-plane and if so, at which camera-space coordinate Y[-1..1] that horizon will show. Since the camera never tilts, the horizon will be (roughly) a straight horizontal line, at least that approximation is good enough for this here purpose.