1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0025201: Visualization - Implementing soft shadows and ambient occlusion in OCCT ray-tracing core

This commit is contained in:
dbp
2015-04-20 10:15:34 +03:00
committed by bugmaster
parent 283b833c8e
commit 189f85a3fd
41 changed files with 3109 additions and 418 deletions

View File

@@ -65,3 +65,5 @@ Graphic3d_Camera.cxx
Graphic3d_Camera.hxx
Graphic3d_RenderingParams.hxx
Graphic3d_NMapOfTransient.hxx
Graphic3d_BSDF.hxx
Graphic3d_BSDF.cxx

View File

@@ -362,6 +362,8 @@ is
imported BndBox4d;
imported BufferType;
imported BSDF;
imported CBitFields20;
---Category: Imported types

View File

@@ -0,0 +1,159 @@
// Created on: 2015-01-19
// Created by: Denis BOGOLEPOV
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Graphic3d_BSDF.hxx>
#include <algorithm>
// =======================================================================
// function : Serialize
// purpose :
// =======================================================================
Graphic3d_Vec4 Graphic3d_Fresnel::Serialize() const
{
Graphic3d_Vec4 aData = Graphic3d_Vec4 (myFresnelData, 0.f);
if (myFresnelType != Graphic3d_FM_SCHLICK)
{
aData.x() = -static_cast<Standard_ShortReal> (myFresnelType);
}
return aData;
}
// =======================================================================
// function : fresnelNormal
// purpose :
// =======================================================================
inline Standard_ShortReal fresnelNormal (Standard_ShortReal theN,
Standard_ShortReal theK)
{
return ((theN - 1.f) * (theN - 1.f) + theK * theK) /
((theN + 1.f) * (theN + 1.f) + theK * theK);
}
// =======================================================================
// function : CreateConductor
// purpose :
// =======================================================================
Graphic3d_Fresnel Graphic3d_Fresnel::CreateConductor (const Graphic3d_Vec3& theRefractionIndex,
const Graphic3d_Vec3& theAbsorptionIndex)
{
return Graphic3d_Fresnel (Graphic3d_FM_SCHLICK,
Graphic3d_Vec3 (fresnelNormal (theRefractionIndex.x(), theAbsorptionIndex.x()),
fresnelNormal (theRefractionIndex.y(), theAbsorptionIndex.y()),
fresnelNormal (theRefractionIndex.z(), theAbsorptionIndex.z())));
}
// =======================================================================
// function : Normalize
// purpose :
// =======================================================================
void Graphic3d_BSDF::Normalize()
{
Standard_ShortReal aMax = std::max (Kd.x() + Ks.x() + Kr.x() + Kt.x(),
std::max (Kd.y() + Ks.y() + Kr.y() + Kt.y(),
Kd.z() + Ks.z() + Kr.z() + Kt.z()));
if (aMax > 1.f)
{
Kd /= aMax;
Ks /= aMax;
Kr /= aMax;
Ks /= aMax;
}
}
// =======================================================================
// function : CreateDiffuse
// purpose :
// =======================================================================
Graphic3d_BSDF Graphic3d_BSDF::CreateDiffuse (const Graphic3d_Vec3& theWeight)
{
Graphic3d_BSDF aBSDF;
aBSDF.Kd = theWeight;
return aBSDF;
}
// =======================================================================
// function : CreateMetallic
// purpose :
// =======================================================================
Graphic3d_BSDF Graphic3d_BSDF::CreateMetallic (const Graphic3d_Vec3& theWeight,
const Graphic3d_Fresnel& theFresnel,
const Standard_ShortReal theRoughness)
{
Graphic3d_BSDF aBSDF;
aBSDF.Roughness = theRoughness;
// Selecting between specular and glossy
// BRDF depending on the given roughness
if (aBSDF.Roughness > 0.f)
{
aBSDF.Ks = theWeight;
}
else
{
aBSDF.Kr = theWeight;
}
aBSDF.Fresnel = theFresnel;
return aBSDF;
}
// =======================================================================
// function : CreateTransparent
// purpose :
// =======================================================================
Graphic3d_BSDF Graphic3d_BSDF::CreateTransparent (const Graphic3d_Vec3& theWeight,
const Graphic3d_Vec3& theAbsorptionColor,
const Standard_ShortReal theAbsorptionCoeff)
{
Graphic3d_BSDF aBSDF;
aBSDF.Kt = theWeight;
aBSDF.AbsorptionColor = theAbsorptionColor;
aBSDF.AbsorptionCoeff = theAbsorptionCoeff;
aBSDF.Fresnel = Graphic3d_Fresnel::CreateConstant (0.f);
return aBSDF;
}
// =======================================================================
// function : CreateGlass
// purpose :
// =======================================================================
Graphic3d_BSDF Graphic3d_BSDF::CreateGlass (const Graphic3d_Vec3& theWeight,
const Graphic3d_Vec3& theAbsorptionColor,
const Standard_ShortReal theAbsorptionCoeff,
const Standard_ShortReal theRefractionIndex)
{
Graphic3d_BSDF aBSDF;
aBSDF.Kt = theWeight;
aBSDF.AbsorptionColor = theAbsorptionColor;
aBSDF.AbsorptionCoeff = theAbsorptionCoeff;
aBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (theRefractionIndex);
return aBSDF;
}

View File

@@ -0,0 +1,203 @@
// Created on: 2015-01-15
// Created by: Danila ULYANOV
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Graphic3d_BSDF_HeaderFile
#define _Graphic3d_BSDF_HeaderFile
#include <Graphic3d_Vec3.hxx>
#include <Graphic3d_Vec4.hxx>
//! Type of the Fresnel model.
enum Graphic3d_FresnelModel
{
Graphic3d_FM_SCHLICK = 0,
Graphic3d_FM_CONSTANT = 1,
Graphic3d_FM_CONDUCTOR = 2,
Graphic3d_FM_DIELECTRIC = 3
};
//! Describes Fresnel reflectance parameters.
class Graphic3d_Fresnel
{
public:
//! Creates uninitialized Fresnel factor.
Graphic3d_Fresnel()
: myFresnelType (Graphic3d_FM_CONSTANT)
{
// ideal specular reflector
myFresnelData = Graphic3d_Vec3 (0.f, 1.f, 0.f);
}
//! Creates Schlick's approximation of Fresnel factor.
static Graphic3d_Fresnel CreateSchlick (const Graphic3d_Vec3& theSpecularColor)
{
return Graphic3d_Fresnel (Graphic3d_FM_SCHLICK, theSpecularColor);
}
//! Creates Fresnel factor for constant reflection.
static Graphic3d_Fresnel CreateConstant (const Standard_ShortReal theReflection)
{
return Graphic3d_Fresnel (Graphic3d_FM_CONSTANT, Graphic3d_Vec3 (0.f, 1.f, theReflection));
}
//! Creates Fresnel factor for physical-based dielectric model.
static Graphic3d_Fresnel CreateDielectric (Standard_ShortReal theRefractionIndex)
{
return Graphic3d_Fresnel (Graphic3d_FM_DIELECTRIC, Graphic3d_Vec3 (0.f, theRefractionIndex, 0.f));
}
//! Creates Fresnel factor for physical-based conductor model.
static Graphic3d_Fresnel CreateConductor (Standard_ShortReal theRefractionIndex,
Standard_ShortReal theAbsorptionIndex)
{
return Graphic3d_Fresnel (Graphic3d_FM_CONDUCTOR, Graphic3d_Vec3 (0.f, theRefractionIndex, theAbsorptionIndex));
}
//! Creates Fresnel factor for physical-based conductor model (spectral version).
Standard_EXPORT static Graphic3d_Fresnel CreateConductor (const Graphic3d_Vec3& theRefractionIndex,
const Graphic3d_Vec3& theAbsorptionIndex);
public:
//! Returns serialized representation of Fresnel factor.
Standard_EXPORT Graphic3d_Vec4 Serialize() const;
//! Performs comparison of two objects describing Fresnel factor.
bool operator== (const Graphic3d_Fresnel& theOther) const
{
return myFresnelType == theOther.myFresnelType
&& myFresnelData == theOther.myFresnelData;
}
protected:
//! Creates new Fresnel reflectance factor.
Graphic3d_Fresnel (Graphic3d_FresnelModel theType, const Graphic3d_Vec3& theData)
: myFresnelType (theType),
myFresnelData (theData)
{
//
}
private:
//! Type of Fresnel approximation.
Graphic3d_FresnelModel myFresnelType;
//! Serialized parameters of specific approximation.
Graphic3d_Vec3 myFresnelData;
};
//! Describes material's BSDF (Bidirectional Scattering Distribution Function) used
//! for physically-based rendering (in path tracing engine). BSDF is represented as
//! weighted mixture of basic BRDFs/BTDFs (Bidirectional Reflectance (Transmittance)
//! Distribution Functions).
class Graphic3d_BSDF
{
public:
//! Weight of the Lambertian BRDF.
Graphic3d_Vec3 Kd;
//! Weight of the reflection BRDF.
Graphic3d_Vec3 Kr;
//! Weight of the transmission BTDF.
Graphic3d_Vec3 Kt;
//! Weight of the Blinn's glossy BRDF.
Graphic3d_Vec3 Ks;
//! Self-emitted radiance.
Graphic3d_Vec3 Le;
//! Parameters of Fresnel reflectance.
Graphic3d_Fresnel Fresnel;
//! Roughness (exponent) of Blinn's BRDF.
Standard_ShortReal Roughness;
//! Absorption color of transparent media.
Graphic3d_Vec3 AbsorptionColor;
//! Absorption intensity of transparent media.
Standard_ShortReal AbsorptionCoeff;
public:
//! Creates BSDF describing diffuse (Lambertian) surface.
static Standard_EXPORT Graphic3d_BSDF CreateDiffuse (const Graphic3d_Vec3& theWeight);
//! Creates BSDF describing polished metallic-like surface.
static Standard_EXPORT Graphic3d_BSDF CreateMetallic (const Graphic3d_Vec3& theWeight,
const Graphic3d_Fresnel& theFresnel,
const Standard_ShortReal theRoughness);
//! Creates BSDF describing transparent object.
//! Transparent BSDF models simple transparency without
//! refraction (the ray passes straight through the surface).
static Standard_EXPORT Graphic3d_BSDF CreateTransparent (const Graphic3d_Vec3& theWeight,
const Graphic3d_Vec3& theAbsorptionColor,
const Standard_ShortReal theAbsorptionCoeff);
//! Creates BSDF describing glass-like object.
//! Glass-like BSDF mixes refraction and reflection effects at
//! grazing angles using physically-based Fresnel dielectric model.
static Standard_EXPORT Graphic3d_BSDF CreateGlass (const Graphic3d_Vec3& theWeight,
const Graphic3d_Vec3& theAbsorptionColor,
const Standard_ShortReal theAbsorptionCoeff,
const Standard_ShortReal theRefractionIndex);
public:
//! Creates uninitialized BSDF.
Graphic3d_BSDF()
{
Roughness = AbsorptionCoeff = 0.f;
}
//! Normalizes BSDF components.
Standard_EXPORT void Normalize();
//! Performs mixing of two BSDFs.
Graphic3d_BSDF& operator+ (const Graphic3d_BSDF& theOther)
{
Kd += theOther.Kd;
Kr += theOther.Kr;
Kt += theOther.Kt;
Ks += theOther.Ks;
Le += theOther.Le;
return *this;
}
//! Performs comparison of two BSDFs.
bool operator== (const Graphic3d_BSDF& theOther) const
{
return Kd == theOther.Kd
&& Kr == theOther.Kr
&& Kt == theOther.Kt
&& Ks == theOther.Ks
&& Le == theOther.Le
&& Fresnel == theOther.Fresnel
&& Roughness == theOther.Roughness
&& AbsorptionCoeff == theOther.AbsorptionCoeff
&& AbsorptionColor == theOther.AbsorptionColor;
}
};
#endif // _Graphic3d_BSDF_HeaderFile

View File

@@ -30,6 +30,8 @@ public:
Graphic3d_Vec4 Params; //!< packed light parameters
Standard_Integer Type; //!< Visual3d_TypeOfLightSource enumeration
Standard_Boolean IsHeadlight; //!< flag to mark head light
Standard_ShortReal Smoothness; //!< radius (cone angle) for point (directional) light
Standard_ShortReal Intensity; //!< intensity multiplier for light
//! Const attenuation factor of positional light source
Standard_ShortReal ConstAttenuation() const { return Params.x(); }
@@ -61,7 +63,9 @@ public:
Direction (0.0f, 0.0f, 0.0f, 0.0f),
Params (0.0f, 0.0f, 0.0f, 0.0f),
Type (0),
IsHeadlight (Standard_False)
IsHeadlight (Standard_False),
Smoothness (0.0f),
Intensity (1.0f)
{
//
}

View File

@@ -336,14 +336,15 @@ void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFil
// Back Material
const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
// Light specificity
ContextFillArea.Back.Shininess = float (aBack.Shininess());
ContextFillArea.Back.Ambient = float (aBack.Ambient());
ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
ContextFillArea.Back.Specular = float (aBack.Specular());
ContextFillArea.Back.Transparency = float (aBack.Transparency());
ContextFillArea.Back.Emission = float (aBack.Emissive());
// Material properties
ContextFillArea.Back.Shininess = float (aBack.Shininess());
ContextFillArea.Back.Ambient = float (aBack.Ambient());
ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
ContextFillArea.Back.Specular = float (aBack.Specular());
ContextFillArea.Back.Transparency = float (aBack.Transparency());
ContextFillArea.Back.Emission = float (aBack.Emissive());
ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
ContextFillArea.Back.BSDF = aBack.BSDF();
// Reflection mode
ContextFillArea.Back.IsAmbient = aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
@@ -378,14 +379,16 @@ void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFil
// Front Material
const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
// Light specificity
ContextFillArea.Front.Shininess = float (aFront.Shininess());
ContextFillArea.Front.Ambient = float (aFront.Ambient());
ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
ContextFillArea.Front.Specular = float (aFront.Specular());
ContextFillArea.Front.Transparency = float (aFront.Transparency());
ContextFillArea.Front.Emission = float (aFront.Emissive());
// Material properties
ContextFillArea.Front.Shininess = float (aFront.Shininess());
ContextFillArea.Front.Ambient = float (aFront.Ambient());
ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
ContextFillArea.Front.Specular = float (aFront.Specular());
ContextFillArea.Front.Transparency = float (aFront.Transparency());
ContextFillArea.Front.Emission = float (aFront.Emissive());
ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
ContextFillArea.Front.BSDF = aFront.BSDF();
// Reflection mode
ContextFillArea.Front.IsAmbient = aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
@@ -636,6 +639,9 @@ void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea
ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
ContextFillArea.Back.BSDF = aBack.BSDF();
// Front Material
const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
// Light specificity
@@ -677,6 +683,9 @@ void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea
ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
ContextFillArea.Front.BSDF = aFront.BSDF();
ContextFillArea.IsDef = 1; // Material definition ok
ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
@@ -892,6 +901,9 @@ void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d
aBack.SetEnvReflexion (anAspFill.Back.EnvReflexion);
aBack.SetRefractionIndex (Standard_Real (anAspFill.Back.RefractionIndex));
aBack.SetBSDF (anAspFill.Back.BSDF);
// Front Material
aFront.SetShininess (Standard_Real (anAspFill.Front.Shininess));
aFront.SetAmbient (Standard_Real (anAspFill.Front.Ambient));
@@ -926,6 +938,9 @@ void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d
aFront.SetEnvReflexion (anAspFill.Front.EnvReflexion);
aFront.SetRefractionIndex (Standard_Real (anAspFill.Front.RefractionIndex));
aFront.SetBSDF (anAspFill.Front.BSDF);
// Edges
anAspFill.Edge == 1 ? theAspFill->SetEdgeOn() : theAspFill->SetEdgeOff();
// Hatch

View File

@@ -34,12 +34,12 @@ class MaterialAspect from Graphic3d
uses
Color from Quantity,
NameOfMaterial from Graphic3d,
TypeOfReflection from Graphic3d,
TypeOfMaterial from Graphic3d,
AsciiString from TCollection
Color from Quantity,
NameOfMaterial from Graphic3d,
TypeOfReflection from Graphic3d,
TypeOfMaterial from Graphic3d,
BSDF from Graphic3d,
AsciiString from TCollection
raises
@@ -148,6 +148,13 @@ is
-- lesser than 1.0.
raises MaterialDefinitionError from Graphic3d is static;
SetBSDF ( me : in out;
theBSDF : BSDF from Graphic3d )
is static;
---Level: Public
---Purpose: Modifies the BSDF (bidirectional scattering distribution function).
-- Category: Methods to modify the class definition
SetColor ( me : in out;
AColor : Color from Quantity )
is static;
@@ -325,6 +332,14 @@ is
---Purpose: Returns the refraction index of the material
---Category: Inquire methods
BSDF ( me )
returns BSDF from Graphic3d
is static;
---C++: return const&
---Level: Public
---Purpose: Returns BSDF (bidirectional scattering distribution function).
---Category: Inquire methods
Emissive ( me )
returns Real from Standard
is static;
@@ -485,6 +500,9 @@ fields
myTransparencyCoef : ShortReal from Standard;
myRefractionIndex : ShortReal from Standard;
-- BSDF (bidirectional scattering distribution function). Physically based material represented as weighted mixture of BxDFs (BRDFs and BTDFs) and its parameters.
myBSDF : BSDF from Graphic3d;
-- the specular exponent
myShininess : ShortReal from Standard;
@@ -501,4 +519,4 @@ fields
-- the string name of the material
myStringName : AsciiString from TCollection;
end MaterialAspect;
end MaterialAspect;

View File

@@ -62,6 +62,8 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
mySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB);
myMaterialName = theName;
myBSDF = Graphic3d_BSDF::CreateDiffuse (Graphic3d_Vec3 (0.2f, 0.2f, 0.2f));
Standard_Integer index = Standard_Integer (theName);
if (index < NumberOfMaterials())
{
@@ -70,23 +72,44 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
switch (theName)
{
case Graphic3d_NOM_PLASTIC: // Blue plastic
case Graphic3d_NOM_PLASTIC:
myShininess = Standard_ShortReal (0.0078125);
myAmbientCoef = Standard_ShortReal (0.5);
myDiffuseCoef = Standard_ShortReal (0.24);
mySpecularCoef = Standard_ShortReal (0.06);
myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
myBSDF.Ks = Graphic3d_Vec3 (0.00784314f, 0.00784314f, 0.00784314f);
myBSDF.Normalize();
myBSDF.Roughness = 32;
break;
case Graphic3d_NOM_SHINY_PLASTIC: // black plastic
case Graphic3d_NOM_SHINY_PLASTIC:
myShininess = Standard_ShortReal (1.0);
myAmbientCoef = Standard_ShortReal (0.44);
myDiffuseCoef = Standard_ShortReal (0.5);
mySpecularCoef = Standard_ShortReal (1.0);
myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
myBSDF.Ks = Graphic3d_Vec3 (0.0156863f, 0.0156863f, 0.0156863f);
myBSDF.Normalize();
myBSDF.Roughness = 64.f;
break;
case Graphic3d_NOM_SATIN :
myShininess = Standard_ShortReal (0.09375);
myAmbientCoef = Standard_ShortReal (0.33);
myDiffuseCoef = Standard_ShortReal (0.4);
mySpecularCoef = Standard_ShortReal (0.44);
myBSDF.Kd = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
myBSDF.Ks = Graphic3d_Vec3 (0.0313726f, 0.0313726f, 0.0313726f);
myBSDF.Roughness = 16.f;
myBSDF.Normalize();
break;
case Graphic3d_NOM_NEON_GNC:
myShininess = Standard_ShortReal (0.05);
@@ -96,6 +119,12 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myEmissiveCoef = Standard_ShortReal (1.0);
myEmissiveActivity = Standard_True;
myAmbientActivity = Standard_False;
myBSDF.Kr = Graphic3d_Vec3 (0.207843f, 0.207843f, 0.207843f);
myBSDF.Le = Graphic3d_Vec3 (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
myBSDF.Fresnel == Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.3f, 0.3f, 0.3f));
break;
case Graphic3d_NOM_METALIZED:
myShininess = Standard_ShortReal (0.13);
@@ -104,10 +133,14 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
mySpecularCoef = Standard_ShortReal (0.45);
myAmbientActivity = Standard_False;
// Color resulting from dispersed
//myDiffuseColor .SetValues (0.87, 0.96, 1.0, Quantity_TOC_RGB);
// Color resulting from specular
//mySpecularColor.SetValues (0.93, 0.95, 0.78, Quantity_TOC_RGB);
{
Graphic3d_Vec3 aColor (static_cast<Standard_ShortReal> (myDiffuseColor.Red()),
static_cast<Standard_ShortReal> (myDiffuseColor.Green()),
static_cast<Standard_ShortReal> (myDiffuseColor.Blue()));
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (aColor), 1024.f);
}
break;
// Ascending Compatibility physical materials. The same definition is taken as in the next constructor.
case Graphic3d_NOM_BRASS:
@@ -118,6 +151,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.58f, 0.42f, 0.20f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.329f, 0.224f, 0.027f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -133,6 +169,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.65f, 0.35f, 0.15f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.213f, 0.128f, 0.054f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -148,6 +187,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.955008f, 0.637427f, 0.538163f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.191f, 0.074f, 0.023f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -163,6 +205,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (1.000000f, 0.765557f, 0.336057f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.300f, 0.230f, 0.095f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -178,6 +223,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateConductor (1.8800f, 3.4900f), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.106f, 0.059f, 0.114f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -197,6 +245,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseColor .SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB);
// Color resulting from specular
mySpecularColor.SetValues (0.508f, 0.508f, 0.508f, Quantity_TOC_RGB);
myBSDF.Kd = Graphic3d_Vec3 (0.482353f, 0.482353f, 0.482353f);
break;
case Graphic3d_NOM_SILVER:
myMaterialType = Graphic3d_MATERIAL_PHYSIC;
@@ -206,6 +257,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.971519f, 0.959915f, 0.915324f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.275f, 0.275f, 0.250f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -221,6 +275,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateConductor (Graphic3d_Vec3 (2.90f, 2.80f, 2.53f), Graphic3d_Vec3 (3.08f, 2.90f, 2.74f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.150f, 0.150f, 0.180f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -242,6 +299,10 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseColor .SetValues (1.0, 0.8, 0.62, Quantity_TOC_RGB);
// Color resulting from specular
mySpecularColor.SetValues (0.98, 1.0, 0.60, Quantity_TOC_RGB);
myBSDF.Kd = Graphic3d_Vec3 (0.243137f, 0.243137f, 0.243137f);
myBSDF.Ks = Graphic3d_Vec3 (0.00392157f, 0.00392157f, 0.00392157f);
break;
// Ascending Compatibility of physical materials. Takes the same definition as in the next constructor. New materials
case Graphic3d_NOM_CHROME:
@@ -252,6 +313,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.549585f, 0.556114f, 0.554256f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.200f, 0.200f, 0.225f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -267,6 +331,9 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myBSDF = Graphic3d_BSDF::CreateMetallic (Graphic3d_Vec3 (0.985f, 0.985f, 0.985f),
Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.913183f, 0.921494f, 0.924524f)), 1024.f);
// Color resulting from ambient
myAmbientColor .SetValues (0.300f, 0.300f, 0.300f, Quantity_TOC_RGB);
// Color resulting from dispersed
@@ -294,6 +361,10 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
mySpecularColor.SetValues (1.0, 1.0, 1.0, Quantity_TOC_RGB);
// Color resulting from specular
myEmissiveColor.SetValues (0.0, 1.0, 0.46, Quantity_TOC_RGB);
myBSDF.Kr = Graphic3d_Vec3 (0.207843f, 0.207843f, 0.207843f);
myBSDF.Le = Graphic3d_Vec3 (0.0f, 1.0f, 0.46f);
myBSDF.Fresnel == Graphic3d_Fresnel::CreateSchlick (Graphic3d_Vec3 (0.3f, 0.3f, 0.3f));
break;
case Graphic3d_NOM_OBSIDIAN:
myMaterialType = Graphic3d_MATERIAL_PHYSIC;
@@ -309,6 +380,10 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseColor .SetValues (0.183f, 0.170f, 0.225f, Quantity_TOC_RGB);
// Color resulting from specular
mySpecularColor.SetValues (0.333f, 0.329f, 0.346f, Quantity_TOC_RGB);
myBSDF.Kd = Graphic3d_Vec3 (0.0156863f, 0.f, 0.0155017f);
myBSDF.Ks = Graphic3d_Vec3 (0.0156863f, 0.0156863f, 0.0156863f);
myBSDF.Roughness = 1024.f;
break;
case Graphic3d_NOM_JADE:
myMaterialType = Graphic3d_MATERIAL_PHYSIC;
@@ -324,6 +399,11 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseColor .SetValues (0.540f, 0.890f, 0.630f, Quantity_TOC_RGB);
// Color resulting from specular
mySpecularColor.SetValues (0.316f, 0.316f, 0.316f, Quantity_TOC_RGB);
myBSDF.Fresnel = Graphic3d_Fresnel::CreateDielectric (1.5f);
myBSDF.Kd = Graphic3d_Vec3 (0.208658f, 0.415686f, 0.218401f);
myBSDF.Ks = Graphic3d_Vec3 (0.611765f, 0.611765f, 0.611765f);
myBSDF.Roughness = 512.f;
break;
case Graphic3d_NOM_CHARCOAL:
myMaterialType = Graphic3d_MATERIAL_PHYSIC;
@@ -339,6 +419,10 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseColor .SetValues (0.150f, 0.150f, 0.150f, Quantity_TOC_RGB);
// Color resulting from specular
mySpecularColor.SetValues (0.000f, 0.000f, 0.000f, Quantity_TOC_RGB);
myBSDF.Kd = Graphic3d_Vec3 (0.0196078f, 0.0196078f, 0.0196078f);
myBSDF.Ks = Graphic3d_Vec3 (0.0196078f, 0.0196078f, 0.0196078f);
myBSDF.Roughness = 8;
break;
case Graphic3d_NOM_WATER:
myMaterialType = Graphic3d_MATERIAL_PHYSIC;
@@ -348,6 +432,10 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myRefractionIndex = 1.33f;
myBSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
Graphic3d_Vec3 (0.7f, 0.75f, 0.85f),
0.05f,
myRefractionIndex);
myTransparencyCoef = 0.80f;
// Color resulting from ambient
@@ -365,6 +453,10 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myRefractionIndex = 1.62f;
myBSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
Graphic3d_Vec3 (0.75f, 0.95f, 0.9f),
0.05f,
myRefractionIndex);
myTransparencyCoef = 0.80f;
// Color resulting from ambient
@@ -382,6 +474,10 @@ void Graphic3d_MaterialAspect::Init (const Graphic3d_NameOfMaterial theName)
myDiffuseCoef = 1.00f;
mySpecularCoef = 1.00f;
myRefractionIndex = 2.42f;
myBSDF = Graphic3d_BSDF::CreateGlass (Graphic3d_Vec3 (1.f),
Graphic3d_Vec3 (0.95f, 0.95f, 0.95f),
0.05f,
myRefractionIndex);
myTransparencyCoef = 0.80f;
// Color resulting from ambient
@@ -664,6 +760,15 @@ void Graphic3d_MaterialAspect::SetRefractionIndex (const Standard_Real theValue)
myRefractionIndex = static_cast<Standard_ShortReal> (theValue);
}
// =======================================================================
// function : SetBSDF
// purpose :
// =======================================================================
void Graphic3d_MaterialAspect::SetBSDF (const Graphic3d_BSDF& theBSDF)
{
myBSDF = theBSDF;
}
// =======================================================================
// function : Color
// purpose :
@@ -790,6 +895,15 @@ Standard_Real Graphic3d_MaterialAspect::RefractionIndex() const
return myRefractionIndex;
}
// =======================================================================
// function : BSDF
// purpose :
// =======================================================================
const Graphic3d_BSDF& Graphic3d_MaterialAspect::BSDF() const
{
return myBSDF;
}
// =======================================================================
// function : Shininess
// purpose :
@@ -863,6 +977,7 @@ Standard_Boolean Graphic3d_MaterialAspect::IsEqual (const Graphic3d_MaterialAspe
&& myEmissiveCoef == theOther.myEmissiveCoef
&& myTransparencyCoef == theOther.myTransparencyCoef
&& myRefractionIndex == theOther.myRefractionIndex
&& myBSDF == theOther.myBSDF
&& myShininess == theOther.myShininess
&& myEnvReflexion == theOther.myEnvReflexion
&& myAmbientColor == theOther.myAmbientColor

View File

@@ -23,6 +23,9 @@ class Graphic3d_RenderingParams
{
public:
//! Default number of samples per pixel.
static const Standard_Integer THE_DEFAULT_SPP = 1;
//! Default ray-tracing depth.
static const Standard_Integer THE_DEFAULT_DEPTH = 3;
@@ -30,12 +33,15 @@ public:
//! Creates default rendering parameters.
Graphic3d_RenderingParams()
: Method (Graphic3d_RM_RASTERIZATION),
RaytracingDepth (THE_DEFAULT_DEPTH),
IsShadowEnabled (Standard_True),
IsReflectionEnabled (Standard_False),
IsAntialiasingEnabled (Standard_False),
IsTransparentShadowEnabled (Standard_False)
: Method (Graphic3d_RM_RASTERIZATION),
RaytracingDepth (THE_DEFAULT_DEPTH),
SamplesPerPixel (THE_DEFAULT_SPP),
IsShadowEnabled (Standard_True),
IsReflectionEnabled (Standard_False),
IsAntialiasingEnabled (Standard_False),
IsTransparentShadowEnabled (Standard_False),
IsGlobalIlluminationEnabled (Standard_False),
UseEnvironmentMapBackground (Standard_False)
{
//
}
@@ -48,6 +54,9 @@ public:
//! Maximum ray-tracing depth.
Standard_Integer RaytracingDepth;
//! Number of samples per pixel (SPP).
Standard_Integer SamplesPerPixel;
//! Enables/disables shadows rendering.
Standard_Boolean IsShadowEnabled;
@@ -60,6 +69,12 @@ public:
//! Enables/disables light propagation through transparent media.
Standard_Boolean IsTransparentShadowEnabled;
//! Enables/disables global illumination effects (uses path tracing).
Standard_Boolean IsGlobalIlluminationEnabled;
//! Enables/disables environment map background (instead of OCCT background).
Standard_Boolean UseEnvironmentMapBackground;
};
#endif // _Graphic3d_RenderingParams_HeaderFile

View File

@@ -807,6 +807,9 @@ Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
aBack.SetEnvReflexion (myCStructure->ContextFillArea.Back.EnvReflexion);
aBack.SetMaterialType (myCStructure->ContextFillArea.Back.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
aBack.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Back.RefractionIndex));
aBack.SetBSDF (myCStructure->ContextFillArea.Back.BSDF);
// Front Material
Graphic3d_MaterialAspect aFront;
aFront.SetShininess (Standard_Real (myCStructure->ContextFillArea.Front.Shininess));
@@ -855,6 +858,9 @@ Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect() const
aFront.SetEnvReflexion (myCStructure->ContextFillArea.Front.EnvReflexion);
aFront.SetMaterialType (myCStructure->ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT);
aFront.SetRefractionIndex (Standard_Real (myCStructure->ContextFillArea.Front.RefractionIndex));
aFront.SetBSDF (myCStructure->ContextFillArea.Front.BSDF);
Quantity_Color anIntColor (Standard_Real (myCStructure->ContextFillArea.IntColor.r),
Standard_Real (myCStructure->ContextFillArea.IntColor.g),
Standard_Real (myCStructure->ContextFillArea.IntColor.b), Quantity_TOC_RGB);
@@ -1004,6 +1010,7 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFill
myCStructure->ContextFillArea.Back.Specular = float (aBack.Specular());
myCStructure->ContextFillArea.Back.Transparency = float (aBack.Transparency());
myCStructure->ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
myCStructure->ContextFillArea.Back.BSDF = aBack.BSDF();
myCStructure->ContextFillArea.Back.Emission = float (aBack.Emissive());
// Reflection mode
@@ -1048,6 +1055,7 @@ void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFill
myCStructure->ContextFillArea.Front.Specular = float (aFront.Specular());
myCStructure->ContextFillArea.Front.Transparency = float (aFront.Transparency());
myCStructure->ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
myCStructure->ContextFillArea.Front.BSDF = aFront.BSDF();
myCStructure->ContextFillArea.Front.Emission = float (aFront.Emissive());
// Reflection mode