2

I'm just trying to write wavefront files loader in c++. I followed the tutorial at www.opengl-tutorial.org. It doesn't say how to handle mtl files, so I decided to do it myself. I know that Kd is responsible for the color of the diffuse property. On the other hand, map_Kd is responsible for the texture that describes this property. There is always Kd in the mtl file and could be map_Kd. My file look like this:

.
.
.
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
.
.
.

Should I multiply the values of map_Kd by Kd? Or should I only use map_Kd?

EDIT:

Here's my fragment shader:

#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);

}

I don't know how to compute MaterialDiffuseColor

  • 1
    Posting a [mcve] would be a good idea. – Jesper Juhl Feb 10 '20 at 14:38
  • What do you mean? I don't have any error in the program. I just want to know how to load this mtl file. – Roman Kwaśniewski Feb 10 '20 at 14:41
  • What I mean is that noone can reproduce your results themselves without your code. A [mcve] is a *minimum* effort to let others help you. Code snippets are just not good enough. – Jesper Juhl Feb 10 '20 at 14:45
  • In the loader, I wrote once, I decided to multiply the diffuse color (Kd) with the texture (Kd_map) if the latter is provided as well. The sample files (downloaded from Web) didn't look that bad - letting me think that was not the worst decision. The link which I used as source: [MTL material format (Lightwave, OBJ)](http://paulbourke.net/dataformats/mtl/) – Scheff's Cat Feb 10 '20 at 16:16
  • From the provided in link in my previous comment: _During rendering, the map_Kd value is multiplied by the Kd value._ ;-) I probably did it according to this statement but have forgotten meanwhile. – Scheff's Cat Feb 10 '20 at 16:19
  • I have the exact same question. – tigertang Apr 28 '23 at 19:18

0 Answers0