When light hits a surface, three possible things can occur. Light can be absorbed by the material, light can be transmitted through a material, or light may be reflected.
Reflected light can be divided into two sub-type, specular reflection and diffuse reflection. Specular reflection reflects all the light from a given direction at the same angle, whereas diffuse reflection reflects that light in a broad range of angles.
What we normally think of when we talk about reflection, is specular reflection. The ray $P$ that first hits the surface is called the incident ray, and the ray $Q$ that bounces of the surface is called the reflected ray.
The angle $\theta_i$ between the normal of the surface and the incident ray is the angle of incident. Likewise, the angle $\theta_r$ between the normal and the reflected ray is the angle of reflection. The fraction of light that is reflected increases with increasing angle of incidence $\theta_i$. The Law of Reflection states that $\theta_i = \theta_r$, meaning that the angle of incidence is the same as the angle of reflection.
The direction of a reflected ray is determined by the vector of incidence and the surface normal vector. Given an incident direction $\hat{\mathbf{d}_i}$ from the surface to the light source and the surface normal direction $\hat{\mathbf{d_n}}$, the specularly reflected direction $\hat{\mathbf{d_s}}$ is: $$ \hat{\mathbf{d_s}} = 2 \left(\hat{\mathbf{d_n}} \bullet \hat{\mathbf{d_i}} \right) \hat{\mathbf{d_n}} - \hat{\mathbf{d_i}}, $$ where $\hat{\mathbf{d_n}} \bullet \hat{\mathbf{d_i}}$ is a scalar product obtained with the dot product.
If all the incident rays are reflected at the same angle, which happens when the surface is smooth, we speak of specular reflection.
An easy way to implement diffuse reflection, is by adding a random angle to the reflection ray.
In physics, refraction is the change in direction of a wave passing from one medium to another or from a gradual change in the medium. For light, refraction follows Snell's Law, which states that, for a given pair of media, the ratio of the sines of the angle of incidence $\theta_1$ and the angle of refraction $\theta_2$ is equal to the ratio of phase velocities $(v_1 / v_2)$ in the two media.
For light, the refractive index $n$ of a material is more often used than the wave sphase speed $v$ in the material. They are, however, directly related through the speed of light through a vacuum $c$ as $$n = \dfrac{c}{d}.$$ In optics, therefore, the law of refraction is typically written as $$n_1\sin\theta_1 = n_2\sin\theta_2. $$ The following table contains a list of materials and the respective refractive index $n$. For liquids, the index is measured at $20^\circ \textrm{C}$.
| Material | Refractive index ($n$) |
| Vacuum | 1 |
| Air | 1.000293 |
| Water | 1.333 |
| Olive oil | 1.47 |
| Ice | 1.31 |
| Glass | 1.52 |
| Diamond | 2.42 |