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.
Related
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 want to animate the cube over the ui panel.
The Canvas is set to Render Mode : Screen Space - Overlay
The Panel have my own source image
The Camera Clear Flags set to Skbox and Culling Mask to UI only
The Cube layer is set to UI
But the Cube is transparent and I want it to be full like a regular Cube.
I think #Draco18s is right, for you to render UI behind stuff you need to change the Canvas to Camera or World space and then configure Z position in transform of the background (or depth in canvas component) to make it stay behind your cube.
Remember to add a camera to the canvas.
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.
I'm importing a sprite into Unity, and adding it to a Screen Space Overlay canvas to use for a UI.
The image I'm importing looks exactly as I want it, but in Unity the anti-aliased edges look like they're going to a white background color, instead of just fading over whatever is actually behind them.
I'm using these import settings:
I'm using a default UI/Image component to add it to the canvas.
This is the image I'm importing - it's a 32 bit PNG exported from Fireworks: (also shown over a black background)
Just to confirm, this looks fine everywhere else in Unity, preview panels, pickers etc. I am packing this sprite using the built in Sprite Packer if that changes anything.
And the final result:
How can I get rid of these artifacts on the corners?
The problem was the RGB values of the transparent pixels. By default they are white, and any scaling operations cause this white color to be blended with the partially transparent pixels.
I essentially made a slightly larger version of the button background shape, put it in a layer behind everything, and then wrote back into the alpha channel making it transparent. This means that the neighboring pixels are then the same color as the partially transparent ones.
The end result:
I am using cocos2d on the iPhone and am wondering if it is possible to use a texture mask in order to create tile transitions / fringe layer. For example, a grass tile and a dirt tile, I would want a tile that had both grass and dirt in it... Has anyone done this, or is the only way to create one tile for every possible transition?
For those who are curious, you can use masks with the following setup:
First draw the mask which should use a black brush on a transparent background. Draw this with src alpha and one-minus src alpha.
Second, draw on top of the mask the texture that you only want to appear over the mask part (the black brush). Draw this texture with dst alpha and gl_zero.
Third, draw the texture that you want to appear over the transparent part of the mask. Draw this texture with one-minus dst alpha and gl_one.
Using this technique, you don't have to make transition / fringe tiles for all of the possible terrains.