Thanks for sharing your findings @jawny and @mikedssx!
mikedssx đã viết
Hey jawny by the way, when you use normal maps on your spine atlases what happens when the character rotates there arms does that change the position of the lighting or is it entirely based on the sheet and because it never rotates or moves the normal map doesn't either?
While I cannot speak for Construct 3 shaders specifically, there is one general thing to understand with normalmaps: the red channel does not correspond to "right", it rather corresponds to "positive U" direction (within the atlas texture that's right). Similar with the green (positive V direction, within the texture that's up) and blue (direction orthogonal to surface) channels respectively. Now this is where tangents and bitangents (or binormals) come into play: positive U direction is described by the tangent, positive V direction by the bitangent (binormal) and obviously, orthogonal-to-surface direction by the vertex-normal (the input normal, before the normalmap is applied). These three vectors are deformed and rotated along with your animation, so when an arm is rotated, its tangent, binormal and normal vectors are rotated accordingly. This ensures that a normal map is acting as expected in combination with transformations like rotation.
So to answer your question: the only problem that needs to be prevented is that a normalmap is generated for each attachment, and then the attachment is rotated 90, 180 or 270 degrees by the texture packer, which does not know that red must point in positive U direction. So rotation needs to be disabled in the texture packer in this case. When generating a normal map from the packed output atlas texture (after attachments have been rotated during packing) instead of single input attachments, rotation can be enabled in the preceding packing step. The drawback of generating the normalmap from the packed atlas texture is that when re-packing attachments slightly differently, the normalmap also needs to be re-created accordingly.
A side note: There are special implementation details where bitangents (binormals) are generated from the normal and tangent to simply save vertex data and computation time, or even the tangents can be calculated in the fragment shader.