gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Mipmaps on the DS

#158637 - AO - Sun Jun 15, 2008 1:09 pm

Here's the problem, I need to figure out the mipmap level per pixel, it doesn't have to be very accurate as long as it's an OK estimate. If the hardware can pick the mipmap level for me automatically then that would be perfect.

Does the DS support mipmaps? Does the DS 3D hardware automatically pick a mipmap level for textures? Is there some way to read back which mipmap level the hardware chose?

I don't know if the DS supports trilinear filtering in hardware, if so it will at least calculate the mipmap levels which could be found by peeking in the right places in memory (possibly?).

Thanks!

#158638 - elhobbs - Sun Jun 15, 2008 1:25 pm

the ds 3d hardware does not support mipmaps or texture filtering. It does support antialiasing edges, but I have never been able to spot the difference on the ds when this feature is on or off. you could implement per poly or per object mipmapping in software. You could try something simple like using the distance from the view point to select a different size texture. keep in mind that this will probably require using more texture memory which may already be at a premium.

#158646 - silent_code - Sun Jun 15, 2008 5:08 pm

You can use the texture matrix to dynamically resize texture coordinates, but you will have to supply a smaller version of the texture. I'm not sure you will benefit (besides slightly improved visual quality) from this, as the rendering speed is quite fixed and (at least mostly) well known.

PS: When doing AA right, it is indeed visible. ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158650 - M3d10n - Sun Jun 15, 2008 8:11 pm

Yeah, there no filtering nor mipmaps. It's plain ol' point sampling.

What are you trying to do? Reading mipmap levels per pixel is something you'd only do on shader model 3 capable video cards or something.

If you're trying to do some kind of rim lighting effect, you might want to look into using normals to generate texture coordinates using TEXGEN.

#158660 - silent_code - Mon Jun 16, 2008 3:12 am

Oh, I just rememebred, that I managed to get "mipmaps" working in a demo (I might still have it somewhere on my backup HDD) a few years ago (that was when I startd with NDS dev and had no HW), but then it only worked in emulators. I made it via "depth slices", with lots of overdraw and rerendering the geometry for every mip level... hackish and very visible (? la linear mipmap nearest.) I guess I could have got it to work on HW, too, but even though the mipmaps helped to a degree (they really did in some places), it was a solution that simply couldn't be used in any game, because each rendered primitive generated three more on average.

Long story short: Again, try distance based texture lod and texture matrix scaling, but don't try to get any kind of mipmapping done - it's simply not working (unfortunately.)

Also, you will have to get familiar with the HW and it's capabilities. And maybe with 3D graphics hardware (APIs, I recommend OpenGL - which libnds' videoGL mimicks to a degree) in general. I assume, from your question, that you're still in a stage of getting to know exactly that. ;^) Happy learning, then!
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.


Last edited by silent_code on Tue Jun 17, 2008 12:10 am; edited 1 time in total

#158663 - a128 - Mon Jun 16, 2008 8:05 am

Midmapping for a 256x192 screen?!
Does this make sense?

#158666 - silent_code - Mon Jun 16, 2008 11:04 am

@ a128:

It would, but as it is not implemented in the HW, there's no way you will get the oversampling artifacts reduced without manual texture lod.
Just make a test scene, that has a broad and long hallway and you'll see, that the oversampling is quite irritating to the eye.

I really hope the next N handheld will be much like a NGC portable. :^)

@ AO: Any feedback to our post? ':^|
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.


Last edited by silent_code on Mon Jun 16, 2008 12:54 pm; edited 2 times in total

#158671 - tepples - Mon Jun 16, 2008 12:34 pm

If you select texture LOD per model, would that be close enough?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#158698 - M3d10n - Mon Jun 16, 2008 5:07 pm

There's also the fog trick: set the fog color to the average of all of the current texture's pixels, and you'll reduce the oversampling along the distance. If you have a "materials" system in place and can preprocess the textures to calculate the average, that wouldn't be too hard to do.

#158706 - sajiimori - Mon Jun 16, 2008 6:22 pm

That's interesting -- I didn't know you could change the fog settings for each poly.

#158711 - silent_code - Mon Jun 16, 2008 7:39 pm

If you don't use fog otherwise, it is indeed a very interesting technique!
Same question: Is it really possible to change the fog color per primitive?
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158722 - AO - Mon Jun 16, 2008 9:00 pm

a128 wrote:
Midmapping for a 256x192 screen?!
Does this make sense?


The plan was to research the possibility for virtual texturing and to stream only the required texture resolution from the flash card. In theory it'd allow the game to have 100s of megabytes of texture data per level and uniquely textured world. Calculating a mipmap level is the biggest problem and if can be solved it might be possible.

Might stick to per object mip level as were suggested, but for the terrain mesh that's not gonna work, hmm.

M3d10n wrote:
There's also the fog trick: set the fog color to the average of all of the current texture's pixels, and you'll reduce the oversampling along the distance. If you have a "materials" system in place and can preprocess the textures to calculate the average, that wouldn't be too hard to do.

What about 2 pass rendering. If you render all objects with a black texture and a uniquely identifiable fog color per object then the framebuffer color would equal the depth and hence a mip level could be chosen for the 2nd draw per object.

So 2 pass = 30 fps instead of 60 (as far as i know), and you might have to point the first fog render pass to some off screen vram for it to work (is this possible?).

#158728 - silent_code - Mon Jun 16, 2008 9:27 pm

Then you don't want to calculate a mipmap level, but a texture lod level. The two are slightly differnt. ;^) use a simple distance (viewer / object) based approach. You would have to have the scene divided into indipendent parts, that can have different textures.

Although in theory that works, it isn't very practical to hide artifacts. It's quite the opposite, you exaggerate them. Given the low video memory available on the platform, you would not want several copies of the same texture, only at different resolutions. Then, you would load a low res texture on startup and load the high res on demand... only that all distant parts of the scene would change immediately and "create" oversampling artifacts...

That was very short and biased, as your specific game might not suffer from oversampling due to it's viewing system / perspective, but it's likely that there will be other problems (popping when replacing the texture - which will *have* to be if you like to be able to use a lot of different textures - assuming from the "100s of megabytes of textures" - as like I already wrote, vram is very limited and having multiple versions of a texture will potentially eat up too much of it!)

But streaming sounds cool and if done right, can give your artist very much room for creativity! Go for it, but leave the mipmapping ... as there is none. ;^) Texture lod levels should probably be only few and only used a placeholders when streaming high res textures.

I hope I don't "sound" like repeating myself too much, thus annoying you guys! :^/
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158734 - AO - Mon Jun 16, 2008 10:46 pm

silent_code wrote:
But streaming sounds cool and if done right, can give your artist very much room for creativity! Go for it, but leave the mipmapping ... as there is none. ;^) Texture lod levels should probably be only few and only used a placeholders when streaming high res textures.


I'm not sure i agree with not having to calculate the mipmap level, I'll see what i can come up with as i experiment, i should be able to calculate a conservative estimate on the texel area / screen area per object quite cheaply. Not sure about how to do the terrain, might split it up into tiles and calculate the mipmap level per tile ;)

The replies have been very useful.

#158737 - silent_code - Mon Jun 16, 2008 11:32 pm

AO wrote:
I'm not sure i agree with not having to calculate the mipmap level...


... Because there is no mipmap. :^) But I actually didn't say you shouldn't. I gave you some optional thoughts, with respect to the platform. You can, however, do what you like to. ;^)

You could, as you wrote, calculate a texture lod level for the whole mesh. I can only say, that I'm very interested in the result. Especially, how much texture variety you can manage that way, because with multiple objects sharing a common texture at different detail levels, I guess you will have a lot of textures in VRAM, but at the same time most will be just lod variants.

PS: What I (and others) suggested was calculating the distance between a mesh (a tile, cell, sector, room, prop, character - whatever) and the point of view and according to that, select a texture detail level for the whole mesh.
That can be done with some simple and fast calculations, whereas true mipmapping requires relatively expensive calculations.
But a simple relation to estimate the area should work aswell. :^)

(I am repeating myself, again, because you still call it mipmaps, which confuses me a lot!)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158738 - tepples - Mon Jun 16, 2008 11:59 pm

silent_code wrote:
Especially, how much texture variety you can manage that way, because with multiple objects sharing a common texture at different detail levels, I guess you will have a lot of textures in VRAM, but at the same time most will be just lod variants.

The set of LOD variants of a texture takes roughly 33 percent more space than the biggest variant by itself. So if you're using banks A-D of VRAM, it's like losing one bank.

Quote:
(I am repeating myself, again, because you still call it mipmaps, which confuses me a lot!)

Wikipedia uses "mipmap" to refer to the set of LOD variants of a texture.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#158741 - silent_code - Tue Jun 17, 2008 12:07 am

A mipmap is a texture lod, yes, but mipmapping is a complete technique, that is more than just the data and how it is represented, it's also about how that data is "used", e.g. how transitions are handles, how levels are chosen etc.

I might by a bit too picky about the term, my bad. ;?)

I'm confused and it's late, so I guess it's bed time. Good night! :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158742 - AO - Tue Jun 17, 2008 12:33 am

OK, I don't want to do mipmapping then, just the "texture lod" :P

silent_code wrote:
PS: What I (and others) suggested was calculating the distance between a mesh (a tile, cell, sector, room, prop, character - whatever) and the point of view and according to that, select a texture detail level for the whole mesh.
That can be done with some simple and fast calculations, whereas true mipmapping requires relatively expensive calculations.

Yep, sounds like the best idea imo.

tepples wrote:
silent_code wrote:
Especially, how much texture variety you can manage that way, because with multiple objects sharing a common texture at different detail levels, I guess you will have a lot of textures in VRAM, but at the same time most will be just lod variants.

The set of LOD variants of a texture takes roughly 33 percent more space than the biggest variant by itself. So if you're using banks A-D of VRAM, it's like losing one bank.

If multiple objects use different mipmap levels of the same texture then you might as well only use the highest quality texture required on all of them.

With virtual texturing you only ever have one mipmap level of a texture in VRAM, all higher/lower quality mipmap levels are on disk. If the texture cannot be streamed in fast enough to Vram the texture will be garbage until streaming from disk is complete. Which is OK (on the PC anyway...), garbage textures should rarely be noticeable since camera movement is usually continuous and predictable.

This would be pretty cool to get working on the DS.

#158743 - M3d10n - Tue Jun 17, 2008 12:42 am

I barely touched fog, and since I remember reading about the fog somewhere, I assumed it was possible to change have different fog colors in the same frame. Can someone confirm if it's possible or not?

Anyway, it's possible to make the fog write to the framebuffer alpha. That way you could render the scene with lod textures, capture, display captured frame in background and draw scene again with fog so it blends into the lod scene based on distance.

#158784 - AO - Tue Jun 17, 2008 10:23 pm

Maybe the most important part i didn't state clearly is that the whole world is uniquely textured which would be different from regular lod texturing.

#158788 - silent_code - Tue Jun 17, 2008 11:17 pm

Is it "uniquely textured" as in "Mega Texture"?
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158792 - AO - Tue Jun 17, 2008 11:50 pm

You could say that, but the technique is different with virtual texturing.