这是我的片段着色器,当我试图在纹理函数中使用Cubemap时,我会看到一个错误,它说:
0.54未找到匹配函数(使用隐式转换) 不知道0.54纹理函数。
纹理函数与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
}
};发布于 2019-06-15 11:31:28
对于samplerCube采样器,纹理坐标必须是三维的,因为纹理坐标被看作是从立方体中心发出的方向矢量(rx ry rz)。
由于TexCoord是二维的,所以会导致编译错误。
幸运的是,您已经计算了世界空间的视图方向:
vec3 viewDir =正常化(viewPos- FragPos);
viewDir是环境地图的正确方向向量:
FragColor = texture(texturecubeMap, viewDir);https://stackoverflow.com/questions/56609856
复制相似问题