Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to use CubeMap as a tiled texture

Author
Message
Kuper
16
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 29th Mar 2022 13:36
Is it possible to use one of cube map sides as a tiled texture? So you can have 6 different textures within 1 cubemap.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Mar 2022 03:52
I know with Milkshape 3D you can easily group all of the individual sides of a cube, texture them and export as an .x file. I did a quick example of 3 textures on a cube. I could easily have done all 6 sides.



So many games to code.....so little time.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 30th Mar 2022 04:14
You could copy the pixels out of the cubemap texture to a separate texture using two memblocks.
Then manipulate the texture co-ordinates of an object to produce the effect.

This would require you to know how to build the image header for the new image in the target memblock. You'd also need to know how to traverse the source memblock to pull the bytes.

The memblock header format is as follows:
ImageWidth as dword
ImageHeight as dword
ImageDepth as dword (this should be 32)

This means each value is a 4 byte dword. So bytes 0-3 are ImageWidth, then bytes 4-7 are ImageHeight and so on.
Then at byte 12 it's the first pixel data, starting left to right, top to bottom.
The pixel format is BGRA and not ARGB. Each color is a single byte. The color format is ARGB when stored in a single RGB() dword value, like when coloring text.

If you want to convert the bytes to a ARGB color value then you need to use 'bit shifting' like this:
newCol = (Alpha << 24) + (Red << 16) + (Green << 8) + Blue
You can use >> and << operations to shift the bits around to trim unwanted bytes and convert back if needed.




Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Kuper
16
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 30th Mar 2022 15:28
Thanks!
I was trying to find way for having up to 6 textures within 1 texture slot - using single cube map.
It is possible, but without tiling. In pixel shader we have:

As a result you can sample each side of cube map individually.
You can use this for example for changing texture on object very quickly ( without load new and retexture )
But tiling requers more UV distortion and I don't see how it can be done without it.
Bored of the Rings
User Banned
Posted: 30th Mar 2022 19:22
I did a similar thing a while ago for a tool I worked on where I stitched 4 images together. I didn't use it to texture a 3d model though, might give that a go.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Kuper
16
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 30th Mar 2022 21:57 Edited at: 30th Mar 2022 21:57
@Bored of the Rings
I decide to switch to atlas texture from this example jGfx_GInst Dec-09-2018.rar
from this page: https://forum.thegamecreators.com/thread/220206?page=2
Its ok - you just need to create border of about 16 pixels for each side for each tile in atlas ( to avoid edges )
also nice info here:
https://mtnphil.wordpress.com/2011/09/26/terrain-texture-atlas-construction/
Bored of the Rings
User Banned
Posted: 31st Mar 2022 16:02
thanks for the link @Kuper. I shall have a look after work and play around with some code quickly.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 1st Apr 2022 04:16
Using a texture atlas will apparently reduce the number of draw calls being used, which will increase performance as Directx9 is bottlenecked by drawcalls. It's the major issue that Directx10 and 11 attempted to resolve. It's why one object with 100k polys can run faster than 1000 objects with 100 polys.

The downside is that you use more memory, and you can have texture bleeding as the squares blur into each other, thus the 16 pixel gutters to isolate each texture square in the atlas that you mentioned.

I was going to mention this method and say that Matrix terrain use a form of this. However I figured you had a good reason for needing the cube map to be used specifically. Otherwise it's fairly trivial to play with texture u/v coordinates to map polys to atlas texture squares.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Kuper
16
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 1st Apr 2022 12:54
For terrain:
I think that best result will be to use 1 big cubemap storing height, normal and blend masks and 1-2 texture atlases for terrain texture tiles.
Limit of 8 texture sets per object must be kept, and creating copy of terrain object with another texture sets is unacceptable as well.
Memory consumption for cubemap is the same like separated 6 images of same size like cubemap's side - so not big deal here
Also you can reduce file size saving with DXT5 compression ( you can use Photoshop or free NVIDIA Texture Tools 2 with command line or even DBPro itself )
The only disadvantage is that saving cubemap is slower than one image.

Login to post a reply

Server time is: 2024-04-20 07:08:51
Your offset time is: 2024-04-20 07:08:51