PSB to Unity Crop Size - unity3d

I have character made of elements done by graphic designer.
I put it to photoshop to match legs/head/weapon etc. save as PSB and import to Unity.
Problem is that free space of images is cropped in Unity.
F.ex.
Hat's contour, color and shadow layer are 512 x 512
But in sprite editor I see it's
contour 360 x 362, color 340 x 342, shadow 299 x 306
It all have to be 512 x 512 even with free space because I've got more hats I swap to bone in code.
If it's cropped all is messed up.
Any pro tip how to save original dimentions?
Is it something in Unity I missed or it's natural PSB thing to optimize size?

Related

UNITY: How to get the width of the line in pixels?

I am working on a project where you have to draw anything using a LineRenderer Component and then I process your drawing using the positions of the Line. To get the positions is pretty simple, but I need to know which width of the line you choose in game. Here is an example:
As you can see, I've done a simple drawing, but the width of the line will be chosen by the player. Now, for this drawing I've used the Width of 0.15 for the LineRenderer Component:
Now, what I have trouble with, is how can I get the width of the Line in pixels. Let's say that the White Image is 900x900 pixels. In this case, how can I get the width of the line in pixels relative to the width of the RawImage used as a Background to draw on top of? Thank you in advance.
That depends on your import settings of the sprite, particulary pixels per unit property. Let's say, that you import your 900x900px image with 90 pixels per unit. Then it will be 10x10 units in Unity. Your line is 0.15 units width (assuming that scale is Vector3.One). 0.15 units * 90 pixels/units = 13.5 pixels.
If your canvas is P pixels wide, it's transform.localScale.x is X and LineRenderer.widthMultiplier is W, then line width in pixels should be (P / X) * W.

Resolution for 2d pixel art games

I'm having problems to set the right resolution on unity to not have pixel distortion on my pixel art assets. When I create an tile grid, on the preview tab the assets look terrible.
I have an tilemap with 64x32 resolution for each tile.
I'm using 64 pixels per unit.
The camera size is set to 5 in a 640x360 resolution (using the following formula: vertical resolution / PPU / 2).
What I'm doing wrong and what I'm missing?
I don't know how the tiles are defined, but assuming those are rects with textures on topm you could check your texture filter setting and play with it a little, setting it up for example to "anisotropic"
To solve this problem and get an "pixel perfect" view, you need to apply the following formula:
Camera size = height of the screen resolution / PPU (pixels per unit) / 2
This will do the job!

Visible gradient/tiered blending in many overlapping particles

I have a particle system for creating "nebulas" in a 2D space game. The results are looking pretty good, except there's a rendering/shader issue with what I'm doing. In game I see a rather ugly tiered blending, almost like I'm looking at 6-bit color rendering (exaggerating for clarity).
Looking at it in unity's scene view, it's nice and smooth (the few "artifacts" are part of the source image used for the particle. It looks exactly as I would hope):
Is there a way to fix this issue? And for curiosity and posterity's sake, why does this happen?
A few specifics:
It's Unity 2018.1.0f2, Windows 10, GTX 1050 ti. There are multiple particles overlapping in that image (I'd guess around 10?), One particle system. the shader is unity's provided Particles/Additive, and I get the same results with Particles/Additive (Soft), Particles/Alpha Blended, and a number of other built in transparent shaders I've tried. The material has alpha = 77 and the particle system adds in alpha = 16 (I believe that's cumulative). The base image is white and transparent. The alpha channel is what defines the actual shape. Color is added with the particle system (resulting in each particle having a different color, even though they all use the same base image).
Edit:
Did some more experimentation, the problem occurs in game (build or in editor) and also in the scene view if not play-testing. I tried reducing the particle count; even single particles (no other overlapping transparent objects/particles) still have the issue. I also experimented with putting all of the transparency control in the particle system or the material, and tried putting both at 255 alpha and using the brightness to control opacity (it's an additive shader), and still no improvement.
I did figure out why the camera and scene view rendered differently. The Camera had "Allow HDR" checked. After unchecking that, the scene view looks identical to the camera's rendering (too bad it didn't go the other way). Perhaps looking into HDR farther will yield answers...
Alright, I've done some experimentation, and I'm beginning to think this is actually a problem with computer displays/graphics cards/color profiles. I took the image in gimp, zoomed in on a part where there was visible stair-stepping in color, and took some color samples at the edges of different color gradients.
Here are the color samples I took, from lighter to darker gradients.
G1 43 48 17 (next to G2)
G2 43 47 17 (next to G1)
G2 39 46 16 (next to G3)
G3 38 45 16 (next to G2)
G3 36 44 16 (next to G4)
What you'll note is that there is substantial difference in RGB value within a gradient, but even zoomed in to where I could fit four pixels on the screen, I couldn't see any pixel outlines within a gradient, but it was very obvious at the edge of the gradient. Either there's something funky with my eyes, or the screen is doing a poor reproduction of the colors. I've tested this on three screens, a cheap HP laptop, a 27" Acer monitor, and a MackBook Pro, all have the same effect.
Also interesting to note, the effect is present even on the brighter image, it's just less noticeable. I'm thinking that unity has absolutely zero to do with this effect, and it's more of a hardware issue (or like, gamma settings in the video drivers).
I'd still be curious if anyone else knows anything more on this topic.

Image Get Jagged in Unity 2D

When images imported into unity gets jagged.
Jagged Image
But the unity 2d pack sprites does not gets jagged:
Jagged Image VS 2D Pack Sprite
I do all tasks like:
1 - Disabling and Enabling Mip Maps
2 - Fit texture size for usage
3 - Change filter mode
4 - Set Compression to None
5 - Importing Images from Photoshop instead of illustrator
Details:
Unity Version 5.5.0f
Images Created in Adobe Illustrator CC 2017
Try the following:
Go into Import Settings by clicking on the file in the project window
Increase pixels per unit to 200-300
For all build platforms:
Increase Max Size to 8192 (or highest)
If you get the option, increase the compressor quality to 100
Not recommended: In the scene, reduce scale and increase width/height
If none of that works:
Use a higher resolution image, or increase import resolution of vector image
Hope this helps!
I solved it.
You should import your textures and sprites in the size that you want for example:
If you need a 64 x 64 texture you should create and import your texture in 128 x 128 size.
By doing this the texture will become anti aliased and a little fade.
Thanks.

Misconception about how the scales work

I am a beginner in Unity and I can't understand how the scales of GameObjects work; in the following picture I have a quad and a sprite. The quad's scale should be smaller than the sprite's scale, but in the editor when I touch them they have the same scale of 1.
Short Answer
Every object has a baseline (1, 1, 1) scale when first created. The size for a 2D sprite and 3D quad object are calculated differently for each, which is why they are not the same size in your screenshot.
Long Answer
The sprite is a 2D object and its size is based on the import settings of the sprite. The default size for sprites is 100 pixels is 1 unit.
The quad is a 3D object and its size is based on what 1 unit is in Unity. In Unity's settings, 1 unit is 1 meter, by default. So, the quad is 1 meter cubed, by default.
If you import a sprite that is 100x100, and keep the default 100 pixels is 1 unit, it should be the same size (with an orthographic camera) as the default quad size.