Iris ignores passed-in vertex normals, messing up smooth shading
haubna opened this issue ยท 5 comments
What happened?
BufferBuilder doesn't allow smooth shading or triangles with Iris (shaders enabled).
Screenshots
No response
Relevant log output
No response
Minecraft Version
Minecraft 1.18.2
Iris Version
iris-mc1.18.2-1.2.4-build.38.jar
Sodium Version
sodium-fabric-mc1.18.2-0.4.1+build.15.jar
Operating System
Windows 10 64-bit
What is your GPU?
RTX 2080 Ti
Java Version
Java 17
Additional context
The function iris$beforeNext currently just drops the normals supplied to it which makes it impossible to have smooth shaded surfaces. It also only supports quads right now which makes it impractible for triangle meshes (used by the physics mod).
https://github.com/IrisShaders/Iris/blob/trunk/src/main/java/net/coderbot/iris/mixin/vertices/MixinBufferBuilder.java
As a small side note: smooth shading was working in Iris 1.2.2. I couldn't really figure out why that was the case though.
I am not sure about the exact reason the passed normals are not used, but I suspect that it is due to block rendering using the light face normal instead of the actual normal. If this is the only use for this normal calculation, the issue can be fixed by either modifying quad baking and block rendering to use the correct pre-baked normal vectors or only calculating normals if the existing normals consist only of -1, 0, or 1.
Also, the drawMode should be checked for the number of vertices so the assumption about quads can be removed.
It is true that the wrong vertex normals on block models is one factor. But another issue is that this is a more complex problem than having Iris just accept the vertex normals as-is. For shaders using parallax effects, the normal vector, tangent vector, and binormal vector should all be orthogonal, or close-to-orthogonal. Here's a post detailing the issue:
https://community.khronos.org/t/tangent-space-with-smoothed-normals/39441/5
From what I can see, the tangent, normal, and binormal vectors must all be smoothed once they are derived from the geometry, rather than leaving the tangent and binormal vectors unsmoothed and only smoothing the normals.
Of course, having other mods supply tangent vectors to Iris is currently very hard without having them reach into Iris internals. Which of course isn't very nice.
Note for clarification: While shader packs require a tangent, normal, and binormal to do parallax effects, since the binormal must be orthogonal to the other two vectors, it can be computed from them as long as there is a boolean "orientation" to figure out whether it needs to be flipped after taking the cross product of the tangent and normal vectors.