- Home /
Renderer using wrong rendering mode (Transparent instead of Opaque)
Hi! I'm working on a project using very basic 3D shapes and a point light:
No matter which shader I use for those objects (Standard shader with Opaque mode selected, Simply Lit shader with only lighting and one color property selectable), profiler tells me they're being rendered using the transparent rendering mode. This results in very bad performance on mobile devices, getting worse with every "step" the objects get bigger and cover more area behind them.
Am I missing something? I'm currently on Unity 5.1.5, tested on other versions as well with the same problem.
Thanks in advance, Maui
EDIT:
Okay I think I got one step further. As the game proceeds, the floor-meshes get assigned materials that are reused so that the color can change gradually from one floor element to the next. To get this working, I set up an array which gets filled with 30 materials at the beginning of runtime. They are then reused everytime a new floor element gets spawned at the end of the path.
I'm already trying to set the material's shaders to Opaque like this: (found inside the Unity docs)
materialArray[i].SetFloat("_Mode", 0);
materialArray[i].SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
materialArray[i].SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
materialArray[i].SetInt("_ZWrite", 1);
materialArray[i].DisableKeyword("_ALPHATEST_ON");
materialArray[i].DisableKeyword("_ALPHABLEND_ON");
materialArray[i].DisableKeyword("_ALPHAPREMULTIPLY_ON");
materialArray[i].renderQueue = -1;
But this doesn't seem to really set the shaders to opaque, they are still rendered as transparent.
Maybe someone has a suggestion to even improve the whole thing so that I don't need to create/use so many different materials and still have multiple colors for the floor elements at the same time.
Thx!
It's difficult to give an answer without knowing more about your setup, like: What's your camera setting's
Camera settings
Player settings
$$anonymous$$aterial settings
Object renderer component settings
Layers
What layers the objects are on
What layers the camera culling mask can see
more... But mostly I'm just guessing.
Answer by MauiMauo · Jun 15, 2016 at 06:15 AM
Okay so the problem was not using the correct renderQueue. Setting it to 2000 is putting it into the Geometry queue which fixed the problem and made the meshes render in opaque mode.
A longer explanation can be found here
For special uses in-between queues can be used. Internally each queue is represented by integer index; Background is 1000, Geometry is 2000, AlphaTest is 2450, Transparent is 3000 and Overlay is 4000.
Thank you tanoshimi!
Answer by tanoshimi · Jun 13, 2016 at 06:29 PM
Why are you assigning a renderqueue of -1? Should you not be using:
materialArray[i].renderQueue = RenderQueue.Geometry;
?
What do I need to import to use this line of code? RenderQueue.Geometry can't be found, "using UnityEngine.Rendering" doesn't help. I'm a noob regarding shaders etc. :/
Looks like this might be a 5.4 thing.
https://docs.unity3d.com/540/Documentation/ScriptReference/Rendering.RenderQueue.html
Don't see it in the 5.3 docs.
Ah okay. So what would I have to do to use that with 5.1.5? Project is in it's final stage and I can't update to another version of Unity now. EDIT: Looks like setting the renderQueue to 2000 is the way to go as described here. I'll test that!
From the docs, -1 means use whatever render queue is defined in the shader, otherwise it should be positive. I'm not sure what the other values might be that correspond with the queue specified in the shader.
@$$anonymous$$aui$$anonymous$$auo Ah, yes, it's a new feature, but it's basically just an enum in which "Geometry" corresponds to 2000, as you've noted. So that should work fine too.
@Dave-Carlile - yes, precisely, -1 means use the renderqueue defined in the shader. But the whole point is that the OP wants not to use the queue in the shader, but to override it!
Your answer
Follow this Question
Related Questions
How to change Render mode in URP at runtime? 1 Answer
how to remove texture show-through? 0 Answers
Rendering a plane is dropping 10 fps 0 Answers
Stencil buffer and transparency 0 Answers
Change color of material on a mesh on a mobile app 0 Answers