Unity3d - How to do transparency images? - unity3d

I have a unity application. When the user hover on the object, I want to change mouse image.So, I want to know how to make part of image transparent in unity3d? If I use directly .png image, the mouse looks like below image :
I don't want to show gray area. How can I do?

An image file can be saved with a crowd of formats. For your arrow can have transparent areas you should save it in a format that handles the so-called "alpha channel". This channel stores information about the degree of transparency (from 0% to 100%) of all and each of the pixels. Simple programs like Windows Paint eliminate this channel. I recommend you use "Gymp", is the one I use (It's free)
If you don't have that problem. Be sure you have selected the correct Shader Type. Not all the shaders are ready to transparency. I recomend you to use the "transparent Cutout" for 3D Objects:
And "Sprite (2d and UI)" for 2D Objects:

In Unity, in the asset explorer, if you click on your .png image, you should be able to select the texture type. It is definitely possible to have textures with transparency.
You should also simple check that you saved your png image with transparency

Transparency shows black when using a non transparent shader so that is not your case. Your image seems to be a jpg so it has no transparency (RGB only).
Unity does not use jpg and converts them to png but as the original has no transparency anyway, it is white pixels in the original and white pixels in the png conversion.
You need to rework the image in Gimp or Photoshop to remove the useless grey parts and make sure you save it as png so the transparency is stored (RGBA).

This is an old question but I guess people could like a more modern solution for most recent Unity versions (like I did).
Unity now supports Shaders Graphs, which means you can create a shader that gives transparency to a selected color in an image that normaly wouldn't have an alpha channel (like jpg or gif).
Sure if you are creating the image just make a .png with alpha channel, but sometimes free assets need a little tweak (as you didn't create them):
Make sure you installed a render pipeline that supports the shader graph (Window -> Package Manager -> Lightweight RP)
Create a render pipeline in your project (Create -> Rendering -> UniversalRenderPipeline -> Forward Render)
Make it active (Edit-> Project Settings -> Graphics -> Scriptable Render Pipeline Settings (select the one you created)
Create a new shader (Create -> Shader -> Unlit Graph), I created this one with good results:
Create a material, so we can actually use this shader in sprites (Create -> Material)
Configure the material to use the new created shader (with material selected, Shader Graphs -> [your shader name]
And voila!
I'm new to this shader graph thing but it looks really, really promising.
If everything went well you'll end up with a material like this:

Related

Making an image button in Unity 2019.3.12f1

When I try to assign a source image to a Unity.UI button it always ends up blurry/distorted on the edges. I played with the resolution and some settings also tried with other images but it doesn't make a difference. the images I tried were png files and had transparent backgrounds.
By default, Unity applies a bilinear filter to textures that blur them slightly. This is often good if you have a high-resolution image since it removes hard edges. However, if you have a low-resolution image (e.g. pixel art) you might not want this. To disable it, click on the image in the project tab and change Filter Mode to Point (no filter) in the inspector.
This is how an image can look with the Bilinear filter mode:
Compared to how it looks with the Point filter mode:

Unity 2D shader graph not correct colored

I tried to create outline shader for my Sprite:
I watched tutorials on YouTube (CodeMonkey and Brackeys) about this, but it worked by half. In Scene Graph I see preview:
But outline color I so faded:
And also I can't see this shader on Scene Preview:
What am I doing wrong?
Thanks for your attention
P.S.: Of course I set render pipeline like on this video
P.P.S: Material settings:
P.P.P.S: Shader file
Ok first of all you hadn't set the color in the according Outline Color slot int he Material settings.
Then what you are using is Add which results in additive color combining towards white.
Since your original texture isn't fully black but grey-ish the outline color is added to the already existing color(s) making it also lighter!
Instead you could use a Blend node and re-use the output of the Substract node as blend texture (Opacity).
Then you have to play a bit with the mode but I think maybe Overwrite or PinLight would be what you want.
(Actually you wouldn't need the additional Multiply node for the Outline Color)
Btw before you added your file I just reproduced one from scratch and it is way less complex than yours ;)

PNG file looks completely different inside of Unity

I purchased the "Set Builder: Back street Manhattan" with came with some png textures such as this one.
When I open the file in the browser or any editing program, it looks completely transparent except for the windows. When I drag the image into Unity, it is completely opaque bricks (which is what I want) If I duplicate the image and drag that image into Unity, it is again completely opaque bricks. If I save a copy of the image with photoshop or another application, the information that contained the bricks is lost and it is now mostly transparent, except it has some blotchy white textures which also aren't seen in the photoshop interpretation. Every texture in this folder is doing this same behavior. Are these files corrupted or compressed? How do I retain the brick information into an image editing program besides taking a screenshot within Unity ? Here is an example : of dragging images onto cubes in Unity. Left is a Photoshop copy. Right is attached image
The developer has not replied to my direct questions.
it can be your texture import format
try changing its format to true color
I found a solution in Photoshop.
Layer>layer mask>from transparency. Then right click on the layer to disable the transparency.

Unity - Render Texture from Camera's targetTexture produces seams

I am attempting to render a specific section of my scene using a separate camera, and a render texture. That object is on a separate layer that the main camera is not rendering, but a separate camera is. The secondary camera has a target texture set to be a render texture that I have created. Everything is working as intended except for the fact that the object, when rendered to a texture, has a bunch of seams that are not present when rendering directly to the screen.
What it looks like when rendered directly to the screen:
Correct
What it looks like when rendered to a texture, and then displayed on a quad in the scene:
Incorrect
Notice how the second image has a bunch of transparent "lines" in between the sprites where there shouldn't be any.
I am using a basic transparent shader to display the render texture on the quad (since the background isn't part of the render texture, just the black crowd part). I have tried a number of different shaders, and none of them seem to make a difference.
The render texture's settings are: Width: Screen.width Height: Screen.height Format: RenderTextureFormat.ARGBFloat;
Unity Version: 5.2.3f1 - iOS Platform
Note: The reason I am doing this is so that I can apply a "Blur" image effect to the texture, and make the crowd in the foreground appear to be out of focus. Any alternative suggestions for how to do this are also welcome.
I'm not quite sure -- but it almost sounds like you have line ghosting. You may want to give this a read and let me know if that's what you're dealing with or not:
The reason for this is due to how the texture image was authored, combined with the filtering that most 3d engines use when textures are displayed at different sizes on screen.
Your image may have coloured areas which are completely opaque, coloured areas which are partially transparent, and areas which are completely transparent. However, the areas where your alpha channel is completely transparent (0% opacity) actually still have a colour value too. In PNGs (or at least, the way Photoshop exports PNGs) seems to default to using white for the completely transparent pixels. With other formats or editors, this may be black. Both are equally undesirable when it comes to use in a 3d engine.
You may think, "why is the white colour a problem if it's completely transparent?". The problem occurs because when your texture appears on screen, it's usually either upscaled or downscaled depending whether the pixels in the texture's image are appearing larger or smaller than actual size. For the downsizing, a series of downscaled versions get created during import. These downscaled versions get used when the texture is displayed at smaller sizes or steeper angles in relation to the view, and is intended to improve visual quality and make rendering faster. This process is called "mip-mapping" - read more about mip-mapping here. For upscaling, simple bilinear interpolation is normally used.
The scaled versions are usually created using simple bilinear interpolation, which means that the transparent pixels are mixed with the neighbouring visible pixels. With the mipmaps, for each smaller level, the problem with the invisible mixing with the visible pixel colours increases (with the result that your nasty white edges become more apparent at further distances away).
The solution is to ensure that these completely transparent pixels have a colour value which matches their neighbouring visible pixels, so that when the interpolation occurs, the colour 'bleed' from the invisible pixels is of the appropriate colour.
To solve this (in Photoshop) I always use the free "Solidify" tool from the Flaming Pear Free Plugins pack, like this:
Download and install the Flaming Pear "Free Plugins" pack (near the bottom of that list)
Open your PNG in photoshop.
Go to Select -> Load Selection and click OK.
Go to Select -> Save Selection and click OK. This will create a new alpha channel.
Now Deselect all (Ctrl-D or Cmd-D)
Select Filter -> Flaming Pear -> Solidify B
Your image will now appear to be entirely made of solid colour, with no transparent areas, however your transparency information is now stored in an explicit alpha channel, which you can view and edit by selecting it in the channels palette.
Now re-save your image, and you should find your white fuzzies have dissappeared!
Source: http://answers.unity3d.com/questions/10302/messy-alpha-problem-white-around-edges.html
Turns out that the shader I was using for my scene was using "Blend SrcAlpha OneMinusSrcAlpha" for some reason, when it should have been using "Blend One OneMinusSrcAlpha". This was causing objects with alpha less than 1 to make the objects under them become semi-transparent as well exposing the camera's clear colour background.

Difficulty in using smooth blurred textures in Unity

I have planned to use blurred textures as shadow for my planes by just placing them on the surface below it.
In the first image you see below, there are three shadows.
1. Smiley's shadow: Default-Particle given by Unity and works great for this purpose.
2. Square: & 3. Arrow: A shape I created are not good enough.
To clarify the exact problem please find the 2nd image I have attached. The shadow(texture) is of very poor quality.
How to get the fine quality in blurred textures?
Image 1:
Image 2:
Check the import settings of your texture asset. This can be done by clicking the texture asset in the Project view. Then in the inspector view you can find "Format" drop down. You probably have either "Compressed" or "16 bit" chosen. If you change it to "Truecolor", the texture should look fine.