Skies and 3D ness

Discuss programming topics for the various GPL'd game engine sources.
taniwha
Posts: 401
Joined: Thu Jan 14, 2010 7:11 am
Contact:

Re: Skies and 3D ness

Post by taniwha »

Texture matrix? Don't think I knew about that one (though I was aware of there being more than just the MVP matrix), but then, I was concentrating on EGL stuff. I'll have to take another look to see what's available.
Leave others their otherness.
http://quakeforge.net/
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Skies and 3D ness

Post by mh »

Texture matrix. :)

The civilized way to handle skybox rotation and orientation. Of course, if you're using shaders you just load a new matrix as a uniform and multiply your texcoords by that.

Code: Select all

// common
INOUTTYPE vec4 texcoords;

#ifdef VERTEXSHADER
uniform mat4 localMatrix;
uniform mat4 skymatrix;

layout(location = 0) in vec4 position;

void SkyVS ()
{
	gl_Position = localMatrix * position;
	texcoords = skymatrix * position;
}
#endif


#ifdef FRAGMENTSHADER
uniform samplerCube skydiffuse;

out vec4 fragColor;

void SkyFS ()
{
	fragColor = texture (skydiffuse, texcoords.xyz);
}
#endif

Code: Select all

void RSky_BeginFrame (void)
{
	glmatrix skymatrix = {0, 0, 1, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1};

	GL_RotateMatrix (&skymatrix, r_newrefdef.time * skyrotate, skyaxis[0], skyaxis[2], skyaxis[1]);
	GL_TranslateMatrix (&skymatrix, -r_origin[0], -r_origin[1], -r_origin[2]);

	glProgramUniformMatrix4fv (gl_skycubeprog, u_skytexturematrix, 1, GL_FALSE, skymatrix.m16);
}

Code: Select all

// load images in this order
char *suf[6] = {"ft", "bk", "up", "dn", "rt", "lf"};

// load cubemap faces in this order
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB8, size, size, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, faces[i].data);
I think that resolves the whole skybox issue; no need for flip/mirror/etc of image data and everything is oriented correctly and nice and fast and clean.
Last edited by mh on Tue Oct 23, 2012 8:58 pm, edited 1 time in total.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Skies and 3D ness

Post by Spike »

one of q2's infostrings controls rotation of the skybox... spinny skies. :)
taniwha
Posts: 401
Joined: Thu Jan 14, 2010 7:11 am
Contact:

Re: Skies and 3D ness

Post by taniwha »

QF actually supports spinning skies (glsl only, but with no run-time control yet). Somewhere between 0.2 and 0.4 radians/second made me feel a little ill.
Leave others their otherness.
http://quakeforge.net/
Post Reply