I created a shader via a node-based shader tool called Shadero Sprite, and I'm trying to debug an issue with it. Since the code was generated by the node-based tool, I'm not entirely sure what the purpose of every line in the shader is, which makes this issue difficult to debug.
The issue is that, although the shader itself works fine, having an object with it in my Unity scene causes certain other objects in my scene to not render at all; they become invisible.
It seems to be something related to this call to UnityObjectToClipPos()
below:
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
...because, if I replace...
o.vertex = UnityObjectToClipPos(v.vertex);
...with...
o.vertex = v.vertex;
then the other shaders/objects render fine. However, this of course means that THIS shader doesn't look right.
The only other clue I've been able to deduce is that the other objects (the ones that go invisible) are Unity UI elements that all have custom shaders. One shader is using a call to UnityObjectToClipPos(). The other doesn't seem to (although it has many #includes
, so perhaps a call to it does exist, buried in one of those #includes
).
Why is this function call causing other objects to go invisible, and what can I replace it with to fix it?
EDIT: Here is the scene configuration for greater context:
CodePudding user response:
In order to display the model in 3D space, we usually multiply all the vertices of this model by the MVP - Model, View and Projection matrices.
The UnityObjectToClipPos()
function just transforms a point from object space to the camera’s clip space in homogeneous coordinates. This is the equivalent of mul(UNITY_MATRIX_MVP, float4(pos, 1.0))
, and should be used in its place.
Therefore, I don't think that the UnityObjectToClipPos()
function is the cause of your problem.
You should describe your issue in more detail and we will try to help you.
CodePudding user response:
The issue ended up being with the shader I was using for my text.
The text uses a Unity asset called SuperTextMesh, which offers multiple shaders for text. I was using the "Dropshadow and outline unlit" shader, when I needed to use the "Dropshadow and outline" shader instead. The "unlit" one caused issues.