Billboards with surface shaders

Hellow. I’m trying to write a billboard shader using #pragma vertex with surface shader. But as I understand you don’t have full control on vertex when using surface shader, and your modified vertex will be multiplied on MVP matrix anyway? With that in mind currently I’m trying smth like:

#pragma surface surf Lambert alphatest:_Cutoff addshadow vertex:vert_func

		void vert_func(inout appdata_full v_input, out Input v_output) 
		{
			float3 view_pos = mul (UNITY_MATRIX_MV, v_input.vertex); // vertex to view space
			float3 view_dir = normalize(view_pos);
			float3 right_dir = cross(view_dir, float3(0.0, 1.0, 0.0));                    
			
                        // rotate our vertex using texcoords so it always face the camera
			float3 result_pos = view_pos + right_dir * v_input.texcoord.x + float3(0.0, 1.0, 0.0) * v_input.texcoord.y;
				
                        // transform it back to model space
			v_input.vertex.xyz = mul (UNITY_MATRIX_T_MV, float4(result_pos, 1.0)); 
		}

but it looks wrong. Is it possible to get such functionality with surface shaders or do I have to use Cg shaders?

You can always do the billboard rotation with a script. And do the color bit with the shader. Although you can do vertex rotation in surface shader as well.

By “billboard shader” I mean something like particle system where can be thousands of particles, so I can not do rotation with a script.

I’m trying to convert it back to local space from the view but I doesn’t work. Isn’t this supose to convert it back?

mult(UNITY_MATRIX_T_MV, v)

What am I missing?

Try mul(_World2Object, v)?

No, world space is not the same as camera view space.

Ahh, i misread your question : )