我只是想用 C++ 编写波前文件加载器。我按照 www.opengl-tutorial.org 上的教程进行操作。没有说如何处理mtl文件,所以我决定自己做。我知道 Kd 负责漫反射属性的颜色。另一方面,map_Kd 负责描述该属性的纹理。mtl 文件中总是有 Kd,可能是 map_Kd。我的文件如下所示:
.
.
.
newmtl Material.001
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd cubetex.bmp
.
.
.
我应该将 map_Kd 的值乘以 Kd 吗?还是我应该只使用 map_Kd?
编辑:
这是我的片段着色器:
#version 430 core
in vec2 uv;
in vec3 Position_worldspace;
in vec3 Normal_cameraspace;
in vec3 EyeDirection_cameraspace;
in vec3 LightDirection_cameraspace;
out vec3 color;
uniform sampler2D tex;
uniform vec3 LightPosition_worldspace;
void main()
{
vec3 LightColor = vec3(1,1,1);
float LightPower = 50.0f;
vec3 MaterialDiffuseColor = texture( tex, uv ).rgb;
vec3 MaterialAmbientColor = vec3(0.1,0.1,0.1) * MaterialDiffuseColor;
vec3 MaterialSpecularColor = vec3(0.3,0.3,0.3);
float distance = length( LightPosition_worldspace - Position_worldspace );
vec3 n = normalize( Normal_cameraspace );
vec3 l = normalize( LightDirection_cameraspace );
float cosTheta = clamp( dot( n,l ), 0,1 );
vec3 E = normalize(EyeDirection_cameraspace);
vec3 R = reflect(-l,n);
float cosAlpha = clamp( dot( E,R ), 0,1 );
color = MaterialAmbientColor + MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance*distance) + MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance*distance);
}
我不知道如何计算 MaterialDiffuseColor