Open all-iver opened 4 years ago
thank @all-iver
the solution looks like that:
open your shapes.shader file and insert the lines flagged with //Inserted
struct appdata_t {
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID // Inserted
};
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 modelPos : TEXCOORD1;
fixed4 color : COLOR;
UNITY_VERTEX_OUTPUT_STEREO // Inserted
};
v2f vert(appdata_t v) {
v2f o;
UNITY_SETUP_INSTANCE_ID(v); // Inserted
UNITY_INITIALIZE_OUTPUT(v2f, o); // Inserted
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); // Inserted
o.pos = UnityObjectToClipPos(v.vertex);
// translate input uv coords (which are from 0 - 1 on either dimension) to something more
// useful (-0.5 to 0.5).
o.uv = v.texcoord.xy - 0.5;
o.modelPos = v.vertex;
// hijack modelPos.z to be distance from camera plane since it
// isn't being used for anything else. used for pixel size.
o.modelPos.z = -UnityObjectToViewPos(v.vertex).z;
// for Unity versions < 5.4.0f3
// o.modelPos.z = -mul(UNITY_MATRIX_MV, v.vertex).z;
o.color = v.color;
return o;
}
But according to a user it can be made to work easily by following the instructions on this page: https://docs.unity3d.com/Manual/SinglePassInstancing.html