Sage-of-Mirrors / J3DUltra

A library for rendering Nintendo's BMD and BDL model formats using OpenGL.
MIT License
7 stars 5 forks source link

Custom model water + BTK animation not rendering properly #7

Closed LagoLunatic closed 1 month ago

LagoLunatic commented 1 month ago

Custom model made by BSZ with SuperBMD, and BTK animation made by btk-conv: model.zip

It renders like this, and isn't being animated by the BTK (neither the waterfall nor the pond): image

It works ingame, it also works in noclip, where renders like this, and is animated by the BTK: image

Tested on latest main commit, with the only change being the bugfix in #6

Sage-of-Mirrors commented 1 month ago

I'll take a look at this in RenderDoc in a bit. Seems J3DUltra still has some bugs to sort out.

Sage-of-Mirrors commented 1 month ago

It appears to render correctly in my viewer program, Jekyll: image

Jekyll is using this sort algorithm: https://github.com/Sage-of-Mirrors/Jekyll/blob/main/src/application/AJ3DContext.cpp#L34. What does GCFT use?

LagoLunatic commented 1 month ago

PyJ3DUltra seems to use this simple sort function that doesn't distinguish between opaque and transparent materials: https://github.com/LagoLunatic/PyJ3DUltra/blob/733abcd52adb72ef91d1fd1446f9fc32107fbde0/src/main.cpp#L38-L43

I copied your SortFuncTest into PyJ3DUltra, and it seems to fix the water not being blue issue.

However, there are two issues. First, loading the BTK still doesn't seem to animate the water, same as before.

Second, almost any transformation to the camera (rotating, zooming, translating) seems to mess up the rendering and make most of the model transparent, which didn't happen with the original sort function. Here's an example, the first image is the default camera position, and the second is after rotating the camera by about 5 degrees or so: image image

Do either of these issues happen in Jekyll?

Sage-of-Mirrors commented 1 month ago

Hmm... you're right that BTK seems broken. I'll look into that.

The other issue doesn't happen. Here's the build of Jekyll I used: jekyll.zip

You can just drag-and-drop the model file onto the viewport.

Sage-of-Mirrors commented 1 month ago

Looks like the materials for the water don't use a tex matrix transform to modify the UVs: image

LagoLunatic commented 1 month ago

noclip's code has this comment in it: https://github.com/magcius/noclip.website/blob/3832c0c84d3c54d1492f6ce0a2834480fd04377c/src/Common/JSYSTEM/J3D/J3DLoader.ts#L1157-L1163

Sage-of-Mirrors commented 1 month ago

Ah. I'll fix that then. Thank you for bringing it to my attention!

Sage-of-Mirrors commented 1 month ago

Try https://github.com/Sage-of-Mirrors/J3DUltra/commit/629e7a09f204231f069d2ee72259674ce333a52a and let me know if it's fixed!

LagoLunatic commented 1 month ago

Yep, animates perfectly now!

I'm still confused about the sort function breaking, so I made a PyJ3DUltra issue for it here: https://github.com/Astral-C/PyJ3DUltra/issues/4