Reputation:
This is my fragment shader and when ever i try to use the Cubemap in the texture function i get a error saying:
0.54 No matching function found( using implicit conversion)
0.54 texture function is not known.
The texture function works with the texture2D.
#version 330 core
out vec4 FragColor;
struct Light {
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
float opacity;
}; uniform Material material;
uniform vec3 viewPos;
uniform Light light;
in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoord;
uniform bool UseColorMap;
uniform sampler2D texture1;
uniform samplerCube texturecubeMap;
void main()
{
vec3 ambient = 0.2 * (light.ambient * material.ambient );
// diffuse
vec3 norm = normalize( Normal );
vec3 lightDir = normalize( -light.direction );
float diff = max( dot( norm, lightDir) , 0.0 );
vec3 diffuse = light.diffuse * diff * material.diffuse;
// specular
vec3 viewDir = normalize( viewPos - FragPos );
vec3 reflectDir = reflect( -lightDir , norm );
float spec = pow(max(dot(viewDir, reflectDir), 0.0),
material.shininess);
vec3 specular = light.specular * spec * material.specular;
vec3 result = ambient + diffuse + specular;
vec3 texDiffuseColor = texture( texture1 , TexCoord ).rgb;
if( !UseColorMap )
{
FragColor = vec4( result , material.opacity / 100.0 );
}
else
{
//FragColor = texture( texture1 , TexCoord ) * vec4( result ,
material.opacity / 100.0 ); // This works fine
FragColor = texture( texturecubeMap , TexCoord ); // Get error here
}
};
Upvotes: 1
Views: 931
Reputation: 211277
In case of a samplerCube
sampler, the texture coordinate has to be 3 dimensional, because the texture coordinate is treated as a direction vector (rx ry rz)
emanating from the center of a cube.
The compile error is caused because TexCoord
is 2 dimensional.
Fortunately you've calculated the direction of view in world space:
vec3 viewDir = normalize(viewPos - FragPos);
viewDir
is the proper direction vector for the environment map:
FragColor = texture(texturecubeMap, viewDir);
Upvotes: 1