Cubemaps problem with AMD Graphics

Hi,
I have problems with my shaders, Ill explain my problem:

I am trying to use a cubemap in which I have previously rendered a depthmap for a pointlight even though the struct is called directional light.

If I use the following shader:

#version 450

//Light Numers
#define NR_LIGHTS 8

out vec4 FragColor;

in vec2 uv_model;

//Material Struct
struct Material {
	sampler2D diffuse;
	sampler2D specular;
	sampler2D normal;
	float shininess;
}; 
uniform Material u_material;

//DirectionLight
struct DirectionLight {
	vec3 direction;
	vec3 ambient;
	vec3 diffuse;
	vec3 specular;
	vec3 position;
	float constant;
	float linear;
	float quadratic;
	float cutOff;
	float outerCutOff;
	mat4 matrix;
	sampler2D depthMap;
};
uniform DirectionLight u_directionLight[NR_LIGHTS];

vec3 CalculateDirectionLight(DirectionLight light,vec3 normal, vec3 viewDir);

void main()
{
  vec3 normalizedNormal = vec3(0.0);
  vec3 viewDirection = vec3(0.0);
  vec3 result;
result += CalculateDirectionLight(u_directionLight[0],normalizedNormal,viewDirection);

  FragColor = vec4(result,1.0);
}

vec3 CalculateDirectionLight(DirectionLight light,vec3 normal, vec3 viewDir)
{
  vec3 light_ambient = light.ambient * texture(u_material.diffuse,uv_model).rgb;
  return (vec3(light_ambient));
}

The shader compiles correctly and the scene can be displayed and it is rendering good.

If I use the next shader that only adds a samplerCube to the structure, the shader compiles correctly again, but the scene is not displayed as if the alpha were at zero:

#version 450

//Light Numers
#define NR_LIGHTS 8

out vec4 FragColor;

in vec2 uv_model;

//Material Struct
struct Material {
	sampler2D diffuse;
	sampler2D specular;
	sampler2D normal;
	float shininess;
}; 
uniform Material u_material;

//DirectionLight
struct DirectionLight {
	vec3 direction;
	vec3 ambient;
	vec3 diffuse;
	vec3 specular;
	vec3 position;
	float constant;
	float linear;
	float quadratic;
	float cutOff;
	float outerCutOff;
	mat4 matrix;
	sampler2D depthMap;
	samplerCube depthMapCube; 
};
uniform DirectionLight u_directionLight[NR_LIGHTS];

vec3 CalculateDirectionLight(DirectionLight light,vec3 normal, vec3 viewDir);

void main()
{
  vec3 normalizedNormal = vec3(0.0);
  vec3 viewDirection = vec3(0.0);
  vec3 result;
result += CalculateDirectionLight(u_directionLight[0],normalizedNormal,viewDirection);

  FragColor = vec4(result,1.0);
}

vec3 CalculateDirectionLight(DirectionLight light,vec3 normal, vec3 viewDir)
{
  vec3 light_ambient = light.ambient * texture(u_material.diffuse,uv_model).rgb;
  return (vec3(light_ambient));
}

The funny thing is that this same code in an NVIDIA works correctly in my AMD R9 390X no.

If within the function I comment the line:
vec3 light_ambient = light.ambient * texture (u_material.diffuse, uv_model) .rgb;
and i return any value to the scene now, yes it is rendering.

I have like two weeks trying to fix this does anyone have any idea why is this happening and how can i solve this?

Well, without seeing relevant code we’re just guessing. But if the only difference is adding a sampler uniform which isn’t even being used, check that you don’t have two samplers of different types (e.g. sampler2D and samplerCube) bound to the same texture unit (that should cause the draw call to fail with GL_INVALID_OPERATION). You need to initialise any sampler uniforms which are declared in the shader regardless of whether they’re being used.

Hi, Thanks for your reply!

Yes im getting in AMD a GL_INVALID_OPERATION, in NVIDIA glGetError(); is returning 0.

This is how i set texture:

    for (uint32 x = 0; x < ptr->textureQueue_.size(); x++) {
		setTexture(ptr->textureQueue_[x].newValue, ptr->textureQueue_[x].keyValue.c_str(), x);
	}

    const void Luna::Graphics::Shaders::setTexture(Graphics::TextureResource newTexture, const char     *newChar, const int & index)
    {
    #ifdef OPENGL_RENDER
    	int uniformPosition = glGetUniformLocation(program_, newChar); 
    	if (newTexture.id_ < 10000) {
    		Graphics::GPUManager::bindTextureResource(newTexture, index);//This function call to glActiveTexture(GL_TEXTURE0 + index) and bindtexture.
    		glUniform1i(uniformPosition, index);
    	}
    #endif // OPENGL_RENDER
    }

I’ve been checking and the text units are correctly set, they are totally different for each one of them.

I have discovered that if for example I take “index and add 1” it works correctly now.

    Graphics::GPUManager::bindTextureResource(newTexture, index+1);//This function call to glActiveTexture(GL_TEXTURE0 + index) and bindtexture.
		glUniform1i(uniformPosition, index+1);

Do i need any offset to work with the cubemap?

In my case the index goes in each shader from 0 to the number of texture that exists.

Thanks!

That suggests that one or more of the sampler uniforms is missing from the list. Any sampler uniforms which aren’t explicitly assigned a value with glUniform1i will retain their initial value of zero, and without adding one to the index the first sampler uniform in the list will also have a value of zero.

Note that adding one to the index won’t be sufficient if you have multiple sampler uniforms omitted from the list. The only reliable solution is to ensure that the initialisation of sampler uniforms is exhaustive, with no omissions.

According to the specification, it’s only an error if

(emphasis mine). But the specification isn’t explicit regarding what constitutes an active uniform:

Which may explain the difference between AMD and Nvidia. If the AMD driver makes less effort to eliminate dead code, the variable may be considered active by the AMD driver but not by the Nvidia driver.

@GClements Thank!! you have helped me a lot!.

You were right, the problem is that im using texture unit 0 to render a framebuffer color texture of the actual scene, then in my shader system, i was using the 0 texture unit as initial position for my texture array, writing in this case the texture of my framebuffer, since this is the framebuffer texture i had not use "
glUniform1i"

Thanks for your reply!