Mipmapping and swizzling
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
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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.
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.
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.
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.
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 !!
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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 ?
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
Alexander Berl
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.
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.
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
greets ghoti
My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
The SDK is installed with the toolchain in /usr/local/pspdev. The samples are in /usr/local/pspdev/psp/sdk/samples.
You can also find them on SVN:
http://svn.ps2dev.org/listing.php?repna ... rev=0&sc=0
You can also find them on SVN:
http://svn.ps2dev.org/listing.php?repna ... rev=0&sc=0
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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
>>> http://wiki.ps2dev.org/psp:ge_faq
I don't know why anyone didn't point you to this sooner ;>
gl
<,<;
Hi, back to this problem again, i have found the ODE example. here is what i have found:
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 ?
Code: Select all
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);
My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Hi well i tried to let it work but i have some trouble with it.
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:
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
Code: Select all
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);
the way i load my textures in an array is as follows:
Code: Select all
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);
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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:
from: http://forums.ps2dev.org/viewtopic.php? ... 3616da57ec
eg:
Code: Select all
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);
Hmmm thats too bad :S (thanks for the reply though) I already had that :S
here is what i have entirely:
maybe someone can get the error from this :S
here is what i have entirely:
Code: Select all
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;
};
My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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 ?
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php