1
/******************************************************************************
3
* El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
4
* Copyright 2003,2004 Nils Thuerey
7
* all other geometry objects are derived from this one
9
*****************************************************************************/
10
#ifndef NTL_MATERIAL_HH
11
#define NTL_MATERIAL_HH
13
#include "ntl_vector3dim.h"
17
//! Properties of an geo object, describing the reflection properties of the surface
22
//! Default constructor
23
inline ntlMaterial( void );
24
//! Constructor with parameters
25
/*! Sets reflectance, ambient reflection, specular intensity
26
* specular exponent, mirror intensity
27
* transparency, refraction index */
28
inline ntlMaterial( string name,
29
const ntlColor& Ref, const ntlColor& Amb,
30
gfxReal Spec, gfxReal Exp, gfxReal Mirror,
31
gfxReal Trans, gfxReal Refrac, gfxReal TAdd,
32
const ntlColor& Att, int fres);
36
//! Calculate reflectance and refratance from Fresnel's law
37
inline void calculateFresnel(const ntlVec3Gfx &dir, const ntlVec3Gfx &normal, gfxReal refIndex,
38
gfxReal &refl, gfxReal &trans );
42
/* name of the material */
45
//! Vector for reflectance of each color component (used in shade() of ray object)
46
ntlColor mDiffuseRefl;
47
//! Ambient reflectance
48
ntlColor mAmbientRefl;
49
//! Specular reflection intensity
51
//! Specular phong exponent
52
gfxReal mSpecExponent;
57
gfxReal mTransparence;
58
//! Refraction index, nu(Air) is assumed 1
60
//! Should transparence be additive?
61
gfxReal mTransAdditive;
62
//! Color dependent transparency attentuation factors (negative logarithm stored)
63
ntlColor mTransAttCol;
64
//! Should the transparence and reflectivity be determined by fresnel?
71
//! Returns the material name
72
inline string getName() { return mName; }
73
//! Returns the reflectance
74
inline ntlColor getDiffuseRefl() const { return ntlColor(mDiffuseRefl); }
75
//! Returns the ambience
76
inline ntlColor getAmbientRefl() const { return ntlColor(mAmbientRefl); }
77
//! Returns the specular component
78
inline gfxReal getSpecular() const { return mSpecular; }
79
//! Returns the specular exponent component
80
inline gfxReal getSpecExponent() const { return mSpecExponent; }
81
//! Returns the mirror component
82
inline gfxReal getMirror() const { return mMirror; }
83
//! Returns the transparence component
84
inline gfxReal getTransparence() const { return mTransparence; }
85
//! Returns the refraction index component
86
inline gfxReal getRefracIndex() const { return mRefracIndex; }
87
//! Returns the transparency additive factor component
88
inline gfxReal getTransAdditive() const { return mTransAdditive; }
89
//! Returns the transparency attentuation
90
inline ntlColor getTransAttCol() const { return mTransAttCol; }
92
inline int getFresnel( void ) { return mFresnel; }
96
//! Returns the mat name
97
inline void setName(string set) { mName = set; }
98
//! Returns the reflectance
99
inline void setDiffuseRefl(ntlColor set) { mDiffuseRefl=set; }
100
//! Returns the ambience
101
inline void setAmbientRefl(ntlColor set) { mAmbientRefl=set; }
102
//! Returns the specular component
103
inline void setSpecular(gfxReal set) { mSpecular=set; }
104
//! Returns the specular exponent component
105
inline void setSpecExponent(gfxReal set) { mSpecExponent=set; }
106
//! Returns the mirror component
107
inline void setMirror(gfxReal set) { mMirror=set; }
108
//! Returns the transparence component
109
inline void setTransparence(gfxReal set) { mTransparence=set; }
110
//! Returns the refraction index component
111
inline void setRefracIndex(gfxReal set) { mRefracIndex=set; }
112
//! Returns the transparency additive factor component
113
inline void setTransAdditive(gfxReal set) { mTransAdditive=set; }
114
//! Returns the transparency attentuation
115
inline void setTransAttCol(ntlColor set) {
116
ntlColor setlog = ntlColor( -log(set[0]), -log(set[1]), -log(set[2]) );
117
mTransAttCol=setlog; }
118
//! Set Fresnel on/off
119
inline void setFresnel(int set) { mFresnel = set; }
126
/******************************************************************************
127
* Default constructor
128
*****************************************************************************/
129
inline ntlMaterial::ntlMaterial( void ) :
131
mDiffuseRefl(0.5,0.5,0.5), mAmbientRefl(0.0,0.0,0.0),
132
mSpecular(0.0), mSpecExponent(0.0), mMirror(0.0),
133
mTransparence(0.0), mRefracIndex(0.0), mTransAdditive(0.0), mTransAttCol(0.0),
135
//mNtfId(0), mNtfFluid(0), mNtfSolid(0)
137
// just do default init...
142
/******************************************************************************
144
*****************************************************************************/
146
ntlMaterial::ntlMaterial( string name,
147
const ntlColor& Ref, const ntlColor& Amb,
148
gfxReal Spec, gfxReal SpecEx, gfxReal Mirr,
149
gfxReal Trans, gfxReal Refrac, gfxReal TAdd,
150
const ntlColor& Att, int fres)
156
mSpecExponent = SpecEx;
158
mTransparence = Trans;
159
mRefracIndex = Refrac;
160
mTransAdditive = TAdd;
165
/******************************************************************************
166
* Macro to define the default surface properties for a newly created object
167
*****************************************************************************/
168
#define GET_GLOBAL_DEFAULT_MATERIAL new ntlMaterial( "default",\
169
ntlColor( 0.5 ), ntlColor(0.0), \
171
/*0.0 test:*/ 0.5 , 1.0, 0.0, \
172
ntlColor( 0.0 ), 0 );
176
/******************************************************************************
177
* Calculate reflectance and refratance from Fresnel's law
179
*****************************************************************************/
181
ntlMaterial::calculateFresnel(const ntlVec3Gfx &dir, const ntlVec3Gfx &normal, gfxReal refIndex,
182
gfxReal &refl, gfxReal &trans)
184
gfxReal c = -dot(dir, normal);
186
refl = 0.0; trans = 0.0; return;
190
gfxReal r0 = ((refIndex-1.0)*(refIndex-1.0)) /
191
((refIndex+1.0)*(refIndex+1.0));
192
gfxReal omc = (1.0-c);
193
gfxReal r =r0 + (1.0 - r0) * omc*omc*omc*omc*omc;
196
//mTransparence = (1.0 - r);
199
//errorOut(" fres ");