Unity2D let's me edit three thing when i create a material - unity3d

enter image description here
When I created a Material it lets me edit Diffuse, Mask and Normal, which doesn't show up in my tutorial. Why is this happening and how do I fix it?

Under 'Shader' you have UniversalRenderPipeline -> 2D -> Sprite-lit-default, and this shader you can take Diffuse which is the main image, Mask which hides a part of the image and Normal Map which will fake depth with a normal map image. You can change the 'Shader' to 'Standard Shader' and that is likely what your tutorial is using.

Related

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 ;)

Custom Shaped Buttons Unity UI

Hi I am trying to create custom buttons on unity (trapeziums). I successfully created the visible area on Photoshop and imported it as Sprite 2D UI as per the following image:
The issue arises, when I'm trying to select one of the buttons in game, their border overlap each other, since the transparent area is still being considered as part of the clickable button area. How can I remove this?
EDIT:
Practically when I import I want the squared boxes to not be counted with the image. I need the edges of the orange area to be cut flush with that and not the entire area(i.e. including the transparent boxes).
You may achieve this by using Alpha Hit Test Minimum Threshold. Take a look at this nice video tutorial.
There is one extra step that is not shown in the video but mentioned in the comments: you have to change "Mesh Type" to "Full Rect" and not "Tight" as it is.
Hope that helps.
The clickable area is based on the Rect Transform component of the GameObject. Adjust the width and height to the clickable area you want. You may have to crop your image in photoshop accordingly. If you select 'Gizmos' in the editor you can toggle viewing the click region.

How to merge an image to fill in other image with shape?

I want to merge an image to another image in one shape. Example:
1- People image
2- Shape Image:
So how to do draw that. I already implement for merging but it's not fill to that shape.
It's possible to do this using the masking functions in the Quartz 2D framework. It's a little bit more involved than using the higher level image functions of UI Kit, but Quartz 2D gives you a lot more power to do cool graphics techniques.
The relevant Apple Developer guide to this can be found here: https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html
For this example, you'd want to create a mask shape for the inside part of the shape image. There are two ways you can do this. One way is to use image editing software to create a second mask image, with the same size as your shape image, with pure black in the area where you want the people image to appear, and white where you don't want to appear. In this example, that would be the area inside the blue shape. It is important to not crop this image, or else they won't match up exactly.
The other way to create the masking image would be to do that dynamically based on the shape image, and honestly, this is the way I would do it. This would mean that you're including fewer images in your app, and if you made any changes to the shape image, you wouldn't have to recreate the mask image as well. You could do this by making a small change to the way your shape image is formatted. You would need to use a format that allows transparency - png is preferred - so that there is alpha transparency in the part of the image outside of the shape, which is white in your JPEG image. Make sure the section in the center of the image is white (really, any color that is NOT USED in the wanted part of the shape image would work, but I'll say white for this example) and that you don't have parts of it that aren't pure white after image compression.
You will then use Quartz to select the area that's white, and create a mask from that. This technique is a bit more involved, but what you need can be found in the document I linked to above. Because of this, you might start with a static masking image, and then convert to the more involved technique after you've got the code to make the first technique work.
When you have your masking image, you would create the mask itself with the function CGImageMaskCreate(::::::::). You can then apply the mask to the people image using the function CGImageCreateWithMask(::), which will give you an image with the person's portrait, with the correct shape cropped from the center.
Finally, you would display this in your app by placing the masked people image on top of the shape image, and voila, you'll have what you're looking for.
Also, keep in mind, when using the Quartz 2D framework, you'll have to make sure you release images when they are no longer needed, or else you could have memory leaks.

Unity3d - How to do transparency images?

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:

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.