Hey,
I successfully built an opengl project on ubuntu 14.04. I wanted to move it to windows now. For some reason the fragment shader doesn’t link…
It can be created, compiled and attached to the program! but for linking, I recieve lots and lots of errors… but only on windows platform.
First, the stats:
Linux Ubuntu 14.04
Window: 1280px * 1024px
GL Version: 3.0 Mesa 10.5.9
GLSL Version: 1.30
Windows
Window: 1280px * 800px
GL Version: 4.5.0 NVIDIA 347.52
GLSL Version: 4.50 NVIDIA
These are the errors:
failed to link shader program:
Fragment infoInternal error: assembly compile error for fragment shader at offset 1350:
– error message –
line 35, column 36: error: invalid local parameter number
line 58, column 18: error: out of bounds array access
line 64, column 24: error: out of bounds array access
line 68, column 23: error: offset for relative array access outside supported range
line 73, column 23: er…
I realize the different graphic cards, but what’s wrong here? How can it work on one computer perfectly and on the other not even work at the linking stage?
Here’s the shader:
///////////////////////////////////////////
///////////////////////////////////////////
// Fragment Shader 3D
///////////////////////////////////////////
///////////////////////////////////////////
#version 150
///////////////////////////////////////////
///////////////////////////////////////////
// Strukturen
///////////////////////////////////////////
///////////////////////////////////////////
struct En_Material
{
sampler2D diffuse;
sampler2D specular;
float shine;
};
struct En_Light
{
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
vec3 position;
int light_kind; // 1 Directional Light, 2 Pointing Light, 3 Spotlight
int light_switcher; // 0 aus, 1 an
float constant;
float linear;
float quadratic;
};
///////////////////////////////////////////
///////////////////////////////////////////
// Globals
///////////////////////////////////////////
///////////////////////////////////////////
in vec2 _uv; // in
in vec3 _normal; // in
in vec3 _frag; // in
uniform vec3 camera; // Kameraposition
uniform En_Material material; // Material
uniform int number_lights; // Anzahl an Lichtern insgesamt
uniform En_Light light[100]; // Lichtstruktur / maximal 100 Lichtquellen!
uniform bool light_affected; // sagt aus, ob Licht bei dem Vertex eine Rolle spielt
out vec4 color;
///////////////////////////////////////////
///////////////////////////////////////////
// Funktionsprototypen
///////////////////////////////////////////
///////////////////////////////////////////
vec4 calc_dir_light(int);
vec4 calc_plight(int);
///////////////////////////////////////////
///////////////////////////////////////////
// Hauptprogramm
///////////////////////////////////////////
///////////////////////////////////////////
void main(void)
{
// output
vec4 sum_color = vec4(0.0f, 0.0f, 0.0f, 0.0f);
vec4 ret_color = vec4(0.0f, 0.0f, 0.0f, 0.0f);
if((texture(material.diffuse, _uv).a < 0.1f) || (texture(material.specular, _uv).a < 0.1f))
{discard;}
else
{
if(!light_affected)
{color = texture(material.diffuse, _uv);}
else
{
for(int i = 0 ; i < number_lights ; i++)
{
if(light[i].light_switcher == 1) // Licht an?
{
switch(light[i].light_kind)
{
case 1: // directional Light
{
ret_color = calc_dir_light(i);
sum_color += ret_color;
} break;
case 2: // pointing Light
{
ret_color = calc_plight(i);
sum_color += ret_color;
} break;
};
}
}
color = sum_color;
}
}
}
///////////////////////////////////////////
///////////////////////////////////////////
// Funktionsdefinition
///////////////////////////////////////////
///////////////////////////////////////////
vec4 calc_dir_light(int i)
{
// Ambient
vec4 ambient = vec4(light[i].ambient, 1.0f) * texture(material.diffuse, _uv);
// Diffuse
vec3 norm = normalize(_normal);
vec3 light_dir = normalize(-(light[i].direction));
float diff = max(dot(norm, light_dir), 0.0f);
vec4 diffuse = vec4(light[i].diffuse, 1.0f) * diff * texture(material.diffuse, _uv);
// Specular
vec3 view_dir = normalize(camera - _frag);
vec3 reflect_dir = reflect(-light_dir, norm);
float spec = pow(max(dot(view_dir, reflect_dir), 0.0f), material.shine);
vec4 specular = vec4(light[i].specular, 1.0f) * spec * texture(material.specular, _uv);
return (ambient + diffuse + specular);
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
vec4 calc_plight(int i)
{
// Ambient
vec4 ambient = vec4(light[i].ambient, 1.0f) * texture(material.diffuse, _uv);
// Diffuse
vec3 norm = normalize(_normal);
vec3 light_dir = normalize(light[i].position - _frag);
float diff = max(dot(norm, light_dir), 0.0f);
vec4 diffuse = vec4(light[i].diffuse, 1.0f) * diff * texture(material.diffuse, _uv);
// Specular
vec3 view_dir = normalize(camera - _frag);
vec3 reflect_dir = reflect(-light_dir, norm);
float spec = pow(max(dot(view_dir, reflect_dir), 0.0f), material.shine);
vec4 specular = vec4(light[i].specular, 1.0f) * spec * texture(material.specular, _uv);
// Pointing Light
float distance = length(light[i].position - _frag);
float attenuation = 1.0f / (light[i].constant + light[i].linear * distance + light[i].quadratic * (distance * distance));
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;
return (ambient + diffuse + specular);
}
Thanks for any help or hint in advance!