I installed a 3d model from internet. I add it to unity scene.But I try to convert transparent model. To do it, I create a material and change A channel(RGBA) in inspector panel.
By the way, I generate a transparent material. I drag it to model gameobject. Now, the model is transparent but it doesn't include rgb datas.
How to a model convert to transparent model with rgb datas?
Solution :
Create material using Assets->Create->Material
Click material, on inspector set rendering mode to 'Transparency'
Change A channel in RGBA
Click object on hierarchy, set material size 2(one of them is rgb, the other is transparency)
Drag yout transparecy material and rgb image to the object.
If you are trying to create a transparent material using an image, make sure that your rendering mode at the top of the material is set to 'Transparent,' and you load the image next to 'Albedo.' If you want to change the transparency uniformly across the object, select 'Transparent,' but modify the A (alpha) channel as you described.
Related
I have a scene need to display a 3d module to ui layer, so i use a secondary camera to render it to a RenderTexture, but when i set a background to the ui layer ,i found that the content is wrong, because the alpha channel is not what i expect
In order to describe my problem more clearly, I created a demo
the content: in the center has the backgorund color, this is what i don't want, i want the center is fully white
the 3d object: a cube with opaque material and sphere with transparent material
the renderTexture's alpha channel:
I tried use colormask to disable alpha output, but the ui layer background size is smaller than my 3d model's content, so where there is no background it is invisible.
Update at 2023-2-15-17:49
this is the problem in my project, the character's hair has some transparent part, i use a camera with renderTexture to display it on Ui layer, but the hair's transparent part make some mistake
Solution:
Set the RenderTexture's Color Format to ARGB32.
Make sure the background of the UI layer is fully opaque.
Enable Alpha Clipping in the material of the 3D object, and set the Alpha to the desired value.
Set the RenderTexture's Clear Flags to "Depth Only", so that the background color will not be taken into account.
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.
I want to apply a brighten effect above my scene.
My scene contains tiles, and I want to perform white flash for a few frames by code.
I have already tried this code:
private Tilemap tm;
...
tm = GetComponent<Tilemap>();
tm.color = new Color(0.5f,1.0f,1.0f,1.0f);
This code darkens the scene by a certain color amount, but I wish to brighten it.
Your code is not working because in Unity if you render an image (in your case tile) the original color of the image is when its color is white (255,255,255,255).
It means that if you change the color of an image it will add this color to this image.
For instance, if you set the color of an image to red, the image colors will become more similar to red than the original image.
As I see it you have 2 ways to perform the white flash:
A) Add another image of a white rectangle that covers all the screen and set it's alpha color to a low number (the lower the number the lighter flash effect).
In the editor disable this object's renderer and when you want to perform a flash effect enable this object from the code (You can improve this with animations or code to get a smooth flash animation).
B) Install the package "2D Light". This is an experimental package that allow you to render 2d light.
This package contains a lot of components that allow you to stimulate light.
I have found a way to do this.
I created a new PNG that only contains white shapes on a transparent background.
There are about 20 pieces that match the shapes of my level tilemap.
Now I just create a new (white) tilemap above the level tilemap in the shape of the highlight.
Then I set the alpha of the white tilemap in code.
It works :)
I got a little problem with my Unity's canvas. I can't set the background image.I've added the Image component to the canvas and I've tried drag the image from the assets to Source Image, but it doesn't allowed that.
You have to set the image to a Sprite (2D and UI) in order to use it in the canvas. This is done by selecting the image in the Project window and making the change in the Inspector window, from the Texture Type dropdown. Make sure you hit apply once you have completed the changes.
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: