Texturing cubes
Blitz3D Forums/Blitz3D Programming/Texturing cubes
| ||
I created a cube and I want to be able to texture it on differnet side with a differnet texture. is there a way to do that? Tired of making plain and forming into a cube lol nack |
| ||
Most people would go the skybox route: Look in your 3D samples directory at the Castle demo. The skybox is basically a cube where the sides are individual pieces, thus, they can be independentally textured. For your use, you probably won't want to flip the meshes (unless you want the cube textured internally). |
| ||
oh thx. I checked the skybox, but it seems its also used plains. create vertex, surface, the works. This is the way I am doing but seem so much work. But i guess it seem this is the only way then. |
| ||
not that hard actually here is a modified verion of a function to make a multisurface cube Function createcubebrush(rectbrush_widthw,rectbrush_heighth,rectbrush_depthd) mainbrush = CreateMesh() surf = CreateSurface(mainbrush) v1handle = AddVertex (surf, 0,0,0, 0 ,0) v2handle = AddVertex (surf, rectbrush_widthw,0,0, 1 ,0) v3handle = AddVertex (surf, 0, rectbrush_heighth,0, 0,1) tri = AddTriangle (surf,v1handle,v3handle,v2handle) v1handle = AddVertex (surf, rectbrush_widthw,rectbrush_heighth,0, 1 ,1) tri = AddTriangle (surf,v1handle,v2handle,v3handle) surf = CreateSurface(mainbrush) v1handle = AddVertex (surf, 0,0,rectbrush_depthd, 0 ,0) v2handle = AddVertex (surf, rectbrush_widthw,0,rectbrush_depthd, 1 ,0) v3handle = AddVertex (surf, 0, rectbrush_heighth,rectbrush_depthd, 0,1) tri = AddTriangle (surf,v1handle,v2handle,v3handle) v1handle = AddVertex (surf, rectbrush_widthw,rectbrush_heighth,rectbrush_depthd, 1 ,1) tri = AddTriangle (surf,v3handle,v2handle,v1handle) surf = CreateSurface(mainbrush) v1handle = AddVertex (surf, rectbrush_widthw,0,0, 0 ,0) v2handle = AddVertex (surf, rectbrush_widthw,0,rectbrush_depthd, 1 ,0) v3handle = AddVertex (surf, rectbrush_widthw, rectbrush_heighth,0, 0,1) tri = AddTriangle (surf,v1handle,v3handle,v2handle) v1handle = AddVertex (surf, rectbrush_widthw,rectbrush_heighth,rectbrush_depthd, 1 ,1) tri = AddTriangle (surf,v1handle,v2handle,v3handle) surf = CreateSurface(mainbrush) v1handle = AddVertex (surf, 0,0,0, 0 ,0) v2handle = AddVertex (surf, 0,0,rectbrush_depthd, 1 ,0) v3handle = AddVertex (surf, 0, rectbrush_heighth,rectbrush_depthd, 1,1) tri = AddTriangle (surf,v1handle,v2handle,v3handle) v1handle = AddVertex (surf, 0,rectbrush_heighth,0, 0 ,1) tri = AddTriangle (surf,v1handle,v2handle,v3handle) surf = CreateSurface(mainbrush) v1handle = AddVertex (surf, 0,0,0, 0 ,1) v2handle = AddVertex (surf, 0,0,rectbrush_depthd, 0 ,0) v3handle = AddVertex (surf, rectbrush_widthw,0,0, 1,1) tri = AddTriangle (surf,v1handle,v3handle,v2handle) v1handle = AddVertex (surf, rectbrush_widthw,0,rectbrush_depthd, 1 ,0) tri = AddTriangle (surf,v1handle,v2handle,v3handle) surf = CreateSurface(mainbrush) v1handle = AddVertex (surf, 0,rectbrush_heighth,0, 0 ,1) v2handle = AddVertex (surf, 0,rectbrush_heighth,rectbrush_depthd, 0 ,0) v3handle = AddVertex (surf, rectbrush_widthw,rectbrush_heighth,rectbrush_depthd, 1,0) tri = AddTriangle (surf,v1handle,v2handle,v3handle) v1handle = AddVertex (surf, rectbrush_widthw,rectbrush_heighth,0, 1 ,1) tri = AddTriangle (surf,v1handle,v2handle,v3handle) Return mainbrush End Function |
| ||
ah but you can specify w,h,d in this one |
| ||
oh, u saved me from a lot of trial and error! thx |
| ||
Having a separate surface for each side is not a good idea, if you can avoid it. It'd be better to combine your textures into one and UV map the cube appropriately. Blitz cubes are comprised unwelded sides, BTW. You may be able to simply alter the UVs to map the cube with your all-in-one texture. Also, I remember other people asking this same question before. Try doing a search - you may discover some handy code/tips. |
| ||
"Having a separate surface for each side is not a good idea, if you can avoid it." why is that? is it because of memory issue? |
| ||
I think this is the way it goes. Blitz sends each surface to the graphics card to be rendered. Everyt9ime it sends a new surface, it stalls the graphics card as the new data is transfered. The less surfaces you use, the faster things will render. However, creating your whole game out of 1 surface, isn't a good idea either :o) Got to have a balance. That's why most people around here will be using a varation of single surface particles, if you want real speed out of them that is. |
| ||
i never had problems using multisurfaced cubes, even with CSG operations and shadow mapping. i fail to see how it would be a bad idea. i even tested my CSG lib using single surface meshs vs multi surface meshes and both clocked the same milliseconds |
| ||
If you only have a few multi-surfaced cubes onscreen, then it won't really matter if you use multi-surfaced cubes or a single-surfaced cube with modified UV-coords. But if you have a lot of them onscreen, rendering them will come to a halt. I'm creating a game in 3D (tile-based) and tried different approaches for generating my terrain. Each tile is 10x10 units in size, and I need a range-of-sight of 500m, so I'm actually having: 500/10 = 50 tiles in each direction = 100 tiles wide and 100 tiles high (when looking from above). That makes 100x100 tiles around the player = 10.000 tiles, each with their own surface. I have a fast laptop, but fps dropped from 999 fps (only 10 tiles in view) to 30 when I was in the middle of all those tiles (so only about 1/3 of the tiles (3000 or so) where being rendered). Now I generate 1 big mesh and I add all vertices to this mesh and now it stays above 200 fps (one mesh with 40.000 vertices). |
| ||
hmm odd, i would have guessed surfaces didnt matter in a triangle buffer whether they are seperate meshes one mesh or multiple surface it still hase to render the same amount of triangles. |
| ||
Try this code to find out the difference between 10.000 seperate quads, each with their own surface (I have Fraps running to count fps) and one big mesh with all vertices of those 10.000 quads merged into one surface: Graphics3D 800, 600, 0, 0 SetBuffer BackBuffer() ; generate 10.000 quads as individual meshes (and also surfaces as each mesh has it's own surface) ;For i = 1 To 10000 ; mesh = CreateMesh() ; surf = CreateSurface(mesh) ; v0 = AddVertex(surf, -1, 0, -1) ; v1 = AddVertex(surf, -1, 0, 1) ; v2 = AddVertex(surf, 1, 0, 1) ; v3 = AddVertex(surf, 1, 0, -1) ; t0 = AddTriangle(surf, v3, v0, v1) ; t1 = AddTriangle(surf, v1, v2, v3) ;Next ; generate one mesh with 10.000 quads on the same surface Global mesh = CreateMesh() Global surf = CreateSurface(mesh) For i = 1 To 10000 v0 = AddVertex(surf, -1, 0, -1) v1 = AddVertex(surf, -1, 0, 1) v2 = AddVertex(surf, 1, 0, 1) v3 = AddVertex(surf, 1, 0, -1) t0 = AddTriangle(surf, v3, v0, v1) t1 = AddTriangle(surf, v1, v2, v3) Next camera = CreateCamera() PositionEntity camera, 0, 10, 0 RotateEntity camera, 90, 0, 0 While Not KeyHit(1) RenderWorld Flip False Wend End As the code is posted here (the first For-loop commented out), it creates one mesh and adds 40.000 vertices and 20.000 triangles to one surface. My laptop's framerate is 53 fps (according to Fraps, which is running in the background). Then comment out the second For-loop (including the Global mesh and surf declarations) and un-comment the first For-loop. Run the code again. The first For-loop creates the same amount of vertices and triangles, but in 10.000 seperate meshes. Now my laptop's framerate drops to 10 fps, and the creation of the seperate meshes also takes a lot longer. Try it and see for yourself. |
| ||
We hit the multi surface problem with qoob. We had 50 * 50 * 50 cubes each with 6 surfaces = 750,000 surfaces. Goodbye FGX card. We now share surfaces so the figure went from 750,000 to 6 and it's a wee bit faster now :-) |
| ||
Damn, I didn't know that. I thought the triangles were the most important thing as well. Oh well, you live and learn. I wish that kind of info was in the documentation though. Is there some kind of Blitz3D efficiency guide out there somewhere? |
| ||
I'm in the midst of creating a screensaver using a cube with various images, this thread is fantastic, thanks for the tips :-) |