PDA

View Full Version : Cubemap texcoords for skybox?



Leadwerks
08-06-2007, 04:32 PM
I am attempting to render a skybox onto level geometry objects. I am having difficulty with the texture mapping coordinates for the cube. Basically the tex coord should just be the vector between the camera positions and vertex positions, both in global space.

vert:

void main(void) {
gl_Position = ftransform();
gl_TexCoord[0].xyz = ???;
gl_FrontColor=gl_Color;
}frag:

uniform samplerCube cubemap;

void main(void) {
gl_FragColor = textureCube(cubemap,gl_TexCoord[0].xyz) * gl_Color;
}I actually just want something that duplicates this FFP code, but in GLSL:

glenable GL_TEXTURE_GEN_S
glenable GL_TEXTURE_GEN_T
glenable GL_TEXTURE_GEN_R
glTexGeni GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR
glTexGeni GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR
glTexGeni GL_R,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR
gltexgenfv GL_S,GL_OBJECT_PLANE,[1.0,0.0,0.0,-camera.mat.grid[3,0]]
gltexgenfv GL_T,GL_OBJECT_PLANE,[0.0,1.0,0.0,-camera.mat.grid[3,1]]
gltexgenfv GL_R,GL_OBJECT_PLANE,[0.0,0.0,1.0,-camera.mat.grid[3,2]]Thanks in advance.

jra101
08-07-2007, 10:11 AM
The equivalent vertex shader code for that glTexGen setup is:

gl_TexCoord[0].s = dot(gl_Vertex, gl_ObjectPlaneS[0]);
gl_TexCoord[0].t = dot(gl_Vertex, gl_ObjectPlaneT[0]);
gl_TexCoord[0].p = dot(gl_Vertex, gl_ObjectPlaneR[0]);
gl_TexCoord[0].q = dot(gl_Vertex, gl_ObjectPlaneQ[0]);

Leadwerks
08-07-2007, 10:27 AM
Thanks.