Forum

Skies and 3D ness

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Re: Skies and 3D ness

Postby taniwha » Tue Oct 23, 2012 3:52 am

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/
taniwha
 
Posts: 399
Joined: Thu Jan 14, 2010 7:11 am

Re: Skies and 3D ness

Postby mh » Tue Oct 23, 2012 5:43 pm

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
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Skies and 3D ness

Postby Spike » Tue Oct 23, 2012 6:53 pm

one of q2's infostrings controls rotation of the skybox... spinny skies. :)
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Skies and 3D ness

Postby taniwha » Wed Oct 24, 2012 9:18 am

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/
taniwha
 
Posts: 399
Joined: Thu Jan 14, 2010 7:11 am

Previous

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest