~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to intern/elbeem/intern/ntl_material.h

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
 *
3
 
 * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
4
 
 * Copyright 2003,2004 Nils Thuerey
5
 
 *
6
 
 * a geometry object
7
 
 * all other geometry objects are derived from this one
8
 
 *
9
 
 *****************************************************************************/
10
 
#ifndef NTL_MATERIAL_HH
11
 
#define NTL_MATERIAL_HH
12
 
 
13
 
#include "ntl_vector3dim.h"
14
 
class ntlRay;
15
 
 
16
 
 
17
 
//! Properties of an geo object, describing the reflection properties of the surface
18
 
class ntlMaterial
19
 
{
20
 
public:
21
 
  // CONSTRUCTORS
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);
33
 
  //! Desctructor
34
 
  ~ntlMaterial() {};
35
 
 
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 );
39
 
 
40
 
protected:
41
 
 
42
 
  /* name of the material */
43
 
  string mName;
44
 
 
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
50
 
  gfxReal mSpecular;
51
 
  //! Specular phong exponent
52
 
  gfxReal mSpecExponent;
53
 
  //! Mirror intensity
54
 
  gfxReal mMirror;
55
 
 
56
 
  //! Transparence
57
 
  gfxReal mTransparence;
58
 
  //! Refraction index, nu(Air) is assumed 1
59
 
  gfxReal mRefracIndex;
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?
65
 
        int mFresnel;
66
 
 
67
 
 
68
 
public:
69
 
  // access methods
70
 
 
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; }
91
 
        //! Get Fresnel flag
92
 
        inline int getFresnel( void ) { return mFresnel; }
93
 
 
94
 
 
95
 
 
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; }
120
 
 
121
 
};
122
 
 
123
 
 
124
 
 
125
 
 
126
 
/******************************************************************************
127
 
 * Default constructor
128
 
 *****************************************************************************/
129
 
inline ntlMaterial::ntlMaterial( void ) : 
130
 
        mName( "default" ),
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),
134
 
        mFresnel( 0 )
135
 
  //mNtfId(0), mNtfFluid(0), mNtfSolid(0)
136
 
137
 
  // just do default init...
138
 
}
139
 
 
140
 
 
141
 
 
142
 
/******************************************************************************
143
 
 * Init constructor
144
 
 *****************************************************************************/
145
 
inline 
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)
151
 
{
152
 
        mName                                   = name;
153
 
        mDiffuseRefl  = Ref;
154
 
        mAmbientRefl  = Amb;
155
 
        mSpecular     = Spec;
156
 
        mSpecExponent = SpecEx;
157
 
        mMirror       = Mirr;
158
 
        mTransparence = Trans;
159
 
        mRefracIndex  = Refrac;
160
 
        mTransAdditive = TAdd;
161
 
        mTransAttCol   = Att;
162
 
        mFresnel                        = fres;
163
 
}
164
 
 
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), \
170
 
                                        1.0, 5.0, 0.0,   \
171
 
                                                                                                                                                                /*0.0 test:*/ 0.5 , 1.0, 0.0, \
172
 
                                                                                                                                                                ntlColor( 0.0 ), 0 ); 
173
 
                                                                                                                                                                                                                                                        
174
 
 
175
 
 
176
 
/******************************************************************************
177
 
 * Calculate reflectance and refratance from Fresnel's law
178
 
 * cf. Glassner p. 46
179
 
 *****************************************************************************/
180
 
inline void 
181
 
ntlMaterial::calculateFresnel(const ntlVec3Gfx &dir, const ntlVec3Gfx &normal, gfxReal refIndex,
182
 
                                                                                                                        gfxReal &refl, gfxReal &trans)
183
 
{
184
 
        gfxReal c = -dot(dir, normal);
185
 
        if(c<0) { 
186
 
                refl = 0.0; trans = 0.0; return;
187
 
                //c = 0.0;
188
 
        }
189
 
 
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;
194
 
 
195
 
        //mMirror = r;
196
 
        //mTransparence = (1.0 - r);
197
 
        refl = r;
198
 
        trans = (1.0 - r);
199
 
        //errorOut(" fres ");
200
 
}
201
 
 
202
 
 
203
 
#endif