Setting Indirect Texture Matrix

Post Reply
Samson
Posts: 35
Joined: Mon May 19, 2008 8:05 am

Setting Indirect Texture Matrix

Post by Samson » Sat May 24, 2008 10:28 pm

As mentioned here this is a quick and dirty function to experiment with the indirect texture matrix:

Code: Select all

void GX_SetIndirectMatrix(u8 indtexid, int ma, int mb, int mc, int md, int me, int mf, int s)
{
        switch (indtexid) {
                case GX_ITM_0: {
                        u32 val1 = (0x06000000|(_SHIFTL(s,22,2))|(_SHIFTL(mb,11,11))|(_SHIFTL(ma,0,11)));
                        u32 val2 = (0x07000000|(_SHIFTL(s>>2,22,2))|(_SHIFTL(md,11,11))|(_SHIFTL(mc,0,11)));
                        u32 val3 = (0x08000000|(_SHIFTL(s>>4,22,2))|(_SHIFTL(mf,11,11))|(_SHIFTL(me,0,11)));
                        GX_LOAD_BP_REG(val1);
                        GX_LOAD_BP_REG(val2);
                        GX_LOAD_BP_REG(val3);
                        break;
                }
                case GX_ITM_1: {
                        u32 val1 = (0x09000000|(_SHIFTL(s,22,2))|(_SHIFTL(mb,11,11))|(_SHIFTL(ma,0,11)));
                        u32 val2 = (0x0a000000|(_SHIFTL(s>>2,22,2))|(_SHIFTL(md,11,11))|(_SHIFTL(mc,0,11)));
                        u32 val3 = (0x0b000000|(_SHIFTL(s>>4,22,2))|(_SHIFTL(mf,11,11))|(_SHIFTL(me,0,11)));
                        GX_LOAD_BP_REG(val1);
                        GX_LOAD_BP_REG(val2);
                        GX_LOAD_BP_REG(val3);
                        break;
                }
                case GX_ITM_2: {
                        u32 val1 = (0x0c000000|(_SHIFTL(s,22,2))|(_SHIFTL(mb,11,11))|(_SHIFTL(ma,0,11)));
                        u32 val2 = (0x0d000000|(_SHIFTL(s>>2,22,2))|(_SHIFTL(md,11,11))|(_SHIFTL(mc,0,11)));
                        u32 val3 = (0x0e000000|(_SHIFTL(s>>4,22,2))|(_SHIFTL(mf,11,11))|(_SHIFTL(me,0,11)));
                        GX_LOAD_BP_REG(val1);
                        GX_LOAD_BP_REG(val2);
                        GX_LOAD_BP_REG(val3);
                        break;
                }
        }
}
Is anyone working on the GXSetTevIndBump* functions? Are they just utility functions on top of the existing functions, or do they work on some undocumented registers?
And I'm a bit confused about the "s" part of the function above: Is it "officially" part of the matrix, or does it refer to Block 525 in Figure 15? And in my experiments GX_SetIndTexCoordScale didn't seem to make any difference to the coordinates. Does it scale the incoming tex coordinates, or the outgoing coordinates (Block 252)?

Samson
Posts: 35
Joined: Mon May 19, 2008 8:05 am

Re: Setting Indirect Texture Matrix

Post by Samson » Tue Jun 03, 2008 8:46 am

Just to update based on what I learned working on my demo:
The "s" part is controlling the scale of the outgoing coordinates (Block 526), GX_SetIndTexCoordScale seems to be the divider for incoming texcoords.
It is important to enable point sampling for the indirect texture if you want tiling, and to enable point sampling for the direct texture if you don't want to interpolate across tile boundaries. Though I guess you can work with a small gap between tiles instead if you need interpolation.
The indirect texture format is how many bits are used for the offset, and how many bits are used for alphabump: The high bits are offsets, the low bits are alphabump.

Samson
Posts: 35
Joined: Mon May 19, 2008 8:05 am

Re: Setting Indirect Texture Matrix

Post by Samson » Tue Jun 03, 2008 8:08 pm

The latest CVS version contains GX_SetIndTexMatrix (thanks shagkur!), but I can't seem to link it right now:
/opt/local/devkitpro/libogc/lib/cube/libogc.a(lwp.o): In function `__lwp_sysinit':
lwp.c:(.text.__lwp_sysinit+0xd6): undefined reference to `__crtmain'
lwp.c:(.text.__lwp_sysinit+0xde): undefined reference to `__crtmain'
collect2: ld returned 1 exit status
Is that a gamecube-specific problem, or do I need to update newlib or gcc as well?

shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: Setting Indirect Texture Matrix

Post by shagkur » Wed Jun 04, 2008 10:57 am

Hi Samson,

first of all: THANKS for your excellent and detailed explanation on how things work! (maybe you could add those documentation into libogc sometimes?)
The latest libogc CVS only works with r15 release of devkitPPC which is out now! So go and grab it! ;)

regards
shagkur

Samson
Posts: 35
Joined: Mon May 19, 2008 8:05 am

Re: Setting Indirect Texture Matrix

Post by Samson » Sat Jun 07, 2008 6:44 pm

Okay, got it, and after a few tweaks I got it build: on 10.3 I had to install the latest gawk + make, and make sure the script uses them. And the strip failed because it didn't like to be run on scripts (for example powerpc-gekko-embedspu).
I adjusted my demo and it works fine. And the scale factor actually makes sense now: with 5 as scale factor I'm multiplying with 32, which is x2 to scale the 0.5 from the matrix to 1.0, and x16 to scale to tile size.
Now let's see if I can get a fancy bump mapping shader working, and if I can find a good way to integrate indirect texturing into my pixel shader assembler.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests