source: golgotha/src/maxtool/sdk_inc/render.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 12.9 KB
Line 
1/**********************************************************************
2 *<
3        FILE: render.h
4
5        DESCRIPTION:
6
7        CREATED BY: Dan Silva
8
9        HISTORY:
10
11 *>     Copyright (c) 1994, All Rights Reserved.
12 **********************************************************************/
13
14
15#ifndef __RENDER__H
16#define __RENDER__H
17
18#define FIELD_EVEN 0
19#define FIELD_ODD 1
20
21// Render Types   RB: I didn't want to include render.h in MAXAPI.H...
22#ifndef _REND_TYPE_DEFINED
23#define _REND_TYPE_DEFINED
24enum RendType {
25        RENDTYPE_NORMAL,
26        RENDTYPE_REGION,
27        RENDTYPE_BLOWUP,
28        RENDTYPE_SELECT
29        };
30#endif
31
32#define PROJ_PERSPECTIVE 0
33#define PROJ_PARALLEL 1
34
35class DefaultLight {
36        public:
37        LightState ls;
38        Matrix3 tm;     
39        };
40
41class ViewParams {
42        public:
43                Matrix3 affineTM;
44                int projType;  // PROJ_PERSPECTIVE or PROJ_PARALLEL
45                float hither,yon;
46                // Parallel projection params
47                float zoom;  // Zoom factor
48                // Perspective params
49                float fov;      // field of view
50        };
51
52
53// Common renderer parameters
54
55class Atmospheric;
56
57// These parameters are passed to the renderer when the renderer is opend.
58class RendParams {
59        public:
60        RendType rendType;     
61        // boundaries of the region for render region or render blowup
62        // in device coords.
63        int regxmin,regxmax;
64        int regymin,regymax;
65
66#if 0 // RB: These come from the bitmap now.
67        int width, height;
68        float aspect;
69#endif
70        BOOL isNetRender;  // is this a render on a network slave?     
71        BOOL fieldRender;
72        int fieldOrder;    // 0->even, 1-> odd
73        TimeValue frameDur; // duration of one frame
74       
75        BOOL colorCheck;
76        int vidCorrectMethod; // 0->FLAG, 1->SCALE_LUMA 2->SCALE_SAT
77        int ntscPAL;  // 0 ->NTSC,  1 ->PAL
78        BOOL superBlack;
79        int sbThresh;
80        BOOL rendHidden;
81        BOOL force2Side;
82        BOOL inMtlEdit;   // rendering in the mtl editor?
83        float mtlEditTile; // if so, scale tiling
84        BOOL mtlEditAA;   // if so, antialias?
85        BOOL multiThread; // for testing only
86        BOOL useEnvironAlpha;  // use alpha from the environment map.
87        BOOL dontAntialiasBG; // Don't antialias against background (for video games)           
88        Texmap *envMap;         // The environment map, may be NULL
89        Atmospheric *atmos; // The atmosphere effects, may be NULL.
90        RendParams() { inMtlEdit=0; mtlEditAA = 0; }
91        };                                                 
92
93// These are passed to the renderer on every frame
94class FrameRendParams {
95        public:
96        Color ambient;
97        Color background;
98        float frameDuration; // duration of one frame, in current frames
99        FrameRendParams() { frameDuration = 1.0f; }
100        };
101
102// Since this dialog is modless and non-interactive, as the user changes
103// parameters in the dialog, the renderer does not need to update it's
104// state. When the user is through, they may choose 'OK' or 'Cancel'.
105//
106// If the user OKs the dialog, AcceptParams() will be called, at which time the
107// renderer can read the parameter out of the UI and modify its state.
108//
109// If RejectParams() is called, typically the renderer will not have to do anything
110// since it has not yet modify its state, but if for some reason it has, it
111// should restore its state.
112class RendParamDlg {
113        public:
114                virtual void AcceptParams()=0;
115                virtual void RejectParams() {}
116                virtual void DeleteThis()=0;           
117        };
118
119// Flag bits for DoMaterialBrowseDlg()
120#define BROWSE_MATSONLY         (1<<0)
121#define BROWSE_MAPSONLY         (1<<1)
122#define BROWSE_INCNONE          (1<<2)  // Include 'None' as an option
123#define BROWSE_INSTANCEONLY     (1<<3)  // Only allow instances, no copy
124
125// passed to SetPickMode. This is a callback that gets called as
126// the user tries to pick objects in the scene.
127class RendPickProc {
128        public:
129                // Called when the user picks something.
130                // return TRUE to end the pick mode.
131                virtual BOOL Pick(INode *node)=0;
132
133                // Return TRUE if this is an acceptable hit, FALSE otherwise.
134                virtual BOOL Filter(INode *node)=0;
135
136                // These are called as the mode is entered and exited
137                virtual void EnterMode() {}
138                virtual void ExitMode() {}
139
140                // Provides two cursor, 1 when over a pickable object and 1 when not.
141                virtual HCURSOR GetDefCursor() {return NULL;}
142                virtual HCURSOR GetHitCursor() {return NULL;}
143        };
144
145
146// This is the interface given to a renderer when it needs to display its parameters
147// It is also given to atmospheric effects to display thier parameters.
148class IRendParams {
149        public:
150                // The current position of the frame slider
151                virtual TimeValue GetTime()=0;
152
153                // Register a callback object that will get called every time the
154                // user changes the frame slider.
155                virtual void RegisterTimeChangeCallback(TimeChangeCallback *tc)=0;
156                virtual void UnRegisterTimeChangeCallback(TimeChangeCallback *tc)=0;
157
158                // Brings up the material browse dialog allowing the user to select a material.
159                // newMat will be set to TRUE if the material is new OR cloned.
160                // Cancel will be set to TRUE if the user cancels the dialog.
161                // The material returned will be NULL if the user selects 'None'
162                virtual MtlBase *DoMaterialBrowseDlg(HWND hParent,DWORD flags,BOOL &newMat,BOOL &cancel)=0;
163
164                // Adds rollup pages to the render params dialog. Returns the window
165                // handle of the dialog that makes up the page.
166                virtual HWND AddRollupPage(HINSTANCE hInst, TCHAR *dlgTemplate,
167                        DLGPROC dlgProc, TCHAR *title, LPARAM param=0,DWORD flags=0)=0;
168
169                // Removes a rollup page and destroys it.
170                virtual void DeleteRollupPage(HWND hRollup)=0;
171
172                // When the user mouses down in dead area, the plug-in should pass
173                // mouse messages to this function which will pass them on to the rollup.
174                virtual void RollupMouseMessage(HWND hDlg, UINT message,
175                                        WPARAM wParam, LPARAM lParam)=0;
176
177                // This will set the command mode to a standard pick mode.
178                // The callback implements hit testing and a method that is
179                // called when the user actually picks an item.
180                virtual void SetPickMode(RendPickProc *proc)=0;
181               
182                // If a plug-in is finished editing its parameters it should not
183                // leave the user in a pick mode. This will flush out any pick modes
184                // in the command stack.
185                virtual void EndPickMode()=0;
186                       
187                // When a plugin has a Texmap, clicking on the button
188                // associated with that map should cause this routine
189                // to be called.
190                virtual void PutMtlToMtlEditor(MtlBase *mb)=0;
191
192                // This is for use only by the scanline renderer.
193                virtual float GetMaxPixelSize() = 0;
194        };
195
196
197// Values returned from Progress()
198#define RENDPROG_CONTINUE       1
199#define RENDPROG_ABORT          0
200
201// Values passed to SetCurField()
202#define FIELD_FIRST             0
203#define FIELD_SECOND    1
204#define FIELD_NONE              -1
205
206// A callback passed in to the renderer
207class RendProgressCallback {
208        public:
209                virtual void SetTitle(const TCHAR *title)=0;
210                virtual int Progress(int done, int total)=0;
211                virtual void SetCurField(int which) {}
212                virtual void SetSceneStats(int nlights, int nrayTraced, int nshadowed, int nobj, int nfaces) {}
213        };
214
215
216// RB: my version of a renderer...
217class Renderer : public ReferenceTarget {
218        public:
219                // Reference/Animatable methods.
220                // In addition, the renderer would need to implement ClassID() and DeleteThis()
221                // Since a renderer will probably not itself have references, this implementation should do
222                RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
223                 PartID& partID,  RefMessage message) {return REF_SUCCEED;}
224                SClass_ID SuperClassID() {return RENDERER_CLASS_ID;}
225               
226                virtual int Open(
227                        INode *scene,           // root node of scene to render
228                        INode *vnode,           // view node (camera or light), or NULL
229                        ViewParams *viewPar,// view params for rendering ortho or user viewport
230                        RendParams &rp,         // common renderer parameters
231                        HWND hwnd,                              // owner window, for messages
232                        DefaultLight* defaultLights=NULL, // Array of default lights if none in scene
233                        int numDefLights=0      // number of lights in defaultLights array
234                        )=0;
235                                               
236                //
237                // Render a frame -- will use camera or view from open
238                //
239                virtual int Render(
240                        TimeValue t,                    // frame to render.
241                        Bitmap *tobm,                   // optional target bitmap
242                        FrameRendParams &frp,   // Time dependent parameters
243                        HWND hwnd,                              // owner window
244                        RendProgressCallback *prog=NULL
245                        )=0;
246                virtual void Close(     HWND hwnd )=0;         
247
248                // Adds rollup page(s) to renderer configure dialog
249                // If prog==TRUE then the rollup page should just display the parameters
250                // so the user has them for reference while rendering, they should not be editable.
251                virtual RendParamDlg *CreateParamDialog(IRendParams *ir,BOOL prog=FALSE)=0;
252                virtual void ResetParams()=0;
253
254
255        };
256
257
258class ShadowBuffer;
259class ShadowQuadTree;
260
261class RendContext {
262        public:
263                virtual ShadowBuffer* NewShadowBuffer() const=0;
264                virtual ShadowQuadTree* NewShadowQuadTree() const=0;
265                virtual int Progress(int done, int total) const { return 1; }
266        };
267
268struct SubRendParams {
269        RendType rendType;     
270        BOOL fieldRender;
271        BOOL evenLines; // when field rendering
272        BOOL doingMirror;
273        BOOL doEnvMap;  // do environment maps?
274        int devWidth, devHeight;
275        float devAspect;
276        int xorg, yorg;           // location on screen of upper left corner of output bitmap
277        int xmin,xmax,ymin,ymax;  // area of screen being rendered
278        };
279
280// flags passed to RenderMapsContext::Render()
281#define RENDMAP_SHOW_NODE  1  // *Dont* exclude this node from the render.
282class RenderMapsContext {
283        public:
284            virtual INode *GetNode()=0;
285                virtual int NodeRenderID()=0;
286                virtual void GetCurrentViewParams(ViewParams &vp)=0;
287                virtual void GetSubRendParams(SubRendParams &srp)=0;
288                virtual int SubMtlIndex()=0;
289            virtual void FindMtlPlane(float pl[4])=0;
290                virtual void FindMtlScreenBox(Rect &sbox, Matrix3* viewTM=NULL, int mtlIndex=-1)=0;
291                virtual int Render(Bitmap *bm, ViewParams &vp, SubRendParams &srp, float *clipPlane=NULL)=0;
292        };     
293
294
295
296// flags passed into ShadowBuffer::Update() and
297//                      ShadowQuadTree::Update() 
298#define SHAD_BIAS_ABSOLUTE  1
299#define SHAD_PARALLEL  2
300
301//------- A generic Shadow Buffer class for use by lights-------------.
302class ShadowBuffer {
303        public:
304        virtual int Update(
305                const ObjLightDesc& light,
306                const RendContext& rendCntxt,
307                Matrix3& lightTM,  // lightToWorld
308                int size,       // width and height of buffer in pixels
309                float aspect, // non-square
310                float param,  // persp:field-of-view  (radians)--       parallel : width in world coords
311                float bias,
312                float sampSize,
313                ULONG flags     )=0;
314        virtual int UpdateViewDepParams(const Matrix3& worldToCam)=0;
315        virtual float Sample(float x, float y, float z, float xslope, float yslope)=0;
316        virtual BOOL QuickSample(int x, int y, float z)=0; // this just tells you if the given point is in a shadow.
317        virtual float FiltSample(int x, int y, float z,int level)=0;
318        virtual float LineSample(int x1, int y1, float z1,int x2, int y2, float z2) {return 1.0f;}
319        virtual void DeleteThis()=0;
320        };
321
322class ShadowQuadTree {
323        public:
324        virtual int Update(
325                const ObjLightDesc &light,
326                const RendContext& rendCntxt,
327                Matrix3& lightToWorld, // light to world space
328                float aspect, // non-square
329                float param,  // persp:field-of-view  (radians)-- parallel : width in world coords
330                float bias,
331                ULONG flags     )=0;
332
333        // update state that depends on view matrix.
334        virtual int UpdateViewDepParams(const Matrix3& worldToCam)=0;
335        virtual float Sample(ShadeContext& sc,
336                Point3 p,  // Point in camera space
337                Color& color
338                )=0;
339        virtual void DeleteThis()=0;
340        };
341
342
343//--- Atmospheric plug-in interfaces -----------------------------------------------
344
345// Returned by an atmospheric effect when it is asked to put up its rollup page.
346class AtmosParamDlg {
347        public:
348                virtual Class_ID ClassID()=0;
349                virtual void SetThing(ReferenceTarget *m)=0;
350                virtual ReferenceTarget* GetThing()=0;
351                virtual void SetTime(TimeValue t) {}           
352                virtual void DeleteThis()=0;           
353        };
354
355// Atmospheric plug-in base class
356class Atmospheric : public ReferenceTarget {
357        public:         
358                RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
359                 PartID& partID,  RefMessage message) {return REF_SUCCEED;}
360                SClass_ID SuperClassID() {return ATMOSPHERIC_CLASS_ID;}
361               
362                // This name will appear in the track view and the list of current atmospheric effects.
363                virtual TSTR GetName() {return _T("");}
364
365                // Put up a modal dialog that lets the user edit the plug-ins parameters.
366                virtual AtmosParamDlg *CreateParamDialog(IRendParams *ip) {return NULL;}
367
368                // Called when the render steps to a new frame
369                virtual void Update(TimeValue t, Interval& valid) {}
370
371                // This is the function that is called to apply the effect.
372                virtual void Shade(ShadeContext& sc,const Point3& p0,const Point3& p1,Color& color, Color& trans, BOOL isBG=FALSE)=0;
373        };
374
375
376#endif
377
Note: See TracBrowser for help on using the repository browser.