1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | FILE: imtl.h
|
---|
4 |
|
---|
5 | DESCRIPTION: Renderer materials
|
---|
6 |
|
---|
7 | CREATED BY: Dan Silva
|
---|
8 |
|
---|
9 | HISTORY:
|
---|
10 |
|
---|
11 | *> Copyright (c) 1994, All Rights Reserved.
|
---|
12 | **********************************************************************/
|
---|
13 |
|
---|
14 | #ifndef __IMTL__H
|
---|
15 | #define __IMTL__H
|
---|
16 |
|
---|
17 |
|
---|
18 | #include <plugapi.h>
|
---|
19 |
|
---|
20 | //#include "gport.h"
|
---|
21 | #include "custcont.h"
|
---|
22 |
|
---|
23 | #define AXIS_UV 0
|
---|
24 | #define AXIS_VW 1
|
---|
25 | #define AXIS_WU 2
|
---|
26 |
|
---|
27 | // Values for SymFlags:
|
---|
28 | #define U_WRAP (1<<0)
|
---|
29 | #define V_WRAP (1<<1)
|
---|
30 | #define U_MIRROR (1<<2)
|
---|
31 | #define V_MIRROR (1<<3)
|
---|
32 |
|
---|
33 | #define X_AXIS 0
|
---|
34 | #define Y_AXIS 1
|
---|
35 | #define Z_AXIS 2
|
---|
36 |
|
---|
37 | static inline float Intens(const AColor& c) { return (c.r+c.g+c.b)/3.0f; }
|
---|
38 | static inline float Intens(const Color& c) { return (c.r+c.g+c.b)/3.0f; }
|
---|
39 |
|
---|
40 | // Meta-materials post this message to the MtlEditor when user
|
---|
41 | // clicks on a sub-material button.
|
---|
42 | #define WM_SUB_MTL_BUTTON WM_USER + 0x04001
|
---|
43 |
|
---|
44 | // Materials or Texture maps post this message to the MtlEditor when user
|
---|
45 | // clicks on a texture map button.
|
---|
46 | #define WM_TEXMAP_BUTTON WM_USER + 0x04002
|
---|
47 |
|
---|
48 | class ShadeContext;
|
---|
49 | class Bitmap;
|
---|
50 | class RenderMapsContext;
|
---|
51 |
|
---|
52 |
|
---|
53 | class TexHandle {
|
---|
54 | public:
|
---|
55 | virtual DWORD GetHandle() = 0;
|
---|
56 | virtual void DeleteThis() = 0;
|
---|
57 | };
|
---|
58 |
|
---|
59 | class TexHandleMaker{
|
---|
60 | public:
|
---|
61 | // choice of two ways to create a texture handle.
|
---|
62 | // From a 3DSMax Bitmap
|
---|
63 | virtual TexHandle* CreateHandle(Bitmap *bm, int symflags=0)=0;
|
---|
64 | // From a 32 bit DIB
|
---|
65 | virtual TexHandle* CreateHandle(BITMAPINFO *bminf, int symflags=0)=0;
|
---|
66 |
|
---|
67 | // This tells you the size desired of the bitmap. It ultimately
|
---|
68 | // needs a square bitmap that is a power of 2 in width and height.
|
---|
69 | // If you already have a bitmap around, just pass it in to CreateHandle
|
---|
70 | // and it will be converted. If you are making a bitmap from scratch
|
---|
71 | // (i.e.) a procedural texture, then you should make it Size() in
|
---|
72 | // width in height, and save us an extra step. In either case
|
---|
73 | // You own your bitmap, and are responsible for ultimately freeing it.
|
---|
74 |
|
---|
75 | virtual int Size()=0;
|
---|
76 | };
|
---|
77 |
|
---|
78 |
|
---|
79 | // Interface that is passed in to the Mtl or Texture Map when it is in the mtl
|
---|
80 | // editor.
|
---|
81 | class IMtlParams {
|
---|
82 | public:
|
---|
83 | // call after mouse up's in mtls params
|
---|
84 | // It causes the viewports to be redrawn.
|
---|
85 | virtual void MtlChanged()=0;
|
---|
86 |
|
---|
87 | // Adds rollup pages to the Material Params. Returns the window
|
---|
88 | // handle of the dialog that makes up the page.
|
---|
89 | virtual HWND AddRollupPage( HINSTANCE hInst, TCHAR *dlgTemplate,
|
---|
90 | DLGPROC dlgProc, TCHAR *title, LPARAM param=0,DWORD flags=0 )=0;
|
---|
91 |
|
---|
92 | // Removes a rollup page and destroys it. When a dialog is destroyed
|
---|
93 | // it need not delete all its rollup pages: the Mtl Editor will do
|
---|
94 | // this for it, and it is more efficient.
|
---|
95 | virtual void DeleteRollupPage( HWND hRollup )=0;
|
---|
96 |
|
---|
97 | // When the user mouses down in dead area, the plug-in should pass
|
---|
98 | // mouse messages to this function which will pass them on to the rollup.
|
---|
99 | virtual void RollupMouseMessage( HWND hDlg, UINT message,
|
---|
100 | WPARAM wParam, LPARAM lParam )=0;
|
---|
101 |
|
---|
102 | virtual int IsRollupPanelOpen(HWND hwnd)=0;
|
---|
103 | virtual int GetRollupScrollPos()=0;
|
---|
104 | virtual void SetRollupScrollPos(int spos)=0;
|
---|
105 |
|
---|
106 | // Registers a dialog window so IsDlgMesage() gets called for it.
|
---|
107 | // This is done automatically for Rollup Pages.
|
---|
108 | virtual void RegisterDlgWnd( HWND hDlg )=0;
|
---|
109 | virtual int UnRegisterDlgWnd( HWND hDlg )=0;
|
---|
110 |
|
---|
111 | // get the current time.
|
---|
112 | virtual TimeValue GetTime()=0;
|
---|
113 | };
|
---|
114 |
|
---|
115 | class ParamDlg;
|
---|
116 | class Texmap;
|
---|
117 |
|
---|
118 | class RenderData {
|
---|
119 | public:
|
---|
120 | virtual void DeleteThis() {delete this;/*should be pure virtual*/}
|
---|
121 | };
|
---|
122 |
|
---|
123 | class LightDesc : public RenderData {
|
---|
124 | public:
|
---|
125 | // determine color and direction of illumination
|
---|
126 | virtual BOOL Illuminate(ShadeContext& sc, Point3& normal, Color& color, Point3 &dir, float &dot_nl) { return 0;}
|
---|
127 | };
|
---|
128 |
|
---|
129 | #define SHADELIM_FLAT 1
|
---|
130 | #define SHADELIM_GOURAUD 2
|
---|
131 | #define SHADELIM_PHONG 3
|
---|
132 |
|
---|
133 | // Transform Reference frames:
|
---|
134 | enum RefFrame { REF_CAMERA=0, REF_WORLD, REF_OBJECT };
|
---|
135 |
|
---|
136 | class ShadeOutput {
|
---|
137 | public:
|
---|
138 | ULONG flags;
|
---|
139 | Color c; // shaded color
|
---|
140 | Color t; // transparency
|
---|
141 | float ior; // index of refraction
|
---|
142 | CoreExport void MixIn(ShadeOutput& a, float f); // (*this) = (1-f)*(*this) + f*a;
|
---|
143 | void Reset() {
|
---|
144 | flags = 0;
|
---|
145 | c.Black(); t.Black(); ior = 1.0f;
|
---|
146 | }
|
---|
147 | };
|
---|
148 |
|
---|
149 | #define SCMODE_NORMAL 0
|
---|
150 | #define SCMODE_SHADOW 1
|
---|
151 | //
|
---|
152 | // Shade Context: passed into Mtls and Texmaps
|
---|
153 | //
|
---|
154 | class ShadeContext {
|
---|
155 | public:
|
---|
156 | ULONG mode; // normal, shadow ...
|
---|
157 | BOOL doMaps; // apply texture maps?
|
---|
158 | BOOL filterMaps; // should texture be filtered
|
---|
159 | BOOL shadow; // apply shadows?
|
---|
160 | BOOL backFace; // are we on the back side of a 2-Sided face?
|
---|
161 | int mtlNum; // sub-mtl number for multi-materials
|
---|
162 | Color ambientLight; //
|
---|
163 | int nLights; // number of lights;
|
---|
164 | ShadeOutput out; // where the material leaves its results
|
---|
165 | void ResetOutput() { out.Reset(); }
|
---|
166 | virtual int Antialias() {return 0;}
|
---|
167 | virtual int ProjType() { return 0;} // returns: 0: perspective, 1: parallel
|
---|
168 | virtual LightDesc* Light(int n)=0; // get the nth light.
|
---|
169 | virtual TimeValue CurTime()=0; // current time value
|
---|
170 | virtual int NodeID() { return -1; }
|
---|
171 | virtual INode *Node() { return NULL; }
|
---|
172 | virtual Point3 BarycentricCoords() { return Point3(0,0,0);} // coords relative to triangular face
|
---|
173 | virtual int FaceNumber()=0; //
|
---|
174 | virtual Point3 Normal()=0; // interpolated normal
|
---|
175 | virtual void SetNormal(Point3 p) {} // for perturbing normal
|
---|
176 | virtual float Curve() { return 0.0f; } // estimate of dN/dsx, dN/dsy
|
---|
177 | virtual Point3 GNormal()=0; // geometric (face) normal
|
---|
178 | virtual Point3 ReflectVector()=0; // reflection vector
|
---|
179 | virtual Point3 RefractVector(float ior)=0; // refraction vector
|
---|
180 | virtual Point3 CamPos()=0; // camera position
|
---|
181 | virtual Point3 V()=0; // Unit view vector: from camera towards P
|
---|
182 | virtual Point3 P()=0; // point to be shaded;
|
---|
183 | virtual Point3 DP()=0; // deriv of P, relative to pixel, for AA
|
---|
184 | virtual void DP(Point3& dpdx, Point3& dpdy){}; // deriv of P, relative to pixel
|
---|
185 | virtual Point3 PObj()=0; // point in obj coords
|
---|
186 | virtual Point3 DPObj()=0; // deriv of PObj, rel to pixel, for AA
|
---|
187 | virtual Box3 ObjectBox()=0; // Object extents box in obj coords
|
---|
188 | virtual Point3 PObjRelBox()=0; // Point rel to obj box [-1 .. +1 ]
|
---|
189 | virtual Point3 DPObjRelBox()=0; // deriv of Point rel to obj box [-1 .. +1 ]
|
---|
190 | virtual void ScreenUV(Point2& uv, Point2 &duv)=0; // screen relative uv (from lower left)
|
---|
191 | virtual IPoint2 ScreenCoord()=0; // integer screen coordinate (from upper left)
|
---|
192 | virtual Point3 UVW()=0; // return UVW coords for point
|
---|
193 | virtual Point3 DUVW()=0; // return UVW derivs for point
|
---|
194 | virtual void DPdUVW(Point3 dP[3])=0; // Bump vectors for UVW
|
---|
195 | virtual AColor EvalEnvironMap(Texmap *map, Point3 view) {return AColor(0,0,0,0);} //evaluate map with given viewDir
|
---|
196 | virtual void GetBGColor(Color &bgcol, Color& transp, BOOL fogBG=TRUE)=0; // returns Background color, bg transparency
|
---|
197 |
|
---|
198 | // Camera ranges set by user in camera's UI.
|
---|
199 | virtual float CamNearRange() {return 0.0f;}
|
---|
200 | virtual float CamFarRange() {return 0.0f;}
|
---|
201 |
|
---|
202 | // Transform to and from internal space
|
---|
203 | virtual Point3 PointTo(const Point3& p, RefFrame ito)=0;
|
---|
204 | virtual Point3 PointFrom(const Point3& p, RefFrame ifrom)=0;
|
---|
205 | virtual Point3 VectorTo(const Point3& p, RefFrame ito)=0;
|
---|
206 | virtual Point3 VectorFrom(const Point3& p, RefFrame ifrom)=0;
|
---|
207 |
|
---|
208 | // After being evaluated, if a map or material has a non-zero GBufID, it should
|
---|
209 | // call this routine to store it into the shade context.
|
---|
210 | virtual void SetGBufferID(int gbid) {}
|
---|
211 |
|
---|
212 | virtual FILE* DebugFile() { return NULL; }
|
---|
213 |
|
---|
214 | ShadeContext() {mode = SCMODE_NORMAL; nLights = 0; shadow = TRUE; }
|
---|
215 | };
|
---|
216 |
|
---|
217 | // Material flags values
|
---|
218 | #define MTL_IN_SCENE (1<<0)
|
---|
219 | #define MTL_BEING_EDITED (1<<1) // mtl params being displayed in medit
|
---|
220 | #define MTL_SUB_BEING_EDITED (1<<2) // mtl OR sub mtl/tex being displayed in medit
|
---|
221 | #define MTL_TEX_DISPLAY_ENABLED (1<<3) // Interactive texture display enabled
|
---|
222 | #define MTL_MEDIT_BACKGROUND (1<<8) // Show background in Mtl Editor
|
---|
223 | #define MTL_MEDIT_BACKLIGHT (1<<9) // Backlight in Mtl Editor
|
---|
224 |
|
---|
225 | #define MTL_OBJTYPE_SHIFT 10
|
---|
226 | #define MTL_MEDIT_OBJTYPE (1<<MTL_OBJTYPE_SHIFT) // Object type displayed in Mtl Editor
|
---|
227 | #define MTL_MEDIT_OBJTYPE_MASK ((1<<MTL_OBJTYPE_SHIFT)|(1<<MTL_OBJTYPE_SHIFT+1)|(1<<MTL_OBJTYPE_SHIFT+2))
|
---|
228 |
|
---|
229 | #define MTL_TILING_SHIFT 13
|
---|
230 | #define MTL_MEDIT_TILING (1<<MTL_TILING_SHIFT) // Object type displayed in Mtl Editor
|
---|
231 | #define MTL_MEDIT_TILING_MASK ((1<<MTL_TILING_SHIFT)|(1<<MTL_TILING_SHIFT+1)|(1<<MTL_TILING_SHIFT+2))
|
---|
232 | #define MTL_MEDIT_VIDCHECK 16
|
---|
233 | #define MTL_MEDIT_NEXT_AVAIL 17
|
---|
234 | #define MTL_WORK_FLAG (1<<31)
|
---|
235 |
|
---|
236 | // Material Requirements flags: returned by Requirements() function
|
---|
237 | #define MTLREQ_2SIDE (1<<0) // 2-sided material
|
---|
238 | #define MTLREQ_WIRE (1<<1) // Wire frame
|
---|
239 | #define MTLREQ_WIRE_ABS (1<<2) // Wire frame, absolute size
|
---|
240 | #define MTLREQ_TRANSP (1<<3) // transparency
|
---|
241 | #define MTLREQ_UV (1<<4) // requires UVW coords
|
---|
242 | #define MTLREQ_FACEMAP (1<<5) // use "face map" UV coords
|
---|
243 | #define MTLREQ_XYZ (1<<6) // requires object XYZ coords
|
---|
244 | #define MTLREQ_OXYZ (1<<7) // requires object ORIGINAL XYZ coords
|
---|
245 | #define MTLREQ_BUMPUV (1<<8) // requires UV bump vectors
|
---|
246 | #define MTLREQ_BGCOL (1<<9) // requires background color (e.g. Matte mtl)
|
---|
247 | #define MTLREQ_PHONG (1<<10) // requires interpolated normal
|
---|
248 | #define MTLREQ_AUTOREFLECT (1<<11) // needs to build auto-reflect map
|
---|
249 | #define MTLREQ_AUTOMIRROR (1<<12) // needs to build auto-mirror map
|
---|
250 | #define MTLREQ_NOATMOS (1<<13) // suppress atmospheric shader (used by Matte mtl)
|
---|
251 | #define MTLREQ_ADDITIVE_TRANSP (1<<14) // composite additively
|
---|
252 |
|
---|
253 | #define MAPSLOT_TEXTURE 0 // texture maps
|
---|
254 | #define MAPSLOT_ENVIRON 1 // environment maps
|
---|
255 |
|
---|
256 | // Base class from which materials and textures are subclassed.
|
---|
257 | class MtlBase: public ReferenceTarget {
|
---|
258 | TSTR name;
|
---|
259 | ULONG mtlFlags;
|
---|
260 | public:
|
---|
261 | ULONG gbufID;
|
---|
262 | CoreExport MtlBase();
|
---|
263 | TSTR& GetName() { return name; }
|
---|
264 | CoreExport void SetName(TSTR s);
|
---|
265 | void SetMtlFlag(int mask, BOOL val=TRUE) {
|
---|
266 | if (val) mtlFlags |= mask; else mtlFlags &= ~mask;
|
---|
267 | }
|
---|
268 | void ClearMtlFlag(int mask) { mtlFlags &= ~mask; }
|
---|
269 | int TestMtlFlag(int mask) { return(mtlFlags&mask?1:0); }
|
---|
270 |
|
---|
271 | // Used internally by materials editor.
|
---|
272 | int GetMeditObjType() { return (mtlFlags&MTL_MEDIT_OBJTYPE_MASK)>>MTL_OBJTYPE_SHIFT; }
|
---|
273 | void SetMeditObjType(int t) { mtlFlags &= ~MTL_MEDIT_OBJTYPE_MASK; mtlFlags |= t<<MTL_OBJTYPE_SHIFT; }
|
---|
274 | int GetMeditTiling() { return (mtlFlags&MTL_MEDIT_TILING_MASK)>>MTL_TILING_SHIFT; }
|
---|
275 | void SetMeditTiling(int t) { mtlFlags &= ~MTL_MEDIT_TILING_MASK; mtlFlags |= t<<MTL_TILING_SHIFT; }
|
---|
276 |
|
---|
277 | // recursively determine if there are any multi-materials or texmaps
|
---|
278 | // in tree
|
---|
279 | CoreExport BOOL AnyMulti();
|
---|
280 |
|
---|
281 | BOOL TextureDisplayEnabled() { return TestMtlFlag(MTL_TEX_DISPLAY_ENABLED); }
|
---|
282 |
|
---|
283 | // Return the "className(instance Name)".
|
---|
284 | // The default implementation should be used in most cases.
|
---|
285 | CoreExport virtual TSTR GetFullName();
|
---|
286 |
|
---|
287 | // Mtls and Texmaps must use this to copy the common portion of
|
---|
288 | // themselves when cloning
|
---|
289 | CoreExport MtlBase& operator=(const MtlBase& m);
|
---|
290 |
|
---|
291 | virtual int BuildMaps(TimeValue t, RenderMapsContext &rmc) { return 1; }
|
---|
292 |
|
---|
293 | // This gives the cumulative requirements of the mtl and its
|
---|
294 | // tree. The default just OR's together the local requirements
|
---|
295 | // of the Mtl with the requirements of all its children.
|
---|
296 | // For most mtls, all they need to implement is LocalRequirements,
|
---|
297 | // if any.
|
---|
298 | CoreExport virtual ULONG Requirements(int subMtlNum);
|
---|
299 |
|
---|
300 | // Specifies various requirements for the material: Should NOT
|
---|
301 | // include requirements of its sub-mtls and sub-maps.
|
---|
302 | virtual ULONG LocalRequirements(int subMtlNum) { return 0; }
|
---|
303 |
|
---|
304 | // This returns true for materials of texmaps that select sub-
|
---|
305 | // materials based on mesh faceMtlIndex. Used in
|
---|
306 | // interactive render.
|
---|
307 | virtual BOOL IsMultiMtl() { return FALSE; }
|
---|
308 |
|
---|
309 | // Methods to access sub texture maps of material or texmap
|
---|
310 | virtual int NumSubTexmaps() { return 0; }
|
---|
311 | virtual Texmap* GetSubTexmap(int i) { return NULL; }
|
---|
312 | virtual int MapSlotType(int i) { return MAPSLOT_TEXTURE; }
|
---|
313 | virtual void SetSubTexmap(int i, Texmap *m) { }
|
---|
314 |
|
---|
315 | // query MtlBase about the On/Off state of each sub map.
|
---|
316 | virtual int SubTexmapOn(int i) { return 1; }
|
---|
317 |
|
---|
318 | // This must be called on a sub-Mtl or sub-Map when it is removed,
|
---|
319 | // in case it or any of its submaps are active in the viewport.
|
---|
320 | CoreExport void DeactivateMapsInTree();
|
---|
321 |
|
---|
322 | CoreExport virtual TSTR GetSubTexmapSlotName(int i);
|
---|
323 | CoreExport TSTR GetSubTexmapTVName(int i);
|
---|
324 | // use this for drag-and-drop of texmaps
|
---|
325 | CoreExport void CopySubTexmap(HWND hwnd, int ifrom, int ito);
|
---|
326 |
|
---|
327 | // To make texture & material evaluation more efficient, this function is
|
---|
328 | // called whenever time has changed. It will be called at the
|
---|
329 | // beginning of every frame during rendering.
|
---|
330 | virtual void Update(TimeValue t, Interval& valid)=0;
|
---|
331 |
|
---|
332 | // set back to default values
|
---|
333 | virtual void Reset()=0;
|
---|
334 |
|
---|
335 | // call this to determine the validity interval of the mtl or texture
|
---|
336 | virtual Interval Validity(TimeValue t)=0;
|
---|
337 |
|
---|
338 | // this gets called when the mtl or texture is to be displayed in the
|
---|
339 | // mtl editor params area.
|
---|
340 |
|
---|
341 | virtual ParamDlg* CreateParamDlg(HWND hwMtlEdit, IMtlParams *imp)=0;
|
---|
342 | // save the common mtlbase stuff.
|
---|
343 | // these must be called in a chunk at the beginning of every mtl and
|
---|
344 | // texmap.
|
---|
345 | CoreExport IOResult Save(ISave *isave);
|
---|
346 | CoreExport IOResult Load(ILoad *iload);
|
---|
347 |
|
---|
348 | // GBuffer functions
|
---|
349 | ULONG GetGBufID() { return gbufID; }
|
---|
350 | void SetGBufID(ULONG id) { gbufID = id; }
|
---|
351 |
|
---|
352 | // Default File enumerator.
|
---|
353 | CoreExport void EnumAuxFiles(NameEnumCallback& nameEnum, DWORD flags);
|
---|
354 |
|
---|
355 | };
|
---|
356 |
|
---|
357 |
|
---|
358 | // Every MtlBase sub-class defines a ParamDlg to manage its part of
|
---|
359 | // the material editor.
|
---|
360 | class ParamDlg {
|
---|
361 | public:
|
---|
362 | virtual Class_ID ClassID()=0;
|
---|
363 | virtual void SetThing(ReferenceTarget *m)=0;
|
---|
364 | virtual ReferenceTarget* GetThing()=0;
|
---|
365 | virtual void SetTime(TimeValue t)=0;
|
---|
366 | virtual void ReloadDialog()=0;
|
---|
367 | virtual void DeleteThis()=0;
|
---|
368 | virtual void ActivateDlg(BOOL onOff)=0;
|
---|
369 |
|
---|
370 | };
|
---|
371 |
|
---|
372 | // Pre-defined categories of texture maps
|
---|
373 | CoreExport TCHAR TEXMAP_CAT_2D[]; // 2D maps
|
---|
374 | CoreExport TCHAR TEXMAP_CAT_3D[]; // 3D maps
|
---|
375 | CoreExport TCHAR TEXMAP_CAT_COMP[]; // Composite
|
---|
376 | CoreExport TCHAR TEXMAP_CAT_COLMOD[]; // Color modifier
|
---|
377 | CoreExport TCHAR TEXMAP_CAT_ENV[]; // Environment
|
---|
378 |
|
---|
379 | class NameAccum {
|
---|
380 | public:
|
---|
381 | virtual void AddMapName(TCHAR *name)=0;
|
---|
382 | };
|
---|
383 |
|
---|
384 |
|
---|
385 | // virual texture map interface
|
---|
386 | class Texmap: public MtlBase {
|
---|
387 | int activeCount;
|
---|
388 | public:
|
---|
389 |
|
---|
390 | Texmap() { activeCount = 0; }
|
---|
391 |
|
---|
392 | SClass_ID SuperClassID() { return TEXMAP_CLASS_ID; }
|
---|
393 | virtual void GetClassName(TSTR& s) { s= TSTR(_T("Texture")); }
|
---|
394 |
|
---|
395 | // Evaluate the color of map for the context.
|
---|
396 | virtual AColor EvalColor(ShadeContext& sc)=0;
|
---|
397 |
|
---|
398 | // Evaluate the map for a "mono" channel.
|
---|
399 | // this just permits a bit of optimization
|
---|
400 | virtual float EvalMono(ShadeContext& sc) {
|
---|
401 | return Intens(EvalColor(sc));
|
---|
402 | }
|
---|
403 |
|
---|
404 | // For Bump mapping, need a perturbation to apply to a normal.
|
---|
405 | // Leave it up to the Texmap to determine how to do this.
|
---|
406 | virtual Point3 EvalNormalPerturb(ShadeContext& sc)=0;
|
---|
407 |
|
---|
408 | // Methods for doing interactive texture display
|
---|
409 | CoreExport void IncrActive();
|
---|
410 | CoreExport void DecrActive();
|
---|
411 |
|
---|
412 | int Active() { return activeCount; }
|
---|
413 | virtual BOOL SupportTexDisplay() { return FALSE; }
|
---|
414 | virtual void ActivateTexDisplay(BOOL onoff) {}
|
---|
415 | virtual DWORD GetActiveTexHandle(TimeValue t, TexHandleMaker& thmaker) {return 0;}
|
---|
416 |
|
---|
417 | virtual void GetUVTransform(Matrix3 &uvtrans) {}
|
---|
418 | virtual int GetTextureTiling() { return U_WRAP|V_WRAP; }
|
---|
419 | virtual void InitSlotType(int sType) {}
|
---|
420 |
|
---|
421 | // System function to set slot type for all subtexmaps in a tree.
|
---|
422 | CoreExport void RecursInitSlotType(int sType);
|
---|
423 | virtual void SetOutputLevel(TimeValue t, float v) {}
|
---|
424 |
|
---|
425 | // called prior to render: missing map names should be added to NameAccum.
|
---|
426 | // return 1: success, 0:failure.
|
---|
427 | virtual int LoadMapFiles(TimeValue t) { return 1; }
|
---|
428 |
|
---|
429 | };
|
---|
430 |
|
---|
431 | // virtual material interface
|
---|
432 | class Mtl: public MtlBase {
|
---|
433 | Texmap *activeTexmap;
|
---|
434 | public:
|
---|
435 | Mtl(){ activeTexmap=NULL; }
|
---|
436 | SClass_ID SuperClassID() { return MATERIAL_CLASS_ID; }
|
---|
437 | virtual void GetClassName(TSTR& s) { s= TSTR(_T("Mtl")); }
|
---|
438 |
|
---|
439 | Texmap* GetActiveTexmap() { return activeTexmap; }
|
---|
440 | void SetActiveTexmap( Texmap *txm) { activeTexmap = txm; }
|
---|
441 |
|
---|
442 | CoreExport void RefDeleted();
|
---|
443 | CoreExport void RefAdded(RefMakerHandle rm);
|
---|
444 |
|
---|
445 | // Must call Update(t) before calling these functions!
|
---|
446 | // Their purpose is for setting up the material for the
|
---|
447 | // GraphicsWindow renderer.
|
---|
448 | virtual Color GetAmbient(int mtlNum=0, BOOL backFace=FALSE)=0;
|
---|
449 | virtual Color GetDiffuse(int mtlNum=0, BOOL backFace=FALSE)=0;
|
---|
450 | virtual Color GetSpecular(int mtlNum=0, BOOL backFace=FALSE)=0;
|
---|
451 | virtual float GetShininess(int mtlNum=0, BOOL backFace=FALSE)=0;
|
---|
452 | virtual float GetShinStr(int mtlNum=0, BOOL backFace=FALSE)=0;
|
---|
453 | virtual float GetXParency(int mtlNum=0, BOOL backFace=FALSE)=0;
|
---|
454 |
|
---|
455 | // used by the scanline renderer
|
---|
456 | virtual float WireSize(int mtlNum=0, BOOL backFace=FALSE) { return 1.0f; }
|
---|
457 |
|
---|
458 | virtual void SetAmbient(Color c, TimeValue t)=0;
|
---|
459 | virtual void SetDiffuse(Color c, TimeValue t)=0;
|
---|
460 | virtual void SetSpecular(Color c, TimeValue t)=0;
|
---|
461 | virtual void SetShininess(float v, TimeValue t)=0;
|
---|
462 |
|
---|
463 | virtual ULONG LocalRequirements(int subMtlNum) { return 0; }
|
---|
464 |
|
---|
465 | // The main method: called by the renderer to compute color and transparency
|
---|
466 | // output returned in sc.out
|
---|
467 | virtual void Shade(ShadeContext& sc)=0;
|
---|
468 |
|
---|
469 | // Methods to access sub-materials of meta-materials
|
---|
470 | virtual int NumSubMtls() { return 0; }
|
---|
471 | virtual Mtl* GetSubMtl(int i) { return NULL; }
|
---|
472 | virtual void SetSubMtl(int i, Mtl *m) { }
|
---|
473 | CoreExport virtual TSTR GetSubMtlSlotName(int i);
|
---|
474 | CoreExport TSTR GetSubMtlTVName(int i);
|
---|
475 |
|
---|
476 | };
|
---|
477 |
|
---|
478 | // A texture map implements this class and passes it into EvalUVMap,
|
---|
479 | // EvalUVMapMono, and EvalDeriv to evaluate itself with tiling & mirroring
|
---|
480 | class MapSampler {
|
---|
481 | public:
|
---|
482 | // required:
|
---|
483 | virtual AColor Sample(ShadeContext& sc, float u,float v)=0;
|
---|
484 | virtual AColor SampleFilter(ShadeContext& sc, float u,float v, float du, float dv)=0;
|
---|
485 | // optional:
|
---|
486 | virtual float SampleMono(ShadeContext& sc, float u,float v) { return Intens(Sample(sc,u,v)); }
|
---|
487 | virtual float SampleMonoFilter(ShadeContext& sc, float u,float v, float du, float dv){
|
---|
488 | return Intens(SampleFilter(sc,u,v,du,dv));
|
---|
489 | }
|
---|
490 | };
|
---|
491 |
|
---|
492 |
|
---|
493 | // This class generates UV coordinates based on the results of a UV
|
---|
494 | // Source and user specified transformation.
|
---|
495 | // A reference to one of these is referenced by all 2D texture maps.
|
---|
496 | class UVGen: public MtlBase {
|
---|
497 | public:
|
---|
498 | // Get texture coords and derivatives for antialiasing
|
---|
499 | virtual void GetUV( ShadeContext& sc, Point2& UV, Point2& dUV)=0;
|
---|
500 |
|
---|
501 | // This is how a Texmap evaluates itself
|
---|
502 | virtual AColor EvalUVMap(ShadeContext &sc, MapSampler* samp, BOOL filter=TRUE)=0;
|
---|
503 | virtual float EvalUVMapMono(ShadeContext &sc, MapSampler* samp, BOOL filter=TRUE)=0;
|
---|
504 | virtual Point2 EvalDeriv( ShadeContext& sc, MapSampler* samp, BOOL filter=TRUE)=0;
|
---|
505 |
|
---|
506 | // Get dPdu and dPdv for bump mapping
|
---|
507 | virtual void GetBumpDP( ShadeContext& sc, Point3& dPdu, Point3& dPdv)=0;
|
---|
508 |
|
---|
509 | virtual void GetUVTransform(Matrix3 &uvtrans)=0;
|
---|
510 |
|
---|
511 | virtual int GetTextureTiling()=0;
|
---|
512 |
|
---|
513 | virtual int SymFlags()=0;
|
---|
514 |
|
---|
515 | virtual void InitSlotType(int sType)=0;
|
---|
516 |
|
---|
517 | SClass_ID SuperClassID() { return UVGEN_CLASS_ID; }
|
---|
518 | };
|
---|
519 |
|
---|
520 | // This class generates Point3 coordinates based on the ShadeContext.
|
---|
521 | // A reference to one of these is referenced by all 3D texture maps.
|
---|
522 | class XYZGen: public MtlBase {
|
---|
523 | public:
|
---|
524 | // Get texture coords and derivatives for antialiasing
|
---|
525 | virtual void GetXYZ( ShadeContext& sc, Point3& p, Point3& dp)=0;
|
---|
526 | SClass_ID SuperClassID() { return XYZGEN_CLASS_ID; }
|
---|
527 |
|
---|
528 | };
|
---|
529 |
|
---|
530 | // This class is used by texture maps to put up the output filter
|
---|
531 | // rollup, and perform the output filtering.
|
---|
532 | class TextureOutput: public MtlBase {
|
---|
533 | public:
|
---|
534 | virtual AColor Filter(AColor c) = 0;
|
---|
535 | virtual float Filter(float f) = 0;
|
---|
536 | virtual Point3 Filter(Point3 p) = 0;
|
---|
537 | virtual float GetOutputLevel(TimeValue t) = 0;
|
---|
538 | virtual void SetOutputLevel(TimeValue t, float v) = 0;
|
---|
539 | virtual void SetInvert(BOOL onoff)=0;
|
---|
540 | virtual BOOL GetInvert()=0;
|
---|
541 | SClass_ID SuperClassID() { return TEXOUTPUT_CLASS_ID; }
|
---|
542 | };
|
---|
543 |
|
---|
544 | typedef MtlBase* MtlBaseHandle;
|
---|
545 | typedef Mtl* MtlHandle;
|
---|
546 | typedef Texmap* TexmapHandle;
|
---|
547 |
|
---|
548 |
|
---|
549 | // Simple list of materials
|
---|
550 | class MtlList: public Tab<MtlHandle> {
|
---|
551 | public:
|
---|
552 | CoreExport int AddMtl(Mtl *m, BOOL checkUnique=TRUE);
|
---|
553 | CoreExport int FindMtl(Mtl *m);
|
---|
554 | CoreExport int FindMtlByName(TSTR& name);
|
---|
555 | void RemoveEntry(int n) { Delete(n,1); }
|
---|
556 | void Empty() { Resize(0); }
|
---|
557 | };
|
---|
558 |
|
---|
559 | // Materials library
|
---|
560 | class MtlLib: public ReferenceTarget, public MtlList {
|
---|
561 | public:
|
---|
562 | SClass_ID SuperClassID() { return REF_MAKER_CLASS_ID; }
|
---|
563 | CoreExport Class_ID ClassID();
|
---|
564 | CoreExport void DeleteAll();
|
---|
565 | void GetClassName(TSTR& s) { s= TSTR(_T("MtlLib")); }
|
---|
566 | CoreExport ~MtlLib();
|
---|
567 |
|
---|
568 | int NumSubs() {
|
---|
569 | return Count();
|
---|
570 | }
|
---|
571 | Animatable* SubAnim(int i) {
|
---|
572 | return (*this)[i];
|
---|
573 | }
|
---|
574 | CoreExport TSTR SubAnimName(int i);
|
---|
575 | CoreExport virtual void Remove(Mtl *m);
|
---|
576 | CoreExport virtual void Add(Mtl *m);
|
---|
577 |
|
---|
578 | // From ref
|
---|
579 | RefResult AutoDelete() { return REF_SUCCEED; }
|
---|
580 | CoreExport void DeleteThis();
|
---|
581 | int NumRefs() { return Count();}
|
---|
582 | RefTargetHandle GetReference(int i) { return (RefTargetHandle)(*this)[i];}
|
---|
583 | CoreExport void SetReference(int i, RefTargetHandle rtarg);
|
---|
584 | CoreExport RefTargetHandle Clone(RemapDir &remap = NoRemap());
|
---|
585 | CoreExport RefResult NotifyRefChanged( Interval changeInt, RefTargetHandle hTarget,
|
---|
586 | PartID& partID, RefMessage message );
|
---|
587 |
|
---|
588 | // IO
|
---|
589 | CoreExport IOResult Save(ISave *isave);
|
---|
590 | CoreExport IOResult Load(ILoad *iload);
|
---|
591 |
|
---|
592 | };
|
---|
593 |
|
---|
594 |
|
---|
595 | // A MtlBase Version of the above
|
---|
596 | class MtlBaseList: public Tab<MtlBaseHandle> {
|
---|
597 | public:
|
---|
598 | CoreExport int AddMtl(MtlBase *m, BOOL checkUnique=TRUE);
|
---|
599 | CoreExport int FindMtl(MtlBase *m);
|
---|
600 | CoreExport int FindMtlByName(TSTR& name);
|
---|
601 | void RemoveEntry(int n) { Delete(n,1); }
|
---|
602 | void Empty() { Resize(0); }
|
---|
603 | };
|
---|
604 |
|
---|
605 | class MtlBaseLib : public ReferenceTarget, public MtlBaseList {
|
---|
606 | public:
|
---|
607 | SClass_ID SuperClassID() { return REF_MAKER_CLASS_ID; }
|
---|
608 | CoreExport Class_ID ClassID();
|
---|
609 | CoreExport void DeleteAll();
|
---|
610 | void GetClassName(TSTR& s) { s= TSTR(_T("MtlBaseLib")); }
|
---|
611 | CoreExport ~MtlBaseLib();
|
---|
612 |
|
---|
613 | int NumSubs() {return Count();}
|
---|
614 | Animatable* SubAnim(int i) {return (*this)[i];}
|
---|
615 | CoreExport TSTR SubAnimName(int i);
|
---|
616 |
|
---|
617 | CoreExport virtual void Remove(MtlBase *m);
|
---|
618 | CoreExport virtual void Add(MtlBase *m);
|
---|
619 | CoreExport virtual void RemoveDuplicates();
|
---|
620 |
|
---|
621 | // From ref
|
---|
622 | RefResult AutoDelete() {return REF_SUCCEED;}
|
---|
623 | CoreExport void DeleteThis();
|
---|
624 | int NumRefs() { return Count();}
|
---|
625 | RefTargetHandle GetReference(int i) { return (RefTargetHandle)(*this)[i];}
|
---|
626 | CoreExport void SetReference(int i, RefTargetHandle rtarg);
|
---|
627 | CoreExport RefTargetHandle Clone(RemapDir &remap = NoRemap());
|
---|
628 | CoreExport RefResult NotifyRefChanged( Interval changeInt, RefTargetHandle hTarget,
|
---|
629 | PartID& partID, RefMessage message );
|
---|
630 |
|
---|
631 | // IO
|
---|
632 | CoreExport IOResult Save(ISave *isave);
|
---|
633 | CoreExport IOResult Load(ILoad *iload);
|
---|
634 | };
|
---|
635 |
|
---|
636 |
|
---|
637 | // Simple list of numbers
|
---|
638 | class NumList: public Tab<int> {
|
---|
639 | public:
|
---|
640 | CoreExport int Add(int j, BOOL checkUnique=TRUE);
|
---|
641 | CoreExport int Find(int j);
|
---|
642 | };
|
---|
643 |
|
---|
644 | class MtlRemap {
|
---|
645 | public:
|
---|
646 | virtual Mtl* Map(Mtl *oldAddr)=0;
|
---|
647 | };
|
---|
648 |
|
---|
649 | CoreExport void SetLoadingMtlLib(MtlLib *ml);
|
---|
650 | CoreExport void SetLoadingMtlBaseLib(MtlBaseLib *ml);
|
---|
651 |
|
---|
652 | CoreExport ClassDesc* GetMtlLibCD();
|
---|
653 | CoreExport ClassDesc* GetMtlBaseLibCD();
|
---|
654 |
|
---|
655 | CoreExport UVGen* GetNewDefaultUVGen();
|
---|
656 | CoreExport XYZGen* GetNewDefaultXYZGen();
|
---|
657 | CoreExport TextureOutput* GetNewDefaultTextureOutput();
|
---|
658 | inline int IsMtl(MtlBase *m) { return m->SuperClassID()==MATERIAL_CLASS_ID; }
|
---|
659 | inline int IsTex(MtlBase *m) { return m->SuperClassID()==TEXMAP_CLASS_ID; }
|
---|
660 |
|
---|
661 | // Combines the two materials into a multi-material.
|
---|
662 | // Either of the two input materials can themselves be multis.
|
---|
663 | // c1 and c2 will be set to the mat count for mat1 and mat2.
|
---|
664 | CoreExport Mtl *CombineMaterials(Mtl *mat1, Mtl *mat2, int &c1, int &c2);
|
---|
665 |
|
---|
666 | #endif
|
---|