Reputation: 521
UPDATE: I answered my own question about what illumination model to use, but now I need to know how to calculate the Fresnel terms for reflected and transmitted rays.
I have a partially-implemented C++ ray tracer. Right now Phong lighting with shadow rays works fine. I chose not to have entities with a single color plus scalar ambient/diffuse/scalar coefficients; the three coefficients each have RGB components, so I can implement materials like these. Lights, on the other hand, have a single RGB color plus scalar diffuse and specular intensities. There's also a single RGB ambient light.
At this point I could also implement completely dielectric entities that reflect or transmit all light, with the proportion of reflected to refracted light determined by the Fresnel equations. However, how do I realistically combine the reflected and refracted colors with the Phong color? I want to have slightly reflective colored plastic, polished gold, perfect mirrored or glass spheres, stained glass, glass panes that are transparent head-on but green on the edges, et cetera. I was planning to add RGB reflectance and transmittance coefficients to each entity, and let the entity designer make sure that ambient+diffuse+specular+reflectance+transmittance lies in a sensible range, but this seems arbitrary. Is there a physically based way?
Upvotes: 4
Views: 2409
Reputation: 521
I found a suitable illumination model myself in the documentation for .mtl files:
color = KaIa
+ Kd { SUM j=1..ls, (N*Lj)Ij }
+ Ks ({ SUM j=1..ls, ((H*Hj)^Ns)Ij Fr(Lj*Hj,Ks,Ns)Ij} +
Fr(N*V,Ks,Ns)Ir})
+ (1.0 - Kx)Ft (N*V,(1.0-Ks),Ns)TfIt
This is dense and actually has some typos (like Kx
and Ft
), so I corrected it:
I = Ka * Ia
+ Kd * [sum for each light: (N . L) * Il]
+ Ks * [sum for each light: ((R . V) ^ Ps) * Fl * Il]
+ Ks * Fr * Ir
+ Kt * (1 - Ks) * Ft * It
I := surface point's color
V := ray direction
P := surface point
N := surface normal
L := light's position - P
R := L - 2 * (N . L) * P
Ka := surface material's ambient coefficient
Kd := surface material's diffuse coefficient
Ks := surface material's specular coefficient
Ps := surface material's shininess
Kt := surface material's transmission coefficient
Ia := ambient light color
Il := light's color
Ir := reflected ray's color
It := transmitted ray's color
Fl := light's Fresnel coefficient
Fr := reflected Fresnel coefficient
Ft := transmitted Fresnel coefficient
This model makes sense to me, especially after reading Lighting 101 -- Phong specular reflection is a performance-minded hack for reflecting light sources, so it's natural to use the same coefficient for specular highlights and reflected rays.
There's still one thing I don't understand. If I don't want to bother with Fresnel terms, I can set Fl
, Fr
, and Ft
to 1. If I want that extra accuracy, though, how would I calculate them in terms of my already-defined variables?
Upvotes: 4