Xceed Chart for WinForms v4.4 Documentation
Working with Lights

Welcome to Xceed Chart for WinForms v4.4 > User Guide > Lighting > Working with Lights

Lighting is one of the most impressive features of Xceed Chart for WinForms: components that do not use a 3D technology such as OpenGL or DirectX to display charts cannot fully reproduce this effect. 

Configuring lighting, however, is sometimes tricky because it requires an understanding of lighting. This is why Xceed has created a set of predefined light schemes that help you configure lighting with ease. It takes only one function call and is very convenient, especially when you're short on time and would like to deliver your project faster. The following code illustrates this:

VB.NET  

Dim lightModel As LightModel
lightModel = (CType((chartControl1.Charts(0)), Chart)).LightModel
lightModel.SetPredefinedScheme(LightScheme.ShinyTopLeft)
C#  

LightModel lightModel;
lightModel = ((Chart)(chartControl1.Charts[0])).LightModel;
lightModel.SetPredefinedScheme(LightScheme.ShinyTopLeft);

The above code will enable lighting and modify the global ambient light to RGB(64, 64, 64). It will also create a light source positioned at (3.0f, 9.0f, 20.0f) with ambient, diffuse, and specular colors set to RGB(64, 64, 64), RGB(255, 255, 255), and RGB(64, 64, 64), respectively. The following example achieves the same effect:

VB.NET  

Dim lightModel As LightModel

lightModel = (CType((cartControl1.Charts(0)), Chart)).LightModel
lightModel.EnableLighting = True
lightModel.LightSources.Clear()
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64)

Dim lightSource As LightSoure = New LightSource()
lightSource.Ambient = Color.FromArgb(64, 64, 64)
lightSource.Diffuse = Color.FromArgb(255, 255, 255)
lightSource.Specular = Color.FromArgb(64, 64, 64)
lightSource.Position = New Vector(3.0f, 9.0f, 20.0f)

lightModel.LightSources.Add(lightSource)
C#  

LightModel lightModel;

lightModel = ((Chart)(cartControl1.Charts[0])).LightModel;
lightModel.EnableLighting = true;
lightModel.LightSources.Clear();
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64);

LightSoure lightSource = new LightSource();
lightSource.Ambient = Color.FromArgb(64, 64, 64);
lightSource.Diffuse = Color.FromArgb(255, 255, 255);
lightSource.Specular = Color.FromArgb(64, 64, 64);
lightSource.Position = new Vector(3.0f, 9.0f, 20.0f);

lightModel.LightSources.Add(lightSource);

This approach is not recommended unless of course you are trying to produce a lighting configuration that differs from the standard ones because it results in bulky code. We'll continue our discussion with a line-by-line explanation of this code. 

1. When you plan to use lighting, the first thing to do is to inform the component. Since lighting is configured on a per-chart basis and Xceed Chart supports an unlimited number of charts, the following code assumes that there is only one chart in the control's chart collection:

VB.NET  

Dim lightModel As LightModel
lightModel = (CType((chartControl1.Charts(0)), Chart)).LightModel
lightModel.EnableLighting = True
C#  

LightModel lightModel;
lightModel = ((Chart)(chartControl1.Charts[0])).LightModel;
lightModel.EnableLighting = true;

2. Sometimes the scene rendered with lighting looks dark. This is why it is recommended to have an ambient global light that makes the objects appear brighter:

VB.NET  
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64)
C#  
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64);

Another consideration to keep in mind when you apply ambient light is that it is applied to all scene elements. This is why it is best to apply a color with equal red, green, and blue components. 

3. After you configure the global ambient properties, you can modify the light sources of the scene. This is done by adding LightSource objects to the LightSources collection of the LightModel object.

VB.NET  

Dim lightSource As LightSoure = New LightSource()
lightModel.LightSources.Add(lightSource)
C#  

LightSoure lightSource = new LightSource();
lightModel.LightSources.Add(lightSource);

4. To modify the light source light and position, you must touch the Ambient, Diffuse, Specular, and Position properties of the LightSource object:

VB.NET  

lightSource.Ambient = Color.FromArgb(64, 64, 64)
lightSource.Diffuse = Color.FromArgb(255, 255, 255)
lightSource.Specular = Color.FromArgb(64, 64, 64)
lightSource.Position = New Vector(3.0f, 9.0f, 20.0f)
C#  

lightSource.Ambient = Color.FromArgb(64, 64, 64);
lightSource.Diffuse = Color.FromArgb(255, 255, 255);
lightSource.Specular = Color.FromArgb(64, 64, 64);
lightSource.Position = new Vector(3.0f, 9.0f, 20.0f);

Note that the Position property is represented as a Vector object.

Related Examples

Windows Forms: Lights\General

See Also

LightSource | LightModel | FillEffect | Vector | Xceed 3D Lighting Model