Convert OpenGL materials to WPF
I am finding a number of sites on the Internet that define material properties for various real world items.  For example:

Is there some easy want to map the OpenGL definitions to WPF?

Good find Arthur!

You can use the following code to convert the samples from the web site you found to WPF:

//float[] mat_ambient  = { 0.329412f, 0.223529f, 0.027451f, 1.0f };
//float[] mat_diffuse  = { 0.780392f, 0.568627f, 0.113725f, 1.0f };
//float[] mat_specular = { 0.992157f, 0.941176f, 0.807843f, 1.0f };
//float shine = 27.8974f;

var diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromScRgb(1, 0.329412f, 0.223529f, 0.027451f)));
diffuseMaterial.AmbientColor = Color.FromScRgb(1, 0.329412f, 0.223529f, 0.027451f);

var specularMaterial = new SpecularMaterial(new SolidColorBrush(Color.FromScRgb(1, 0.992157f, 0.941176f, 0.807843f)), 27.8974);

var materialGroup = new MaterialGroup();

After that you can assign materialGroup to a Material property.

You get better results when you also add some AmbientLight to the scene - for example the following xaml does that:

           <AmbientLight Color="#333333"/>
Andrej Benedik
Excellent!  Thank you.

Forum Jump:

Users browsing this thread:
1 Guest(s)