How to calculate pixel size of object knowing distance and FOV without Unity methods

Anyone know how to calculate pixel size of an object as seen by the camera without any Unity methods?

Reason being I’d like to compile a spreadsheet that I can calculate to figure out necessary texel densities for combinations of FOV and view distances of a 1x1 unit plane.

I found this post from a different forum that does output the right size, but it uses the WorldToScreenPoint camera method which I cannot view the math for:

It’s just trigonometry.

FOV in Unity is the angle from directly forward to the top edge of the screen, so 2 * FOV is the full top to bottom range.

If you insist on not using Unity, you will still need to chose nominal target pixel density, the red line below, obviously.

As found on some random page:

2 Likes

Hmm, I thought it was a little more involved than this :stuck_out_tongue:

Isn’t this just the calculation for frustum height though? Like I am looking for the size of an object inside of that frustum plane at a given distance.

Oddly enough though, the screen height divided by the number generated by this equation gives me the correct size of a unit plane at said distance. I’m not sure of the math behind that now though / what is going on with that relation.

For example, a full HD display (1920x1080) with a unit plane 1 unit away from the camera at the default 60 degree FOV equates to size = 1.155. 1080 divided by 1.155 equals approximately 935 pixels which matches with the result from the linked post equations and also confirmed in Photoshop.

Do you know why that is?

worldToScreenPoint is likely to just be some matrix math, eg:

Trigonometry!

sin(60) = 0.866 (appx)

0.866 * 1080 is 935 (appx)

Extra tidbits:

  • remember angles can be measured in degrees (360 is a circle) or radians (pi * 2 is circle).
  • camera FOV is measured in degrees (by Unity convention)
  • Mathf.Sin() accepts radians (by typical C# Math library convention)
  • multiply by either of the conversion constants: Mathf.Rad2Deg or Mathf.Deg2Rad

Who ever said grade school trig wasn’t gonna be useful?

1 Like

Wasn’t so much the trig, but not keeping units in the equation was what was confusing me. The end result being a fustrum of Y units when object is X units away. Thus screen height dividing by Y units results in pixels per unit, which is also how tall a unit plane is at same distance. Coffee hadn’t kicked in yet :stuck_out_tongue:

Thanks @Kurt-Dekker for your assistance with this though.

1 Like