[Broomstick] BitmapMaterial - Bitmap-Size has to be pow2 - Problem

132 views
Skip to first unread message

Vatrobot

unread,
Apr 13, 2011, 5:16:21 PM4/13/11
to Away3D.dev
Hello,

I don't understand why BitmapMaterial-Bitmaps (be it loaded as an
Image or created on runtime) have to be pow2 in size?

My task (should be simple, but I just cant do it beacuse of the pow2-
restriction):
texture a Plane (w: 100, h: 20) with a Bitmap-Image (Image has
billboard-like text on it, so it should not be distorted for
readability reasons).

How to achive this? I need a 5:1 Bitmap-Texture and that semms not be
possible with the pow2-restriction.
Am I getting something wrong? Is there a workaround for this (some
sort of cropping)?

Would appriciate any Information on that.

Thanks,
Vatro

Dave

unread,
Apr 13, 2011, 6:20:21 PM4/13/11
to away3...@googlegroups.com
Put it in a larger texture, and use UV mapping to only map the portion you'd like.

e.g. put it in 128x128
but set UV's to be

Upper Left UV - 0,0
Lower Left UV - 0,20/128
Upper Right UV - 100/128, 0
Lower Right UV - 100/128, 20/128

I may have the UV's slightly wrong (flipped?)

It's possible you can use a non-square texture (this I am not sure of).  e.g.
128x32
adjust the math above accordingly.

-Dave

Dave

unread,
Apr 13, 2011, 6:21:12 PM4/13/11
to away3...@googlegroups.com
Oh, and the reason why textures must be power of 2 is 3D hardware limitations. This is required by the hardware.

Fabrice3D

unread,
Apr 13, 2011, 6:30:55 PM4/13/11
to away3...@googlegroups.com
if you make the image as you wish and save to a power of 2, you will be just fine
the images are not sensitive to their own format but the mapping an object have.
make sure the original info is not upscaled for best results.

Fabrice

Vatrobot

unread,
Apr 13, 2011, 7:45:48 PM4/13/11
to Away3D.dev
Hi Dave & Fabrice,

Thank you for replying!

I came across uv-manipulation too in the meanwhile, and am already
nerding around with it.

@Dave: Thank you for the Math, I'll use it wisely! :)

@pow2-limitation: okay, so it has to be this way.

I just realized that everything seems to be "squared" in the 3D-
Hardware-World (don't know if it was in previous Away3D-Versions
though, never dug so deep into it).
I've traced the UVData of my Plane and the coordinates were 0,1,
1,1, 0,0, 1,0.

[0,1] seems to be lower-left corner
[1,1] seems to be lower-right corner
[0,0] seems to be upper-left corner
[1,0] seems to be upper-right-corner

so its a 1x1 square although my plane was 100x20.

@Fabrice:
hmmm... I dont't quite understand the "save to a power of 2"-part...
If I make an image let's say 100x20px, how can I save this to power of
two? The engine throws an error if image-width or image-height or both
of them are not pow2.


Thanks again,
Vatro

Vatrobot

unread,
Apr 13, 2011, 8:29:10 PM4/13/11
to Away3D.dev
Hello,

just to share the result:
http://www.vatrobot.de/molehill_broomstick/HelloPlane_BmpMat_Text.html

I wanted to make the height of the plane not-pow2 without distorting
the text-texture.
As you can see it works now.

I've tweeked 2 UV-points (width constant):

var uv:Vector.<Number> = plane.geometry.subGeometries[0].UVData;
var uvOffset:Number = plane.height/bmpData.height;

//lower corners Y-value
uv[1] = uvOffset;
uv[3] = uvOffset;


Thanks again + bye,
Vatro

Fabrice3D

unread,
Apr 14, 2011, 4:50:19 AM4/14/11
to away3...@googlegroups.com
if your plane is 100x20, and you make a 100x20 image with your text, then change the size to 128x32, it will be displayed in ratio of your plane, 1/1 100x20 exactly as you wish
so no matter the eventual distort the original image gets, it will be corrected automatically. Even if you make your image 1024x1024, its will be spreaded and displayed entirely over your plane at 100x20
And yes, you could change the uv's but why bother as its so easy to do by just saving the image in ratio.

you can use different values for the image source dimension, as long as both width/height are power of 2. 2,4,8,16,32,64 etc...
It doesn't have to be a square.

if you add extra maps, for instance if you make a BitmapMaterial and add a normalmap, the normalmap has to be of the same size as the diffuse map.
If you don't respect these rules, the engine will remember it to you anyway.

Fabrice

John Brookes

unread,
Apr 14, 2011, 5:08:25 AM4/14/11
to away3...@googlegroups.com
"It doesn't have to be a square."

If its not I get an error with awd 1024*512

Vatrobot

unread,
Apr 14, 2011, 5:15:06 AM4/14/11
to Away3D.dev
Hi Fabrice,

thanks for replying!

On 14 Apr., 10:50, Fabrice3D <fabric...@gmail.com> wrote:
> if your plane is 100x20, and you make a 100x20 image with your text, then change the size to 128x32, it will be displayed in ratio of your plane, 1/1 100x20 exactly as you wish
> so no matter the eventual distort the original image gets, it will be corrected automatically. Even if you make your image 1024x1024, its will be spreaded and displayed entirely over your plane at 100x20

Vatrobot:
Haven't tried it, but 100x20 = 5:1 ratio, 128x32 = 4:1 ratio, so I
assume the texture will be streched over the plane horizontaly, right?

> And yes, you could change the uv's but why bother as its so easy to do by just saving the image in ratio.
>
> you can use different values for the image source dimension, as long as both width/height are power of 2. 2,4,8,16,32,64 etc...
> It doesn't have to be a square.
>
> if you add extra maps, for instance if you make a BitmapMaterial and add a normalmap, the normalmap has to be of the same size as the diffuse map.
> If you don't respect these rules, the engine will remember it to you anyway.
>
> Fabrice

The point is: I don't want anything to stretched (not even a bit,
cause it's text I want to map), nor I want to adjust the size of the
plane to fit with pow2-texture. I'm looking for a worklflow in case I
want a Plane with desired width x height + an image that fits exactly
into that plane without stretching & distortion. The texture itself
must be pow2 (Xpow2 x Ypow2) I've understood that, and it doesn't need
be a square. But to fit the the desired texture-area (someX x SomeY in
a pow2-image) 100%ly to my plane-dimensions (which don't have to be
pow2) I got to use uv-manipulation, right?

but I actually already am on the right way 'I think:
http://www.vatrobot.de/molehill_broomstick/HelloPlane_BmpMat_Text.html

In the demo above, plane-size can be changed in height without
affecting the ratio of the texture, so the text is not distorted.
Right now I want to adapt it to plane-width too, so I will be to
change the size of the plane as I whish without affecting the ratio of
the texture.

regards,
Vatro

Vatrobot

unread,
Apr 14, 2011, 5:26:03 AM4/14/11
to Away3D.dev
> On 14 Apr., 10:50, Fabrice3D <fabric...@gmail.com> wrote:
>
> > if your plane is 100x20, and you make a 100x20 image with your text, then change the size to 128x32, it will be displayed in ratio of your plane, 1/1 100x20 exactly as you wish
> > so no matter the eventual distort the original image gets, it will be corrected automatically.

okay, now I've understood what you mean. But thats the thing I don't
want, I don't want to interpolate the image size from 100x20 to
128x32, because I assume there will be some undesired pixel-effects...
but I'll try and compare the results.

thanks,
Vatro

Vatrobot

unread,
Apr 14, 2011, 5:39:00 AM4/14/11
to Away3D.dev
I've just updated the demo, so the desired effect is more visible
(plane is now constantly changing in height):
http://www.vatrobot.de/molehill_broomstick/HelloPlane_BmpMat_Text.html

thanks,
Vatro
Reply all
Reply to author
Forward
0 new messages