Nevron .NET Vision
Framework / Presentation Layer / Graphics / Lights / How Lighting Works

In This Topic
    How Lighting Works
    In This Topic
    This topic refers only to components with 3D Rendering abilities

    Lighting works by applying the contribution of one or more lights sources to the 3D objects visualized on a 3D scene. A light source is represented by an instance of one of the following types:




    You can think of the light source object as a light bulb in a room. In real world most of the light comes from the bulb, but some light comes after bouncing off one, two, three or more walls. This bounced light is called ambient light that seems to come from no particular direction, but it disappears if the light source is turned off. You can modify this light by setting the Ambient color property of the NLightSource object. There might be a general ambient light in the scene that comes from no particular source as if it had been scattered so many times that its original source is impossible to determine. You can control this global ambient light by modifying the GlobalAmbientLight color property of the NLightModel object.

    Light sources have an effect only when there are surfaces that absorb and reflect light. Each surface is assumed to be composed of a material with various properties. A material might emit its own light, scatter some light, or reflect light in a desired direction like a mirror.

    Therefore light is divided into four independent components: emissive, ambient, diffuse and specular. All four of them are computed independently and then added together to produce the final color visualized on each pixel of the screen.

    Ambient light as already mentioned is the light scattered so many times that its original light source is impossible to determine.

    Diffuse light comes from a particular direction so it is brighter if it comes squarely down on a surface than if it barely glances off the surface, but once it hits the surface however it is scattered equally in all directions. You can modify the diffuse component of a particular light by modifying the Diffuse color property of the NLightSource object.

    Specular light comes from a particular direction and bounces off a surface in a preferred direction. You can modify the specular component of a particular light by modifying the Specular color property of the NLightSource object.

    In addition to this you can also modify the attenuation factors for every light source. In the real world the intensity of the light decreases as distance from the light increases. You can control this process by modifying the ConstantAttenuation, LinearAttenuation and QuadraticAttenuation properties of the NLightSource object. Light is attenuated by multiplying the contribution of that light source by an attenuation factor using the formula:

    Attenuation factor = 1 / (KC + KL * D + KQ * D * D)

    KC - is the ConstantAttenuation
    KL - is the LinearAttenuation
    KQ - is the QuadraticAttenuation
    D  - is the distance from the light source to the object

    On the other hand materials are characterized by the percentages of light they reflect from the different light components. You can modify these percentages by changing the values of the Ambient , Diffuse and Specular properties of the NMaterialStyle class instance, accessible from the MaterialStyle property of the NFillStyle class. In addition to this, materials can also emit light. You can modify the emissive light of a material by changing the value of the Emissive property of the  NMaterialStyle class. By default this value is RGB(0, 0, 0), which means that the object does not emit any light.

    You may have noticed that when working with the fill styles in the previous topics we did not touch any of these properties. The reason behind this is that the NFillStyle object automatically modified the material properties according to the current fill style. For example when you create a solid color fill style it will also modify the Ambient and Diffuse colors to match the specified color. This ensures that when you turn on lighting the object will have the same color. When you assign an image, gradient, pattern or advanced gradient these two colors are modified to White. In general you'll seldom need to modify the material properties because they've already been assigned for you.

    See Also