Images with gradient poorly managed by Unity - image

I'm currently creating a 2D game on Unity and I have a problem with images with gradients or transparency. Here for example, the beginning of one of my levels before importing it in Unity (PNG-8):
Here when the image is imported into Unity:
We can see that the gradation is very poorly managed by Unity. What are the ways to fix this problem?

Have you tried playing with the image compression settings of the image in Unity?
Usually, I see that sort of gradient display when my images are set to use the 16bits setting.
If you go on the image in Unity's project tab and you will find "Format" in the Inspector tab. You can play around with it and see if any of the other settings will improve the quality.

Unity is bad with 2D texture. You have 2 choice:
1 - Change the Format of the texture to True Color (Result will be as you wish but the size could increase by 4 so it can choke the CPU if it's for a mobile game, I don't recommend it)
2 - Use Crunch Compression to 100%, the result will be the same as the original image but the compression could take a very long time depending on the resolution of the image and if it's a POT.

Related

Rendering 2D image using Direct3D

I am trying to replace my GDIPlus rendering with Direct3D. I am rendering some large images of the order (10K x 10K) and it gets really slow with GDI. I am now rendering the image as texture onto a Quad using Direct3D. The image does render but the quality is really off when the image is zoomed out.
I am using the following filters.
m_pDevice3D->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
m_pDevice3D->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
//m_pDevice3D->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 4);
m_pDevice3D->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
I have already tried rendering using Anisotropic filter already with no significant improvement.
You can not render a large image on a small surface with a good quality without paying the price of an extensive filtering.
This is a signal processing issue named aliasing. To reproduce a signal, you need a medium that has at least twice the resolution or the spectrum will fold on itself.
In 3D rendering, the typical way to do it is by generating a mipchain. It consists of pre filtered version of the image dividing the resolution by two until we reach a size of 1x1. The GPU is then able to pick the proper version.
If your image is dynamic, and you know the display area, you will prefer a runtime filtering, but to do that with a GPU, you will have to recent direct x version with shaders or work with temporary offscreen surface to ping pong the reduction step by step.

Sprite texture compression in Unity

I wish to compress my png sprite textures a bit so they don't take up that much memory as I build for mobile devices. As I use a lot of gif animations this is crucial for my game's performance.
I looked for an answer but the threads I found were more than 1 year old and not about sprites so I figured I ask my version. An image that's 224 KB in size takes up 1.6 MB in Unity with the generate mip maps turned off
So compressing the png sprite textures in my game. How to do that?
Try setting Format to Automatic Compressed.
For this to work on all mobile platforms make sure the initial image has sizes that are power of 2 (actually I think that multiple of 4 should be enough, but just to be on the safe side).
This will lower the quality of the image but should save you some space.
Turning mip map off is again a good idea as mim map increase the size of the image by about 33%.
And one more thing, make sure that Non Power of 2 is set to None, that may be the reason you see an increase in size at the moment.

how to speed up load time for MFC ribbon application

I have a native MFC C++ application for which I've got a ribbon UI based version and a toolbar based version. Both EXEs are similar size (~30mb), but running the ribbon based version takes about 25s whereas the toolbar version takes about 5s. This is just to get the frame window displayed with tools. I've profiled the start up of the ribbon UI based version, and sure enough the time is being spent in CMFCRibbonBar::LoadFromResource and deeper down in
BOOL CMFCRibbonInfoLoader::LoadImage(CMFCRibbonInfo::XImage& image, BOOL bSingle)
{
'
'
'
image.m_Image.SetTransparentColor(GetGlobalData()->clrBtnFace); // 15%
image.m_Image.SmoothResize(dblScale); // 64%
'
}
Digging deeper, a lot of time seems to be spent manually shading the toolbar ~44% of the total time.
Is there any way to speed up this load time, possibly by setting a non-transparent drawing scheme? 25 seconds to run a program seems a bit excessive, this is on an 8 core 4ghz AMD 8350 with the EXE image coming from an SSD.
Edit: Tried the following which helped understand the problem but doesn't really make for a useful answer.
After some poking around, it seems a call to afxGlobalData.EnableRibbonImageScale(FALSE); disables the scaling but can leave poor results visually on some monitors. If the image sizes are correct for the monitor to start with, 40x40 pixels on my 1920x1080 display, the scaling will also get skipped. I haven't tried it yet, but I'd imagine if you specify HDPI images for all the ribbon controls and you are lucky enough to get 1:1 scaling for your HDPI images, it would also get skipped. Searching the MFC source code (\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\afxglobals.h) for m_bIsRibbonImageScale and m_dblRibbonImageScale yield most of the relevant code.
If the large button images aren't 32x32 the ribbon editor seems to treat them as they were, and chops the base BMP up incorrectly. So resizing a the base large button BMP to 40x40 resulted in garbage on screen.
Edit: I had thought Vlad's answer would work, but apparently the XML used in an MFC ribbon resource is not Ribbon XML. See related question on MSDN here.
Edit Further discussion on MSDN here
The page Specifying Ribbon Image Resources states:
For any image, the exact pixel size is dependent on the display
resolution, or dots per inch (dpi), of the monitor being used. At 96
dpi, large images are 32x32 pixels in size and small images are 16x16
pixels in size. The image sizes increase in a linear fashion relative
to dpi as illustrated in the following table.
DPI Small Image Large Image
96 dpi 16x16 pixels 32x32 pixels
120 dpi 20x20 pixels 40x40 pixels
144 dpi 24x24 pixels 48x48 pixels
192 dpi 32x32 pixels 64x64 pixels
The Ribbon framework scales image resources as required. However,
because resizing may yield undesirable artifacts and image
degradation, it is highly recommended that the application provide a
small set of image resources that span various commonly used dpi
settings. If an exact match is not found, the nearest image will be
scaled up or down.
To facilitate this, image resources can be declared in Ribbon markup
by using a set of Image elements for each Command element. At run
time, the framework selects the image to display based on the MinDPI
attribute of each Image element.
There is an example at the bottom.
Problem solved: Configuration -> Manifest Tool -> Input And Output -> Enable DPI Awareness NO
NO, is the solution. The default value is unfortunately YES.

How to size down a vector shape in Sketch 3 without losing quality?

I have been trying to resize a logo and make it fit into my navigation bar, but the problem is that it started off as an image from someone at 3932 X 1712px. I traced it with the vector tool, but I need to resize the entire logo as 108 X 47px. Every time I scale the vector down that much, it totally loses clarity and looks extremely pixelated. I tried resizing a little down then exporting that and then resizing a little more, but that also eventually loses quality. I even resized it down a little then vectorized that, but even the vector lines were pixelated. Would love to use this logo in my website and this is annoying. Help!
Open Vector image in Photoshop
Go to file menu > Save for Web
Use Original image to save
Set height-47, width-108
Save image in .png format
Try it, it can be work

XCode - when it comes to UiWebView there is an issue

I'm totally new when it comes to xcode, but there occured a problem:
I'm designing an iPad-App(Retina Display) in html/css with the standard retina resolution of 2048x1536px...the problem is, that when I open the app on the pad, the page turns out to be way too huge. If I'm reading out the UiWebView-Resolution I get 1024x768...am I able to change this to get the real iPad dimension?
thx for your help!
Best regards,
daft
Dimension values on iOS are described in points. Each point can have different number of pixels - depends on screen's pixel density. UIWebView interprets html document size value as point - so 1 html pixel means 1 point.
I suggest you two options to cope with that:
1. Design you're web app to resolution 1024x768 and insert images which are scaled to 50% size to have more pixel density.
2. Leave page in 2048x1536 resolution and use UIWebView api to scale content.

Resources