AntonioND / nitro-engine

3D engine for the Nintendo DS
150 stars 10 forks source link

Textures above 128*128 are not rendered correctly #3

Closed JustMeDaFaq closed 2 years ago

JustMeDaFaq commented 2 years ago

Hi, got into NE quiete a bit. After spending some time on the engine itself i started 3D modelling. Theres some optimisation to be done for sure, but i quick tested my 3D Modell and Texture. It works as long as the texture is only 128x128 big. As soon i try to use an 256x256 Texture it looks pretty ugly and like UV coordinates not respected anymore?

Following package contains: -Screenshots of the issue -Compiled NDS files of that example -Texture Files i used in 128 -and the 3D modell itself

Texture_Size_Error.zip

Tested on Desmume, MelonDS and real Hardware (Nintendo DSI and DS Lite) :) 128x128 Texture Screenshot128

256x256 Texture Screenshot256

@AntonioND

AntonioND commented 2 years ago

That's weird... Can you try to convert the model from format 3DS to MD2 and using md2_2_bin instead of the other converter?

The texture you're using is huge (256x256, 16 bits per pixel!), but it should fit in exactly one VRAM bank, so that's not a problem. And the code of the engine doesn't do anything different for any texture size. All I can think of is that maybe the exporter isn't playing nice.

You could try to draw a 2D quad with the 128x128 texture and 256x256 texture, that should rule out problems with the 3D exporter.

Also, in the source, are you directly using the bin textures or are you loading the BMP files? It could happen that the BMP loader is broken.

Are you using the free camera example as it is? I mean, if I load your files, should I see the same problem without changing anything in the code?

JustMeDaFaq commented 2 years ago

That's weird... Can you try to convert the model from format 3DS to MD2 and using md2_2_bin instead of the other converter?

The texture you're using is huge (256x256, 16 bits per pixel!), but it should fit in exactly one VRAM bank, so that's not a problem. And the code of the engine doesn't do anything different for any texture size. All I can think of is that maybe the exporter isn't playing nice.

You could try to draw a 2D quad with the 128x128 texture and 256x256 texture, that should rule out problems with the 3D exporter.

Also, in the source, are you directly using the bin textures or are you loading the BMP files? It could happen that the BMP loader is broken.

Are you using the free camera example as it is? I mean, if I load your files, should I see the same problem without changing anything in the code?

Hi @AntonioND , i did md2 thingy that and got whats shown at the screenshot in the bottom.

Just to make sure: NE_MaterialTexLoad(Material, GL_RGB, 256, 256, TEXGEN_TEXCOORD, (u8 *) terrainTexture_bin); is correct?

Seems still to be messed up when using a 2D quad if im not wrong. (wouldnt count on it tho, im good in doing dumb things 🤓 ...)

Yes, im using bin textures, no BMP loader involved!

And yes, im just using the free_camera example. Changed the rotation since that was messed up, but other than that, you get the same result regarding the textures.

(md2 256x256) stillnot

AntonioND commented 2 years ago

Screenshot from 2022-01-20 22-07-44

This is weird, it says that the GPU has been told this texture is 128x128 pixels. Did you change the values in the source code when you switched files?

JustMeDaFaq commented 2 years ago

Could be i didnt in the applied examples. That is still happening tho: https://user-images.githubusercontent.com/6432949/150427423-c0f78077-c973-4867-b970-bf5ba37e5720.png thats with NE_MaterialTexLoad(Material, GL_RGB, 256, 256, TEXGEN_TEXCOORD, (u8 *) terrainTexture_bin);

[256StillBroken.zip] (https://github.com/AntonioND/nitro-engine/files/7908809/256StillBroken.zip) @AntonioND

AntonioND commented 2 years ago

That last rom still says 12x128 in the debugger, but it looks like the texture is also 128x128 so it shows up fine for me (at least in no$gba).

JustMeDaFaq commented 2 years ago

Can you try that one free_camera.zip ? @AntonioND

AntonioND commented 2 years ago

Screenshot from 2022-01-20 22-42-30

That one shows as 256x256, but it looks correct in the emulator. Both DeSmuMe and no$gba show the texture correctly.

JustMeDaFaq commented 2 years ago

Texture doesnt seems to be correct on yours, i took 2 screenshots of both texture sizes:

How it should look (128x128) 128

How it looks(256x256): 256

@AntonioND

AntonioND commented 2 years ago

Oh, ok. Could you send me the source code so that I check? Or you could try placing the textures in this example https://github.com/AntonioND/nitro-engine/tree/e98698febf02c30d1daf12d98bde9ade06760ce4/examples/2d_system/quad_texture_sizes and seeing if they are displayed correctly or not.

JustMeDaFaq commented 2 years ago

Oh, ok. Could you send me the source code so that I check? Or you could try placing the textures in this example https://github.com/AntonioND/nitro-engine/tree/e98698febf02c30d1daf12d98bde9ade06760ce4/examples/2d_system/quad_texture_sizes and seeing if they are displayed correctly or not.

I attached the source :) Its basically just the free_camera source with my model loading free_camera.zip @AntonioND

AntonioND commented 2 years ago

Okay, I've just realized what the issue is.

Models don't store coordinates from 0.0 to 1.0, they store them from 0.0 to whatever the size of your texture is. You can't use the same model with two texture sizes, you need to export it once per texture size.

In any case, thanks for this. Just to rule out other issues I've tried using nitro texture converter and discovered a bug that I've fixed here: https://github.com/AntonioND/nitro-engine/commit/5850ae5d5998e08681e1248771f25a775503dab6

JustMeDaFaq commented 2 years ago

Okay, I've just realized what the issue is.

Models don't store coordinates from 0.0 to 1.0, they store them from 0.0 to whatever the size of your texture is. You can't use the same model with two texture sizes, you need to export it once per texture size.

In any case, thanks for this. Just to rule out other issues I've tried using nitro texture converter and discovered a bug that I've fixed here: 5850ae5

@AntonioND That did the trick, thanks alot! Wouldnt have expected to not use the usual 0.0 to 1.0 coordinates, thanks!

AntonioND commented 2 years ago

No problem. And yes, the NDS 3D hardware is a bit unusual...