Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: error C5060: out can't be used with non-varying color

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4

    error C5060: out can't be used with non-varying color

    Hello.
    Does anyone know why for shaders like...

    Vertex.shader: (recompiled 32 times with difference NUM_LIGHTS for multiple lights)
    Code :
    #version 330 core
     
    layout(location = 0) in vec3 vertexPosition;
    layout(location = 1) in vec3 vertexNormal;
    layout(location = 2) in vec2 vertexTexcoord;
     
    out vec3 gouraud;
    out vec2 texcoord;
     
    uniform mat4 pMatrix; // projection matrix
    uniform mat4 vMatrix; // view matrix
    uniform mat4 mMatrix; // model matrix
    uniform mat3 nMatrix; // mMatrix -> inverted and transposed
     
    #define NUM_LIGHTS 32
    struct Light {
     
    	vec3 ambient;
    	vec3 diffuse;
    	vec3 specular;
    	vec4 position; // w == 0 -> directional
    	vec4 attenuation;
     
    };
    uniform Light lights[NUM_LIGHTS];
     
    struct Material {
     
    	vec3 ambient;
    	vec3 diffuse;
    	vec3 specular;
    	float shininess;
     
    };
    uniform Material material;
     
    void main() {
     
    	vec4 position = vec4(vertexPosition, 1.0);
     
    	vec3 vertex = vec3(mMatrix * position); // vertex in model space
    	vec3 normal = normalize(nMatrix * vertexNormal); // normal in model space
     
    	vec3 finalColor = vec3(0.0, 0.0, 0.0); // phong result
     
    	for(int i = 0; i < NUM_LIGHTS; ++i) {
     
    		if(lights[i].position.w == 0.0) { // directional light
     
    			vec3 lightDirection = normalize(lights[i].position.xyz);
     
    			vec3 N = normalize(normal); // normalize because normal will be interpolated (possible not unit vector)
    			vec3 E = normalize(-vertex);
    			vec3 R = normalize(-reflect(lightDirection, N));
     
    			finalColor += lights[i].ambient; // * material.ambient; // ambient
     
    			float lambert = max(dot(N, lightDirection), 0.0);
     
    			if(lambert > 0.0) {
     
    				finalColor += lights[i].diffuse * material.diffuse * lambert; // diffuse
     
    				float specular = pow(max(0.0, dot(reflect(-lightDirection, N), E)), material.shininess);
    				finalColor += lights[i].specular * material.specular * clamp(specular, 0.0, 1.0); // specular
     
    			}
     
    		}
    		else { // point light
     
    			vec3 lightDirection = lights[i].position.xyz - vertex;
     
    			float lightDistance = length(lightDirection);
     
    			lightDirection = normalize(lightDirection);
     
    			float attenuation = 1.0;
    			if(lights[i].attenuation[0] != 0.0) { // attenuation based on light radius
     
    				attenuation = smoothstep(lights[i].attenuation[0], 0.0, lightDistance);
     
    			}
    			else { // attenuation based on distance
     
    				attenuation = clamp(1.0 /
    								   (lights[i].attenuation[1]				 +
    									lights[i].attenuation[2] * lightDistance +
    									lights[i].attenuation[3] * pow(lightDistance, 2)), 0.0, 1.0);
     
    			}
     
    			finalColor += lights[i].ambient * material.ambient;
     
    			vec3 N = normalize(normal); // normalize because normal will be interpolated (possible not unit vector)
    			float lambert = max(dot(N, lightDirection), 0.0);
     
    			if(lambert > 0.0) {
     
    				finalColor += lights[i].diffuse * material.diffuse * lambert * attenuation; // diffuse
     
    				vec3 E = normalize(-vertex);
    				vec3 R = normalize(-reflect(lightDirection, N));
     
    				float specular = pow(max(0.0, dot(reflect(-lightDirection, N), E)), material.shininess);
    				finalColor += lights[i].specular * material.specular * clamp(specular, 0.0, 1.0) * attenuation; // specular
     
    			}
     
    		}
     
    	}
     
    	gouraud = finalColor;
    	texcoord = vertexTexcoord;
     
    	gl_Position = pMatrix * vMatrix * mMatrix * position;
     
    }

    Fragment.shader:
    Code :
    #version 330 core
     
    in vec3 gouraud;
    in vec2 texcoord;
     
    out vec3 color;
     
    uniform sampler2D diffuseMap;
     
    void main() {
     
    	// color = gouraud * texture(diffuseMap, texcoord).rgb; on 8600GT i have to change texture to texture2D
            color = gouraud * texture2D(diffuseMap, texcoord).rgb;
     
    }

    These shaders are working on intel hd 2500 but aren't working on nVidia GeForce 8600GT and nVidia 710m..
    Log output is: error C5060: out can't be used with non-varying color

    But these shader are compiled correctly on GeForce 8600GT and 710m:
    Vertex.shader:
    Code :
    #version 330 core
     
    layout(location = 0) in vec3 vertexPosition;
     
    uniform mat4 pMatrix;
    uniform mat4 vMatrix;
    uniform mat4 mMatrix;
     
    void main() {
     
    	gl_Position = pMatrix * vMatrix * mMatrix * vec4(vertexPosition, 1.0);
     
    }

    Fragment.shader:
    Code :
    #version 330 core
     
    out vec3 color;
     
    uniform vec3 pickColor;
     
    void main() {
     
    	color = pickColor;
     
    }

    What is going on?!
    GeForce 8600GT is running on Linux.
    nVidia 710m is running on Windows.

    Help :/
    Last edited by GreyMist; 11-17-2013 at 07:51 AM.

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    I changed "out vec3 color;" to "varying out vec3 color;" and now it's working on nVidia but not on intel... ?!

  3. #3
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,077
    Chech OpenGL version on both computers with NV cards (probably 2.1) and update drivers to latest ones.

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    Logs:

    Intel:
    Graphics card parameters:
    Vendor: Intel
    Renderer: Intel(R) HD Graphics
    OpenGL: 4.0.0 - Build 9.17.10.2932
    GLSL: 4.00 - Build 9.17.10.2932
    Shader "shaders/330/color.vertex" status: compiled successful
    Shader "shaders/330/color.fragment" status: compiled successful
    Shader "shaders/330/flat.vertex" status: compiled successful
    Shader "shaders/330/flat.fragment" status: compiled successful


    nVidia with shader:
    #version 330 core

    in vec3 gouraud;
    in vec2 texcoord;

    layout(location = 0) out vec4 color;

    uniform sampler2D diffuseMap;

    void main() {

    color = vec4(gouraud * texture2D(diffuseMap, texcoord).rgb, 1.0);

    }

    nVidia output:
    Graphics card parameters:
    Vendor: NVIDIA Corporation
    Renderer: GeForce 710M/PCIe/SSE2
    OpenGL: 4.3.0
    GLSL: 4.30 NVIDIA via Cg compiler
    Shader "shaders/330/color.vertex" status: compiled successful
    Shader "shaders/330/color.fragment" status: compiled successful
    Shader "shaders/330/flat.fragment" errors: 0(6) : error C0000: syntax error, unexpected '(', expecting "::" at token "("

    Shader program "shaders/330/flat.vertex" + "shaders/330/flat.fragment" errors: Fragment info
    -------------


    ATI:
    Graphics card parameters:
    Vendor: ATI Technologies Inc.
    Renderer: AMD Radeon HD 6800 Series
    OpenGL: 4.2.12217 Compatibility Profile Context 12.104.0.0
    GLSL: 4.20
    Shader "shaders/330/color.vertex" status: compiled successful
    Shader "shaders/330/color.fragment" status: compiled successful
    Shader "shaders/330/flat.vertex" status: compiled successful
    Shader "shaders/330/flat.fragment" status: compiled successful


    I have got latest drivers installed.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    I removed loop and changed lights array "lights[NUM_LIGHTS]" to lights and now it work. Why?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •