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.
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.
Originally posted by @cjmaxik in https://github.com/MizunagiKB/gd_cubism/issues/102#issuecomment-2301594475
@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:
- When the mask size was small and scaling was applied, the scale could become less than one pixel, rendering the mask ineffective.
- When the canvas and mask sizes differed, the values specified for Adjust also needed to change proportionally, but they were not being recalculated correctly.
To address this issue, we made the following fixes:
- We ensured that scaling does not reduce the precision of the mask.
- Corresponding adjustments were made to the shader calculations.
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.
Thank you for the fix, I will try to test it out in the following hours.
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
I've adjusted the projects to have a predictable set of values to test against:
- Viewport Size - 1000*1000
- Adjust Scale - 0.25
- Adjust Position - 0, 500
- Mask Viewport - 250, 250 (1/4 of the Viewport Size)
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.
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
@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
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
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.
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.
I'm still experiencing this issue in main(d0c03f6).
I'm using macOS, Godot Engine v4.4.dev4.mono.
One particular model of mine only shows the right eye and not the left; even if I don't use mask viewport at all with auto scale & scale disabled.
If I play around with the mask viewport, I can manage to get both eyes to not show; but I don't have any way to get both eyes to show.
Do you have any ideas? I can't provide models or screenshots in public due to copyright restrictions; but I'd be more than happy to help with some investigation.
@univeous
I mentioned the wrong person, so I am correcting it.
It seems that some Live2D models do not display correctly.
Currently, GDCubism renders the mask image and then uses it as a texture for drawing.
Possible issues on the GDCubism side include:
The drawing position and mask position are misaligned.
Since GDCubism 0.6.3, it has become possible to specify different sizes for the viewport used for drawing and the viewport used for masking. This change allows for a trade-off in output quality while reducing GPU memory consumption.
Although this may seem beneficial, it means that different calculation formulas are used for the drawing process and the masking process. As a result, if there is a bug in the calculation, the drawing and mask positions may be misaligned, leading to unexpected drawing results.
If this is the cause, it is very likely that the correct drawing will be achieved with a previous version. For example, GDCubism 0.6.0 uses the same calculation formula and the same viewport size for both the drawing process and the masking process, ensuring that the positions do not misalign.
If GDCubism 0.6.0 displays correctly, then there might be an issue with the calculation formula implemented in version 0.6.3.
If the left eye does not display correctly even with GDCubism 0.6.0, then there may be another issue elsewhere.
You may have already tried this, but we should first identify if the areas most likely to affect the rendering results are causing any issues.
0.6.0 seems to give me the same result (left eye doesn't show up) - although I'm not sure I'm actually using 0.6.0; I switched to the 0.6 branch and compiled the binaries, copied them to the corresponding location, but I can't confirm this in the editor. It might be nice if there was somewhere that displayed the version number of GDCubism.
@univeous
The original issue we were discussing has been resolved, but I did not close it. Therefore, I have created a new issue.
Both the issue described in this thread and the additional reported issue have been resolved, so I will close this issue.