# How can I combine Phong lighting with dielectric reflection / Fresnel transmission in a realistic way?

**UPDATE:** I answered my own question about which lighting model to use, but now I need to know how to calculate the Fresnel coefficients for reflected and transmitted rays.

I have a partially implemented C ++ ray tracer. Right now, Phong's lighting with shadow rays is working great. I decided not to have objects with one color plus the ambient / diffuse / scalar scalar coefficients; each of the three coefficients has RGB components, so I can implement materials like these . Lights, on the other hand, has one RGB color plus scalar diffuse and specular intensities. There's also one RGB ambient light.

At this point, I could also implement fully dielectric objects that reflect or transmit all of the light, with the fraction of light reflected to refracted being 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, transparent but green around the edges, etc. I was planning to add RGB reflections and transmittances for each object and let the entity designer make sure that ambient + diffuse + specular + reflectivity + transmittance is within a reasonable range, but that seems arbitrary. Is there a physical way?

source to share

I found a suitable lighting model in the documentation for the .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
```

It's tight and actually has some typos (like `Kx`

and `Ft`

), so I fixed 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 color V := ray direction P := surface point N := surface normal L := light position - P R := L - 2 * (N . L) * P Ka := surface material ambient coefficient Kd := surface material diffuse coefficient Ks := surface material specular coefficient Ps := surface material shininess Kt := surface material transmission coefficient Ia := ambient light color Il := light color Ir := reflected ray color It := transmitted ray color Fl := light Fresnel coefficient Fr := reflected Fresnel coefficient Ft := transmitted Fresnel coefficient`

This model makes sense to me, especially after reading Lighting 101 - Phong Reflective is a clever hack for bouncing light sources, so it's natural to use the same factor for specular highlights and reflected rays.

**There is one more thing that I don't understand. **If I don't want to worry about Fresnel terms, I can set `Fl`

, `Fr`

and `Ft`

to 1. However, if I need this extra precision, how would I calculate them in terms of my already defined variables?

source to share