Advertising (This ad goes away for registered users. You can Login or Register)

Mip mapping sample

Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Locked
Mills
Posts: 36
Joined: Sat Aug 02, 2014 10:09 am

Mip mapping sample

Post by Mills »

Hi.

Anyone got mip mapping working on pspsdk?.

I just did not find any working code... If someone is interested this might help.

The following code is supposed to work (from the homebrew game kurok), but it just displays the first texture.

I loaded the textures so that pixel data is at texturedata0 and texturedata1. Textures were also swizzled.

Code: Select all

sceGuTexLevelMode(GU_TEXTURE_CONST,-5); //I don't know if this is needed
sceGuTexMode(GU_PSM_8888,1, 0,1); //Second parameter sets 1 mip map level, last parameter activates swizzled textures.
sceGuTexFilter(GU_LINEAR_MIPMAP_LINEAR, GU_LINEAR_MIPMAP_LINEAR);
sceGuTexImage(0,256,256,256, &texturedata0);
sceGuTexImage(1,128,128,128, &texturedata1);
Hope somebody finds this usefull and makes it work.

Thanks.
Advertising
RedLikeRoses
Posts: 98
Joined: Fri Jun 17, 2016 2:37 am
Location: Idk, I'm lost.

Re: Mip mapping sample

Post by RedLikeRoses »

Take this example of functioning mipmaps:

Code: Select all


//pWidth, pHeight, are power of 2 width and height.
inline void bindMipMaps(Texture* mipmap) {
		sceGuTexMode(colorMode, 2, 0, swizzled); //ColorMode and Swizzled are of the current texture
		sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); //Doesn't necessarily need to be set. Modulation is useful if you know how to use it.
		sceGuTexOffset(0.0f, 0.0f); //No offsets
		sceGuTexWrap(GU_CLAMP, GU_CLAMP); //Doesn't matter
		sceGuTexLevelMode(GU_TEXTURE_AUTO, 0.0f); //This should work
		sceGuTexFilter(GU_NEAREST_MIPMAP_NEAREST, GU_NEAREST); //Set your filters according to what you want

                //The mipmaps are for the long range, as doing only 0 and 1 would make them appear too close and result in weird experiences.

		sceGuTexImage(0, pWidth, pHeight, pWidth, data); 
		sceGuTexImage(1, pWidth, pHeight, pWidth, data);
		sceGuTexImage(2, mipmap->pWidth, mipmap->pHeight, mipmap->pWidth, mipmap->data);
}
Advertising
Mills
Posts: 36
Joined: Sat Aug 02, 2014 10:09 am

Re: Mip mapping sample

Post by Mills »

RedLikeRoses wrote: Tue Jul 09, 2019 1:34 pm Take this example of functioning mipmaps:

Code: Select all


//pWidth, pHeight, are power of 2 width and height.
inline void bindMipMaps(Texture* mipmap) {
		sceGuTexMode(colorMode, 2, 0, swizzled); //ColorMode and Swizzled are of the current texture
		sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); //Doesn't necessarily need to be set. Modulation is useful if you know how to use it.
		sceGuTexOffset(0.0f, 0.0f); //No offsets
		sceGuTexWrap(GU_CLAMP, GU_CLAMP); //Doesn't matter
		sceGuTexLevelMode(GU_TEXTURE_AUTO, 0.0f); //This should work
		sceGuTexFilter(GU_NEAREST_MIPMAP_NEAREST, GU_NEAREST); //Set your filters according to what you want

                //The mipmaps are for the long range, as doing only 0 and 1 would make them appear too close and result in weird experiences.

		sceGuTexImage(0, pWidth, pHeight, pWidth, data); 
		sceGuTexImage(1, pWidth, pHeight, pWidth, data);
		sceGuTexImage(2, mipmap->pWidth, mipmap->pHeight, mipmap->pWidth, mipmap->data);
}
Thank you very much for answering.

Unfortunately, it didn't work, it just shows sceGuTexImage 0. I'm starting to think this is broken in the sdk :o, or I'm missing something important.

I made a very simple test that draws a square with a texture, and checked texture data is loaded:

Code: Select all

// setup texture
sceGuTexMode(GU_PSM_8888, 2, 0, 0); 
sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA);
sceGuTexOffset(0.0f,0.0f);
sceGuTexWrap(GU_CLAMP, GU_CLAMP);
sceGuTexLevelMode(GU_TEXTURE_AUTO, 0.0f); 
sceGuTexFilter(GU_NEAREST_MIPMAP_NEAREST, GU_NEAREST);
		
sceGuTexImage(0,32,32,32,mip0);
sceGuTexImage(1,32,32,32,mip0);
sceGuTexImage(2,16,16,16,mip1);
		
sceGuColor(0xffffffff);
sceGuAmbientColor(0xffffffff);

//draw a plane					
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,2*3,0,vertices);

The plane moves away from cam, and nothing happens, it always shows the same texture.
RedLikeRoses
Posts: 98
Joined: Fri Jun 17, 2016 2:37 am
Location: Idk, I'm lost.

Re: Mip mapping sample

Post by RedLikeRoses »

Hm... that is very strange...
RedLikeRoses
Posts: 98
Joined: Fri Jun 17, 2016 2:37 am
Location: Idk, I'm lost.

Re: Mip mapping sample

Post by RedLikeRoses »

Have you tried looking at the textures at an angle, because sometimes the mipmapping only shows then
Mills
Posts: 36
Joined: Sat Aug 02, 2014 10:09 am

Re: Mip mapping sample

Post by Mills »

RedLikeRoses wrote: Wed Jul 10, 2019 12:16 am Have you tried looking at the textures at an angle, because sometimes the mipmapping only shows then
Yes I tried that.

This is the source.
MIPMAPPING.7z
(16.62 KiB) Downloaded 513 times
.

The images are included as colour arrays in the main.c, and also I included the original pngs.
I tried several image sizes from 512x512 to 8x8 (4x4 images don't work), I also tried the real psp and ppsspp emulator... Nothing seems to work.
Mills
Posts: 36
Joined: Sat Aug 02, 2014 10:09 am

Re: Mip mapping sample

Post by Mills »

I set the texture like this:

Code: Select all

sceGuTexMode(tex->TexFormat,2, 0, 0);
sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); know how to use it.
sceGuTexLevelMode(GU_TEXTURE_AUTO, 0.0f);
sceGuTexFilter(GU_LINEAR_MIPMAP_LINEAR, GU_LINEAR); //Set your filters according to what you want
sceGuTexImage(0, tex->rw, tex->rh, tex->Width, &imagedata);
sceGuTexImage(1, tex->rw>>1, tex->rh>>1, tex->Width>>1, &imagedata);
sceGuTexImage(2, tex->rw>>2, tex->rh>>2, tex->Width>>2, &imagedata);

I could see the texture changes with the distance :). Of course it looks bad because it is using part of the same texture for the mip mapping and I could not make it work using more than one texture.

Well, at least I made it work :).
Mills
Posts: 36
Joined: Sat Aug 02, 2014 10:09 am

Re: Mip mapping sample

Post by Mills »

Well, I did it!. Thanks a lot!.
MIPMAPPING.7z
(43.03 KiB) Downloaded 478 times
It only works if this part of the code is correctly comfigured so that every mip map texture is half the size of the previous one.

Code: Select all

sceGuTexImage(0,128,128,128,mip0_start);
sceGuTexImage(1,64,64,64,mip1_start);
sceGuTexImage(2,32,32,32,mip2_start);
Below 32 pixels it won't work.

I'm also uploading it to pspsdk github.

Solved!
Last edited by Mills on Wed Jul 10, 2019 6:25 pm, edited 1 time in total.
RedLikeRoses
Posts: 98
Joined: Fri Jun 17, 2016 2:37 am
Location: Idk, I'm lost.

Re: Mip mapping sample

Post by RedLikeRoses »

Yes, that's generally how mipmaps work. The more levels of mipmapping you have, the smaller the textures must be.
Locked

Return to “Programming and Security”