Reputation: 23
The following is my code for a fragment shader to generate a texture on the floor and sphere and a fog effect above it.
I get an error which says "Fragment shader writes to more than 1 type of output gl_FragData, gl_FragColor or user bound frag data." when I try to compile it.
out vec4 color;
out vec2 texCoord;
uniform int fogType;
uniform int enableFloorTexture;
uniform int sphereTexture;
uniform int objectType;
uniform sampler2D texture;
uniform sampler1D stexture;
void main()
{
vec4 finColor = color;
if (objectType == 1)
{
if(enableFloorTexture == 1)
{
finColor = color * texture2D( texture, texCoord );
}
}
else if (objectType == 2)
{
if(sphereTexture != 0)
{
finColor = color * texture1D( stexture, texCoord.x );
}
}
float fogFactor = 0.0;
float fogDepth = (18.0 - 0.0);
float fogDensity = 0.09;
vec4 fogColor = vec4(0.7, 0.7, 0.7, 0.5);
float z = gl_FragCoord.z / gl_FragCoord.w;
if(fogType == 1)
{
fogFactor = (18.0 - z) / fogDepth;
}
else if (fogType == 2)
{
fogFactor = exp( -fogDensity * z );
}
else if (fogType == 3)
{
fogFactor = exp( -fogDensity * fogDensity * z * z );
}
fogFactor = clamp(fogFactor, 0.0, 1.0);
if(fogType == 0)
{
gl_FragColor = finColor;
}
else
{
gl_FragColor = mix(fogColor, finColor, fogFactor);
}
}
Upvotes: 0
Views: 526
Reputation: 282
What confuses me in your program is that you are using color
as an output but you are using it in your program. Is this just a slip of a pen?
If you want to use #version 400
output format,the output should be like this:
layout(location = 0) out vec4 color;
Upvotes: 1
Reputation: 2312
You have some outputs declared:
out vec4 color;
out vec2 texCoord;
Try making them inputs.
Upvotes: 0