Assuming that I’ve created a cube with a side that has a (x:y) scale of 1920:1080 (1080p), and I have a texture of 1920x1080 pixels, is it possible to apply the image to that face and then position the object so that the image is shown pixel-perfect on a 1920x1080 pixel screen?
In other words, is it possible to show an image pixel perfect on the screen while still existing in 3d space so that I can have it fly into position? This would have a very strong effect while showing very high definition photography.
Thanks!
Sure, it’s just a little mathematics
For a general approach, placing a virtual plane as child to the camera which will create a normalized “screen space” for 3D objects, see my answer here for example.
The most important fact is the distance from your object to the camera, which is just:
cameraZ=0.5/Mathf.Tan(Camera.main.fieldOfView/2*Mathf.Deg2Rad)*heightOfYourObjectInWorldCoordinates
Some additional notes:
- There might be a 0.5 pixel height shift/offset (I seem to remember width was OK), depending on the render path (Forward/Deferred). UPDATE: since some version >=5.x, the 0.5 pixel shift problems have been fixed. So if you use Integer coordinates (and Textures with an even resolution, as odd numbered resolutions WILL be shifted, unless the pivot is in a corner), it will now be pixel aligned, and pixel coordinates will match ehen when switching between Forward and Deferred.
- You may have to experiment with the texture settings to find out which gives the best results in your situation (for example, if you’re animating towards that position, you’ll probably need MipMaps, but this might introduce slight blurring, etc.)
- Point filtering will recreate true pixel colors, but will introduce aliasing in animation.
- Non-PowerOf2-Textures in 1920x1080 will be sharper, since they are not interpolated, but it will prevent MipMapping to work.
- When using MipMapping, use “ToNearest”, to enforce 2048x1024.
- Trilinear filtering gives the smoothest results, but it will always be slightly blurry.
- Bilinear filtering will be sharper, but the texture/pixels will visibly flip to the next mip level at certain distances
- Note that mipmaping in Unity is only relevant if the texture is smaller/farther away than a 1:1 representation, it won’t help you when zooming closer.
- Note that the difference between point filtering and one of the two linear inpterpolation filter settings is only relevant if the texture is larger/closer than a 1:1 representation - if mipmapping is disabled. If it is enabled, the filterMode will also influence the appearance of the texture if it is further away (see above).