Hi!
I’m making a vertex shader for transform the vertex coordinates. For some reason when I use cubes or plane gameobjects and I have several in the viewport with the same mesh and shader/material geometry vertices seems to arrive in v.vertex with the coordinates relative to the scene (0, 0, 0) instead of the gameobject center (which is the behaviour that I expected). When only one mesh is visible, then the coordinates comes relative to the gameobject center, or when different gameobjects have different shaders, or when mesh is more complex (like an sphere). It’s like Unity is grouping the geometry underneath somehow…
Is this behaviour configurable? There is something I’m doing wrong?
I attach the shader I used to finally realize that something wasn’t going like I expected:
Shader "Custom/BasicVertex" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_MainTex ("Texture", 2D) = "white" { }
_Mx ("Mx", Float) = 1
_My ("My", Float) = 1
_Mz ("Mz", Float) = 1
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
sampler2D _MainTex;
float _Mx, _My, _Mz;
struct v2f {
float4 pos: SV_POSITION;
float2 uv: TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert(appdata_base v) {
v2f o;
float4 trvertex = float4(v.vertex.x * _Mx, v.vertex.y * _My, v.vertex.z * _Mz, v.vertex.w);
o.pos = mul(UNITY_MATRIX_MVP, trvertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
half4 frag(v2f i): COLOR {
half4 texcol = tex2D(_MainTex, i.uv);
return texcol * _Color;
}
ENDCG
}
}
Fallback "VertexLit"
}