render.h 13 KB

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