I have done probably in a weird way, where viewport width is being divided by its height, clamped with the minimum 1 and multiplied by constant. Here is screenshot of the full solution. It has been tested on the “standard” (4:3), stretched horizontally and stretched vertically window sizes and even when height is bigger than width, but has not been tested on different computers.