exploring lighting in jitter [part 1]
Lighting can get pretty confusing, pretty quickly. Luckily, Jitter makes it easy to light our objects by simply setting their lighting_enable attributes to 1. We then have one light which can be used for all the objects in our scene and its fairly easy to use the color attribute to differentiate between the various objects. When lighting is enabled, we are in fact utilising jitter’s auto material facility to provide material properties for an object based on the colour we specify for the jitter object. (This is equivalent to enabling openGL’s glColorMaterial() and using glColor() to update the diffuse and ambient material properties for the front and back faces.)
download the patches to explore lighting: jitter lighting [max 5]

jitter lighting
material properties
Things gets a bit more interesting when we start to design our own material properties. They’re called material properties because they attempt to provide a means to simulating how objects in the real world reflect light. For example, a snooker ball is highly polished and shiny, whereas a rubber tyre is dark and dull in comparrison. These properties are emulated in OpenGL by defining values for ambient, diffuse, specular, emission and shininess. The contribution they make to the final colour we see is calculated by treating these properties as the amount of light that the material reflects.
To design your own materials you need to disable the auto_material attribute for your Jitter object and change it’s material parameters using mat_ambient, mat_diffuse, mat_specular, shininess and mat_emission to build up interesting blends. The immediate difference we see on changing the auto_material setting is that the specular, shininess and emission values now also contribute to the lighting equation.
light properties
In addition to setting the material properties for our Jitter object, a selection of lighting parameters is available using jit.gl.render. Here we can set light properties that affect the colour, position and direction of the source of the light in our scene. The light properties consist of diffuse, ambient and specular contributions and shouldn’t be confused with the material properties. the jitter attributes that control these parameters are light_ambient, light_diffuse and light_specular. As with all the light and material properties, each of the attributes are represented as colours and have four components (RGBA) although the alpha value only has an effect when blending is enabled (and then only the material’s diffuse value).
The difference between material and light properties is that the rgb values for the light properties are calculated as the intensity of light for each contribution of red, green and blue whereas material rgb values define the amount of each colour that is reflected towards the eye. So, if you set the material rgb values of a light source to bright white (1 1 1) but have the light properties set to zero intensity (0 0 0) then no colour will be reflected from the object and it appears to be black. In other words, you can multiply the rgb values of the global light properties with the material rgb values to get the final amount of red, green and blue that is reflected and we perceive as colour. (If there is more than one light then the material properties for each light source are added together and clamped at the value of 1).
light model
Furthermore, there is also an ambient light parameter available through jit.gl.render (light_global_ambient) that is not attributed to any one light source but adds ambient light to the scene even if no light source is directed at an object. it’s contribution is scaled by the material’s ambient property. In openGL terms, this forms part of the light model.
Confused? This is what the RedBook has to say: “…the interaction between an object’s material surface and incident light is complex, specifying material properties so that an object has a certain desired appearance is an art.”
light position
Light position is easier to comprehend with values for the position given by x,y and z co-ordinates. The fourth value for the light position is known as w, if its value is zero then the light is deemed to be directional, with rays that are parallel because the source is infinitely far away. If the value is not zero then the light becomes positional and the effect it has on our scene is more pronounced. Think of the difference between the sun (directional light) and a candle in a room (positional).
Whilst it’s possible to have more than one object in jitter with different material properties for each object, we can’t have more than one light source without resorting to command lists in jit.gl.sketch.
part2 looks at lighting using command lists with jit.gl.sketch.

a spotlight and two sided lighting using sketch

2 Comments, Comment or Ping
Chuck Henry
I’m very interested in multiple light sources … many thanks!!
Nov 6th, 2008
pelado
i’m glad you find it helpful
Nov 6th, 2008
Reply to “exploring lighting in jitter [part 1]”