I need to take a models normal into world space to compare it to a position to determine how it should be rendered. I assume Unity has a built-in variable to do this or do I need to upload something myself to do this?
Also is there any way in Unity to do larger than float2 texcoords? Only thing I can think of is pass them through the tangent vector or are the appdata type structs the only options? Creating a shader that does deformable splines completely on the gpu and it works fine but issue is I need 1 more float then is offered by the largest appdata structure if I want lighting and texturing unless I want to compute the normals on the gpu each frame which is pretty wasteful. Gpu’s enlarge all structs into 16 byte alignments so there is excess padding / data spaces that exist I simply can’t find a way to use : (
Do you mean rotating normalmap’s normals or object’s normals?
If you simply want to rotate the object’s normals from object space to world space then it’s as simple as this (in your vertex program):
This is because object to world matrices containing scaling mess up the normals:
Notice that the normal in the triangle of the right is no longer perpendicular to it’s surface.
There’s a really nice explanation of this in “Introduction to 3D Game Programming with DirectX 9.0c a shader approach” by Frank D. Luna, pages 246 - 247. If you read it, you’ll notice that the correct matrix is the inverse transpose of the _Object2World matrix, that’s why the multiplication here: