Post by chrisg on Jan 13, 2020 5:06:37 GMT
Hi everyone,
I'm attempting to add mtl file parsing to my raytracer. The file format itself is pretty straightforward. The part that I'm having a bit of confusion with is that the mtl file defines the ambient, diffuse, and specular components as colors rather than as scalars.
This is in contrast to how the book has us define these components - using scalars.
After having seen some mtl files, and squinted closely at the mtl specification, I have a hypothesis about the situation, but I'm hoping someone with more experience might be able to weigh in.
This is in contrast to how the book has us define these components - using scalars.
After having seen some mtl files, and squinted closely at the mtl specification, I have a hypothesis about the situation, but I'm hoping someone with more experience might be able to weigh in.
- All the ambient/diffuse/specular components that I've seen so far have been in grayscale (the r,g,b values are equal)
Ks r g b
The Ks statement specifies the specular reflectivity using RGB values.
"r g b" are the values for the red, green, and blue components of the
atmosphere. The g and b arguments are optional. If only r is
specified, then g, and b are assumed to be equal to r. The r g b values
are normally in the range of 0.0 to 1.0. Values outside this range
increase or decrease the relectivity accordingly.
The Ks statement specifies the specular reflectivity using RGB values.
"r g b" are the values for the red, green, and blue components of the
atmosphere. The g and b arguments are optional. If only r is
specified, then g, and b are assumed to be equal to r. The r g b values
are normally in the range of 0.0 to 1.0. Values outside this range
increase or decrease the relectivity accordingly.
The g and b components being optional arguments leads me to believe it's relatively common for the color to be some shade of gray.
I'm guessing that it's so common, that most implementations of phong shading have stopped supporting using colors instead of a scalar (or never supported it to begin with).
Looking at the math, how a color vs scalar might impact the Lighting() function --
ambient <- effectiveColor * m.ambient
If m.ambient is a scalar, this is equivalent to
ambient <- color(effectiveColor.r * m.ambient, effectiveColor.g * m.ambient, effectiveColor.b * m.ambient)
versus if it were a color:
ambient <- color(effectiveColor.r * m.ambient.r, effectiveColor.g * m.ambient.g, effectiveColor.b * m.ambient.b)
so - if ambient was a grayscale -- it would be effectively be the same regardless of if it were a color or scalar. The same goes for diffuse and specular.
So moving forward, I think I can do one of two things:
- only support reading one value from the components in the mtl file, and assume it's a grayscale
- change my material to store ambient, diffuse, and specular components as colors, and update my lighting function accordingly.
Has anyone had any experience where the values aren't grayscale? Would anyone be able to give me any more insight?