# Houdini VOP raytracer part 5

Posted on October 2, 2013

# Specular Hilight

A specular highlight is a bright spot of light that appears on shiny objects when illuminated. The term specular means that light is perfectly reflected in a mirror-like way from the light source to the viewer. We are going to cover two specular reflection models.

Phong reflection model.

Where is normalised mirror reflection of the light vector off the surface, and is normalised viewpoint vector. The number is called the Phong exponent, and is a user-chosen value that controls the apparent smoothness of the surface. When calculating , again we will get negative values like we had in diffuse calculation, so we have to clamp it, .

You can refer to the example above, that we get specular also on the back of our sphere. There are few ways to fix that issue, for e.g. we can multiply sampled position by shadow that we already have calculated (shadowed area ==0, non shadowed ==1) or make another dot product test with normal vector.

Below is a phong model representation in Houdini nodes. First, calculate reflection vector . As law of reflection states – direction of incoming light (the incident ray), and the direction of outgoing light reflected (the reflected ray) make the same angle with respect to the surface normal. In this situation reflect vex node comes in handy. It takes input of vector to be reflected – in our case vector of Light towards the surface (It is very important to check your vector direction) and input of normalised surface normal vector. As an output we will get reflected vector which should be normalised (). Vector is normalised Houdini (“I”) – vector towards Eye (Camera). After calculating dot product between those two vectors , we need make sure that we clamp negative values. I use clamp vex node instead of maxing it with zero as I know that values from dot product of normalised vectors won’t exceed value of 1. Last part is to use power function to control exponent and simple multiplication for overall intensity.

## Phong-Blinn reflection model

Where is normalised smooth surface normal vector off the surface, and is the half-angle direction (the direction vector midway between *L*, the vector to the light, and *V*, the viewpoint vector).

First problem we will find here is that our halfway vector will jump as soon as angle in between L and V is larger than 180°. Here is an example with non clamped values of rotating light by 360°.

H – half-angle direction between L and VN – smooth surface normal

R – Mirror reflection of the light vector

L – Light vector towards surface

V – viewpoint vector (eye/camera)

Here you can see both specular models with clamped values.

As you have noticed, Blinn reflection model give us wider specular as the angle between R-V is more aggressive than N-H. We can compensate the difference by adjusting exponent. Maxing (or clamping in this example) dot product is very important as we would get undesirable effect when calculating exponent from negative values.

First lets calculate vector between the viewer and light-source vector.

Halfway vector equals sum of vectors and divided by sum of their lengths. In many internet examples you will see calculation of halfway vector presented like this:

This is not the mathematically correct way of calculating vector but in our case vectors and are normalised (their length is equal of 1.0) so sum of their lengths will equal 2.

Next step is a dot product calculation with normalised surface normal. Rest of nodes are exactly the same as in phong model.

To get rid of jumping vector, we can add second dot product calculation for negated halfway vector.

## Mantra shader version of specular model

Mantra has build in specular vex node with few specular models. To create your own model, we need Illuminance Loop vex node that will iterate through all active lights in scene file. To get vector, you can create global variables vex node (global variables vex node is different inside and outside illuminance loop). vector vector provided by global variables is a *“Direction From Surface to Light” * so we need to negate it (reverse its direction). Global vector (eye) is *“Direction From Eye to Surface”* (equivalent of our – Viewpoint vector), also needs to be negated for proper dot product calculation. This setup should produce exactly same effect as build in Phong model from specular vex node.

# << [ 4 ] [ 5 ] [ 6 ] >>

## Be the first to leave a comment