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.
15 #include <Graphic3d_MaterialAspect.ixx>
16 #include <Standard_Assert.hxx>
18 // =======================================================================
19 // function : Graphic3d_MaterialAspect
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)
26 myRequestedMaterialName = Graphic3d_NOM_DEFAULT;
27 Init (myRequestedMaterialName);
30 // =======================================================================
31 // function : Graphic3d_MaterialAspect
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)
38 myRequestedMaterialName = theName;
39 Init (myRequestedMaterialName);
42 // =======================================================================
45 // =======================================================================
46 void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
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;
55 mySpecularActivity = Standard_True;
56 mySpecularCoef = 0.0f;
57 myEmissiveActivity = Standard_False;
58 myEmissiveCoef = 0.0f;
59 myEnvReflexion = 0.0f;
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;
65 myBSDF = Graphic3d_BSDF::CreateDiffuse (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f));
67 Standard_Integer index = Standard_Integer (theName);
68 if (index < NumberOfMaterials())
70 myStringName = MaterialName (index + 1);
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);
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);
86 myBSDF.Roughness = 32;
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);
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);
99 myBSDF.Roughness = 64.f;
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);
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;
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;
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));
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;
137 Graphic3d_Vec3 aColor (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
138 static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
139 static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
141 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
142 Graphic3d_Fresnel::CreateSchlick (aColor), 1024.f);
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;
150 myAmbientCoef = 1.00f;
151 myDiffuseCoef = 1.00f;
152 mySpecularCoef = 1.00f;
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);
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);
164 case Graphic3d_NOM_BRONZE:
165 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
168 myAmbientCoef = 1.00f;
169 myDiffuseCoef = 1.00f;
170 mySpecularCoef = 1.00f;
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);
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);
182 case Graphic3d_NOM_COPPER:
183 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
186 myAmbientCoef = 1.00f;
187 myDiffuseCoef = 1.00f;
188 mySpecularCoef = 1.00f;
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);
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);
200 case Graphic3d_NOM_GOLD:
201 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
204 myAmbientCoef = 1.00f;
205 myDiffuseCoef = 1.00f;
206 mySpecularCoef = 1.00f;
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);
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);
218 case Graphic3d_NOM_PEWTER:
219 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
222 myAmbientCoef = 1.00f;
223 myDiffuseCoef = 1.00f;
224 mySpecularCoef = 1.00f;
226 myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
227 Graphic3d_Fresnel::CreateConductor (1.8800f, 3.4900f), 1024.f);
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);
236 case Graphic3d_NOM_PLASTER:
238 myAmbientCoef = 0.26f;
239 myDiffuseCoef = 0.75f;
240 mySpecularCoef = 0.05f;
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);
249 myBSDF.Kd = Graphic3d_Vec3 (0.482353f, 0.482353f, 0.482353f);
252 case Graphic3d_NOM_SILVER:
253 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
256 myAmbientCoef = 1.00f;
257 myDiffuseCoef = 1.00f;
258 mySpecularCoef = 1.00f;
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);
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);
270 case Graphic3d_NOM_STEEL:
271 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
274 myAmbientCoef = 1.00f;
275 myDiffuseCoef = 1.00f;
276 mySpecularCoef = 1.00f;
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);
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);
288 case Graphic3d_NOM_STONE:
289 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
292 myAmbientCoef = 0.19f;
293 myDiffuseCoef = 0.75f;
294 mySpecularCoef = 0.08f;
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);
303 myBSDF.Kd = Graphic3d_Vec3 (0.243137f, 0.243137f, 0.243137f);
304 myBSDF.Ks = Graphic3d_Vec3 (0.00392157f, 0.00392157f, 0.00392157f);
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;
312 myAmbientCoef = 1.00f;
313 myDiffuseCoef = 1.00f;
314 mySpecularCoef = 1.00f;
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);
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);
326 case Graphic3d_NOM_ALUMINIUM:
327 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
330 myAmbientCoef = 1.00f;
331 myDiffuseCoef = 1.00f;
332 mySpecularCoef = 1.00f;
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);
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);
344 case Graphic3d_NOM_NEON_PHC:
345 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
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;
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);
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));
369 case Graphic3d_NOM_OBSIDIAN:
370 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
373 myAmbientCoef = 1.0f;
374 myDiffuseCoef = 1.0f;
375 mySpecularCoef = 1.0f;
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);
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;
388 case Graphic3d_NOM_JADE:
389 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
392 myAmbientCoef = 1.00f;
393 myDiffuseCoef = 1.00f;
394 mySpecularCoef = 1.00f;
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);
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;
408 case Graphic3d_NOM_CHARCOAL:
409 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
412 myAmbientCoef = 1.00f;
413 myDiffuseCoef = 1.00f;
414 mySpecularCoef = 1.00f;
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);
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;
427 case Graphic3d_NOM_WATER:
428 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
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),
439 myTransparencyCoef = 0.80f;
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);
448 case Graphic3d_NOM_GLASS:
449 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
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),
460 myTransparencyCoef = 0.80f;
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);
469 case Graphic3d_NOM_DIAMOND:
470 myMaterialType = Graphic3d_MATERIAL_PHYSIC;
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),
481 myTransparencyCoef = 0.80f;
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);
490 case Graphic3d_NOM_UserDefined:
491 myStringName = "UserDefined";
493 case Graphic3d_NOM_DEFAULT:
495 myStringName = "Default";
500 // =======================================================================
501 // function : IncreaseShine
503 // =======================================================================
504 void Graphic3d_MaterialAspect::IncreaseShine (const Standard_Real theDelta)
506 Standard_ShortReal anOldShine = myShininess;
507 myShininess = Standard_ShortReal(myShininess + myShininess * theDelta / 100.0);
508 if (myShininess > 1.0 || myShininess < 0.0)
510 myShininess = anOldShine;
514 // =======================================================================
515 // function : SetMaterialType
517 // =======================================================================
518 void Graphic3d_MaterialAspect::SetMaterialType (const Graphic3d_TypeOfMaterial theType)
520 myMaterialType = theType;
521 if (theType != myMaterialType)
523 SetMaterialName ("UserDefined");
527 // =======================================================================
528 // function : SetAmbient
530 // =======================================================================
531 void Graphic3d_MaterialAspect::SetAmbient (const Standard_Real theValue)
536 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetAmbient < 0. or > 1.0");
539 myAmbientCoef = Standard_ShortReal (theValue);
540 if (myAmbientActivity
541 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
543 SetMaterialName ("UserDefined");
547 // =======================================================================
548 // function : SetColor
550 // =======================================================================
551 void Graphic3d_MaterialAspect::SetColor (const Quantity_Color& theColor)
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)
560 SetMaterialName ("UserDefined");
564 // =======================================================================
565 // function : SetAmbientColor
567 // =======================================================================
568 void Graphic3d_MaterialAspect::SetAmbientColor (const Quantity_Color& theColor)
570 myAmbientColor = theColor;
571 if (myAmbientActivity
572 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
574 SetMaterialName ("UserDefined");
578 // =======================================================================
579 // function : SetDiffuseColor
581 // =======================================================================
582 void Graphic3d_MaterialAspect::SetDiffuseColor (const Quantity_Color& theColor)
584 myDiffuseColor = theColor;
585 if (myDiffuseActivity
586 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
588 SetMaterialName ("UserDefined");
592 // =======================================================================
593 // function : SetSpecularColor
595 // =======================================================================
596 void Graphic3d_MaterialAspect::SetSpecularColor (const Quantity_Color& theColor)
598 mySpecularColor = theColor;
599 if (mySpecularActivity
600 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
602 SetMaterialName ("UserDefined");
606 // =======================================================================
607 // function : SetEmissiveColor
609 // =======================================================================
610 void Graphic3d_MaterialAspect::SetEmissiveColor (const Quantity_Color& theColor)
612 myEmissiveColor = theColor;
613 if (myEmissiveActivity
614 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
616 SetMaterialName ("UserDefined");
620 // =======================================================================
621 // function : SetDiffuse
623 // =======================================================================
624 void Graphic3d_MaterialAspect::SetDiffuse (const Standard_Real theValue)
629 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetDiffuse < 0. or > 1.0");
632 myDiffuseCoef = Standard_ShortReal (theValue);
633 if (myDiffuseActivity
634 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
636 SetMaterialName ("UserDefined");
640 // =======================================================================
641 // function : SetEmissive
643 // =======================================================================
644 void Graphic3d_MaterialAspect::SetEmissive (const Standard_Real theValue)
649 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetEmissive < 0. or > 1.0");
652 myEmissiveCoef = Standard_ShortReal (theValue);
653 if (myDiffuseActivity
654 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
656 SetMaterialName ("UserDefined");
660 // =======================================================================
661 // function : SetReflectionModeOn
663 // =======================================================================
664 void Graphic3d_MaterialAspect::SetReflectionModeOn (const Graphic3d_TypeOfReflection theType)
668 case Graphic3d_TOR_AMBIENT:
669 myAmbientActivity = Standard_True;
671 case Graphic3d_TOR_DIFFUSE:
672 myDiffuseActivity = Standard_True;
674 case Graphic3d_TOR_SPECULAR:
675 mySpecularActivity = Standard_True;
677 case Graphic3d_TOR_EMISSION:
678 myEmissiveActivity = Standard_True;
681 if (myMaterialType == Graphic3d_MATERIAL_PHYSIC)
683 SetMaterialName ("UserDefined");
687 // =======================================================================
688 // function : SetReflectionModeOff
690 // =======================================================================
691 void Graphic3d_MaterialAspect::SetReflectionModeOff (const Graphic3d_TypeOfReflection theType)
695 case Graphic3d_TOR_AMBIENT:
696 myAmbientActivity = Standard_False;
698 case Graphic3d_TOR_DIFFUSE:
699 myDiffuseActivity = Standard_False;
701 case Graphic3d_TOR_SPECULAR:
702 mySpecularActivity = Standard_False;
704 case Graphic3d_TOR_EMISSION:
705 myEmissiveActivity = Standard_False;
708 if (myMaterialType == Graphic3d_MATERIAL_PHYSIC)
710 SetMaterialName ("UserDefined");
714 // =======================================================================
715 // function : SetSpecular
717 // =======================================================================
718 void Graphic3d_MaterialAspect::SetSpecular (const Standard_Real theValue)
723 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetSpecular < 0. or > 1.0");
726 mySpecularCoef = Standard_ShortReal (theValue);
727 if (mySpecularActivity
728 && myMaterialType == Graphic3d_MATERIAL_PHYSIC)
730 SetMaterialName ("UserDefined");
734 // =======================================================================
735 // function : SetTransparency
737 // =======================================================================
738 void Graphic3d_MaterialAspect::SetTransparency (const Standard_Real theValue)
743 Graphic3d_MaterialDefinitionError::Raise ("Bad value for SetTransparency < 0. or > 1.0");
746 myTransparencyCoef = Standard_ShortReal (theValue);
749 // =======================================================================
750 // function : SetRefractionIndex
752 // =======================================================================
753 void Graphic3d_MaterialAspect::SetRefractionIndex (const Standard_Real theValue)
757 Graphic3d_MaterialDefinitionError::Raise ("Bad value for refraction index < 1.0");
760 myRefractionIndex = static_cast<Standard_ShortReal> (theValue);
763 // =======================================================================
764 // function : SetBSDF
766 // =======================================================================
767 void Graphic3d_MaterialAspect::SetBSDF (const Graphic3d_BSDF& theBSDF)
772 // =======================================================================
775 // =======================================================================
776 const Quantity_Color& Graphic3d_MaterialAspect::Color() const
778 // It is generally accepted to consider diffuse color as
779 // "general" color of a material when light shines on it
780 return myDiffuseColor;
783 // =======================================================================
784 // function : AmbientColor
786 // =======================================================================
787 const Quantity_Color& Graphic3d_MaterialAspect::AmbientColor() const
789 return myAmbientColor;
792 // =======================================================================
793 // function : DiffuseColor
795 // =======================================================================
796 const Quantity_Color& Graphic3d_MaterialAspect::DiffuseColor() const
798 return myDiffuseColor;
801 // =======================================================================
802 // function : SpecularColor
804 // =======================================================================
805 const Quantity_Color& Graphic3d_MaterialAspect::SpecularColor() const
807 return mySpecularColor;
810 // =======================================================================
811 // function : EmissiveColor
813 // =======================================================================
814 const Quantity_Color& Graphic3d_MaterialAspect::EmissiveColor() const
816 return myEmissiveColor;
819 // =======================================================================
820 // function : MaterialType
822 // =======================================================================
823 Standard_Boolean Graphic3d_MaterialAspect::MaterialType (const Graphic3d_TypeOfMaterial theType) const
825 return myMaterialType == theType;
828 // =======================================================================
829 // function : ReflectionMode
831 // =======================================================================
832 Standard_Boolean Graphic3d_MaterialAspect::ReflectionMode (const Graphic3d_TypeOfReflection theType) const
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;
841 return Standard_False;
844 // =======================================================================
845 // function : Ambient
847 // =======================================================================
848 Standard_Real Graphic3d_MaterialAspect::Ambient() const
850 return Standard_Real (myAmbientCoef);
853 // =======================================================================
854 // function : Diffuse
856 // =======================================================================
857 Standard_Real Graphic3d_MaterialAspect::Diffuse() const
859 return Standard_Real (myDiffuseCoef);
862 // =======================================================================
863 // function : Emissive
865 // =======================================================================
866 Standard_Real Graphic3d_MaterialAspect::Emissive() const
868 return Standard_Real (myEmissiveCoef);
871 // =======================================================================
872 // function : Specular
874 // =======================================================================
875 Standard_Real Graphic3d_MaterialAspect::Specular() const
877 return Standard_Real (mySpecularCoef);
880 // =======================================================================
881 // function : Transparency
883 // =======================================================================
884 Standard_Real Graphic3d_MaterialAspect::Transparency() const
886 return Standard_Real (myTransparencyCoef);
889 // =======================================================================
890 // function : RefractionIndex
892 // =======================================================================
893 Standard_Real Graphic3d_MaterialAspect::RefractionIndex() const
895 return myRefractionIndex;
898 // =======================================================================
901 // =======================================================================
902 const Graphic3d_BSDF& Graphic3d_MaterialAspect::BSDF() const
907 // =======================================================================
908 // function : Shininess
910 // =======================================================================
911 Standard_Real Graphic3d_MaterialAspect::Shininess() const
913 return Standard_Real (myShininess);
916 // =======================================================================
917 // function : SetShininess
919 // =======================================================================
920 void Graphic3d_MaterialAspect::SetShininess (const Standard_Real theValue)
925 Graphic3d_MaterialDefinitionError::Raise ("Bad value for Shininess < 0. or > 1.0");
928 myShininess = Standard_ShortReal (theValue);
929 SetMaterialName ("UserDefined");
932 // =======================================================================
933 // function : SetEnvReflexion
935 // =======================================================================
936 void Graphic3d_MaterialAspect::SetEnvReflexion (const Standard_ShortReal theValue)
938 myEnvReflexion = theValue;
941 // =======================================================================
942 // function : EnvReflexion
944 // =======================================================================
945 Standard_ShortReal Graphic3d_MaterialAspect::EnvReflexion() const
947 return myEnvReflexion;
950 // =======================================================================
953 // =======================================================================
954 Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::Name() const
956 return myMaterialName;
959 // =======================================================================
962 // =======================================================================
963 void Graphic3d_MaterialAspect::Reset()
965 Init (myRequestedMaterialName);
968 // =======================================================================
969 // function : IsEqual
971 // =======================================================================
972 Standard_Boolean Graphic3d_MaterialAspect::IsEqual (const Graphic3d_MaterialAspect& theOther) const
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;
993 // =======================================================================
994 // function : IsDifferent
996 // =======================================================================
997 Standard_Boolean Graphic3d_MaterialAspect::IsDifferent (const Graphic3d_MaterialAspect& theOther) const
999 return !IsEqual (theOther);
1002 typedef struct _Material
1005 Graphic3d_TypeOfMaterial type;
1008 static Material theMaterials[] =
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}
1036 // =======================================================================
1037 // function : NumberOfMaterials
1039 // =======================================================================
1040 Standard_Integer Graphic3d_MaterialAspect::NumberOfMaterials()
1042 Standard_STATIC_ASSERT(sizeof(theMaterials)/sizeof(Material) == Graphic3d_NOM_DEFAULT);
1043 return Graphic3d_NOM_DEFAULT;
1046 // =======================================================================
1047 // function : MaterialName
1049 // =======================================================================
1050 Standard_CString Graphic3d_MaterialAspect::MaterialName (const Standard_Integer theRank)
1052 if (theRank < 1 || theRank > NumberOfMaterials())
1054 Standard_OutOfRange::Raise ("BAD index of material");
1056 return theMaterials[theRank - 1].name;
1059 // =======================================================================
1060 // function : MaterialFromName
1062 // =======================================================================
1063 Graphic3d_NameOfMaterial Graphic3d_MaterialAspect::MaterialFromName (const Standard_CString theName)
1065 TCollection_AsciiString aName (theName);
1068 const Standard_Integer aNbMaterials = Graphic3d_MaterialAspect::NumberOfMaterials();
1069 for (Standard_Integer aMatIter = 1; aMatIter <= aNbMaterials; ++aMatIter)
1071 if (aName == Graphic3d_MaterialAspect::MaterialName (aMatIter))
1073 return Graphic3d_NameOfMaterial(aMatIter - 1);
1078 if (aName == "Plastic") // Plastified
1080 return Graphic3d_NOM_PLASTIC;
1082 else if (aName == "Shiny_plastic") // Shiny_plastified
1084 return Graphic3d_NOM_SHINY_PLASTIC;
1086 else if (aName == "Plaster") // Plastered
1088 return Graphic3d_NOM_PLASTER;
1090 else if (aName == "Satin") // Satined
1092 return Graphic3d_NOM_SATIN;
1094 else if (aName == "Neon_gnc") // Ionized
1096 return Graphic3d_NOM_NEON_GNC;
1098 else if (aName == "Neon_phc") // Neon
1100 return Graphic3d_NOM_NEON_PHC;
1102 return Graphic3d_NOM_DEFAULT;
1105 // =======================================================================
1106 // function : MaterialType
1108 // =======================================================================
1109 Graphic3d_TypeOfMaterial Graphic3d_MaterialAspect::MaterialType (const Standard_Integer theRank)
1111 if (theRank < 1 || theRank > NumberOfMaterials())
1113 Standard_OutOfRange::Raise ("BAD index of material");
1115 return theMaterials[theRank - 1].type;
1118 // =======================================================================
1119 // function : MaterialName
1121 // =======================================================================
1122 Standard_CString Graphic3d_MaterialAspect::MaterialName() const
1124 return myStringName.ToCString();
1127 // =======================================================================
1128 // function : SetMaterialName
1130 // =======================================================================
1131 void Graphic3d_MaterialAspect::SetMaterialName (const Standard_CString theNewName)
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;