Quantcast
Channel: Latest Questions by x4000
Viewing all articles
Browse latest Browse all 49

How to properly set up quad positions for 2d with an orthographic camera?

$
0
0

For once, a brief question, as a corollary to my longer one here:

http://answers.unity3d.com/questions/20459/how-to-retain-full-quality-on-a-rotated-textured-quad

Basically, I'm still seeing quality drop issues where my sprites look fuzzy (see examples above), but ONLY at specific resolutions. Or rather, I'm seeing it at all resolutions except a few odds ones. This is most evident when resizing the unity editor and looking at what happens. At 1267x721, it is just as crystal clear as can be. At any sane resolution, and most other nonstandard resolutions to boot, it looks muddy. Depending on the resolution, it might look more or less muddy. It seems to be that the more a resolution trends toward prime numbers, the clearer it seems, oddly.

The code I'm using to set my orthographic camera size is simply:

 double orthoSize = Game.Instance.MainCameraCamera.pixelHeight / 2.0;
 Game.Instance.MainCameraCamera.orthographicSize = (float)orthoSize;

And then I'm using Game.Instance.MainCameraCamera.ScreenToWorldPoint in order to translate my screen coordinates to world coordinates. I've tried doing some stuff with the following:

 WorldUnitsPerScreenPixel = ( Game.Instance.MainCameraCamera.orthographicSize 
      * 2f ) / Game.Instance.MainCameraCamera.pixelHeight;

But no matter what I multiply by this (quad scale, position, etc), it doesn't seem to really have any effect.

Presumably I'm missing some critical step for fully setting up an orthographic camera for use in 2D. Any ideas? Or, for that matter, if there's a setup pattern for using a perspective camera, then I'd be fine with that, too. I've also experimented around there, but I can't figure out the relationship between Z depth, fov, and the screen resolution for getting pixel-perfect results.

Update

So very close on this one. This example project shows something extremely curious, though: textures positioned on the half-pixels show up pixel-perfect, whereas textures positioned on the full pixels show up blurry.

The transform of the camera that Eric posted about below is absolutely awesome, and that let me stop doing the stupid Camera.ScreenToWorldPoint conversion all over the place, which is wonderful. Those ideas are incorporated into the above example project.

I should note that the example project uses Graphics.DrawMeshNow, and imports the textures asynchronously at runtime from a WWW class, but as you can see the texture itself is able to be drawn perfectly fine... as long as its transform is at an offset.

I suppose I can just offset everything by 0.5 if I have to, and that seems to work reliably, but it's just hokey enough that it makes me worry that some user, somewhere, is going to get majorly messed up because of that. Any ideas on this last part?


Viewing all articles
Browse latest Browse all 49

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>