rust3ds / citro3d-rs

Rust bindings and safe wrappers for citro3d
https://rust3ds.github.io/citro3d-rs
14 stars 11 forks source link

Example Porting issue: Normal Mapping #11

Open hYdos opened 1 year ago

hYdos commented 1 year ago

I'm having trouble porting the Normal Mapping example from C to Rust to test the new bindings. The only difference is in image and shader loading and I can't really put my finger on whats wrong. For some reason the 3ds freezes at C3D_FrameBegin

https://gist.github.com/hYdos/c260e0afe72200a4872e7f9000ddae5d - main.rs https://gist.github.com/hYdos/8f4c4bea934714be008d7157b1512c79 - util.rs

Wondering if you guys would have more knowledge to whats going on

Assets should not be the issue as i use the command from the bitmap example in rust3ds/citru-rs to generate textures and use picasso to generate the shader bytes

hYdos commented 1 year ago

image Stacktrace related to the issue

hYdos commented 1 year ago

With some more debugging, Looks like an issue with the gpu cmd buffer but im not sure whats messing with it or what is missing still

AzureMarker commented 1 year ago

I don't know much about how the citro3D stuff works, but it would be helpful to have a link to the C code you're trying to port.

hYdos commented 1 year ago

This example is based off of https://github.com/devkitPro/3ds-examples/tree/master/graphics/gpu/normal_mapping Also Update: I've gotten the issue to be a lot less severe now. I can see a clear colour now but still get issues with rendering a cube

New Sources (Not the best) main.rs: https://gist.github.com/hYdos/20943d62a19dfbb878f747ddc3a57704 new_utils.rs: https://gist.github.com/hYdos/2d6b85539e0602bc0479098ef26f5fb0

ian-h-chamberlain commented 1 year ago

I noticed your wait function which might be starving the CPU and preventing the rendering from working as expected?

https://gist.github.com/hYdos/2d6b85539e0602bc0479098ef26f5fb0#file-new_utils-rs-L54-L63

Generally, I think it's recommended to use while apt.main_loop() to allow events to come in during the main loop, but there might be something else going on here too.

I also noticed an if false branch here https://gist.github.com/hYdos/20943d62a19dfbb878f747ddc3a57704#file-main-rs-L410 not sure if that's meant to be used at all? The C example seems to have some other lighting setup related to the shader stages which might also be needed to render the cube?

It looks like you skipped the tangent part of the vertex that was used in the C example, but idk if that's relevant at all, but might be needed if the shader expects the tangent as input.

Otherwise, I don't see anything obvious that jumps out, but I am by no means a c3d expert, still learning how to use it myself, but maybe one of these things puts you on the right track?

hYdos commented 1 year ago

I've debugged the last second thing you mentioned and found out it works without tangents on the C example but ill take a look into while apt.main_loop() and the lighting thing thanks