- Home /
Eliminate automatic vertex * mvp from surface shader
Hi,
I have a custom vertex shader for the surface shader that affects vertex position based on projection and model view matrices. It works well if I don't use surface shaders and write whole vertex/fragment shaders with all passes etc. However since I prefer to use surface shaders for this purpose I moved my shader to surface version. The problem is caused by the fact that after compilation shader looks like this:
void vert( inout appdata_full v ) {
// code that modifies v.vertex
}
v2f_surf vert_surf( in appdata_full v ) {
v2f_surf o;
vert( v);
o.pos = (glstate_matrix_mvp * v.vertex); // <-- this is causing problems
o.pack0.xy = ((v.texcoord.xy * _MainTex_ST.xy) + _MainTex_ST.zw);
highp vec3 worldN = (mat3( _Object2World) * (v.normal * unity_Scale.w));
o.normal = worldN;
highp vec3 shlight = ShadeSH9( vec4( worldN, 1.0));
o.vlight = shlight;
return o;
}
Now I know that I can multiply everything by inversed matrices in correct order to remove this effect but let's face it - this is not very performance friendly :).
And the actual question is: is it possible to somehow tell unity not to add this single line of code? Pragma or something? I was not able to find anything like this in documentation so far.
Thanks