Question about multitexturing...

Blitz3D Forums/Blitz3D Programming/Question about multitexturing...

OrcSlayer(Posted 2006) [#1]
Alright, after reading about multitexturing limits, I decided to try another method. Here's what I do:

Create three quads. Use entityorder to put them in the right rendering position, add any effects I need (alpha tattoos to blend with skin, etc)...then I have a camera (positioned 1 unit away from the quads so it will be visible) take a shot of the whole thing and save it to a new texture, thus allowing all three textures to be merged into one. It works great, except for one problem.

The texture cam has the viewport set to 512x512, same as all the textures. When I copyrect from the that cam, I copy a 512x512 area starting at 0,0. However, for some reason, the resulting texture always appears stretched horizontally, thus making it unusable. The stretch appears to be at a 3x4 aspect ratio, so the final image seems to be rendered at 512x683. But of course it's cropped to 512x512 meaning the right side of the texture is cropped away.

Does anyone have any idea why this doesn't work? It's really frustrating when something that seems simple doesn't work...and you can't figure out why.


OrcSlayer(Posted 2006) [#2]
Problem solved (partially): It seems the problem was that the graphics3D height was less than the texture height, resulting a clipped render. Increasing the gaphics3D mode from 640x480 to 800x600 allows it to render properly.

So, unless anyone knows a way around that, I guess I can't allow 512x512 (high detail) player textures in 640x480 resolution...only medium (256x256) and low (128x128)...


jfk EO-11110(Posted 2006) [#3]
Unfortunately, and since you cannot render to a texture, as far as I know the resolution must be at least as big as the texture (what you said). But I don't think it's a problem, I rarely see a machine that cannot go higher than 640*480. Tho some people may prefer that resolution for speed reasons, but I think it isn't a big problem to offer 800*600 and higher only.


OrcSlayer(Posted 2006) [#4]
Oh well, if someone wants to use 640x480 for speed...they don't need high rez character textures anyway. The difference shouldn't even be noticable at that resolution...

Thanks for the info.


Pongo(Posted 2006) [#5]
For what you are talking about, why even bother going through with multitexturing? You would be better off just building the complete texture in your paint program. In photoshop for example, you can use layers and use multiple blending modes like additive or multiply. I know not everyone has Photoshop, but lots of paint programs support these kind of layers now.

Anyways, the real use of multi texturing is when you have multiple textures, and you can tile them at different levels. A lower res texture can provide an overall color, while another map has lots of detail. When they mix you get the end result of more detail than you would get with a single texture, while avoiding obvious tiling. Another use for multitexturing is for masking things like reflection maps, and this is something that cannot be really collapsed.


OrcSlayer(Posted 2006) [#6]
Well, you see, I am in fact now building the textures in game, out of multiple base textures. I wanted to do real multitexturing at first, but it turned out to be too limited, and wouldn't do certain things I needed. In fact, that's what I was asking about when I first started this thread.

So, my method of building them in game is the only real option since pre-assembling them would require hundreds of possible combinations. I'm saving a lot of space this way :-)


OrcSlayer(Posted 2006) [#7]
Actually, now I noticed a little thing...it's not severe but I was wondering if there was a workaround. The resulting texture looks a bit blurred (I exported the finished merge to compare with the original).

Anyone know if there's a way I can prevent that, or is it just an unavoidable side effect of the method I'm using?


jfk EO-11110(Posted 2006) [#8]
It's filtering, and mipmapping. Unfortunately this happens in the default setting. You may turn off mipmapping by using the flag 256 for the texture, and maybe there has been a further custom solution to turn off filtering in the past, you maybe can find it with the forum search tool.

But be warned, using flag 256 (that is btw also turning off mipmapping) will make rendering slower, and it will make the object "corny".

There are many good reasons for multitexturing, of course. Be it Lightmapping, or a layer containing an animated texture (I use this for underwater caustics), or a fine grainy detail texture. You could not embed the detail texture in a main texture that was made using photoshop layers as it was suggested before because the scaling of the grainy detail texture is so tiny, much smaller than a single pixel of the other texture. So this way you won't see the details form the distance, but if you're very close to the object, the details become visible, preventing huge texels of the main texture from becoming obvious.


OrcSlayer(Posted 2006) [#9]
I was using 256 anyway...seems to make textures sharper. I also heard it made rendering faster (but you said it makes it slower?)...but I didn't notice it making anything look corny, just less blurred...

I looked again, and actually there's nothing big enough to notice in game. It still looks pretty sharp, and the process is fast enough for dynamic character generation without pre-prepared textures or multitexturing.

Thanks for all the help guys.


Pongo(Posted 2006) [#10]
Definately makes sense to use a method like this to merge all the combinations. I have done similar things in the past.

The blurring I would guess is mipmapping, as was already pointed out by JFK.

You should be able to get better quality by writing a bit of compositing code with different blend modes and then mixing the bitmaps directly rather than relying on texturing/grabbing them again. You could easily write a function to read all the pixels in an image and blend them with another image. This may be a bit slow, but if it is only done on startup or initialization it really should not be too bad.


OrcSlayer(Posted 2006) [#11]
Hmmm, that would seem to be a good idea, but sadly they have to be done dynamically. Mainly during player creation (a live preview will be updated), and at start of a game if the random opponents option is used. I think the texture grabbing is the fastest reliable option that also allows me to use effects like alpha, entity color, and blend modes.

Also, I'll be releasing the first promo art for this game within the next few days. Hope everyone takes a look.


Pongo(Posted 2006) [#12]
Ok, I was a bit curious so I had to try this a bit further.

This code allows you to blend 2 images together using clip, add, multiply, overlay, and soft light modes.

You will need to supply your own images (image1.png and image2.png) or change the code to fit what you need.

I have a use for this so I'm going to develop this a bit further by adding support for a transparency mask, and also allow tinting of an image for color effects. Since it only needs to be done once per effect, it is quite fast and could easily be used to mix textures together.

let me know what you think. The code is a bit of a mess but should work fine. The only thing you need to do is make both images the same size for now. (I recommend 256x256 for testing)




OrcSlayer(Posted 2006) [#13]
Cool, Pongo. I'll have a look at it, but I think I may just stick with my current method, since I've done a lot of revision since I started and it actually works quite nicely now, and is fast enough for real time updating. The bluring isn't even noticable in game...