Generating Mimap Manually

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
thomascheah
Posts: 77
Joined: Sat Jul 08, 2006 5:55 am
Location: Cyberjaya, Malaysia

Generating Mimap Manually

Post by thomascheah »

I know this question is a bit unusual, but is there any way to generate Mipmap of a texure manually?

The main reason is I wish to apply a vectorized image (in WMF) as texture, which obviously Irrlicht does not support directly. I know I can convert the WMF file into a bitmap image and set it as the texture. But I don't want to use the default Mipmap behavior as its pixel resample tends to make my vectorized image blury, which in fact I can avoid it, if only I can generate the Mipmap manually, by rendering the WMF file into a set of textures of different scales, the texture will remain crisp and sharp most of the time.

Any ideas? Thanks in advance.

p/s: Just for your info, the WMF file contains a bunch of lines that make up some schematic drawings. Thus my goal is to render it on a 3D plane as sharp as possible.
Objective World Pvt. Ltd.
"Turning Knowledge Into Wisdom."
http://www.objectiveworld.com
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

My guess would be that you'd need to alter the source of irrlicht to do this...

You could definetly do it by having a new version of the texture creation function where you pass in an array of images instead of just one and then use each one to define each level of mipmap required. In OpenGL this would be really simple and i imagine it would be in DX as well so if you feel up for editing the source then it shouldn't be hard!
Image Image Image
thomascheah
Posts: 77
Joined: Sat Jul 08, 2006 5:55 am
Location: Cyberjaya, Malaysia

Post by thomascheah »

Thanks JP! I am not familliar with OpenGL. But can anyone point me some lights on how this works under DirectX SDK? I might then try to modify Irrlicht source once I get to know how.

BTW, my main objective is to render a vectorized image (in my case, a WMF file) on a plane that looks crisp and sharp at most distance. The method that I wrote above is one that is on top my mind. If anyone has other creative "out of the box" ideas in achieving this, I will greatly appreciate! :)
Objective World Pvt. Ltd.
"Turning Knowledge Into Wisdom."
http://www.objectiveworld.com
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I don't have any experience with DX but i should think it will be pretty much exactly the same way as OGL but with different function names and slightly different parameters.

OGL:

Code: Select all

for (uint32_t i = 0; i < num_mips; i++) {
  glTexImage2D(GL_TEXTURE_2D,i,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,pixels[i]);
  width/=2; height/=2;
  if (width == 0) width  = 1;
  if (height == 0) height = 1;
}
What that does is generate num_mips mipmap levels for the currently bound texture, reading from an array of images named pixels. So all you'd have to do there is set pixels to your array of mipmap images you've rendered.

Irrlicht may do the mipmap creation differently using a function called something like glBuildMipMaps which creates the mipmap images automatically instead of being fed in the scaled down versions so you'd have to switch that with this.

You should be able to google for the DX mipmap creation techniques.
Image Image Image
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

It's on my todo list, together with mipmap lod etc. You will get a level parameter to access separate mipmaps directly.
thomascheah
Posts: 77
Joined: Sat Jul 08, 2006 5:55 am
Location: Cyberjaya, Malaysia

Post by thomascheah »

Hybrid, can you can guide me through on how this work under DirectX SDK, and I can try to modify the Irrlicht source a bit for my immediate needs, while waiting for your next release with this feature. :)
Objective World Pvt. Ltd.
"Turning Knowledge Into Wisdom."
http://www.objectiveworld.com
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

This might help. But I don't know if the mipmap generated is sharp enough for your needs.

http://msdn2.microsoft.com/en-us/library/bb206251.aspx
My company: https://kloena.com
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, the link is good. You simply have to change the third parameter to the mipmap level you need. Please have a look at the d3d9texture.cpp source. You will find the manual mipmap creation code there. It scales down the texture and sets the next mipmap level. At least for opengl you will have to set all levels or the texturing won't work at all (or set a higher LOD).
A proper interface for Irrlicht might use setMipMap(level, image) or something like that, adding to the ITexture interface. I did not yet think about the actual methods.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

t's on my todo list, together with mipmap lod etc. You will get a level parameter to access separate mipmaps directly.
God bless you :) ...or whatever you believe to ;)
thomascheah
Posts: 77
Joined: Sat Jul 08, 2006 5:55 am
Location: Cyberjaya, Malaysia

Post by thomascheah »

Just curious, is there a way to switch off the automatic generation of mipmaps in Irrlicht? Not sure it will give me a better result without hacking through the code of implementing the manual access to mipmaps in Irrlicht. But I guess it is worth trying if Irrlicht can allow me to disable the mipmaps generation.
Objective World Pvt. Ltd.
"Turning Knowledge Into Wisdom."
http://www.objectiveworld.com
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can turn off mipmap generation by setting the proper texture creation flag. No further support for other things, though.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Check the tutorials that use skyboxes as these are loaded without mipmaps.
Image Image Image
thomascheah
Posts: 77
Joined: Sat Jul 08, 2006 5:55 am
Location: Cyberjaya, Malaysia

Post by thomascheah »

Hybrid, so what are the default texture creation flags (or combination of texture creation flags)?

JP, just curious. Any ideas why the skybox are loaded without MipMap? Because it was not necessary? Or it is due to performance optimizations?
Objective World Pvt. Ltd.
"Turning Knowledge Into Wisdom."
http://www.objectiveworld.com
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

IMO, you don't need a mipmap for the skybox. Because it will remain the same distance even if your camera is moving around.

Correct me if I'm wrong.
My company: https://kloena.com
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The default is none of the flags set. Just let the drivers do what they think would be best.
Post Reply