alfredbaudisch / GodotShaderCollection

A collection of 3D Shaders for Godot 4
45 stars 3 forks source link

Fix the Godot 4 bug where object space is incorrectly calculated #2

Closed nekotogd closed 1 year ago

nekotogd commented 1 year ago

Also did the matrix multiplication in vertex function so that the result is calculated per-vertex and then interpolated across the fragments.

Final result:

https://user-images.githubusercontent.com/81257780/197825079-1acbcf8f-ce59-40dd-9adf-8d7a7424f4de.mp4

nekotogd commented 1 year ago

Fixes #1

alfredbaudisch commented 1 year ago

That was fast, thanks @nekotogd !

Unfortunately with your solution when rotating the object, the dissolve is not being preserved like it is with the Godot 3 shader. You can see it's incorrectly acting like a clipping plane:

https://user-images.githubusercontent.com/248383/197826575-b0aa5836-60e0-48fe-a4e4-db76031b62c6.mp4

But when moving the object the shader is working as expected.

alfredbaudisch commented 1 year ago

As a comparison, rotate in Godot 3 - you can see half of the head always stays dissolved, the offset is always respected:

https://user-images.githubusercontent.com/248383/197827616-3ccfff82-3673-41e8-8988-40ea625e81ce.mp4

nekotogd commented 1 year ago

Rookie mistake! My bad!

I realized you're just looking for the object-space position of the VERTEX in the fragment shader. Luckily, the vertex() function uses VERTEX in object-space anyways.

So, I just dragged that from the vertex() function to the fragment() function using a varying vec3 vertexOS

smooth is just to ensure its interpolated across fragments. I believe this is default behavior but I wasn't sure so I added the smooth just in case.

alfredbaudisch commented 1 year ago

Oh I can't believe it doesn't even need all the MATRIX transformations. Thanks a lot! Works beautifully!

alfredbaudisch commented 1 year ago

Also thanks for this @nekotogd:

smooth is just to ensure its interpolated across fragments. I believe this is default behavior but I wasn't sure so I added the smooth just in case.

I didn't know this.

paddy-exe commented 1 year ago

Leave it to Nekoto to solve issues like this in a matter of minutes xD