MizunagiKB / gd_cubism

Unofficial Live2D Player for Godot Engine
https://mizunagikb.github.io/gd_cubism/
Other
138 stars 17 forks source link

When I try to use Mask Viewport, it stops rendering the eyes (and other facial features such as blush), and I am not sure why. #111

Open MizunagiKB opened 2 weeks ago

MizunagiKB commented 2 weeks ago

When I try to use Mask Viewport, it stops rendering the eyes (and other facial features such as blush), and I am not sure why.

UPD: "Adjust Scale" option is the culprit, if you have the scale less than 1, the mask viewport will be shifted towards (0;0) in scale. Mask Viewport does not follow the Scale properly.

image

_Originally posted by @cjmaxik in https://github.com/MizunagiKB/gd_cubism/issues/102#issuecomment-2301594475_

MizunagiKB commented 2 weeks ago

@cjmaxik

We have addressed an issue where the mask was not being referenced correctly when the canvas and mask sizes differed, and the default values for Scale or Adjust were changed.

The causes were as follows:

To address this issue, we made the following fixes:

This fix has been implemented in branch 0.7. https://github.com/MizunagiKB/gd_cubism/tree/0.7

Note: Branch 0.7 is still under development and has not been released yet. Additionally, it is intended for Godot 4.3 and above, so please apply with caution.

cjmaxik commented 2 weeks ago

Thank you for the fix, I will try to test it out in the following hours.

cjmaxik commented 2 weeks ago

Unfortunately, 0.7 not only failed to resolve the issue in question, but it also changed how "Adjust Scale" and "Adjust Position" works - in 0.7, "Position" values are multiplied by "Scale", where in 0.6 there was no correlation whatsoever.

I've included the examples with 0.6 and 0.7 versions and our Live2D model. If you set the Position and Scale values the same, it won't produce the same result.

Both extenstions were built against https://github.com/godotengine/godot-cpp/tree/godot-4.3-stable testproject-0.6.zip testproject-0.7.zip

cjmaxik commented 2 weeks ago

I've adjusted the projects to have a predictable set of values to test against:

testproject-0.6.zip testproject-0.7.zip

MizunagiKB commented 2 weeks ago

Thank you for testing the functionality across multiple versions.

There were insufficient changes made regarding the Adjust Position feature.

Due to the difficulty in aligning positions when the sizes of the Canvas and Mask differ, we have altered the calculation method in version 0.7.

We have identified that the issue arises from the combined calculations of Live2D’s position correction, Auto Scale, and Adjust Scale. However, due to my technical limitations, I am currently using a method that ensures the Canvas and Mask are correct but lacks compatibility.

While maintaining compatibility is preferable, I will review this further. If no suitable method is found, it may be necessary to include prominent notes or warnings in the documentation.

MizunagiKB commented 1 week ago

The cause of the calculation discrepancy lies in the InternalCubismRenderer2D::make_ArrayMesh function within internal_cubism_renderer_2d.cpp. To maintain compatibility with version 0.6, it is understood that the adjust_pos should be processed in a way that it is not affected by the scale.

Ultimately, this needs to be implemented in C++ and GDShader. However, I first translated the calculations into Python for easier verification and organization.

The calculations appear to yield the desired results in Python. Based on these results, I will update the relevant sections of GDCubism. During this process, I also discovered that it does not function correctly when auto_scale is set to False, which I will address as well.

https://gist.github.com/MizunagiKB/ffeae04267e59c5547f16be173b74c89

MizunagiKB commented 1 week ago

@cjmaxik

I have organized the mathematical expressions in internal_cubism_renderer_2d.cpp and modified the code so that the specified parameter results in the same outcome as 0.6.

Although it is a development branch, we merged it into 0.7 with bugs remaining last time. Therefore, this time, we made changes in the fix_vertex_calc branch and created the following pull request: https://github.com/MizunagiKB/gd_cubism/pull/112

fig_01

fig_02

cjmaxik commented 1 week ago

Other than a feathered outline on lower canvas sizes, everything else seems fine and on par with 0.6 version, while having an advantage of lowering GPU usage. Well done!

Although the feathered outline won't let me use it for our production, the fact that one can now choose between quality and performance is a really handy improvement.

Canvas size 128x128, Viewport size 2200x2200, Scale 0.88 image

image

MizunagiKB commented 1 week ago

Thank you for your confirmation.

We consider Live2D to be a technology that enables animation while maintaining the quality of the artwork. However, as you mentioned, it is more convenient for users to be able to choose between quality and performance as a module. By default, it is set to prioritize quality (with the mask size being the same as the rendering size), so the displayed image should not be compromised.

We will merge this into version 0.7.

cjmaxik commented 1 week ago

After some consideration, I have to issue a correction.

My previous example showed the mask viewport size of 128x128, which is not a good example. I believe that the mask size must be a fraction of the model viewport, and not the arbitrary value. Our model uses the viewport size of 2200x2200, so to benefit from this feature and to not lose the quality too much, we must use something like 1100x1100 (half) or 550x550 (quarter). This way, the mask is properly sized against the viewport, and yields way better results in both performance and quality. This is my oversight, and I apologize for misrepresenting the result.

Here is the 1100x1100 viewport (half of the model's viewport), it still yields 200 MB of video memory advantage while having no immediately visible quality loss. image

image