Nevron .NET Vision Documentation
Working with Lights

This topic refers only to components with 3D Rendering abilities

Lighting is one of the most impressive features delivered by Nevron components. Configuring lighting however is sometimes tricky, because it requires understanding of lighting. There is a set of predefined light schemes that can help you configure lightning with ease. The following code shows how to apply a predefined light model to a chart panel: 
C#
Copy Code
NChart chart = nChartControl1.Charts[0];
chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft);
Visual Basic
Copy Code
Dim chart As NChart = NChartControl1.Charts(0)
chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyTopLeft)

The above code will enable lighting and modify the global ambient light to RGB(64, 64, 64). It will also create a point 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 code example achieves the same effect:

C#
Copy Code
NLightModel lightModel = nChartControl1.Charts[0].LightModel;
lightModel.EnableLighting = true;
lightModel.LightSources.Clear();
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64);
NPointLightSource lightSource = new NPointLightSource();
lightSource.Ambient = Color.FromArgb(64, 64, 64);
lightSource.Diffuse = Color.FromArgb(255, 255, 255);
lightSource.Specular = Color.FromArgb(64, 64, 64);
lightSource.Position = new NVector3DF(3.0f, 9.0f, 20.0f);

lightModel.LightSources.Add(lightSource);
Visual Basic
Copy Code
Dim lightModel As NLightModel = NChartControl1.Charts(0).LightModel
lightModel.EnableLighting = True
lightModel.LightSources.Clear()
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64)
Dim lightSource As New NPointLightSource
lightSource.Ambient = Color.FromArgb(64, 64, 64)
lightSource.Diffuse = Color.FromArgb(255, 255, 255)
lightSource.Specular = Color.FromArgb(64, 64, 64)
lightSource.Position = New NVector3DF(3.0F, 9.0F, 20.0F)
lightModel.LightSources.Add(lightSource)

Now let's examine the above code line by line:

1. The first two lines of code obtain a reference the light model applied on the chart and enables lighting (note that you must also switch the chart in 3D mode, because lighting has effect only for 3D charts) :

C#
Copy Code
NLightModel lightModel = nChartControl1.Charts[0].LightModel;
lightModel.EnableLighting = true;
Visual Basic
Copy Code
Dim lightModel As NLightModel = NChartControl1.Charts(0).LightModel

lightModel.EnableLighting = True

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

C#
Copy Code
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64);
Visual Basic
Copy Code
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64)

Another thing to consider when applying ambient light is that it affects all scene elements. This is why it is best to apply a color with equal red, green and blue components (or in other words use to use shades of gray) as this will result in more realistic lighting.

3. After you configure the global ambient properties you can modify the light sources of the scene. This is done by adding NLightSource derived objects (NDirectionalLightSource, NPointLightSource, NSpotLightSource) to the LightSources collection of the NLightModel class.

C#
Copy Code
NPointLightSoure lightSource = new NPointLightSource();
lightModel.LightSources.Add(lightSource);
Visual Basic
Copy Code
Dim lightSource As New NPointLightSoure
lightModel.LightSources.Add(lightSource)

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

C#
Copy Code
lightSource.Ambient = Color.FromArgb(64, 64, 64);
lightSource.Diffuse = Color.FromArgb(255, 255, 255);
lightSource.Specular = Color.FromArgb(64, 64, 64);
lightSource.Position = new NVector(3.0f, 9.0f, 20.0f);
Visual Basic
Copy Code
lightSource.Ambient = Color.FromArgb(64, 64, 64)
lightSource.Diffuse = Color.FromArgb(255, 255, 255)
lightSource.Specular = Color.FromArgb(64, 64, 64)
lightSource.Position = New NVector(3.0f, 9.0f, 20.0f)
See Also

 

 


©2017. Nevron Software LLC.

Send Feedback