alfredbaudisch / GodotShaderCollection

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

Calculate Object Space in Godot 4, and dissolve it in Object Space, preserving the dissolve even if the object moves in world space #1

Closed alfredbaudisch closed 1 year ago

alfredbaudisch commented 1 year ago

The dissolve shader is currently broken in Godot 4 - I couldn't find a way to dissolve in object space, it's currently in view space (currently if the object or camera moves, the dissolve offset is also incorrectly moving - the dissolve should be preserved - see samples below).

This is how object space is calculated with the Godot 3 shader:

vec3 position = (inverse(WORLD_MATRIX) * CAMERA_MATRIX * vec4(VERTEX, 1.0)).xyz;

I couldn't find how to port it to Godot 4. So far I have in the shader, which is broken:

vec3 position = (inverse(MODEL_MATRIX) * vec4(VERTEX, 1.0)).xyz;

Expected

Dissolves the object with respect to the Object Space, even if the object is transformed in world/global space (moved around and rotated), the dissolve position and offset is preserved.

Currently working in Godot 3 as per the video below, the important part is that the dissolve offset is kept even with the object moving around the world.

See sample project.

https://user-images.githubusercontent.com/248383/197817669-04a1cfea-c57f-4958-8ca1-c6cb0daa23fa.mp4

Current Broken Godot 4 Result

Sample Godot 4 project

The object or the camera is moved around and the dissolve also moves.

https://user-images.githubusercontent.com/248383/197817708-c6adfaa2-55cd-4570-9d2e-b9edd6942c3a.mp4