Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ntl_lighting.h « intern « elbeem « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: be54e835c6c017e3ed6f078b86389aa62d958a30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/** \file \ingroup elbeem
 */
/******************************************************************************
 *
 * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
 * Copyright 2003-2006 Nils Thuerey
 *
 * a light object
 * default omni light implementation
 *
 *****************************************************************************/
#ifndef NTL_LIGHTING_H
#define NTL_LIGHTING_H

#include "ntl_vector3dim.h"

#ifdef WITH_CXX_GUARDEDALLOC
#  include "MEM_guardedalloc.h"
#endif

class ntlMaterial;
class ntlRay;
class ntlRenderGlobals;
class ntlGeometryObject;



/* shadow map directions */
#define LSM_RIGHT 0
#define LSM_LEFT  1
#define LSM_UP    2
#define LSM_DOWN  3
#define LSM_FRONT 4
#define LSM_BACK  5

/*! Basic object for lights, all other light are derived from this one */
class ntlLightObject
{
public:
  /* CONSTRUCTORS */
  /*! Default constructor */
  ntlLightObject(ntlRenderGlobals *glob);
  /*! Constructor with parameters */
  ntlLightObject(ntlRenderGlobals *glob, const ntlColor& col);
  /*! Destructor */
  virtual ~ntlLightObject();

	/*! prepare light for rendering (for example shadow maps) */
	virtual void prepare( bool );
	
	/*! do the illumination... */
	virtual ntlColor illuminatePoint(ntlRay &reflectedRay, 
																	 ntlGeometryObject *closest,
																	 ntlColor &highlight);
	/*! shade the point */
	const ntlColor
	getShadedColor(const ntlRay &reflectedray, ntlVec3Gfx lightDir,
								 ntlMaterial *surf, ntlColor &highlight) const;


  /* access methods */
  /*! Access the active flag */
  inline void setActive(bool set) { mActive = set; }
  inline bool getActive() const { return mActive; }
  /*! Access the shadow flag */
  inline void setCastShadows(bool set) { mCastShadows = set; }
  inline bool getCastShadows() const { return mCastShadows; }
  /*! Access the light color */
  inline void setColor(ntlColor set) { mcColor = set; }
  inline ntlColor getColor() const { return mcColor; }
  
  /*! Access the omni light position */
  void setPosition(ntlVec3Gfx set) { mvPosition = set; }
  ntlVec3Gfx getPosition() const { return mvPosition; }
	

protected:
	/*! render globals */
	ntlRenderGlobals *mpGlob;

	/*! is this light acitve? */
	bool mActive;

	/*! does it cast shadows? */
	bool mCastShadows;

  /*! color of this light */
	ntlColor  mcColor;

	/*! light position */
	ntlVec3Gfx  mvPosition;

private:

private:
#ifdef WITH_CXX_GUARDEDALLOC
	MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlLightObject")
#endif
};


//! Properties of an geo object, describing the reflection properties of the surface
class ntlMaterial
{
public:
  // CONSTRUCTORS
  //! Default constructor
  ntlMaterial( void );
  //! Constructor with parameters
  /*! Sets reflectance, ambient reflection, specular intensity
   *  specular exponent, mirror intensity 
   *  transparency, refraction index */
  ntlMaterial( string name,
         const ntlColor& Ref, const ntlColor& Amb, 
			   gfxReal Spec, gfxReal Exp, gfxReal Mirror,
			   gfxReal Trans, gfxReal Refrac, gfxReal TAdd,
			   const ntlColor& Att, int fres);
  //! Desctructor
  ~ntlMaterial() {};

	//! Calculate reflectance and refratance from Fresnel's law
	inline void calculateFresnel(const ntlVec3Gfx &dir, const ntlVec3Gfx &normal, gfxReal refIndex,
															 gfxReal &refl, gfxReal &trans );

protected:

  /* name of the material */
  string mName;

  //! Vector for reflectance of each color component (used in shade() of ray object)
  ntlColor  mDiffuseRefl;
  //! Ambient reflectance
  ntlColor mAmbientRefl;
  //! Specular reflection intensity
  gfxReal mSpecular;
  //! Specular phong exponent
  gfxReal mSpecExponent;
  //! Mirror intensity
  gfxReal mMirror;

  //! Transparence
  gfxReal mTransparence;
  //! Refraction index, nu(Air) is assumed 1
  gfxReal mRefracIndex;
  //! Should transparence be additive?
  gfxReal mTransAdditive;
  //! Color dependent transparency attentuation factors (negative logarithm stored)
  ntlColor mTransAttCol;
	//! Should the transparence and reflectivity be determined by fresnel?
	int mFresnel;


public:
  // access methods

  //! Returns the material name
  inline string getName() { return mName; }
  //! Returns the reflectance
  inline ntlColor  getDiffuseRefl() const { return ntlColor(mDiffuseRefl); }
  //! Returns the ambience
  inline ntlColor getAmbientRefl() const { return ntlColor(mAmbientRefl); }
  //! Returns the specular component
  inline gfxReal getSpecular() const { return mSpecular; }
  //! Returns the specular exponent component
  inline gfxReal getSpecExponent() const { return mSpecExponent; }
  //! Returns the mirror component
  inline gfxReal getMirror() const { return mMirror; }
  //! Returns the transparence component
  inline gfxReal getTransparence() const { return mTransparence; }
  //! Returns the refraction index component
  inline gfxReal getRefracIndex() const { return mRefracIndex; }
  //! Returns the transparency additive factor component
  inline gfxReal getTransAdditive() const { return mTransAdditive; }
  //! Returns the transparency attentuation
  inline ntlColor getTransAttCol() const { return mTransAttCol; }
	//! Get Fresnel flag
	inline int getFresnel( void ) { return mFresnel; }



  //! Returns the mat name
  inline void setName(string set) { mName = set; }
  //! Returns the reflectance
  inline void setDiffuseRefl(ntlColor set) { mDiffuseRefl=set; }
  //! Returns the ambience
  inline void setAmbientRefl(ntlColor set) { mAmbientRefl=set; }
  //! Returns the specular component
  inline void setSpecular(gfxReal set) { mSpecular=set; }
  //! Returns the specular exponent component
  inline void setSpecExponent(gfxReal set) { mSpecExponent=set; }
  //! Returns the mirror component
  inline void setMirror(gfxReal set) { mMirror=set; }
  //! Returns the transparence component
  inline void setTransparence(gfxReal set) { mTransparence=set; }
  //! Returns the refraction index component
  inline void setRefracIndex(gfxReal set) { mRefracIndex=set; }
  //! Returns the transparency additive factor component
  inline void setTransAdditive(gfxReal set) { mTransAdditive=set; }
  //! Returns the transparency attentuation
  inline void setTransAttCol(ntlColor set) { 
		ntlColor setlog = ntlColor( -log(set[0]), -log(set[1]), -log(set[2]) );
		mTransAttCol=setlog; }
	//! Set Fresnel on/off
	inline void setFresnel(int set) { mFresnel = set; }

private:
#ifdef WITH_CXX_GUARDEDALLOC
	MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlMaterial")
#endif
};


/******************************************************************************
 * Macro to define the default surface properties for a newly created object
 *****************************************************************************/
#define GET_GLOBAL_DEFAULT_MATERIAL new ntlMaterial( "default",\
                                        ntlColor( 0.5 ), ntlColor(0.0), \
                                        1.0, 5.0, 0.0,   \
																				/*0.0 test:*/ 0.5 , 1.0, 0.0, \
																				ntlColor( 0.0 ), 0 ); 
																															


/******************************************************************************
 * Calculate reflectance and refratance from Fresnel's law
 * cf. Glassner p. 46
 *****************************************************************************/
inline void 
ntlMaterial::calculateFresnel(const ntlVec3Gfx &dir, const ntlVec3Gfx &normal, gfxReal refIndex,
															gfxReal &refl, gfxReal &trans)
{
	gfxReal c = -dot(dir, normal);
	if(c<0) { 
		refl = 0.0; trans = 0.0; return;
		//c = 0.0;
	}

	gfxReal r0 = ((refIndex-1.0)*(refIndex-1.0)) /
		((refIndex+1.0)*(refIndex+1.0));
	gfxReal omc = (1.0-c);
	gfxReal r =r0 + (1.0 - r0) * omc*omc*omc*omc*omc;

	//mMirror = r;
	//mTransparence = (1.0 - r);
	refl = r;
	trans = (1.0 - r);
	//errorOut(" fres ");
}


#endif