1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Graphic3d_MaterialAspect.hxx>
17 #include <Graphic3d_MaterialDefinitionError.hxx>
18 #include <Quantity_Color.hxx>
19 #include <Standard_Assert.hxx>
20 #include <Standard_OutOfRange.hxx>
22 // =======================================================================
23 // function : Graphic3d_MaterialAspect
25 // =======================================================================
26 Graphic3d_MaterialAspect::Graphic3d_MaterialAspect()
27 : myDiffuseColor (0.2, 0.2, 0.2, Quantity_TOC_RGB),
28 myAmbientColor (0.2, 0.2, 0.2, Quantity_TOC_RGB)
30 myRequestedMaterialName = Graphic3d_NOM_DEFAULT;
31 Init (myRequestedMaterialName);
34 // =======================================================================
35 // function : Graphic3d_MaterialAspect
37 // =======================================================================
38 Graphic3d_MaterialAspect::Graphic3d_MaterialAspect (const Graphic3d_NameOfMaterial theName)
39 : myDiffuseColor (0.2, 0.2, 0.2, Quantity_TOC_RGB),
40 myAmbientColor (0.2, 0.2, 0.2, Quantity_TOC_RGB)
42 myRequestedMaterialName = theName;
43 Init (myRequestedMaterialName);
46 // =======================================================================
49 // =======================================================================
50 void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
52 myMaterialType = Graphic3d_MATERIAL_ASPECT;
53 myTransparencyCoef = 0.0f;
54 myRefractionIndex = 1.0f;
55 myDiffuseActivity = Standard_True;
56 myDiffuseCoef = 0.65f;
57 myAmbientActivity = Standard_True;
59 mySpecularActivity = Standard_True;
60 mySpecularCoef = 0.0f;
61 myEmissiveActivity = Standard_False;
62 myEmissiveCoef = 0.0f;
63 myEnvReflexion = 0.0f;
65 myDiffuseColor .SetValues (0.2, 0.2, 0.2, Quantity_TOC_RGB);
66 mySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB);
67 myMaterialName = theName;
69 myBSDF = Graphic3d_BSDF::CreateDiffuse (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f));
71 Standard_Integer index = Standard_Integer (theName);
72 if (index < NumberOfMaterials())
74 myStringName = MaterialName (index + 1);
79 case Graphic3d_NOM_PLASTIC:
80 myShininess = Standard_ShortReal (0.0078125);
81 myAmbientCoef = Standard_ShortReal (0.5);
82 myDiffuseCoef = Standard_ShortReal (0.24);
83 mySpecularCoef = Standard_ShortReal (0.06);
85 myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
86 static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
87 static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
88 myBSDF.Ks = Graphic3d_Vec3 (0.00784314f, 0.00784314f, 0.00784314f);
90 myBSDF.Roughness = 32;
92 case Graphic3d_NOM_SHINY_PLASTIC:
93 myShininess = Standard_ShortReal (1.0);
94 myAmbientCoef = Standard_ShortReal (0.44);
95 myDiffuseCoef = Standard_ShortReal (0.5);
96 mySpecularCoef = Standard_ShortReal (1.0);
98 myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
99 static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
100 static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
101 myBSDF.Ks = Graphic3d_Vec3 (0.0156863f, 0.0156863f, 0.0156863f);
103 myBSDF.Roughness = 64.f;
105 case Graphic3d_NOM_SATIN :
106 myShininess = Standard_ShortReal (0.09375);
107 myAmbientCoef = Standard_ShortReal (0.33);
108 myDiffuseCoef = Standard_ShortReal (0.4);
109 mySpecularCoef = Standard_ShortReal (0.44);
111 myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
112 static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
113 static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
114 myBSDF.Ks = Graphic3d_Vec3 (0.0313726f, 0.0313726f, 0.0313726f);
115 myBSDF.Roughness = 16.f;
118 case Graphic3d_NOM_NEON_GNC:
119 myShininess = Standard_ShortReal (0.05);
120 myAmbientCoef = Standard_ShortReal (1.0);
121 myDiffuseCoef = Standard_ShortReal (1.0);
122 mySpecularCoef = Standard_ShortReal (0.62);
123 myEmissiveCoef = Standard_ShortReal (1.0);
124 myEmissiveActivity = Standard_True;
125 myAmbientActivity = Standard_False;
127 myBSDF.Kr = Graphic3d_Vec3 (0.207843f, 0.207843f, 0.207843f);
128 myBSDF.Le = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
129 static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
130 static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
131 myBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.3f, 0.3f, 0.3f));
133 case Graphic3d_NOM_METALIZED:
134 myShininess = Standard_ShortReal (0.13);
135 myAmbientCoef = Standard_ShortReal (0.9);
136 myDiffuseCoef = Standard_ShortReal (0.47);
137 mySpecularCoef = Standard_ShortReal (0.45);
138 myAmbientActivity = Standard_False;
141 Graphic3d_Vec3 aColor (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
142 static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
143 static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
145 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
146 Graphic3d_Fresnel::CreateSchlick (aColor), 1024.f);
149 // Ascending Compatibility physical materials. The same definition is taken as in the next constructor.
150 case Graphic3d_NOM_BRASS:
151 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
154 myAmbientCoef = 1.00f;
155 myDiffuseCoef = 1.00f;
156 mySpecularCoef = 1.00f;
158 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
159 Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.58f, 0.42f, 0.20f)), 1024.f);
161 // Color resulting from ambient
162 myAmbientColor .SetValues (0.329f, 0.224f, 0.027f, Quantity_TOC_RGB);
163 // Color resulting from dispersed
164 myDiffuseColor .SetValues (0.780f, 0.569f, 0.114f, Quantity_TOC_RGB);
165 // Color resulting from specular
166 mySpecularColor.SetValues (0.992f, 0.941f, 0.808f, Quantity_TOC_RGB);
168 case Graphic3d_NOM_BRONZE:
169 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
172 myAmbientCoef = 1.00f;
173 myDiffuseCoef = 1.00f;
174 mySpecularCoef = 1.00f;
176 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
177 Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.65f, 0.35f, 0.15f)), 1024.f);
179 // Color resulting from ambient
180 myAmbientColor .SetValues (0.213f, 0.128f, 0.054f, Quantity_TOC_RGB);
181 // Color resulting from dispersed
182 myDiffuseColor .SetValues (0.714f, 0.428f, 0.181f, Quantity_TOC_RGB);
183 // Color resulting from specular
184 mySpecularColor.SetValues (0.590f, 0.408f, 0.250f, Quantity_TOC_RGB);
186 case Graphic3d_NOM_COPPER:
187 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
190 myAmbientCoef = 1.00f;
191 myDiffuseCoef = 1.00f;
192 mySpecularCoef = 1.00f;
194 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
195 Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.955008f, 0.637427f, 0.538163f)), 1024.f);
197 // Color resulting from ambient
198 myAmbientColor .SetValues (0.191f, 0.074f, 0.023f, Quantity_TOC_RGB);
199 // Color resulting from dispersed
200 myDiffuseColor .SetValues (0.604f, 0.270f, 0.083f, Quantity_TOC_RGB);
201 // Color resulting from specular
202 mySpecularColor.SetValues (0.950f, 0.640f, 0.540f, Quantity_TOC_RGB);
204 case Graphic3d_NOM_GOLD:
205 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
208 myAmbientCoef = 1.00f;
209 myDiffuseCoef = 1.00f;
210 mySpecularCoef = 1.00f;
212 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
213 Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (1.000000f, 0.765557f, 0.336057f)), 1024.f);
215 // Color resulting from ambient
216 myAmbientColor .SetValues (0.300f, 0.230f, 0.095f, Quantity_TOC_RGB);
217 // Color resulting from dispersed
218 myDiffuseColor .SetValues (0.752f, 0.580f, 0.100f, Quantity_TOC_RGB);
219 // Color resulting from specular
220 mySpecularColor.SetValues (1.000f, 0.710f, 0.290f, Quantity_TOC_RGB);
222 case Graphic3d_NOM_PEWTER:
223 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
226 myAmbientCoef = 1.00f;
227 myDiffuseCoef = 1.00f;
228 mySpecularCoef = 1.00f;
230 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
231 Graphic3d_Fresnel::CreateConductor (1.8800f, 3.4900f), 1024.f);
233 // Color resulting from ambient
234 myAmbientColor .SetValues (0.106f, 0.059f, 0.114f, Quantity_TOC_RGB);
235 // Color resulting from dispersed
236 myDiffuseColor .SetValues (0.427f, 0.471f, 0.541f, Quantity_TOC_RGB);
237 // Color resulting from specular
238 mySpecularColor.SetValues (0.333f, 0.333f, 0.522f, Quantity_TOC_RGB);
240 case Graphic3d_NOM_PLASTER:
242 myAmbientCoef = 0.26f;
243 myDiffuseCoef = 0.75f;
244 mySpecularCoef = 0.05f;
246 // Color resulting from ambient
247 myAmbientColor .SetValues (0.192f, 0.192f, 0.192f, Quantity_TOC_RGB);
248 // Color resulting from dispersed
249 myDiffuseColor .SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB);
250 // Color resulting from specular
251 mySpecularColor.SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB);
253 myBSDF.Kd = Graphic3d_Vec3 (0.482353f, 0.482353f, 0.482353f);
256 case Graphic3d_NOM_SILVER:
257 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
260 myAmbientCoef = 1.00f;
261 myDiffuseCoef = 1.00f;
262 mySpecularCoef = 1.00f;
264 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
265 Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.971519f, 0.959915f, 0.915324f)), 1024.f);
267 // Color resulting from ambient
268 myAmbientColor .SetValues (0.275f, 0.275f, 0.250f, Quantity_TOC_RGB);
269 // Color resulting from dispersed
270 myDiffuseColor .SetValues (0.630f, 0.630f, 0.630f, Quantity_TOC_RGB);
271 // Color resulting from specular
272 mySpecularColor.SetValues (0.950f, 0.930f, 0.880f, Quantity_TOC_RGB);
274 case Graphic3d_NOM_STEEL:
275 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
278 myAmbientCoef = 1.00f;
279 myDiffuseCoef = 1.00f;
280 mySpecularCoef = 1.00f;
282 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
283 Graphic3d_Fresnel::CreateConductor (Graphic3d_Vec3 (2.90f, 2.80f, 2.53f), Graphic3d_Vec3 (3.08f, 2.90f, 2.74f)), 1024.f);
285 // Color resulting from ambient
286 myAmbientColor .SetValues (0.150f, 0.150f, 0.180f, Quantity_TOC_RGB);
287 // Color resulting from dispersed
288 myDiffuseColor .SetValues (0.500f, 0.510f, 0.520f, Quantity_TOC_RGB);
289 // Color resulting from specular
290 mySpecularColor.SetValues (0.560f, 0.570f, 0.580f, Quantity_TOC_RGB);
292 case Graphic3d_NOM_STONE:
293 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
296 myAmbientCoef = 0.19f;
297 myDiffuseCoef = 0.75f;
298 mySpecularCoef = 0.08f;
300 // Color resulting from ambient
301 myAmbientColor .SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB);
302 // Color resulting from dispersed
303 myDiffuseColor .SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB);
304 // Color resulting from specular
305 mySpecularColor.SetValues (0.98, 1.0, 0.60, Quantity_TOC_RGB);
307 myBSDF.Kd = Graphic3d_Vec3 (0.243137f, 0.243137f, 0.243137f);
308 myBSDF.Ks = Graphic3d_Vec3 (0.00392157f, 0.00392157f, 0.00392157f);
311 // Ascending Compatibility of physical materials. Takes the same definition as in the next constructor. New materials
312 case Graphic3d_NOM_CHROME:
313 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
316 myAmbientCoef = 1.00f;
317 myDiffuseCoef = 1.00f;
318 mySpecularCoef = 1.00f;
320 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
321 Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.549585f, 0.556114f, 0.554256f)), 1024.f);
323 // Color resulting from ambient
324 myAmbientColor .SetValues (0.200f, 0.200f, 0.225f, Quantity_TOC_RGB);
325 // Color resulting from dispersed
326 myDiffuseColor .SetValues (0.550f, 0.550f, 0.550f, Quantity_TOC_RGB);
327 // Color resulting from specular
328 mySpecularColor.SetValues (0.975f, 0.975f, 0.975f, Quantity_TOC_RGB);
330 case Graphic3d_NOM_ALUMINIUM:
331 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
334 myAmbientCoef = 1.00f;
335 myDiffuseCoef = 1.00f;
336 mySpecularCoef = 1.00f;
338 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
339 Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.913183f, 0.921494f, 0.924524f)), 1024.f);
341 // Color resulting from ambient
342 myAmbientColor .SetValues (0.300f, 0.300f, 0.300f, Quantity_TOC_RGB);
343 // Color resulting from dispersed
344 myDiffuseColor .SetValues (0.600f, 0.600f, 0.600f, Quantity_TOC_RGB);
345 // Color resulting from specular
346 mySpecularColor.SetValues (0.910f, 0.920f, 0.920f, Quantity_TOC_RGB);
348 case Graphic3d_NOM_NEON_PHC:
349 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
352 myAmbientCoef = 1.00f;
353 myDiffuseCoef = 1.00f;
354 mySpecularCoef = 0.62f;
355 myEmissiveCoef = 0.90f;
356 myAmbientActivity = Standard_False;
357 myDiffuseActivity = Standard_False;
358 myEmissiveActivity = Standard_True;
360 // Color resulting from ambient
361 myAmbientColor .SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB);
362 // Color resulting from dispersed
363 myDiffuseColor .SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB);
364 // Color resulting from specular
365 mySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB);
366 // Color resulting from specular
367 myEmissiveColor.SetValues (0.0, 1.0, 0.46, Quantity_TOC_RGB);
369 myBSDF.Kr = Graphic3d_Vec3 (0.207843f, 0.207843f, 0.207843f);
370 myBSDF.Le = Graphic3d_Vec3 (0.0f, 1.0f, 0.46f);
371 myBSDF.Fresnel = Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.3f, 0.3f, 0.3f));
373 case Graphic3d_NOM_OBSIDIAN:
374 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
377 myAmbientCoef = 1.0f;
378 myDiffuseCoef = 1.0f;
379 mySpecularCoef = 1.0f;
381 // Color resulting from ambient
382 myAmbientColor .SetValues (0.054f, 0.050f, 0.066f, Quantity_TOC_RGB);
383 // Color resulting from dispersed
384 myDiffuseColor .SetValues (0.183f, 0.170f, 0.225f, Quantity_TOC_RGB);
385 // Color resulting from specular
386 mySpecularColor.SetValues (0.333f, 0.329f, 0.346f, Quantity_TOC_RGB);
388 myBSDF.Kd = Graphic3d_Vec3 (0.0156863f, 0.f, 0.0155017f);
389 myBSDF.Ks = Graphic3d_Vec3 (0.0156863f, 0.0156863f, 0.0156863f);
390 myBSDF.Roughness = 1024.f;
392 case Graphic3d_NOM_JADE:
393 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
396 myAmbientCoef = 1.00f;
397 myDiffuseCoef = 1.00f;
398 mySpecularCoef = 1.00f;
400 // Color resulting from ambient
401 myAmbientColor .SetValues (0.135f, 0.223f, 0.158f, Quantity_TOC_RGB);
402 // Color resulting from dispersed
403 myDiffuseColor .SetValues (0.540f, 0.890f, 0.630f, Quantity_TOC_RGB);
404 // Color resulting from specular
405 mySpecularColor.SetValues (0.316f, 0.316f, 0.316f, Quantity_TOC_RGB);
407 myBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (1.5f);
408 myBSDF.Kd = Graphic3d_Vec3 (0.208658f, 0.415686f, 0.218401f);
409 myBSDF.Ks = Graphic3d_Vec3 (0.611765f, 0.611765f, 0.611765f);
410 myBSDF.Roughness = 512.f;
412 case Graphic3d_NOM_CHARCOAL:
413 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
416 myAmbientCoef = 1.00f;
417 myDiffuseCoef = 1.00f;
418 mySpecularCoef = 1.00f;
420 // Color resulting from ambient
421 myAmbientColor .SetValues (0.050f, 0.050f, 0.050f, Quantity_TOC_RGB);
422 // Color resulting from dispersed
423 myDiffuseColor .SetValues (0.150f, 0.150f, 0.150f, Quantity_TOC_RGB);
424 // Color resulting from specular
425 mySpecularColor.SetValues (0.000f, 0.000f, 0.000f, Quantity_TOC_RGB);
427 myBSDF.Kd = Graphic3d_Vec3 (0.0196078f, 0.0196078f, 0.0196078f);
428 myBSDF.Ks = Graphic3d_Vec3 (0.0196078f, 0.0196078f, 0.0196078f);
429 myBSDF.Roughness = 8;
431 case Graphic3d_NOM_WATER:
432 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
435 myAmbientCoef = 1.00f;
436 myDiffuseCoef = 1.00f;
437 mySpecularCoef = 1.00f;
438 myRefractionIndex = 1.33f;
439 myBSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
440 Graphic3d_Vec3 (0.7f, 0.75f, 0.85f),
443 myTransparencyCoef = 0.80f;
445 // Color resulting from ambient
446 myAmbientColor.SetValues (0.450f, 0.450f, 0.475f, Quantity_TOC_RGB);
447 // Color resulting from dispersed
448 myDiffuseColor.SetValues (0.050f, 0.050f, 0.075f, Quantity_TOC_RGB);
449 // Color resulting from specular
450 mySpecularColor.SetValues (0.380f, 0.380f, 0.380f, Quantity_TOC_RGB);
452 case Graphic3d_NOM_GLASS:
453 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
456 myAmbientCoef = 1.00f;
457 myDiffuseCoef = 1.00f;
458 mySpecularCoef = 1.00f;
459 myRefractionIndex = 1.62f;
460 myBSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
461 Graphic3d_Vec3 (0.75f, 0.95f, 0.9f),
464 myTransparencyCoef = 0.80f;
466 // Color resulting from ambient
467 myAmbientColor.SetValues (0.550f, 0.575f, 0.575f, Quantity_TOC_RGB);
468 // Color resulting from dispersed
469 myDiffuseColor.SetValues (0.050f, 0.075f, 0.075f, Quantity_TOC_RGB);
470 // Color resulting from specular
471 mySpecularColor.SetValues (0.920f, 0.920f, 0.920f, Quantity_TOC_RGB);
473 case Graphic3d_NOM_DIAMOND:
474 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
477 myAmbientCoef = 1.00f;
478 myDiffuseCoef = 1.00f;
479 mySpecularCoef = 1.00f;
480 myRefractionIndex = 2.42f;
481 myBSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
482 Graphic3d_Vec3 (0.95f, 0.95f, 0.95f),
485 myTransparencyCoef = 0.80f;
487 // Color resulting from ambient
488 myAmbientColor.SetValues (0.550f, 0.550f, 0.550f, Quantity_TOC_RGB);
489 // Color resulting from dispersed
490 myDiffuseColor.SetValues (0.100f, 0.100f, 0.100f, Quantity_TOC_RGB);
491 // Color resulting from specular
492 mySpecularColor.SetValues (0.970f, 0.970f, 0.970f, Quantity_TOC_RGB);
494 case Graphic3d_NOM_UserDefined:
495 myStringName = "UserDefined";
497 case Graphic3d_NOM_DEFAULT:
499 myStringName = "Default";
504 // =======================================================================
505 // function : IncreaseShine
507 // =======================================================================
508 void Graphic3d_MaterialAspect::IncreaseShine (const Standard_Real theDelta)
510 Standard_ShortReal anOldShine = myShininess;
511 myShininess = Standard_ShortReal(myShininess + myShininess * theDelta / 100.0);
512 if (myShininess > 1.0 || myShininess < 0.0)
514 myShininess = anOldShine;
518 // =======================================================================
519 // function : SetMaterialType
521 // =======================================================================
522 void Graphic3d_MaterialAspect::SetMaterialType (const Graphic3d_TypeOfMaterial theType)
524 myMaterialType = theType;
525 if (theType != myMaterialType)
527 SetMaterialName ("UserDefined");
531 // =======================================================================
532 // function : SetAmbient
534 // =======================================================================
535 void Graphic3d_MaterialAspect::SetAmbient (const Standard_Real theValue)
540 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetAmbient < 0. or > 1.0");
543 myAmbientCoef = Standard_ShortReal (theValue);
544 if (myAmbientActivity
545 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
547 SetMaterialName ("UserDefined");
551 // =======================================================================
552 // function : SetColor
554 // =======================================================================
555 void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& theColor)
557 const Standard_ShortReal anAmbientCoeff = 0.25f;
558 myAmbientColor.SetValues (theColor.Red() * anAmbientCoeff,
559 theColor.Green() * anAmbientCoeff,
560 theColor.Blue() * anAmbientCoeff, Quantity_TOC_RGB);
561 myDiffuseColor = theColor;
562 if (myAmbientActivity && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
564 SetMaterialName ("UserDefined");
568 // =======================================================================
569 // function : SetAmbientColor
571 // =======================================================================
572 void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& theColor)
574 myAmbientColor = theColor;
575 if (myAmbientActivity
576 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
578 SetMaterialName ("UserDefined");
582 // =======================================================================
583 // function : SetDiffuseColor
585 // =======================================================================
586 void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& theColor)
588 myDiffuseColor = theColor;
589 if (myDiffuseActivity
590 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
592 SetMaterialName ("UserDefined");
596 // =======================================================================
597 // function : SetSpecularColor
599 // =======================================================================
600 void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& theColor)
602 mySpecularColor = theColor;
603 if (mySpecularActivity
604 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
606 SetMaterialName ("UserDefined");
610 // =======================================================================
611 // function : SetEmissiveColor
613 // =======================================================================
614 void Graphic3d_MaterialAspect::SetEmissiveColor (const Quantity_Color& theColor)
616 myEmissiveColor = theColor;
617 if (myEmissiveActivity
618 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
620 SetMaterialName ("UserDefined");
624 // =======================================================================
625 // function : SetDiffuse
627 // =======================================================================
628 void Graphic3d_MaterialAspect::SetDiffuse (const Standard_Real theValue)
633 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetDiffuse < 0. or > 1.0");
636 myDiffuseCoef = Standard_ShortReal (theValue);
637 if (myDiffuseActivity
638 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
640 SetMaterialName ("UserDefined");
644 // =======================================================================
645 // function : SetEmissive
647 // =======================================================================
648 void Graphic3d_MaterialAspect::SetEmissive (const Standard_Real theValue)
653 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetEmissive < 0. or > 1.0");
656 myEmissiveCoef = Standard_ShortReal (theValue);
657 if (myDiffuseActivity
658 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
660 SetMaterialName ("UserDefined");
664 // =======================================================================
665 // function : SetReflectionModeOn
667 // =======================================================================
668 void Graphic3d_MaterialAspect::SetReflectionModeOn (const Graphic3d_TypeOfReflection theType)
672 case Graphic3d_TOR_AMBIENT:
673 myAmbientActivity = Standard_True;
675 case Graphic3d_TOR_DIFFUSE:
676 myDiffuseActivity = Standard_True;
678 case Graphic3d_TOR_SPECULAR:
679 mySpecularActivity = Standard_True;
681 case Graphic3d_TOR_EMISSION:
682 myEmissiveActivity = Standard_True;
685 if (myMaterialType == Graphic3d_MATERIAL_PHYSIC)
687 SetMaterialName ("UserDefined");
691 // =======================================================================
692 // function : SetReflectionModeOff
694 // =======================================================================
695 void Graphic3d_MaterialAspect::SetReflectionModeOff (const Graphic3d_TypeOfReflection theType)
699 case Graphic3d_TOR_AMBIENT:
700 myAmbientActivity = Standard_False;
702 case Graphic3d_TOR_DIFFUSE:
703 myDiffuseActivity = Standard_False;
705 case Graphic3d_TOR_SPECULAR:
706 mySpecularActivity = Standard_False;
708 case Graphic3d_TOR_EMISSION:
709 myEmissiveActivity = Standard_False;
712 if (myMaterialType == Graphic3d_MATERIAL_PHYSIC)
714 SetMaterialName ("UserDefined");
718 // =======================================================================
719 // function : SetSpecular
721 // =======================================================================
722 void Graphic3d_MaterialAspect::SetSpecular (const Standard_Real theValue)
727 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetSpecular < 0. or > 1.0");
730 mySpecularCoef = Standard_ShortReal (theValue);
731 if (mySpecularActivity
732 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
734 SetMaterialName ("UserDefined");
738 // =======================================================================
739 // function : SetTransparency
741 // =======================================================================
742 void Graphic3d_MaterialAspect::SetTransparency (const Standard_Real theValue)
747 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetTransparency < 0. or > 1.0");
750 myTransparencyCoef = Standard_ShortReal (theValue);
753 // =======================================================================
754 // function : SetRefractionIndex
756 // =======================================================================
757 void Graphic3d_MaterialAspect::SetRefractionIndex (const Standard_Real theValue)
761 Graphic3d_MaterialDefinitionError::Raise ("Bad value for refraction index < 1.0");
764 myRefractionIndex = static_cast<Standard_ShortReal> (theValue);
767 // =======================================================================
768 // function : SetBSDF
770 // =======================================================================
771 void Graphic3d_MaterialAspect::SetBSDF (const Graphic3d_BSDF& theBSDF)
776 // =======================================================================
779 // =======================================================================
780 const Quantity_Color& Graphic3d_MaterialAspect::Color() const
782 // It is generally accepted to consider diffuse color as
783 // "general" color of a material when light shines on it
784 return myDiffuseColor;
787 // =======================================================================
788 // function : AmbientColor
790 // =======================================================================
791 const Quantity_Color& Graphic3d_MaterialAspect::AmbientColor() const
793 return myAmbientColor;
796 // =======================================================================
797 // function : DiffuseColor
799 // =======================================================================
800 const Quantity_Color& Graphic3d_MaterialAspect::DiffuseColor() const
802 return myDiffuseColor;
805 // =======================================================================
806 // function : SpecularColor
808 // =======================================================================
809 const Quantity_Color& Graphic3d_MaterialAspect::SpecularColor() const
811 return mySpecularColor;
814 // =======================================================================
815 // function : EmissiveColor
817 // =======================================================================
818 const Quantity_Color& Graphic3d_MaterialAspect::EmissiveColor() const
820 return myEmissiveColor;
823 // =======================================================================
824 // function : MaterialType
826 // =======================================================================
827 Standard_Boolean Graphic3d_MaterialAspect::MaterialType (const Graphic3d_TypeOfMaterial theType) const
829 return myMaterialType == theType;
832 // =======================================================================
833 // function : ReflectionMode
835 // =======================================================================
836 Standard_Boolean Graphic3d_MaterialAspect::ReflectionMode (const Graphic3d_TypeOfReflection theType) const
840 case Graphic3d_TOR_AMBIENT: return myAmbientActivity;
841 case Graphic3d_TOR_DIFFUSE: return myDiffuseActivity;
842 case Graphic3d_TOR_SPECULAR: return mySpecularActivity;
843 case Graphic3d_TOR_EMISSION: return myEmissiveActivity;
845 return Standard_False;
848 // =======================================================================
849 // function : Ambient
851 // =======================================================================
852 Standard_Real Graphic3d_MaterialAspect::Ambient() const
854 return Standard_Real (myAmbientCoef);
857 // =======================================================================
858 // function : Diffuse
860 // =======================================================================
861 Standard_Real Graphic3d_MaterialAspect::Diffuse() const
863 return Standard_Real (myDiffuseCoef);
866 // =======================================================================
867 // function : Emissive
869 // =======================================================================
870 Standard_Real Graphic3d_MaterialAspect::Emissive() const
872 return Standard_Real (myEmissiveCoef);
875 // =======================================================================
876 // function : Specular
878 // =======================================================================
879 Standard_Real Graphic3d_MaterialAspect::Specular() const
881 return Standard_Real (mySpecularCoef);
884 // =======================================================================
885 // function : Transparency
887 // =======================================================================
888 Standard_Real Graphic3d_MaterialAspect::Transparency() const
890 return Standard_Real (myTransparencyCoef);
893 // =======================================================================
894 // function : RefractionIndex
896 // =======================================================================
897 Standard_Real Graphic3d_MaterialAspect::RefractionIndex() const
899 return myRefractionIndex;
902 // =======================================================================
905 // =======================================================================
906 const Graphic3d_BSDF& Graphic3d_MaterialAspect::BSDF() const
911 // =======================================================================
912 // function : Shininess
914 // =======================================================================
915 Standard_Real Graphic3d_MaterialAspect::Shininess() const
917 return Standard_Real (myShininess);
920 // =======================================================================
921 // function : SetShininess
923 // =======================================================================
924 void Graphic3d_MaterialAspect::SetShininess (const Standard_Real theValue)
929 Graphic3d_MaterialDefinitionError::Raise ("Bad value for Shininess < 0. or > 1.0");
932 myShininess = Standard_ShortReal (theValue);
933 SetMaterialName ("UserDefined");
936 // =======================================================================
937 // function : SetEnvReflexion
939 // =======================================================================
940 void Graphic3d_MaterialAspect::SetEnvReflexion (const Standard_ShortReal theValue)
942 myEnvReflexion = theValue;
945 // =======================================================================
946 // function : EnvReflexion
948 // =======================================================================
949 Standard_ShortReal Graphic3d_MaterialAspect::EnvReflexion() const
951 return myEnvReflexion;
954 // =======================================================================
957 // =======================================================================
958 Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::Name() const
960 return myMaterialName;
963 // =======================================================================
966 // =======================================================================
967 void Graphic3d_MaterialAspect::Reset()
969 Init (myRequestedMaterialName);
972 // =======================================================================
973 // function : IsEqual
975 // =======================================================================
976 Standard_Boolean Graphic3d_MaterialAspect::IsEqual (const Graphic3d_MaterialAspect& theOther) const
978 return myAmbientCoef == theOther.myAmbientCoef
979 && myDiffuseCoef == theOther.myDiffuseCoef
980 && mySpecularCoef == theOther.mySpecularCoef
981 && myEmissiveCoef == theOther.myEmissiveCoef
982 && myTransparencyCoef == theOther.myTransparencyCoef
983 && myRefractionIndex == theOther.myRefractionIndex
984 && myBSDF == theOther.myBSDF
985 && myShininess == theOther.myShininess
986 && myEnvReflexion == theOther.myEnvReflexion
987 && myAmbientColor == theOther.myAmbientColor
988 && myDiffuseColor == theOther.myDiffuseColor
989 && mySpecularColor == theOther.mySpecularColor
990 && myEmissiveColor == theOther.myEmissiveColor
991 && myAmbientActivity == theOther.myAmbientActivity
992 && myDiffuseActivity == theOther.myDiffuseActivity
993 && mySpecularActivity == theOther.mySpecularActivity
994 && myEmissiveActivity == theOther.myEmissiveActivity;
997 // =======================================================================
998 // function : IsDifferent
1000 // =======================================================================
1001 Standard_Boolean Graphic3d_MaterialAspect::IsDifferent (const Graphic3d_MaterialAspect& theOther) const
1003 return !IsEqual (theOther);
1006 typedef struct _Material
1009 Graphic3d_TypeOfMaterial type;
1014 static const Material theMaterials[] =
1016 {"Brass", Graphic3d_MATERIAL_PHYSIC},
1017 {"Bronze", Graphic3d_MATERIAL_PHYSIC},
1018 {"Copper", Graphic3d_MATERIAL_PHYSIC},
1019 {"Gold", Graphic3d_MATERIAL_PHYSIC},
1020 {"Pewter", Graphic3d_MATERIAL_PHYSIC},
1021 {"Plastered", Graphic3d_MATERIAL_ASPECT},
1022 {"Plastified", Graphic3d_MATERIAL_ASPECT},
1023 {"Silver", Graphic3d_MATERIAL_PHYSIC},
1024 {"Steel", Graphic3d_MATERIAL_PHYSIC},
1025 {"Stone", Graphic3d_MATERIAL_PHYSIC},
1026 {"Shiny_plastified", Graphic3d_MATERIAL_ASPECT},
1027 {"Satined", Graphic3d_MATERIAL_ASPECT},
1028 {"Metalized", Graphic3d_MATERIAL_ASPECT},
1029 {"Ionized", Graphic3d_MATERIAL_ASPECT},
1030 {"Chrome", Graphic3d_MATERIAL_PHYSIC},
1031 {"Aluminium", Graphic3d_MATERIAL_PHYSIC},
1032 {"Obsidian", Graphic3d_MATERIAL_PHYSIC},
1033 {"Neon", Graphic3d_MATERIAL_PHYSIC},
1034 {"Jade", Graphic3d_MATERIAL_PHYSIC},
1035 {"Charcoal", Graphic3d_MATERIAL_PHYSIC},
1036 {"Water", Graphic3d_MATERIAL_PHYSIC},
1037 {"Glass", Graphic3d_MATERIAL_PHYSIC},
1038 {"Diamond", Graphic3d_MATERIAL_PHYSIC}
1043 // =======================================================================
1044 // function : NumberOfMaterials
1046 // =======================================================================
1047 Standard_Integer Graphic3d_MaterialAspect::NumberOfMaterials()
1049 Standard_STATIC_ASSERT(sizeof(theMaterials)/sizeof(Material) == Graphic3d_NOM_DEFAULT);
1050 return Graphic3d_NOM_DEFAULT;
1053 // =======================================================================
1054 // function : MaterialName
1056 // =======================================================================
1057 Standard_CString Graphic3d_MaterialAspect::MaterialName (const Standard_Integer theRank)
1059 if (theRank < 1 || theRank > NumberOfMaterials())
1061 Standard_OutOfRange::Raise ("BAD index of material");
1063 return theMaterials[theRank - 1].name;
1066 // =======================================================================
1067 // function : MaterialFromName
1069 // =======================================================================
1070 Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName)
1072 TCollection_AsciiString aName (theName);
1075 const Standard_Integer aNbMaterials = Graphic3d_MaterialAspect::NumberOfMaterials();
1076 for (Standard_Integer aMatIter = 1; aMatIter <= aNbMaterials; ++aMatIter)
1078 if (aName == Graphic3d_MaterialAspect::MaterialName (aMatIter))
1080 return Graphic3d_NameOfMaterial(aMatIter - 1);
1085 if (aName == "Plastic") // Plastified
1087 return Graphic3d_NOM_PLASTIC;
1089 else if (aName == "Shiny_plastic") // Shiny_plastified
1091 return Graphic3d_NOM_SHINY_PLASTIC;
1093 else if (aName == "Plaster") // Plastered
1095 return Graphic3d_NOM_PLASTER;
1097 else if (aName == "Satin") // Satined
1099 return Graphic3d_NOM_SATIN;
1101 else if (aName == "Neon_gnc") // Ionized
1103 return Graphic3d_NOM_NEON_GNC;
1105 else if (aName == "Neon_phc") // Neon
1107 return Graphic3d_NOM_NEON_PHC;
1109 return Graphic3d_NOM_DEFAULT;
1112 // =======================================================================
1113 // function : MaterialType
1115 // =======================================================================
1116 Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType (const Standard_Integer theRank)
1118 if (theRank < 1 || theRank > NumberOfMaterials())
1120 Standard_OutOfRange::Raise ("BAD index of material");
1122 return theMaterials[theRank - 1].type;
1125 // =======================================================================
1126 // function : MaterialName
1128 // =======================================================================
1129 Standard_CString Graphic3d_MaterialAspect::MaterialName() const
1131 return myStringName.ToCString();
1134 // =======================================================================
1135 // function : SetMaterialName
1137 // =======================================================================
1138 void Graphic3d_MaterialAspect::SetMaterialName (const Standard_CString theNewName)
1140 // if a component of a "standard" material change, the
1141 // result is no more standard (a blue gold is not a gold)
1142 myMaterialName = Graphic3d_NOM_UserDefined;
1143 myStringName = theNewName;