GArt
GArt

Reputation: 25

Cannot use cubemap and 2D texture at the same time

Creates a shadow map with a 2D texture and the cube map contains the radiance. When I fetch the values from each and render, they are displayed correctly. However, when I calculate the two values, only the glClearColor() color is displayed and the object disappears.

layout(location = 0) out vec4 color;

in vec2 ShadowTexCoord;

uniform sampler2D ShadowMap;
uniform samplerCube CubeMap;

void main() {
  color = texture2D(ShadowMap, ShadowTexCoord);
}

This result displays the area illuminated by direct light.

layout(location = 0) out vec4 color;

in vec2 ShadowTexCoord;

uniform sampler2D ShadowMap;
uniform samplerCube CubeMap;

void main() {
  color = texture(CubeMap, WorldPosition - CubePos);
}

This result displays the radiance value obtained in the pre-calculation.

layout(location = 0) out vec4 color;

in vec2 ShadowTexCoord;

uniform sampler2D ShadowMap;
uniform samplerCube CubeMap;

void main() {
  color = texture2D(ShadowMap, ShadowTexCoord) * texture(CubeMap, WorldPosition - CubePos);
}

This result should be displayed only for the radiance value in the range illuminated by direct light. Both of them give the correct result, but when I calculate their each values the only result is glClearColor().

What are the possible factors?

Upvotes: 2

Views: 730

Answers (1)

derhass
derhass

Reputation: 45332

You need to use different texture units for your two textures. Even if each texture unit in the GL has a different binding slot for the different texture types (1D,2D,3D,Cube,1D Array, 2D Array, Cube Array and what ever), only one texture can be accessed via each texture unit during the draw call (meaning all texture accesses you're doing in all of the shader stages).

So it is fine if you have both a 2D texture and a cube map bount to the unit 0, and do one draw call which acceses unit 0 via sampler2D, and then switch to a program which accesses unit 0 via samplerCube, but it will fail as soon as a program tries to access unit 0 by more than one sampler type.

Upvotes: 2

Related Questions