-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rmodels] Potential problem with transforming normals during animations #4581
Comments
Sorry for the title, I'm tired 😨 |
@Bigfoot71 Interesting... sincerely, I don't know... but it seems to work ok with the transform... could you test with some other models to confirm the issue? |
I have also faced similar issue with Mixamo y bot it was working before but then i updated to raylib5 or 5.5(can't recall) and messed up normals. I thought it was issue with model. it looks like normals are overrotated or bone rotation also brightens the part. |
Unfortunately, I tried just under ten models from Sketchfab, all in GLB format. Most of the models either "disappear" during animation or are animated in a completely distorted way. Regarding the deformation issue, I noticed there's already a related issue here: #4569. That said, I did manage to get one model working without visible differences between the two versions. However, the range of movement relative to the idle animation isn't very significant, which I think might have an impact. For the robot, the limbs are noticeably misaligned between the idle and the animation used in my screenshots. As for the solution I proposed, while it is mathematically correct for transforming normals, it does raise an efficiency concern. Performing a matrix inversion per vertex and per bone during each pose update (as I suggested) is quite expensive. This is why I was wondering if this behavior might be intentional and handled differently, but I couldn't find any information about it. I'll try again when I have time with formats other than GLB. I'll use Blender if necessary to attempt to make the models work in raylib. Example of the only model I managed to get working: Edit: GitHub doesn't seem to display videos for me, so I'm adding the links here just in case |
I just tested with a new model, and there is indeed an issue with the transformation of normals in the original function. Moreover, there seem to be additional animation problems... Here it is with the current function: simplescreenrecorder-2024-12-14_17.43.19.mp4Here it is with my quick fix: simplescreenrecorder-2024-12-14_17.43.56.mp4Here is the original model: |
Issue description
There seems to be a potential error in the normal transformation process within the
UpdateModelAnimation()
function. I noticed that the shading looked strange when using my lighting shader during an animation, which led me to suspect the normals were being handled incorrectly. After some investigation, I checked the code responsible for transforming the normals in rmodels.c:2358:I observed that the normals are being transformed like this:
But shouldn’t we be transforming the normals using only the rotational part of the matrix, by obtaining the inverse transpose?
Or maybe I’m missing something else to properly solve this issue, which could explain why the function was written this way.
Here’s an example with the current function (look at the robot's hands):
And here’s an example with the inverse-transpose transformation applied:
The text was updated successfully, but these errors were encountered: