- Home /
What subspace are SurfaceOutput vectors in?
I'm creating an anisotropic metal surface shader for my application. I needed tangent vectors in order to compute it correctly in my Lighting function.
Apparently no one ever needs tangents to compute lighting so they didn't bother to make it an easily accessible vector.
So I created a custom SurfaceOutput struct...
struct SurfaceOutputTangent
{
half3 Albedo;
half3 Normal;
half3 Emission;
half Specular;
half Gloss;
half Alpha;
half3 Tangent; //What space should this be in?
};
And I have to grab it from a custom vertex shader too...
void vert(inout appdata_full i, out Input o)
{
half3 tangent_input= normalize(i.tangent.xyz); //Transform to correct space here.
o.tangent_input = tangent_input; //Presumably model space at the moment.
}
So my question is what subspace should my tangent vector be in to be compatible with Normal, and lightDir and viewDir. World (This would be unfortunate), View, or some other space?
I tried looking around for this information but the documentation just glazes over the fact that subspace matters for lighting.
What space should I put my tangent in? Bonus points if you point me to the matrix name to get it there.
This is beyond me and deserves to be answered! Consider this bumped!
Just eyeballing it and trying different subspaces it seems to be world. But I'd love some confirmation.
So if I understand this, you want the tangent output from your vertex shader to be compatible with the normal and other vectors inside the surface shader?
Couldn't you just get the normal and tangent vectors into whatever space you want within the vert shader and then pass them along to be used later, rather than relying on whatever the surface shader is doing? Then you can just use the UNITY_$$anonymous$$ATRIX_* matrices to get it into whatever form you want. $$anonymous$$g. $$anonymous$$V or $$anonymous$$VP.
True I could explicitly put them in whatever space I felt like but I was trying to conform to Unity's innards. Which is cleaner and keeps my shader shorter. Also I suspect if I recalculate the normal in my preferred space I may create redundancy in the compiled shader depending on how comprehensive their surface shader compiler is.