Is this a script somewhere forcing only 1 material?
The materials and submeshes arrays at the MeshRenderer
component are populated every frame by the SkeletonRenderer
. This is necessary to mirror the currently active attachments. E.g. when in the first frame of the current animation all attachments come from a single atlas page texture, everything can be rendered as a single submesh with a single material. When another frame suddenly has attachments active from two atlas pages, it suddenly requires e.g. three submeshes (atlasA
, atlasB
, atlasA
) with the respective materials shown in the array (materialA
, materialB
, materialA
).
rxmarcus ha scritto
Do you think this idea has potential? Is it possible to add outlines by creating a "Renderer Feature" in URP in some fashion? Any other ideas?
The general idea is good, unfortunately Unity's MeshRenderer
design is flawed in this regard:
From https://docs.unity3d.com/Manual/class-MeshRenderer.html:
If a Mesh contains more Materials than sub-Meshes, Unity renders the last sub-Mesh with each of the remaining Materials, one on top of the next. This allows you to set up multi-pass rendering
on that sub-Mesh.
It is only the last submesh that is repeatedly drawn (instead of iterating over the whole array multiple times via [index % count]
). :rolleyes: Unfortunately, your solution would then only work when a single atlas page texture is used.
Since Unity also still does not allow multiple MeshRenderer
components at the same GameObject, the best scalable workaround that comes to my mind is to create a second GameObject as child fo the skeleton GameObject with it's own MeshRenderer
(and MeshFilter
). This MeshFilter
would then have the same mesh assigned, but different materials.
I just created a component to render the same mesh with replacement materials, please find the zip package attached below.
.. as a solid color that is slightly larger than the 1st, creating an outline.
As outline-only shader, I would recommend to not scale the mesh but use the original outline shader code and remove the other render passes from the shader. I will later create a clean official release of the component and outline-only shader.