Sorry for the late reply.
Jamez0r wroteThink this part should say "Solve Tangents"?
Thanks very much for the hint, just fixed it!
Jamez0r wroteI've been curious as to what is going on behind the scenes with the "Add Normals" and "Solve Tangents" buttons - is it just providing normals/tangents based on the sprite's mesh being "flat"? Like, per vertex?
The data is provided (generated and uploaded to the GPU) per vertex, yes. this is additional data per vertex adding to the already existing data like position, uv, vertex color.
The normals are all simply facing direction (0, 0, -1)
, so generating them is not much effort.
While the tangents are also "flat" (tangent.z == 0
), generating them takes more processing time as it needs to analyse where the +U and +V coordinate axes are pointing in object space. This is needed to interpret the normal map, since the +red channel in the normal map does not point right, it points in +U direction, similar for green channel and +V direction, and +blue channel for +normal direction. The tangents will change when e.g. an animation rotates or even deforms (stretches) an attachment.
Jamez0r wroteWhen I'm using the URP/2D/Spine/Sprite shader with normal-maps, it doesn't seem to require either of those options being selected.
Hm, I don't think that your normal map is applied correctly then. It needs both the normal, which can come from Add normals
or from material parameter Fixed normal
. The tangents need to be provided though, otherwise undefined vertex data might have been used as tangents?
Did you test what changes when providing tangents and normals? I would be surprised if it applied the normal map correctly before.
Jamez0r wrote
1) Write the entire shader in Shader Graph, and use Unity's Sprite Lit Master Node like Squallio did in that other thread. Would there be a downside to this? (namely, if there is overhead in having to select the Add Normals / Solve Tangents that I could avoid). I'd like to stay as CPU efficient as possible - we have a ton of plant/environment assets that are spine animations that have normal maps.
There is no basic downside in using Shader Graph, as it's just a code generator. You should be able to add (or create custom) shader nodes yourself in case you see some functionality missing, like providing a fixed normal as input instead of using the standard vertex normal. You still have to provide tangents when using normalmaps. Well, actually you could deduce tangents in the fragment shader using the derivative functions ddx()
and ddy()
on both position and texcoords. If you cannot find any reference online, I can dig out some shader code and post it here for reference if you like.
Anyway, please always perform some measurements with Solve Tangents
enabled vs disabled, otherwise your efforts might be on the wrong topic. If you mind to share, it would be nice to see your real-world values of how much enabling Solve Tangents
really costs.
Jamez0r wrote2) I read that it might be possible to take the shader code generated from Shader Graph, and combine it into the Spine shader? I haven't looked too much into this yet
Yes, basically you can of course always combine generated code with your existing hand-written one. You just have to understand what each function call does and combine and adjust it accordingly. Finding all variable and method definitions of included files may be the more labour-intensive part of it.