Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rendering a cube map as a 2D texture.

578 views
Skip to first unread message

VelociChicken

unread,
Feb 17, 2013, 8:47:03 AM2/17/13
to
Hi, I've rendered my environment code into a cube map, and now I want to
display the six panels in the traditional cross-roads fashion just to
view them in 2D.
But I can't seem to do it properly, I've got something like this:


// The first line sets the Uniform of a sampler2D in the shader
...
glUniform1i(shaders->progBasicTexture.GetUniform("texture2D"), 0);
glActiveTextureARB(GL_TEXTURE0_ARB);
// I just want to view POS_X for example...
glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, cubeMapTextureID);
...
// Render a quad to the screen

I'm getting a disjointed white brick brick wall effect, which is
completely unconnected and random.

The rest of the code appears to work OK, and has been tested with other
normal 2D textures.

Is possible to render any side of a cube map on the screen as a normal
texture, or do I have to reference it as a cube map in the shader to
access it?

Thanks.
Dave.







Nobody

unread,
Feb 19, 2013, 1:06:54 AM2/19/13
to
On Sun, 17 Feb 2013 13:47:03 +0000, VelociChicken wrote:

> Hi, I've rendered my environment code into a cube map, and now I want to
> display the six panels in the traditional cross-roads fashion just to view
> them in 2D.
> But I can't seem to do it properly, I've got something like this:
>
>
> // The first line sets the Uniform of a sampler2D in the shader ...
> glUniform1i(shaders->progBasicTexture.GetUniform("texture2D"), 0);
> glActiveTextureARB(GL_TEXTURE0_ARB);
> // I just want to view POS_X for example...
> glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, cubeMapTextureID);
> ...
> // Render a quad to the screen

IIUC: you can't use a single face of a cube map as a normal 2D texture for
rendering. The face-specific targets exist for use by glTexImage2D,
glGetTexImage2D, etc. For rendering, you have to bind an entire cube map
to the GL_TEXTURE_CUBE_MAP target.

> Is possible to render any side of a cube map on the screen as a normal
> texture, or do I have to reference it as a cube map in the shader to
> access it?

I believe so. Alternatively, you could just copy the data from the faces
into normal 2D textures.

VelociChicken

unread,
Feb 19, 2013, 10:37:26 AM2/19/13
to
Thanks for clearing that up, it's slightly annoying but I can live with
it! :)

There is one thing I noticed when rendering my world to the cube is that
I had to rotate (roll) the camera 180 degrees for the horizontal faces
and +-90 degrees for the vertical (Y) views, just to get it orientated
and joined up correctly. This isn't mentioned anywhere on the Net it seems.
To test it, I'm using a single quad covering the screen and accessing
the cube map like this:-

Frag shader:-

// The texST goes from 0,0 to 1,1 across the entire screen.

vec2 texel = (-1.0+2.0*texST); // Get it in 2D -1 to +1 range

vec3 dir = vec3(texel, tanFOV); // Get a 3D ray using the
projection FOV as Z.
dir.x *= aspectRatio;
dir *= cameraMatrix; // Rotate it to the camera's angle
dir = normalize(dir);
vec3 colour = textureCube(EnvironmentCube, dir).xyz;

It works perfectly, but only if I rotate the cube map faces as mentioned
above. Is that a standard 'problem'?

Thanks,
Dave.































Nobody

unread,
Feb 22, 2013, 10:50:27 AM2/22/13
to
On Tue, 19 Feb 2013 15:37:26 +0000, VelociChicken wrote:

> There is one thing I noticed when rendering my world to the cube is that I
> had to rotate (roll) the camera 180 degrees for the horizontal faces and
> +-90 degrees for the vertical (Y) views, just to get it orientated and
> joined up correctly. This isn't mentioned anywhere on the Net it seems.

> It works perfectly, but only if I rotate the cube map faces as mentioned
> above. Is that a standard 'problem'?

The section on "Cube Map Texture Selection" in the specification has the
following table:

Major Axis
Direction | Target | sc | tc | ma
----------+-----------------------------+-----+-----+---
+rx | TEXTURE_CUBE_MAP_POSITIVE_X | -rz | -ry | rx
-rx | TEXTURE_CUBE_MAP_NEGATIVE_X | rz | -ry | rx
+ry | TEXTURE_CUBE_MAP_POSITIVE_Y | rx | rz | ry
-ry | TEXTURE_CUBE_MAP_NEGATIVE_Y | rx | -rz | ry
+rz | TEXTURE_CUBE_MAP_POSITIVE_Z | rx | -ry | rz
-rz | TEXTURE_CUBE_MAP_NEGATIVE_Z | -rx | -ry | rz

The section and table numbers vary between versions (in 4.3 "core", it's
table 8.18 in section 8.13).

0 new messages