0025201: Visualization - Implementing soft shadows and ambient occlusion in OCCT...
[occt.git] / src / Graphic3d / Graphic3d_MaterialAspect.cxx
1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <Graphic3d_MaterialAspect.ixx>
16 #include <Standard_Assert.hxx>
17
18 // =======================================================================
19 // function : Graphic3d_MaterialAspect
20 // purpose  :
21 // =======================================================================
22 Graphic3d_MaterialAspect::Graphic3d_MaterialAspect()
23 : myDiffuseColor (0.2, 0.2, 0.2, Quantity_TOC_RGB),
24   myAmbientColor (0.2, 0.2, 0.2, Quantity_TOC_RGB)
25 {
26   myRequestedMaterialName = Graphic3d_NOM_DEFAULT;
27   Init (myRequestedMaterialName);
28 }
29
30 // =======================================================================
31 // function : Graphic3d_MaterialAspect
32 // purpose  :
33 // =======================================================================
34 Graphic3d_MaterialAspect::Graphic3d_MaterialAspect (const Graphic3d_NameOfMaterial theName)
35 : myDiffuseColor (0.2, 0.2, 0.2, Quantity_TOC_RGB),
36   myAmbientColor (0.2, 0.2, 0.2, Quantity_TOC_RGB)
37 {
38   myRequestedMaterialName = theName;
39   Init (myRequestedMaterialName);
40 }
41
42 // =======================================================================
43 // function : Init
44 // purpose  :
45 // =======================================================================
46 void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
47 {
48   myMaterialType     = Graphic3d_MATERIAL_ASPECT;
49   myTransparencyCoef = 0.0f;
50   myRefractionIndex  = 1.0f;
51   myDiffuseActivity  = Standard_True;
52   myDiffuseCoef      = 0.65f;
53   myAmbientActivity  = Standard_True;
54   myAmbientCoef      = 0.3f;
55   mySpecularActivity = Standard_True;
56   mySpecularCoef     = 0.0f;
57   myEmissiveActivity = Standard_False;
58   myEmissiveCoef     = 0.0f;
59   myEnvReflexion     = 0.0f;
60   myShininess        = 0.039f;
61   myDiffuseColor .SetValues (0.2, 0.2, 0.2, Quantity_TOC_RGB);
62   mySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB);
63   myMaterialName     = theName;
64
65   myBSDF = Graphic3d_BSDF::CreateDiffuse (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f));
66
67   Standard_Integer index = Standard_Integer (theName);
68   if (index < NumberOfMaterials())
69   {
70     myStringName = MaterialName (index + 1);
71   }
72
73   switch (theName)
74   {
75     case Graphic3d_NOM_PLASTIC:
76       myShininess    = Standard_ShortReal (0.0078125);
77       myAmbientCoef  = Standard_ShortReal (0.5);
78       myDiffuseCoef  = Standard_ShortReal (0.24);
79       mySpecularCoef = Standard_ShortReal (0.06);
80
81       myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
82                                   static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
83                                   static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
84       myBSDF.Ks = Graphic3d_Vec3 (0.00784314f, 0.00784314f, 0.00784314f);
85       myBSDF.Normalize();
86       myBSDF.Roughness = 32;
87       break;
88     case Graphic3d_NOM_SHINY_PLASTIC:
89       myShininess    = Standard_ShortReal (1.0);
90       myAmbientCoef  = Standard_ShortReal (0.44);
91       myDiffuseCoef  = Standard_ShortReal (0.5);
92       mySpecularCoef = Standard_ShortReal (1.0);
93
94       myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
95                                   static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
96                                   static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
97       myBSDF.Ks = Graphic3d_Vec3 (0.0156863f, 0.0156863f, 0.0156863f);
98       myBSDF.Normalize();
99       myBSDF.Roughness = 64.f;
100       break;
101     case Graphic3d_NOM_SATIN :
102       myShininess    = Standard_ShortReal (0.09375);
103       myAmbientCoef  = Standard_ShortReal (0.33);
104       myDiffuseCoef  = Standard_ShortReal (0.4);
105       mySpecularCoef = Standard_ShortReal (0.44);
106
107       myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
108                                   static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
109                                   static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
110       myBSDF.Ks = Graphic3d_Vec3 (0.0313726f, 0.0313726f, 0.0313726f);
111       myBSDF.Roughness = 16.f;
112       myBSDF.Normalize();
113       break;
114     case Graphic3d_NOM_NEON_GNC:
115       myShininess    = Standard_ShortReal (0.05);
116       myAmbientCoef  = Standard_ShortReal (1.0);
117       myDiffuseCoef  = Standard_ShortReal (1.0);
118       mySpecularCoef = Standard_ShortReal (0.62);
119       myEmissiveCoef = Standard_ShortReal (1.0);
120       myEmissiveActivity = Standard_True;
121       myAmbientActivity  = Standard_False;
122
123       myBSDF.Kr = Graphic3d_Vec3 (0.207843f, 0.207843f, 0.207843f);
124       myBSDF.Le = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
125                                   static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
126                                   static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
127       myBSDF.Fresnel == Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.3f, 0.3f, 0.3f));
128       break;
129     case Graphic3d_NOM_METALIZED:
130       myShininess    = Standard_ShortReal (0.13);
131       myAmbientCoef  = Standard_ShortReal (0.9);
132       myDiffuseCoef  = Standard_ShortReal (0.47);
133       mySpecularCoef = Standard_ShortReal (0.45);
134       myAmbientActivity  = Standard_False;
135
136       {
137         Graphic3d_Vec3 aColor (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
138                                static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
139                                static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
140
141         myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
142           Graphic3d_Fresnel::CreateSchlick (aColor), 1024.f);
143       }
144       break;
145     // Ascending Compatibility physical materials. The same definition is taken as in the next constructor.
146     case Graphic3d_NOM_BRASS:
147       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
148
149       myShininess    = 0.65f;
150       myAmbientCoef  = 1.00f;
151       myDiffuseCoef  = 1.00f;
152       mySpecularCoef = 1.00f;
153
154       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
155         Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.58f, 0.42f, 0.20f)), 1024.f);
156
157       // Color resulting from ambient
158       myAmbientColor .SetValues (0.329f, 0.224f, 0.027f, Quantity_TOC_RGB);
159       // Color resulting from dispersed
160       myDiffuseColor .SetValues (0.780f, 0.569f, 0.114f, Quantity_TOC_RGB);
161       // Color resulting from specular
162       mySpecularColor.SetValues (0.992f, 0.941f, 0.808f, Quantity_TOC_RGB);
163       break;
164     case Graphic3d_NOM_BRONZE:
165       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
166
167       myShininess    = 0.65f;
168       myAmbientCoef  = 1.00f;
169       myDiffuseCoef  = 1.00f;
170       mySpecularCoef = 1.00f;
171
172       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
173         Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.65f, 0.35f, 0.15f)), 1024.f);
174
175       // Color resulting from ambient
176       myAmbientColor .SetValues (0.213f, 0.128f, 0.054f, Quantity_TOC_RGB);
177       // Color resulting from dispersed
178       myDiffuseColor .SetValues (0.714f, 0.428f, 0.181f, Quantity_TOC_RGB);
179       // Color resulting from specular
180       mySpecularColor.SetValues (0.590f, 0.408f, 0.250f, Quantity_TOC_RGB);
181       break;
182     case Graphic3d_NOM_COPPER:
183       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
184
185       myShininess    = 0.65f;
186       myAmbientCoef  = 1.00f;
187       myDiffuseCoef  = 1.00f;
188       mySpecularCoef = 1.00f;
189
190       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
191         Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.955008f, 0.637427f, 0.538163f)), 1024.f);
192
193       // Color resulting from ambient
194       myAmbientColor .SetValues (0.191f, 0.074f, 0.023f, Quantity_TOC_RGB);
195       // Color resulting from dispersed
196       myDiffuseColor .SetValues (0.604f, 0.270f, 0.083f, Quantity_TOC_RGB);
197       // Color resulting from specular
198       mySpecularColor.SetValues (0.950f, 0.640f, 0.540f, Quantity_TOC_RGB);
199       break;
200     case Graphic3d_NOM_GOLD:
201       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
202
203       myShininess    = 0.80f;
204       myAmbientCoef  = 1.00f;
205       myDiffuseCoef  = 1.00f;
206       mySpecularCoef = 1.00f;
207
208       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
209         Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (1.000000f, 0.765557f, 0.336057f)), 1024.f);
210
211       // Color resulting from ambient
212       myAmbientColor .SetValues (0.300f, 0.230f, 0.095f, Quantity_TOC_RGB);
213       // Color resulting from dispersed
214       myDiffuseColor .SetValues (0.752f, 0.580f, 0.100f, Quantity_TOC_RGB);
215       // Color resulting from specular
216       mySpecularColor.SetValues (1.000f, 0.710f, 0.290f, Quantity_TOC_RGB);
217       break;
218     case Graphic3d_NOM_PEWTER:
219       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
220
221       myShininess    = 0.50f;
222       myAmbientCoef  = 1.00f;
223       myDiffuseCoef  = 1.00f;
224       mySpecularCoef = 1.00f;
225
226       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
227         Graphic3d_Fresnel::CreateConductor (1.8800f, 3.4900f), 1024.f);
228
229       // Color resulting from ambient
230       myAmbientColor .SetValues (0.106f, 0.059f, 0.114f, Quantity_TOC_RGB);
231       // Color resulting from dispersed
232       myDiffuseColor .SetValues (0.427f, 0.471f, 0.541f, Quantity_TOC_RGB);
233       // Color resulting from specular
234       mySpecularColor.SetValues (0.333f, 0.333f, 0.522f, Quantity_TOC_RGB);
235       break;
236     case Graphic3d_NOM_PLASTER:
237       myShininess    = 0.01f;
238       myAmbientCoef  = 0.26f;
239       myDiffuseCoef  = 0.75f;
240       mySpecularCoef = 0.05f;
241
242       // Color resulting from ambient
243       myAmbientColor .SetValues (0.192f, 0.192f, 0.192f, Quantity_TOC_RGB);
244       // Color resulting from dispersed
245       myDiffuseColor .SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB);
246       // Color resulting from specular
247       mySpecularColor.SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB);
248
249       myBSDF.Kd = Graphic3d_Vec3 (0.482353f, 0.482353f, 0.482353f);
250
251       break;
252     case Graphic3d_NOM_SILVER:
253       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
254
255       myShininess    = 0.75f;
256       myAmbientCoef  = 1.00f;
257       myDiffuseCoef  = 1.00f;
258       mySpecularCoef = 1.00f;
259
260       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
261         Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.971519f, 0.959915f, 0.915324f)), 1024.f);
262
263       // Color resulting from ambient
264       myAmbientColor .SetValues (0.275f, 0.275f, 0.250f, Quantity_TOC_RGB);
265       // Color resulting from dispersed
266       myDiffuseColor .SetValues (0.630f, 0.630f, 0.630f, Quantity_TOC_RGB);
267       // Color resulting from specular
268       mySpecularColor.SetValues (0.950f, 0.930f, 0.880f, Quantity_TOC_RGB);
269       break;
270     case Graphic3d_NOM_STEEL:
271       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
272
273       myShininess    = 0.90f;
274       myAmbientCoef  = 1.00f;
275       myDiffuseCoef  = 1.00f;
276       mySpecularCoef = 1.00f;
277
278       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
279         Graphic3d_Fresnel::CreateConductor (Graphic3d_Vec3 (2.90f, 2.80f, 2.53f), Graphic3d_Vec3 (3.08f, 2.90f, 2.74f)), 1024.f);
280
281       // Color resulting from ambient
282       myAmbientColor .SetValues (0.150f, 0.150f, 0.180f, Quantity_TOC_RGB);
283       // Color resulting from dispersed
284       myDiffuseColor .SetValues (0.500f, 0.510f, 0.520f, Quantity_TOC_RGB);
285       // Color resulting from specular
286       mySpecularColor.SetValues (0.560f, 0.570f, 0.580f, Quantity_TOC_RGB);
287       break;
288     case Graphic3d_NOM_STONE:
289       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
290
291       myShininess    = 0.17f;
292       myAmbientCoef  = 0.19f;
293       myDiffuseCoef  = 0.75f;
294       mySpecularCoef = 0.08f;
295
296       // Color resulting from ambient
297       myAmbientColor .SetValues (1.0,  0.8, 0.62, Quantity_TOC_RGB);
298       // Color resulting from dispersed
299       myDiffuseColor .SetValues (1.0,  0.8, 0.62, Quantity_TOC_RGB);
300       // Color resulting from specular
301       mySpecularColor.SetValues (0.98, 1.0, 0.60, Quantity_TOC_RGB);
302
303       myBSDF.Kd = Graphic3d_Vec3 (0.243137f, 0.243137f, 0.243137f);
304       myBSDF.Ks = Graphic3d_Vec3 (0.00392157f, 0.00392157f, 0.00392157f);
305
306       break;
307     // Ascending Compatibility of physical materials. Takes the same definition as in the next constructor. New materials
308     case Graphic3d_NOM_CHROME:
309       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
310
311       myShininess    = 0.90f;
312       myAmbientCoef  = 1.00f;
313       myDiffuseCoef  = 1.00f;
314       mySpecularCoef = 1.00f;
315
316       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
317         Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.549585f, 0.556114f, 0.554256f)), 1024.f);
318
319       // Color resulting from ambient
320       myAmbientColor .SetValues (0.200f, 0.200f, 0.225f, Quantity_TOC_RGB);
321       // Color resulting from dispersed
322       myDiffuseColor .SetValues (0.550f, 0.550f, 0.550f, Quantity_TOC_RGB);
323       // Color resulting from specular
324       mySpecularColor.SetValues (0.975f, 0.975f, 0.975f, Quantity_TOC_RGB);
325       break;
326     case Graphic3d_NOM_ALUMINIUM:
327       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
328
329       myShininess    = 0.75f;
330       myAmbientCoef  = 1.00f;
331       myDiffuseCoef  = 1.00f;
332       mySpecularCoef = 1.00f;
333
334       myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
335         Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.913183f, 0.921494f, 0.924524f)), 1024.f);
336
337       // Color resulting from ambient
338       myAmbientColor .SetValues (0.300f, 0.300f, 0.300f, Quantity_TOC_RGB);
339       // Color resulting from dispersed
340       myDiffuseColor .SetValues (0.600f, 0.600f, 0.600f, Quantity_TOC_RGB);
341       // Color resulting from specular
342       mySpecularColor.SetValues (0.910f, 0.920f, 0.920f, Quantity_TOC_RGB);
343       break;
344     case Graphic3d_NOM_NEON_PHC:
345       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
346
347       myShininess    = 0.05f;
348       myAmbientCoef  = 1.00f;
349       myDiffuseCoef  = 1.00f;
350       mySpecularCoef = 0.62f;
351       myEmissiveCoef = 0.90f;
352       myAmbientActivity  = Standard_False;
353       myDiffuseActivity  = Standard_False;
354       myEmissiveActivity = Standard_True;
355
356       // Color resulting from ambient
357       myAmbientColor .SetValues (1.0, 1.0, 1.0,  Quantity_TOC_RGB);
358       // Color resulting from dispersed
359       myDiffuseColor .SetValues (1.0, 1.0, 1.0,  Quantity_TOC_RGB);
360       // Color resulting from specular
361       mySpecularColor.SetValues (1.0, 1.0, 1.0,  Quantity_TOC_RGB);
362       // Color resulting from specular
363       myEmissiveColor.SetValues (0.0, 1.0, 0.46, Quantity_TOC_RGB);
364
365       myBSDF.Kr = Graphic3d_Vec3 (0.207843f, 0.207843f, 0.207843f);
366       myBSDF.Le = Graphic3d_Vec3 (0.0f, 1.0f, 0.46f);
367       myBSDF.Fresnel == Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.3f, 0.3f, 0.3f));
368       break;
369     case Graphic3d_NOM_OBSIDIAN:
370       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
371
372       myShininess    = 0.3f;
373       myAmbientCoef  = 1.0f;
374       myDiffuseCoef  = 1.0f;
375       mySpecularCoef = 1.0f;
376
377       // Color resulting from ambient
378       myAmbientColor .SetValues (0.054f, 0.050f, 0.066f, Quantity_TOC_RGB);
379       // Color resulting from dispersed
380       myDiffuseColor .SetValues (0.183f, 0.170f, 0.225f, Quantity_TOC_RGB);
381       // Color resulting from specular
382       mySpecularColor.SetValues (0.333f, 0.329f, 0.346f, Quantity_TOC_RGB);
383
384       myBSDF.Kd = Graphic3d_Vec3 (0.0156863f, 0.f, 0.0155017f);
385       myBSDF.Ks = Graphic3d_Vec3 (0.0156863f, 0.0156863f, 0.0156863f);
386       myBSDF.Roughness = 1024.f;
387       break;
388     case Graphic3d_NOM_JADE:
389       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
390
391       myShininess    = 0.10f;
392       myAmbientCoef  = 1.00f;
393       myDiffuseCoef  = 1.00f;
394       mySpecularCoef = 1.00f;
395
396       // Color resulting from ambient
397       myAmbientColor .SetValues (0.135f, 0.223f, 0.158f, Quantity_TOC_RGB);
398       // Color resulting from dispersed
399       myDiffuseColor .SetValues (0.540f, 0.890f, 0.630f, Quantity_TOC_RGB);
400       // Color resulting from specular
401       mySpecularColor.SetValues (0.316f, 0.316f, 0.316f, Quantity_TOC_RGB);
402
403       myBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (1.5f);
404       myBSDF.Kd = Graphic3d_Vec3 (0.208658f, 0.415686f, 0.218401f);
405       myBSDF.Ks = Graphic3d_Vec3 (0.611765f, 0.611765f, 0.611765f);
406       myBSDF.Roughness = 512.f;
407       break;
408     case Graphic3d_NOM_CHARCOAL:
409       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
410
411       myShininess    = 0.01f;
412       myAmbientCoef  = 1.00f;
413       myDiffuseCoef  = 1.00f;
414       mySpecularCoef = 1.00f;
415
416       // Color resulting from ambient
417       myAmbientColor .SetValues (0.050f, 0.050f, 0.050f, Quantity_TOC_RGB);
418       // Color resulting from dispersed
419       myDiffuseColor .SetValues (0.150f, 0.150f, 0.150f, Quantity_TOC_RGB);
420       // Color resulting from specular
421       mySpecularColor.SetValues (0.000f, 0.000f, 0.000f, Quantity_TOC_RGB);
422
423       myBSDF.Kd = Graphic3d_Vec3 (0.0196078f, 0.0196078f, 0.0196078f);
424       myBSDF.Ks = Graphic3d_Vec3 (0.0196078f, 0.0196078f, 0.0196078f);
425       myBSDF.Roughness = 8;
426       break;
427     case Graphic3d_NOM_WATER:
428       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
429
430       myShininess    = 0.90f;
431       myAmbientCoef  = 1.00f;
432       myDiffuseCoef  = 1.00f;
433       mySpecularCoef = 1.00f;
434       myRefractionIndex  = 1.33f;
435       myBSDF             = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
436                                                         Graphic3d_Vec3 (0.7f, 0.75f, 0.85f),
437                                                         0.05f,
438                                                         myRefractionIndex);
439       myTransparencyCoef = 0.80f;
440
441       // Color resulting from ambient
442       myAmbientColor.SetValues (0.450f, 0.450f, 0.475f, Quantity_TOC_RGB);
443       // Color resulting from dispersed
444       myDiffuseColor.SetValues (0.050f, 0.050f, 0.075f, Quantity_TOC_RGB);
445       // Color resulting from specular
446       mySpecularColor.SetValues (0.380f, 0.380f, 0.380f, Quantity_TOC_RGB);
447       break;
448     case Graphic3d_NOM_GLASS:
449       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
450
451       myShininess    = 0.50f;
452       myAmbientCoef  = 1.00f;
453       myDiffuseCoef  = 1.00f;
454       mySpecularCoef = 1.00f;
455       myRefractionIndex  = 1.62f;
456       myBSDF             = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
457                                                         Graphic3d_Vec3 (0.75f, 0.95f, 0.9f),
458                                                         0.05f,
459                                                         myRefractionIndex);
460       myTransparencyCoef = 0.80f;
461
462       // Color resulting from ambient
463       myAmbientColor.SetValues (0.550f, 0.575f, 0.575f, Quantity_TOC_RGB);
464       // Color resulting from dispersed
465       myDiffuseColor.SetValues (0.050f, 0.075f, 0.075f, Quantity_TOC_RGB);
466       // Color resulting from specular
467       mySpecularColor.SetValues (0.920f, 0.920f, 0.920f, Quantity_TOC_RGB);
468       break;
469     case Graphic3d_NOM_DIAMOND:
470       myMaterialType = Graphic3d_MATERIAL_PHYSIC;
471
472       myShininess    = 0.90f;
473       myAmbientCoef  = 1.00f;
474       myDiffuseCoef  = 1.00f;
475       mySpecularCoef = 1.00f;
476       myRefractionIndex  = 2.42f;
477       myBSDF             = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
478                                                         Graphic3d_Vec3 (0.95f, 0.95f, 0.95f),
479                                                         0.05f,
480                                                         myRefractionIndex);
481       myTransparencyCoef = 0.80f;
482
483       // Color resulting from ambient
484       myAmbientColor.SetValues (0.550f, 0.550f, 0.550f, Quantity_TOC_RGB);
485       // Color resulting from dispersed
486       myDiffuseColor.SetValues (0.100f, 0.100f, 0.100f, Quantity_TOC_RGB);
487       // Color resulting from specular
488       mySpecularColor.SetValues (0.970f, 0.970f, 0.970f, Quantity_TOC_RGB);
489       break;
490     case Graphic3d_NOM_UserDefined:
491       myStringName = "UserDefined";
492       break;
493     case Graphic3d_NOM_DEFAULT:
494     default:
495       myStringName = "Default";
496       break;
497   }
498 }
499
500 // =======================================================================
501 // function : IncreaseShine
502 // purpose  :
503 // =======================================================================
504 void Graphic3d_MaterialAspect::IncreaseShine (const Standard_Real theDelta)
505 {
506   Standard_ShortReal anOldShine = myShininess;
507   myShininess = Standard_ShortReal(myShininess + myShininess * theDelta / 100.0);
508   if (myShininess > 1.0 || myShininess < 0.0)
509   {
510     myShininess = anOldShine;
511   }
512 }
513
514 // =======================================================================
515 // function : SetMaterialType
516 // purpose  :
517 // =======================================================================
518 void Graphic3d_MaterialAspect::SetMaterialType (const Graphic3d_TypeOfMaterial theType)
519 {
520   myMaterialType = theType;
521   if (theType != myMaterialType)
522   {
523     SetMaterialName ("UserDefined");
524   }
525 }
526
527 // =======================================================================
528 // function : SetAmbient
529 // purpose  :
530 // =======================================================================
531 void Graphic3d_MaterialAspect::SetAmbient (const Standard_Real theValue)
532 {
533   if (theValue < 0.0
534    || theValue > 1.0)
535   {
536     Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetAmbient < 0. or > 1.0");
537   }
538
539   myAmbientCoef = Standard_ShortReal (theValue);
540   if (myAmbientActivity
541    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
542   {
543     SetMaterialName ("UserDefined");
544   }
545 }
546
547 // =======================================================================
548 // function : SetColor
549 // purpose  :
550 // =======================================================================
551 void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& theColor)
552 {
553   const Standard_ShortReal anAmbientCoeff = 0.25f;
554   myAmbientColor.SetValues (theColor.Red()   * anAmbientCoeff,
555                             theColor.Green() * anAmbientCoeff,
556                             theColor.Blue()  * anAmbientCoeff, Quantity_TOC_RGB);
557   myDiffuseColor = theColor;
558   if (myAmbientActivity && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
559   {
560     SetMaterialName ("UserDefined");
561   }
562 }
563
564 // =======================================================================
565 // function : SetAmbientColor
566 // purpose  :
567 // =======================================================================
568 void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& theColor)
569 {
570   myAmbientColor = theColor;
571   if (myAmbientActivity
572    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
573   {
574     SetMaterialName ("UserDefined");
575   }
576 }
577
578 // =======================================================================
579 // function : SetDiffuseColor
580 // purpose  :
581 // =======================================================================
582 void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& theColor)
583 {
584   myDiffuseColor = theColor;
585   if (myDiffuseActivity
586    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
587   {
588     SetMaterialName ("UserDefined");
589   }
590 }
591
592 // =======================================================================
593 // function : SetSpecularColor
594 // purpose  :
595 // =======================================================================
596 void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& theColor)
597 {
598   mySpecularColor = theColor;
599   if (mySpecularActivity
600    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
601   {
602     SetMaterialName ("UserDefined");
603   }
604 }
605
606 // =======================================================================
607 // function : SetEmissiveColor
608 // purpose  :
609 // =======================================================================
610 void Graphic3d_MaterialAspect::SetEmissiveColor (const Quantity_Color& theColor)
611 {
612   myEmissiveColor = theColor;
613   if (myEmissiveActivity
614    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
615   {
616     SetMaterialName ("UserDefined");
617   }
618 }
619
620 // =======================================================================
621 // function : SetDiffuse
622 // purpose  :
623 // =======================================================================
624 void Graphic3d_MaterialAspect::SetDiffuse (const Standard_Real theValue)
625 {
626   if (theValue < 0.0
627    || theValue > 1.0)
628   {
629     Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetDiffuse < 0. or > 1.0");
630   }
631
632   myDiffuseCoef  = Standard_ShortReal (theValue);
633   if (myDiffuseActivity
634    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
635   {
636     SetMaterialName ("UserDefined");
637   }
638 }
639
640 // =======================================================================
641 // function : SetEmissive
642 // purpose  :
643 // =======================================================================
644 void Graphic3d_MaterialAspect::SetEmissive (const Standard_Real theValue)
645 {
646   if (theValue < 0.0
647    || theValue > 1.0)
648   {
649     Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetEmissive < 0. or > 1.0");
650   }
651
652   myEmissiveCoef = Standard_ShortReal (theValue);
653   if (myDiffuseActivity
654    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
655   {
656     SetMaterialName ("UserDefined");
657   }
658 }
659
660 // =======================================================================
661 // function : SetReflectionModeOn
662 // purpose  :
663 // =======================================================================
664 void Graphic3d_MaterialAspect::SetReflectionModeOn (const Graphic3d_TypeOfReflection theType)
665 {
666   switch (theType)
667   {
668     case Graphic3d_TOR_AMBIENT:
669       myAmbientActivity  = Standard_True;
670       break;
671     case Graphic3d_TOR_DIFFUSE:
672       myDiffuseActivity  = Standard_True;
673       break;
674     case Graphic3d_TOR_SPECULAR:
675       mySpecularActivity = Standard_True;
676       break;
677     case Graphic3d_TOR_EMISSION:
678       myEmissiveActivity = Standard_True;
679       break;
680   }
681   if (myMaterialType == Graphic3d_MATERIAL_PHYSIC)
682   {
683     SetMaterialName ("UserDefined");
684   }
685 }
686
687 // =======================================================================
688 // function : SetReflectionModeOff
689 // purpose  :
690 // =======================================================================
691 void Graphic3d_MaterialAspect::SetReflectionModeOff (const Graphic3d_TypeOfReflection theType)
692 {
693   switch (theType)
694   {
695     case Graphic3d_TOR_AMBIENT:
696       myAmbientActivity  = Standard_False;
697       break;
698     case Graphic3d_TOR_DIFFUSE:
699       myDiffuseActivity  = Standard_False;
700       break;
701     case Graphic3d_TOR_SPECULAR:
702       mySpecularActivity = Standard_False;
703       break;
704     case Graphic3d_TOR_EMISSION:
705       myEmissiveActivity = Standard_False;
706       break;
707   }
708   if (myMaterialType == Graphic3d_MATERIAL_PHYSIC)
709   {
710     SetMaterialName ("UserDefined");
711   }
712 }
713
714 // =======================================================================
715 // function : SetSpecular
716 // purpose  :
717 // =======================================================================
718 void Graphic3d_MaterialAspect::SetSpecular (const Standard_Real theValue)
719 {
720   if (theValue < 0.0
721    || theValue > 1.0)
722   {
723     Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetSpecular < 0. or > 1.0");
724   }
725
726   mySpecularCoef  = Standard_ShortReal (theValue);
727   if (mySpecularActivity
728    && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
729   {
730     SetMaterialName ("UserDefined");
731   }
732 }
733
734 // =======================================================================
735 // function : SetTransparency
736 // purpose  :
737 // =======================================================================
738 void Graphic3d_MaterialAspect::SetTransparency (const Standard_Real theValue)
739 {
740   if (theValue < 0.0
741    || theValue > 1.0)
742   {
743     Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetTransparency < 0. or > 1.0");
744   }
745
746   myTransparencyCoef  = Standard_ShortReal (theValue);
747 }
748
749 // =======================================================================
750 // function : SetRefractionIndex
751 // purpose  :
752 // =======================================================================
753 void Graphic3d_MaterialAspect::SetRefractionIndex (const Standard_Real theValue)
754 {
755   if (theValue < 1.0)
756   {
757     Graphic3d_MaterialDefinitionError::Raise ("Bad value for refraction index < 1.0");
758   }
759
760   myRefractionIndex = static_cast<Standard_ShortReal> (theValue);
761 }
762
763 // =======================================================================
764 // function : SetBSDF
765 // purpose  :
766 // =======================================================================
767 void Graphic3d_MaterialAspect::SetBSDF (const Graphic3d_BSDF& theBSDF)
768 {
769   myBSDF = theBSDF;
770 }
771
772 // =======================================================================
773 // function : Color
774 // purpose  :
775 // =======================================================================
776 const Quantity_Color& Graphic3d_MaterialAspect::Color() const
777 {
778   // It is generally accepted to consider diffuse color as
779   // "general" color of a material when light shines on it
780   return myDiffuseColor;
781 }
782
783 // =======================================================================
784 // function : AmbientColor
785 // purpose  :
786 // =======================================================================
787 const Quantity_Color& Graphic3d_MaterialAspect::AmbientColor() const
788 {
789   return myAmbientColor;
790 }
791
792 // =======================================================================
793 // function : DiffuseColor
794 // purpose  :
795 // =======================================================================
796 const Quantity_Color& Graphic3d_MaterialAspect::DiffuseColor() const
797 {
798   return myDiffuseColor;
799 }
800
801 // =======================================================================
802 // function : SpecularColor
803 // purpose  :
804 // =======================================================================
805 const Quantity_Color& Graphic3d_MaterialAspect::SpecularColor() const
806 {
807   return mySpecularColor;
808 }
809
810 // =======================================================================
811 // function : EmissiveColor
812 // purpose  :
813 // =======================================================================
814 const Quantity_Color& Graphic3d_MaterialAspect::EmissiveColor() const
815 {
816   return myEmissiveColor;
817 }
818
819 // =======================================================================
820 // function : MaterialType
821 // purpose  :
822 // =======================================================================
823 Standard_Boolean Graphic3d_MaterialAspect::MaterialType (const Graphic3d_TypeOfMaterial theType) const
824 {
825   return myMaterialType == theType;
826 }
827
828 // =======================================================================
829 // function : ReflectionMode
830 // purpose  :
831 // =======================================================================
832 Standard_Boolean Graphic3d_MaterialAspect::ReflectionMode (const Graphic3d_TypeOfReflection theType) const
833 {
834   switch (theType)
835   {
836     case Graphic3d_TOR_AMBIENT:  return myAmbientActivity;
837     case Graphic3d_TOR_DIFFUSE:  return myDiffuseActivity;
838     case Graphic3d_TOR_SPECULAR: return mySpecularActivity;
839     case Graphic3d_TOR_EMISSION: return myEmissiveActivity;
840   }
841   return Standard_False;
842 }
843
844 // =======================================================================
845 // function : Ambient
846 // purpose  :
847 // =======================================================================
848 Standard_Real Graphic3d_MaterialAspect::Ambient() const
849 {
850   return Standard_Real (myAmbientCoef);
851 }
852
853 // =======================================================================
854 // function : Diffuse
855 // purpose  :
856 // =======================================================================
857 Standard_Real Graphic3d_MaterialAspect::Diffuse() const
858 {
859   return Standard_Real (myDiffuseCoef);
860 }
861
862 // =======================================================================
863 // function : Emissive
864 // purpose  :
865 // =======================================================================
866 Standard_Real Graphic3d_MaterialAspect::Emissive() const
867 {
868   return Standard_Real (myEmissiveCoef);
869 }
870
871 // =======================================================================
872 // function : Specular
873 // purpose  :
874 // =======================================================================
875 Standard_Real Graphic3d_MaterialAspect::Specular() const
876 {
877   return Standard_Real (mySpecularCoef);
878 }
879
880 // =======================================================================
881 // function : Transparency
882 // purpose  :
883 // =======================================================================
884 Standard_Real Graphic3d_MaterialAspect::Transparency() const
885 {
886   return Standard_Real (myTransparencyCoef);
887 }
888
889 // =======================================================================
890 // function : RefractionIndex
891 // purpose  :
892 // =======================================================================
893 Standard_Real Graphic3d_MaterialAspect::RefractionIndex() const
894 {
895   return myRefractionIndex;
896 }
897
898 // =======================================================================
899 // function : BSDF
900 // purpose  :
901 // =======================================================================
902 const Graphic3d_BSDF& Graphic3d_MaterialAspect::BSDF() const
903 {
904   return myBSDF;
905 }
906
907 // =======================================================================
908 // function : Shininess
909 // purpose  :
910 // =======================================================================
911 Standard_Real Graphic3d_MaterialAspect::Shininess() const
912 {
913   return Standard_Real (myShininess);
914 }
915
916 // =======================================================================
917 // function : SetShininess
918 // purpose  :
919 // =======================================================================
920 void Graphic3d_MaterialAspect::SetShininess (const Standard_Real theValue)
921 {
922   if (theValue < 0.0
923    || theValue > 1.0)
924   {
925     Graphic3d_MaterialDefinitionError::Raise ("Bad value for Shininess < 0. or > 1.0");
926   }
927
928   myShininess = Standard_ShortReal (theValue);
929   SetMaterialName ("UserDefined");
930 }
931
932 // =======================================================================
933 // function : SetEnvReflexion
934 // purpose  :
935 // =======================================================================
936 void Graphic3d_MaterialAspect::SetEnvReflexion (const Standard_ShortReal theValue)
937 {
938   myEnvReflexion = theValue;
939 }
940
941 // =======================================================================
942 // function : EnvReflexion
943 // purpose  :
944 // =======================================================================
945 Standard_ShortReal Graphic3d_MaterialAspect::EnvReflexion() const
946 {
947   return myEnvReflexion;
948 }
949
950 // =======================================================================
951 // function : Name
952 // purpose  :
953 // =======================================================================
954 Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::Name() const
955 {
956   return myMaterialName;
957 }
958
959 // =======================================================================
960 // function : Reset
961 // purpose  :
962 // =======================================================================
963 void Graphic3d_MaterialAspect::Reset()
964 {
965   Init (myRequestedMaterialName);
966 }
967
968 // =======================================================================
969 // function : IsEqual
970 // purpose  :
971 // =======================================================================
972 Standard_Boolean Graphic3d_MaterialAspect::IsEqual (const Graphic3d_MaterialAspect& theOther) const
973 {
974   return myAmbientCoef      == theOther.myAmbientCoef
975       && myDiffuseCoef      == theOther.myDiffuseCoef
976       && mySpecularCoef     == theOther.mySpecularCoef
977       && myEmissiveCoef     == theOther.myEmissiveCoef
978       && myTransparencyCoef == theOther.myTransparencyCoef
979       && myRefractionIndex  == theOther.myRefractionIndex
980       && myBSDF             == theOther.myBSDF
981       && myShininess        == theOther.myShininess
982       && myEnvReflexion     == theOther.myEnvReflexion
983       && myAmbientColor     == theOther.myAmbientColor
984       && myDiffuseColor     == theOther.myDiffuseColor
985       && mySpecularColor    == theOther.mySpecularColor
986       && myEmissiveColor    == theOther.myEmissiveColor
987       && myAmbientActivity  == theOther.myAmbientActivity
988       && myDiffuseActivity  == theOther.myDiffuseActivity
989       && mySpecularActivity == theOther.mySpecularActivity
990       && myEmissiveActivity == theOther.myEmissiveActivity;
991 }
992
993 // =======================================================================
994 // function : IsDifferent
995 // purpose  :
996 // =======================================================================
997 Standard_Boolean Graphic3d_MaterialAspect::IsDifferent (const Graphic3d_MaterialAspect& theOther) const
998 {
999   return !IsEqual (theOther);
1000 }
1001
1002 typedef struct _Material
1003 {
1004   const char*              name;
1005   Graphic3d_TypeOfMaterial type;
1006 } Material;
1007
1008 static Material theMaterials[] =
1009 {
1010   {"Brass",            Graphic3d_MATERIAL_PHYSIC},
1011   {"Bronze",           Graphic3d_MATERIAL_PHYSIC},
1012   {"Copper",           Graphic3d_MATERIAL_PHYSIC},
1013   {"Gold",             Graphic3d_MATERIAL_PHYSIC},
1014   {"Pewter",           Graphic3d_MATERIAL_PHYSIC},
1015   {"Plastered",        Graphic3d_MATERIAL_ASPECT},
1016   {"Plastified",       Graphic3d_MATERIAL_ASPECT},
1017   {"Silver",           Graphic3d_MATERIAL_PHYSIC},
1018   {"Steel",            Graphic3d_MATERIAL_PHYSIC},
1019   {"Stone",            Graphic3d_MATERIAL_PHYSIC},
1020   {"Shiny_plastified", Graphic3d_MATERIAL_ASPECT},
1021   {"Satined",          Graphic3d_MATERIAL_ASPECT},
1022   {"Metalized",        Graphic3d_MATERIAL_ASPECT},
1023   {"Ionized",          Graphic3d_MATERIAL_ASPECT},
1024   {"Chrome",           Graphic3d_MATERIAL_PHYSIC},
1025   {"Aluminium",        Graphic3d_MATERIAL_PHYSIC},
1026   {"Obsidian",         Graphic3d_MATERIAL_PHYSIC},
1027   {"Neon",             Graphic3d_MATERIAL_PHYSIC},
1028   {"Jade",             Graphic3d_MATERIAL_PHYSIC},
1029   {"Charcoal",         Graphic3d_MATERIAL_PHYSIC},
1030   {"Water",            Graphic3d_MATERIAL_PHYSIC},
1031   {"Glass",            Graphic3d_MATERIAL_PHYSIC},
1032   {"Diamond",          Graphic3d_MATERIAL_PHYSIC}
1033
1034 };
1035
1036 // =======================================================================
1037 // function : NumberOfMaterials
1038 // purpose  :
1039 // =======================================================================
1040 Standard_Integer Graphic3d_MaterialAspect::NumberOfMaterials()
1041 {
1042   Standard_STATIC_ASSERT(sizeof(theMaterials)/sizeof(Material) == Graphic3d_NOM_DEFAULT);
1043   return Graphic3d_NOM_DEFAULT;
1044 }
1045
1046 // =======================================================================
1047 // function : MaterialName
1048 // purpose  :
1049 // =======================================================================
1050 Standard_CString Graphic3d_MaterialAspect::MaterialName (const Standard_Integer theRank)
1051 {
1052   if (theRank < 1 || theRank > NumberOfMaterials())
1053   {
1054     Standard_OutOfRange::Raise ("BAD index of material");
1055   }
1056   return theMaterials[theRank - 1].name;
1057 }
1058
1059 // =======================================================================
1060 // function : MaterialFromName
1061 // purpose  :
1062 // =======================================================================
1063 Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName)
1064 {
1065   TCollection_AsciiString aName (theName);
1066   aName.LowerCase();
1067   aName.Capitalize();
1068   const Standard_Integer aNbMaterials = Graphic3d_MaterialAspect::NumberOfMaterials();
1069   for (Standard_Integer aMatIter = 1; aMatIter <= aNbMaterials; ++aMatIter)
1070   {
1071     if (aName == Graphic3d_MaterialAspect::MaterialName (aMatIter))
1072     {
1073       return Graphic3d_NameOfMaterial(aMatIter - 1);
1074     }
1075   }
1076
1077   // parse aliases
1078   if (aName == "Plastic")            // Plastified
1079   {
1080     return Graphic3d_NOM_PLASTIC;
1081   }
1082   else if (aName == "Shiny_plastic") // Shiny_plastified
1083   {
1084     return Graphic3d_NOM_SHINY_PLASTIC;
1085   }
1086   else if (aName == "Plaster")       // Plastered
1087   {
1088     return Graphic3d_NOM_PLASTER;
1089   }
1090   else if (aName == "Satin")         // Satined
1091   {
1092     return Graphic3d_NOM_SATIN;
1093   }
1094   else if (aName == "Neon_gnc")      // Ionized
1095   {
1096     return Graphic3d_NOM_NEON_GNC;
1097   }
1098   else if (aName == "Neon_phc") // Neon
1099   {
1100     return Graphic3d_NOM_NEON_PHC;
1101   }
1102   return Graphic3d_NOM_DEFAULT;
1103 }
1104
1105 // =======================================================================
1106 // function : MaterialType
1107 // purpose  :
1108 // =======================================================================
1109 Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType (const Standard_Integer theRank)
1110 {
1111   if (theRank < 1 || theRank > NumberOfMaterials())
1112   {
1113     Standard_OutOfRange::Raise ("BAD index of material");
1114   }
1115   return theMaterials[theRank - 1].type;
1116 }
1117
1118 // =======================================================================
1119 // function : MaterialName
1120 // purpose  :
1121 // =======================================================================
1122 Standard_CString Graphic3d_MaterialAspect::MaterialName() const
1123 {
1124   return myStringName.ToCString();
1125 }
1126
1127 // =======================================================================
1128 // function : SetMaterialName
1129 // purpose  :
1130 // =======================================================================
1131 void Graphic3d_MaterialAspect::SetMaterialName (const Standard_CString theNewName)
1132 {
1133   // if a component of a "standard" material change, the
1134   // result is no more standard (a blue gold is not a gold)
1135   myMaterialName = Graphic3d_NOM_UserDefined;
1136   myStringName   = theNewName;
1137 }