Closed Shfty closed 4 years ago
Following the latest batch of geometry fixes, the generated tangents are causing the deep parallax setting to crash the editor again. Upgrading this to a bug.
The crash may be related to invalid tangents on faces with a normal that aligns with -Y, as those are displaying incorrectly with non-parallax depth mapping at present.
The latest commit fixes tangents for standard-format UVs, but Valve-format ones still need looking at.
Since tangents are represented as Plane(u_axis, v_axis_sign) Valve-format already has the U axis ready to go, but the V axis' sign needs to be calculated somehow. Cross prodct of normal and U axis, then dot with provided V axis and take its sign?
Valve tangents are fixed insofar as they can be at generation time.
As Godot omits the binormal and automatically calculates it from the cross product of normal and tangent combined with a 1.0 / -1.0 binormal flip value, all binormals are guaranteed to be 90 degrees from their respective tangent.
This works fine for everything except skewed textures, which have non-transverse tangents and binormals. This causes some unexpected behaviour with shader techniques that use tangents, such as depth mapping (odd rotation when viewed up close, incorrect parallax axes), but are unavoidable without mandating a vertex shader that injects a correct binormal (valve format V axis) into its corresponding fragment shader.
Implementation is left as an exercise for the user, as making this general-purpose would introduce too much mandatory structure.
The autogenerated tangents from SurfaceTool are broken for all Qodot faces, and cause the deep parallax depth mapping functionality of the SpatialMaterial to crash the engine, and in some cases the GPU driver.
Adding custom tangents during the SurfaceTool building process makes it work, though I don't know if my algorithm is valid.
I'm getting some extreme texture warping from certain angles, but enabling deep parallax makes that stop so I'm unsure if it's simply a known aspect of non-parallax depth mapping on heavily-zoomed textures.
Probably worth reporting the hard crash to the Godot repo too, time allowing.