From 6e2d625d3682262833499536b2e11d9c9002ac37 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 12 Jan 2012 15:13:19 +0900 Subject: [PATCH] Load the skybox faces into the correct cubemap slots. Quake and GL are rotated relative to each other, so care must be taken when loading and rendering. --- libs/video/renderer/glsl/glsl_bsp.c | 6 ++++-- libs/video/renderer/glsl/quakeskb.frag | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index 6c4007cf1..2bd082d75 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -1181,14 +1181,16 @@ R_LoadSkys (const char *sky) { const char *name; int i; + // NOTE: quake's world and GL's world are rotated relative to each other + // quake has x right, y in, z up. gl has x right, y up, z out static const char *sky_suffix[] = { "ft", "bk", "lf", "rt", "up", "dn"}; static int sky_target[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, - GL_TEXTURE_CUBE_MAP_POSITIVE_Z, - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, }; if (!sky || !*sky) diff --git a/libs/video/renderer/glsl/quakeskb.frag b/libs/video/renderer/glsl/quakeskb.frag index 067e6a01d..10146e843 100644 --- a/libs/video/renderer/glsl/quakeskb.frag +++ b/libs/video/renderer/glsl/quakeskb.frag @@ -8,5 +8,10 @@ main (void) vec3 dir = direction; dir *= inversesqrt (dot (dir, dir)); - gl_FragColor = textureCube(sky, dir); + + // NOTE: quake's world and GL's world are rotated relative to each other + // quake has x right, y in, z up. gl has x right, y up, z out + // The textures are loaded with GL's z (quake's y) already negated, so + // all that's needed here is to swizzle y and z. + gl_FragColor = textureCube(sky, dir.xzy); }