 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Mar 23, 2007 5:30 am Post subject: Mipmapping and swizzling |
|
|
Hi folks,
I have this problem with my 3D rendering, the textures that are used are to big for the distance :S like when i use a 512x512 it goes really slow with a small object, when i make it 128x128 it does not go slow.
now i know it has to do with mipmapping and with swizzling, which of these has the most impact?
i have seen the texturetool but it is made with some kind of library or something so i can't use that. So i decided to make it myself the swizzling and mipmapping but can i do that with the png lib and the graphics function file (i was told from the lua player) ?
any ideas how i should handle the problem? what should i do first etc. etc. ?
every bit of feedback is welcome,
greets ghoti _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Bytrix
Joined: 14 Sep 2005 Posts: 72 Location: England
|
Posted: Fri Mar 23, 2007 7:59 pm Post subject: |
|
|
Swizzling makes the most difference. Objects closer and further away will both render faster using swizzled textures. It helps on pretty much everything.
There are plenty of swizzling functions in the SDK examples.
Mipmapping as you know can help greatly if you are rendering alot of objects at various distances. I have yet to add mipmapping to my engine so I don't really know much about how to implement it on the PSP.
Also using different texture formats can greatly increase the speed of rendering. I've just started converting all my 32bit textures to 8bit CLUT (and 4bit would be even better), it has two advantages, less texture memory used and faster rendering. |
|
| Back to top |
|
 |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Fri Mar 23, 2007 11:32 pm Post subject: |
|
|
Mipmaping has most impact on performance on far distances objects with 512*512 textures.
the GU has a cache for texturedata, each cachemiss gives you a very painfull slowdown. if you draw fardistances objects, let's assume an 32*32 pixel quad/sprite with an 512*512 texture on it, then you're mapping every 16th texel to one pixel, obviously the cache does not have read 16 texels ahead, so probably every pixel on screen causes a cachemiss.
swizzling is an optimisation to get more cachehits. the GU reads quads of texels instead of lines, lot of local texelreads like they happen during normal rendering will cause less cachemisses, but this should probably not help you as you dont have localreads, but kinda random texture reads.
swizzling will give you a great improvement used together with mipmaps tho.
I'm using both in my engine and it gives an awesome speed, one important thing to mention is the texture format, using highres textures in RGBA8 gives you half the speed compared to R5G6B5 and nearly no visual advantage. Always try to use as few bits per texel as possible, I always try to use 4bit-palleted textures, then 8bit, then R5G6B5. This is especially important on highres textures as mipmapping does not help if you have pixel:texel of 1:1, then it's just up to the raw bandwitch-power of the psp. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Mar 27, 2007 2:52 am Post subject: |
|
|
Hi where can i find those SDK examples ? my version of the SDk has only some examples but i can't seem to find anything on swizzling :S is it possible to combine the png loading with the swizzle ?
and mipmapping, do i have to implement my own distance to texture algorythm or has the psp some build in functions that automatically detect which texture to render?
any ideas and thoughts are welcome !!
greets ghoti
EDIT: i have found the TexMode function, it allows for swizzling, will test it out., mipmapping have found some info about it but it is not clear to me yet so reaction still welcome !! _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Mar 27, 2007 4:05 am Post subject: |
|
|
have read some info but could not find much:
i use this: sceGuTexMode(GU_PSM_8888, 0 ,0 ,0); when i turn the last 0 in a 1, swizzling is turned on. if i do this then the textures are all messed up :S (repeating the texture alot of times for example although it normally is applied only once over the whole object.
if i only change the first parameter into GU_PSM_4444 but then the texture are messed up with al different colors :S
I guess it is not the only thing to get it working so what am i missing ?
greets ghoti _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
sturatt
Joined: 13 Jul 2006 Posts: 46
|
Posted: Tue Mar 27, 2007 5:09 am Post subject: |
|
|
if you turn on swizzling, you need to actually change your texture data, so it knows how to read it.
if you look around the forums, there are plenty of examples on how to swizzle your textures, and i think there are some examples on this site's wiki. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Mar 27, 2007 11:58 pm Post subject: |
|
|
Hi agian, i will handle swizzling after i have made mipmapping possible :) I get the idea of mipmapping and i have created multiple images of the texture in the correct sizes. Do i have to make them 512x512 all the way to 2x2?
Here is what i'm planning to do, read all the textures into memory, then calculating the distance from the current position to the objects position. Then rendering the imagesize belonging to that distance. however this way I don't do anything automatic. how should i do it ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Wed Mar 28, 2007 1:39 am Post subject: |
|
|
Search for the ODE test application on the forums here and download it. It contains source using hardware mipmapping (though only one level). _________________ <Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
Alexander Berl |
|
| Back to top |
|
 |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Wed Mar 28, 2007 8:44 pm Post subject: |
|
|
you should not do it manualy as it would be a waste of ur time and performance and it will probably look worse if you do it just per object (the gu is doing it per triangle afaik, other hardware even per pixel). The psp is selecting the mip-level automatically, you just have to provide all the mipmaps.
swizzling is done pretty easy, look at the speed sample in the sdk, I think there was a simple swizzling function, or look in the yapspd, it's straightforward to implement. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Mar 28, 2007 9:17 pm Post subject: |
|
|
Hi, i'll look into the ODE example but where do i get my examples from the SDK ? i don't have the speed example, i don't have the swizzling examples :S where can i get those ? i just have some basic samples which let you see how you can build some basic stuff not these kinds of things :S
greets ghoti _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Bytrix
Joined: 14 Sep 2005 Posts: 72 Location: England
|
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Mar 28, 2007 9:40 pm Post subject: |
|
|
whaaaaaaaaaaaaaaaaa why didn't i know that anytime sooner :S I have a pspdev sdk folder on my computer in which also samples are but not as many as these !!! this will help me a lot thank you very much !!! _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Conflict

Joined: 11 May 2005 Posts: 8 Location: UK, York
|
Posted: Fri Mar 30, 2007 11:51 am Post subject: |
|
|
Q: How do I swizzle a texture?
>>> http://wiki.ps2dev.org/psp:ge_faq
I don't know why anyone didn't point you to this sooner ;>
gl _________________ <,<; |
|
| Back to top |
|
 |
Bytrix
Joined: 14 Sep 2005 Posts: 72 Location: England
|
Posted: Fri Mar 30, 2007 6:53 pm Post subject: |
|
|
| As I said in the first reply, there are plenty of swizzling functions in the SDK examples. Anyone developing for the PSP should have the SDK and samples installed, it was the first thing I looked at. It's always better to find things yourself, he just needed to be pointed in the right direction ;-) |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Mon Apr 23, 2007 6:26 pm Post subject: |
|
|
Hi, back to this problem again, i have found the ODE example. here is what i have found:
| Code: |
sceGuTexImage(0,64,64,64,metalRibbed_temp);
sceGuTexImage(1,32,32,32,metalRibbedMedium_temp);
sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
sceGuTexEnvColor(0xffff00);
sceGuTexFilter(GU_LINEAR_MIPMAP_LINEAR,GU_LINEAR_MIPMAP_LINEAR); |
it seems here that it loads a 64 by 64 texture and a 32 by 32 texture for mipmapping. my question is however, i have alot of different objects, is passing each objectrender function 8 textures to the textimage function not expensive ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Bytrix
Joined: 14 Sep 2005 Posts: 72 Location: England
|
Posted: Mon Apr 23, 2007 7:28 pm Post subject: |
|
|
| I haven't done much testing, but I wouldn't imagine it would slow it down much as the actual TexImage command simply tells the GU what textures to use at each mipmap level. The actual rendering process will determine which texture to show and I wouldn't imagine it would slow down rendering at all. |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Mon Apr 23, 2007 7:51 pm Post subject: |
|
|
Hi well i tried to let it work but i have some trouble with it.
| Code: | sceGuTexImage(0, ObjMeshParts[i].texture[0]->textureWidth, ObjMeshParts[i].texture[0]->textureHeight, ObjMeshParts[i].texture[0]->textureWidth, (void*)ObjMeshParts[i].texture[0]->data);
sceGuTexImage(1, ObjMeshParts[i].texture[1]->textureWidth, ObjMeshParts[i].texture[1]->textureHeight, ObjMeshParts[i].texture[1]->textureWidth, (void*)ObjMeshParts[i].texture[1]->data);
sceGuTexImage(2, ObjMeshParts[i].texture[2]->textureWidth, ObjMeshParts[i].texture[2]->textureHeight, ObjMeshParts[i].texture[2]->textureWidth, (void*)ObjMeshParts[i].texture[2]->data); |
This should load 3 texture to the mipmap function right ? Well it does not work I get a data error (psplink) when i remove the third mipmaplevel so commenting the sceGuTexImage(2,... it works fine (well my level is rendered.)
the way i load my textures in an array is as follows:
| Code: | sprintf(sBuffer, "%s",Textures[iNumberOfGroups]);
ObjMeshParts[iNumberOfGroups].texture[0] = loadImage(sBuffer);
if (ObjMeshParts[iNumberOfGroups].texture[0] == NULL) { return -4; }
char * pch;
pch = strtok(sBuffer,".");
// add the other files.
sprintf(sBuffer, "%s1.png",pch);
ObjMeshParts[iNumberOfGroups].texture[1] = loadImage(sBuffer);
sprintf(sBuffer, "%s2.png",pch);
ObjMeshParts[iNumberOfGroups].texture[2] = loadImage(sBuffer); |
the texturestring is loaded from a material, lets say "texture.png"
then i create the names of the two levels extra "texture1.png" and "texture2.png" all these files are in the folder I specify and it works for the "texture.png" and the "texture1.png" but as soon as i add the "texture2.png" I get the error in my rendering sub (because when i load three texture but only use 2 of them in the rendering function it does not crash, so i guess there is a problem that the third texture is not loaded correctly or that the file can't be located. however i have gone through my dir and everything is as it should :S
any ideas ?? (i hope i have explained it correctly and clearly _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Bytrix
Joined: 14 Sep 2005 Posts: 72 Location: England
|
Posted: Mon Apr 23, 2007 11:13 pm Post subject: |
|
|
The only thing I can think is that you have not allowed enough mipmap levels in your sceGuTexMode call? The second parameter is the number of mipmap levels (so you should set it to 2).
eg:
| Code: | sceGuTexMode(GU_PSM_8888,2,0,0); // 2 levels mipmap
sceGuTexImage(0,128,128,128,texture128);
sceGuTexImage(1,64,64,64,texture64);
sceGuTexImage(2,32,32,32,texture32);
sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB); |
from: http://forums.ps2dev.org/viewtopic.php?t=6701&view=next&sid=328ab16eb9b72517b65afd3616da57ec |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Mon Apr 23, 2007 11:31 pm Post subject: |
|
|
Hmmm thats too bad :S (thanks for the reply though) I already had that :S
here is what i have entirely:
| Code: | void Obj::Render(float x, float y, float z, float turn) {
matrix_identity((float*)&world);
if (turn != 0) {
matrix_identity((float*)&tmpworld);
matrix_rotate((float*)&tmpworld,0,turn,0);
matrix_multiply((float*)&world, (float*)&world, (float*)&tmpworld);
}
matrix_identity((float*)&tmpworld);
matrix_translate((float*)&tmpworld,x,y,z);
matrix_multiply((float*)&world, (float*)&tmpworld, (float*)&world);
sceGuSetMatrix(GU_MODEL,&world);
sceGuTexMode(GU_PSM_8888, 2 ,0 ,0); // 2 mipmaplevels
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
//sceGuTexFilter(GU_LINEAR, GU_LINEAR);
sceGuTexFilter(GU_LINEAR_MIPMAP_LINEAR,GU_LINEAR_MIPMAP_LINEAR);
sceGuTexScale(1.0f, 1.0f);
//sceGuTexOffset(0.0f, 0.0f);
int i;
for (i=0;i<iNumberOfParts;i++)
{
sceGuTexImage(0, ObjMeshParts[i].texture[0]->textureWidth, ObjMeshParts[i].texture[0]->textureHeight, ObjMeshParts[i].texture[0]->textureWidth, (void*)ObjMeshParts[i].texture[0]->data);
sceGuTexImage(1, ObjMeshParts[i].texture[1]->textureWidth, ObjMeshParts[i].texture[1]->textureHeight, ObjMeshParts[i].texture[1]->textureWidth, (void*)ObjMeshParts[i].texture[1]->data);
sceGuTexImage(2, ObjMeshParts[i].texture[2]->textureWidth, ObjMeshParts[i].texture[2]->textureHeight, ObjMeshParts[i].texture[2]->textureWidth, (void*)ObjMeshParts[i].texture[2]->data);
sceGuDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,ObjMeshParts[i].iFaces*3,0,ObjMeshParts[i].Vertices);
}
return;
}; |
maybe someone can get the error from this :S _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Bytrix
Joined: 14 Sep 2005 Posts: 72 Location: England
|
Posted: Mon Apr 23, 2007 11:40 pm Post subject: |
|
|
Try putting in some debugging lines to check if (void*)ObjMeshParts[i].texture[2]->data is null ? and check the rest of ObjMeshParts[i].texture[2] to see that it's width and height are set properly..
Also, are the textures all 32bit? |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Apr 24, 2007 12:18 am Post subject: |
|
|
hi, well not all textures are physically 32 bit, most of them are 24 bit but that does not seem to be a problem because using 1 level of mipmap works fine also 24 and 32 bit mixed.
Both checking wheter the data of the texture is null when loaded and when used seems not to be the problem. :S
I have tried to just load the zero texture as the zero mipmap, the first texture to the first AND the second mipmap but that also gave an error (also bus error data)
I have not looked into the width of the textures but speaking of that, i have a question about it. Every texture has a different starting dimension. Some start at 512x512, some at 256x256 and some other 128x128. So this results in different stage on example:
0: 512x512
1: 256x256
2: 128x128
and some other
0:128x128
1:64x64
2:32x32
does this have any bad influence ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|