Cannot make transparent plane work in 2D game with several layers
I am creating a side-to-side scrolling 2D game with a number of environment layers and am having problems getting one of the layers to be semi-transparent to create a sort of distance haze effect. The layers I have include (from back to front):
Stars –Sphere MeshFilter, Mesh Renderer, Sprites/Default Shader
Mountains - Mesh Filter (procedurally generated), Mesh Renderer, Sprites/Default Shader
Haze – Plane Mesh Filter, Mesh Renderer, custom material
Landscape - Mesh Filter (procedurally generated), Mesh Renderer, Sprites/Default Shader
I am trying to set up the Haze layer with some transparency as a simple, or not so simple as it turns out, distance haze effect. Using a standard shader on the material the layer either does or does not render at all depending on the alpha value, but is not transparent, i.e. if it renders then it blocks the stars/mountains completely. I can get a transparent looking effect if I use the Skybox/Panoramic shader although the mountains are still rendered in front of the Haze layer even though they are physically behind it in the z-dimension.
I have read a page on how to fix transparent rendering problems here: [https://answers.unity.com/questions/609021/how-to-fix-transparent-rendering-problem.html][1] and tried using a Standard shader with Rendering Mode set to cutout, but get the same problem that the Haze layer is either solid or invisible.
I am a total noob when it comes to this stuff so am just groping in the dark changing options to see what happens. I don’t know enough about the suggestions on the ”how to fix transparent rendering problems” page to understand how to implement the solutions or if they will work for me. I've read lots of other pages, but am none the wiser.
Can anyone give me any suggestions about how I might fix this problem so that my Haze layer is rendered semi-transparently in front of the stars/mountains? If I haven’t provided enough information here then let me know (not sure what is relevant/isn’t!)
Just for completeness, I have tried another approach by making the mountains transparent (which works fine... so not sure why the Haze layer doesn’t!) and using a script to selectively disable my stars if they are behind the mountains using a raycast, however this is not 100% accurate and can lead to parallax errors where the stars are something visible behind the semi-transparent mountains. It seemed like it would be easier just to have a semi-transparent plane in from of the mountains that tracked the camera, but can't work out what I am doing wrong.
ps apologies for the bad paragraph spacing, but I can't get the line breaks to work for some reason. :s
pps I fixed the paragraph spacing using basic html.
[1]: https://answers.unity.com/questions/609021/how-to-fix-transparent-rendering-problem.html
Double Enter for paragraph
Like this.
For multi layer of mesh + shader for haze effects, it sound dumb.Especially for custom shader.
Use Post processing.
https://assetstore.unity.com/packages/essentials/post-processing-stack-83912
Thanks @NoDumbQuestion. I tried double enter and double space+enter as per the markdown instructions. Neither worked. I have fixed it using html markers ins$$anonymous$$d.
Can you expand on "it sound dumb" (especially since your name implies there are no dumb questions!)? It would be useful to know what you think the problem with my approach is to that I can learn something about the underlying technology. Why is post-processing a better solution?
Press Ctrl + R for Line Break.
Sorry I didn't notice you are making 2D games. So Post processing is out of question.
The problem here could be:
Custom $$anonymous$$aterial + Shader (if you use unity standard shader for sprite. Set it to opaque and set alpha color of picture down), it didn't support transparent. Due to lack of alpha channel or missing property for cutout alpha. If you know how to post shader code here, then I maybe can help somewhat.
Simply your texture(image) for haze do not have alpha channel.
Ok, I don't know how to post the shader code. I'm just using a standard one (sprite/default) and from what I've read online I can't get the code to that from within Unity. Do you know how I get that? I can download a version from the asset store. I assume it's the same thing... is that right?
$$anonymous$$eanwhile, I have set my Haze plane up to have the same set up as the $$anonymous$$ountains and added a script to set the colour of the attached $$anonymous$$esh Renderer including a transparency. This works in that it makes the Haze layer transparent (if I make it red I can set it from solid red through to invisible and all points in between), however the $$anonymous$$ountains and Stars are still visible behind the Haze layer even if it is set to 100% opaque. So I think I am having the problems referred to in the link I put in my original post ("how to fix transparent rendering problems") rather than being unable to set up a semi-transparent layer.
Answer by tedbox39 · Aug 13, 2018 at 07:37 PM
Workaround suggested by @NoDumbQuestion : "... you can do some hack. Like using Unity UI or sprite instead of plane for haze. Since they come with transparent support by default. UI would just be a World canvas with an image of haze texture."
Your answer
Follow this Question
Related Questions
Is it Possible to Layer Sprites More Accurately 0 Answers
Problems when transparency axis meets multiple tiles in 2D 0 Answers
How can I layer images and mesh? 0 Answers
2D: Erase a part of top layer to see the background 0 Answers
Layer Collision 0 Answers