Game Development Community

Mipmaps for generated bitmaps

by Konrad Kiss · in Torque 3D Professional · 08/09/2009 (3:22 am) · 15 replies

Edit: The original title was renamed to better reflect the topic of this thread. The original title was: Translucent objects and prepass

Hey guys,

I'm creating billboards that show various info such as damage, levelup, badge gfx, skill fx, etc.. on any ShapeBase object. I'm creating the billboard via PrimBuild, and directly assigning a generated texture to it through GFX->setTexture (no shader / material assignment).

I'm rendering it as a RIT_Object. As far as I know, translucent objects do not get sorted into the depth buffer. I think this might be what's causing it to display like this:

www.xenocell.com/dev/infobubbleproblem.jpg

How should I go about correcting this? Is it a depth buffer issue, or am I totally lost?

Any help would be much appreciated.
--Konrad


#1
08/09/2009 (4:07 am)
Nevermind, I made it its own RenderInstType - much like RIT_Foliage, and that seems to have corrected the problem.

Thanks if anyone gave this a thought.
#2
08/13/2009 (2:06 pm)
Cool Konrad! :-)
#3
08/13/2009 (2:10 pm)
Thanks JoZ! :) I might revert back to a 2D / screen overlay solution, because this poses a number of problems - one being detail and the lack of anti-aliasing. I'm not sure how I should add different texture LODs to the billboard...
#4
08/13/2009 (2:59 pm)
Hum... that looks like fog being drawn over your text.

If you look at the FogPostFx you'll see it renders before the ObjTranslucentBin. If your RIT_Object had the translucent flag enabled it should have worked i think.
#5
08/13/2009 (3:09 pm)
The weird part was what you see in front of the sky. It would display the whole billboard that way with RIT_Object and the translucent flag set IIRC.

Well, it's working fine now, it made me level up in Render Instances though, so it was a good excercise.

Tom, forgive me, but while I have your attention; how would it be possible to apply LODed textures to that billboard? Is there a convenient way to do that without using materials or shaders?
#6
08/13/2009 (8:10 pm)
Not sure what your looking for. Do you mean like a texture with mip maps?
#7
08/14/2009 (7:14 am)
Sorry for choosing the wrong words. Yes, I'd like to assemble a texture with mipmaps and feed that to GFX->setTexture. Is there an easy way within the engine to combine the generated textures with different resolutions and pack them in a dds for instance?
#8
08/14/2009 (9:58 am)
Well... at runtime its harder... but doable.

You need to generate a new texture of the size and miplevels you want with GFXTexHandle.set().

Then you need to lock each mipmap level one at a time and copy over the texture content.

This sort of texture will be completely managed by your own code meaning you'll need to subscribe to texture mananger zombify/ressurect events and rebuild your texture.

I guess the other method is to make a GBitmap in the same way... right size and miplevels... copy over content... then initialize a GFXTexHandle with the GBitmap.

Really... if at all possible you should generate your textures offline and save them as mipmapped DDS files to begin with.
#9
08/14/2009 (12:50 pm)
Thanks for the info, Tom.

I can't really pregenerate the textures, since they would be displaying dynamic text and badge symbols. This will be a generic system for displaying shape name, damage inflicted, ai behavior state changes, xp gain, levelup, etc.. anything basically. It's a framework that makes it easy to set anything up with animation, animation duration, easing, color, etc.. I have a number of profiles through which I can display stuff like the damage suffered on a ShapeBase. This is why I can't create the textures beforehand.

I'm working with a GBitmap right now, which has the characters copied over from a font resource. I will probably scale it to dimensions of the nearest powers of 2 to not have to worry about texture coords. I'll take a look at a GBitmap and find the methods that let me copy the different mip levels into it.

Thank you very much for the great lead once again! :)
#10
08/14/2009 (1:38 pm)
I've found some mipMap generation routines. GBitmap doesn't yet create mipmaps for textures with an alpha channel, but given bitmapExtrudeRGBA and bitmapExtrudeRGBA_c, it doesn't seem like a hard thing to do... I'll see if I can get anywhere from there.

I'll also rename this thread to better reflect the majority of the topic.

Edit: Oh, it does handle textures with an alpha. it also has methods to resize a texture to the nearest pow 2 dimensions. Really cool!
#11
08/14/2009 (2:20 pm)
Looks like I got lucky:

... bmp created, stuff drawn onto it ...

   GBitmap * pow2bmp = bmp.createPow2Bitmap();
   pow2bmp->extrudeMipLevels();

   ... GFXTexHandle ...

It works beautifully.

Thanks again, Tom.
#12
08/14/2009 (3:40 pm)
Hum... that all sounds really expensive.

Why is it that you need mips for this?
#13
08/14/2009 (3:59 pm)
The original problem was (no mipmaps there) that if I rendered my text with a small font size on a small texture, the texture was pixely up close. If I used a larger font, up close was great, but I lost detail in the distance, and font parts were disappearing - much like the details of a large image on the web disappears when the image is forced to appear a lot smaller.

I wanted to solve that through mips for the text from a bitmap that was rendered with a large font size. Right now, it looks better a little probably, but still not good enough. I was thinking that maybe another bitmapExtrudeRGBA_c -like method should be written that creates mips that look better/sharper for text - meaning not taking the average of neighboring pixels, but something that preserves more contrast.

Now, my newest idea is to create the mip levels myself, and render each one using different sized fonts to preserve the smoothness of the fonts, which does not sound right, and I don't really want to do this, I'm just not sure why.

Still, I have a feeling that I am already shooting this bird with a BFG9000.. A little anti-aliasing on the text would probably work great, but I imagine that that would be even more taxing.
#14
08/14/2009 (5:01 pm)
This is all text then?

Internally Pat and others have been looking at implementing Alpha Test Distance Fields for sharp high quality fonts at any resolution.

It may be worth looking into here.
#15
08/14/2009 (5:06 pm)
That looks very impressive, and indeed is just what I need here! I'll read through the forum and the paper and see if I can implement it.

Thank you!