Texture coordinates generation, projection. Unknown states.

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Texture coordinates generation, projection. Unknown states.

Post by ReJ »

Hi,


Recently, while playing with texture projection, I've discovered the following things:

1) sceGuEnable( 19 )
does flipping of the normal, which affects both lighting ant texture projection

2) sceGuTexMapMode( arg0, arg1, arg2 )
arg0 (0-3?):
0 - disables texture projection, enables sceGuTexOffset/Scale.
1 - enables texture coordinates generation. Uses matrix (spcified as GU_TEXTURE) to transform source 2d/3d vector. Source vector is a vertex component specified using sceGuTexProjMapMode. Disables sceGuOffset/Scale. Strangely enough, source vectors are in object space, _not_ post-transformed ones.
2 - ? (sampled texels seems to be uniform other the poly, but somewhat darker than pure white)
3 - ?
arg1, arg2: ??? (no effect)

sceGuTexProjMapMode( arg0 )
arg0 (0-3) source for texture coord calculation, is multiplied by GU_TEXTURE and projected into 2d if necessary:
0 - position in object space, resulting 3d vector is projected into 2d
1 - object UV
2 - normalized normal, resulting 3d vector is projected into 2d
3 - not-normalized normal, resulting 3d vector is projected into 2d

3) sceGuEnable( 15 )
uses post-transformed and projected object position as a 2d texture coordinates. Omits both UV specified in vertices and generated texture coordinates. Is not affected by sceGuTexOffset/Scale or GU_TEXTURE.

4) sceGuEnable( 21 )
seems to multiply resulting fragment (after applying texture function) by 2.


Hope that provides some usefull information.
adresd
Posts: 43
Joined: Sat Jan 17, 2004 11:32 am

Post by adresd »

2) sceGuTexMapMode( arg0, arg1, arg2 )
arg0 (0-3?):
arg0 = 2 seems to be envmap mode

still playing with it
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Post by ReJ »

adresd wrote: arg0 = 2 seems to be envmap mode
Yeah, seems to be the envmap mode. Although the envmap matrix setup is a bit strange, that's what I've figured out:

The envmap matrix (2x3) is specified as a combination of 2 columns. Columns can be set using sceGuLight() [sic!] as a light position (maybe it's some kind of error in pspgulib?). So 4 different columns can be specified. The actual envmap matrix is assembled specifying column indices using sceGuTexMapMode().
The UV coordinates (calculated by GU/GE from normals) are multiplied by the envmap matrix (2x3) to generate actual texture UV coords.

sceGuTexMapMode( arg0, arg1, arg2 )
arg0: 2 - envmap mode
arg1 (0-3): index of the 1st column for the envmap matrix (2x3)
arg2 (0-3): index of the 2nd column


it may look abit strange, but it works:

Code: Select all

	ScePspFVector3 columns[4] = {
		{ 0.707f, 0.707f, 0.0f },   // cos(a), sin(a), tx
		{ -0.707f, 0.707f, 0.0f },  // -sin(a), cos(a), ty
		{ 0.86f, 0.5f, 0.0f },
		{ -0.5f, 0.86f, 0.0f }
	};
	sceGuLight( 0, GU_DIRECTIONAL, GU_DIFFUSE, &columns[0] );
	sceGuLight( 1, GU_DIRECTIONAL, GU_DIFFUSE, &columns[1] );
	sceGuLight( 2, GU_DIRECTIONAL, GU_DIFFUSE, &columns[2] );
	sceGuLight( 3, GU_DIRECTIONAL, GU_DIFFUSE, &columns[3] );

	sceGuTexProjMapMode( 0 );
	sceGuTexMapMode( 2, 0, 1 ); // rotate envmap 45 degrees
	//sceGuTexMapMode( 2, 2, 3 ); // rotate envmap 30 degrees
adresd
Posts: 43
Joined: Sat Jan 17, 2004 11:32 am

Post by adresd »

Nice work, that works nicely :)
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Post by ReJ »

Thanks :)

I did a sample showing environment mapping:
http://rej.50megs.com/psp/envmap
Last edited by ReJ on Sat Jul 23, 2005 10:54 pm, edited 1 time in total.
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

Good work! I'll update GU right away with this information, and I'll update your sample to use these new defines aswell.

The new defines will be:

Code: Select all

/* States*/
#define GU_FACE_NORMAL_REVERSE  (19)
#define GU_FRAGMENT_2X          (21)

/* Texture Map Mode */
#define GU_TEXTURE_COORDS       (0)
#define GU_TEXTURE_MATRIX       (1)
#define GU_ENVIRONMENT_MAP      (2)

/* Texture Projection Map Mode */
#define GU_POSITION             (0)
#define GU_UV                   (1)
#define GU_NORMALIZED_NORMAL    (2)
#define GU_NORMAL               (3)
If you think they should be named differently, let me know.
GE Dominator
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Re: Texture coordinates generation, projection. Unknown stat

Post by jsgf »

ReJ wrote: 2 - ? (sampled texels seems to be uniform other the poly, but somewhat darker than pure white)
Could it be some other lighting thing? Shadows? I don't suppose there's any support for depth textures?
ReJ
Posts: 25
Joined: Sun Apr 04, 2004 12:32 am
Location: Lithuania, Vilnius
Contact:

Re: Texture coordinates generation, projection. Unknown stat

Post by ReJ »

jsgf wrote:
ReJ wrote: 2 - ? (sampled texels seems to be uniform other the poly, but somewhat darker than pure white)
Could it be some other lighting thing? Shadows? I don't suppose there's any support for depth textures?
As it is already discovered, 2 is an environment mapping mode.
Post Reply