Material.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __MATERIAL_H__
  21. #define __MATERIAL_H__
  22. /*
  23. ===============================================================================
  24. Material
  25. ===============================================================================
  26. */
  27. class idImage;
  28. class idCinematic;
  29. class idUserInterface;
  30. class idMegaTexture;
  31. // moved from image.h for default parm
  32. typedef enum {
  33. TF_LINEAR,
  34. TF_NEAREST,
  35. TF_DEFAULT // use the user-specified r_textureFilter
  36. } textureFilter_t;
  37. typedef enum {
  38. TR_REPEAT,
  39. TR_CLAMP,
  40. TR_CLAMP_TO_BORDER, // this should replace TR_CLAMP_TO_ZERO and TR_CLAMP_TO_ZERO_ALPHA,
  41. // but I don't want to risk changing it right now
  42. TR_CLAMP_TO_ZERO, // guarantee 0,0,0,255 edge for projected textures,
  43. // set AFTER image format selection
  44. TR_CLAMP_TO_ZERO_ALPHA // guarantee 0 alpha edge for projected textures,
  45. // set AFTER image format selection
  46. } textureRepeat_t;
  47. typedef struct {
  48. int stayTime; // msec for no change
  49. int fadeTime; // msec to fade vertex colors over
  50. float start[4]; // vertex color at spawn (possibly out of 0.0 - 1.0 range, will clamp after calc)
  51. float end[4]; // vertex color at fade-out (possibly out of 0.0 - 1.0 range, will clamp after calc)
  52. } decalInfo_t;
  53. typedef enum {
  54. DFRM_NONE,
  55. DFRM_SPRITE,
  56. DFRM_TUBE,
  57. DFRM_FLARE,
  58. DFRM_EXPAND,
  59. DFRM_MOVE,
  60. DFRM_EYEBALL,
  61. DFRM_PARTICLE,
  62. DFRM_PARTICLE2,
  63. DFRM_TURB
  64. } deform_t;
  65. typedef enum {
  66. DI_STATIC,
  67. DI_SCRATCH, // video, screen wipe, etc
  68. DI_CUBE_RENDER,
  69. DI_MIRROR_RENDER,
  70. DI_XRAY_RENDER,
  71. DI_REMOTE_RENDER
  72. } dynamicidImage_t;
  73. // note: keep opNames[] in sync with changes
  74. typedef enum {
  75. OP_TYPE_ADD,
  76. OP_TYPE_SUBTRACT,
  77. OP_TYPE_MULTIPLY,
  78. OP_TYPE_DIVIDE,
  79. OP_TYPE_MOD,
  80. OP_TYPE_TABLE,
  81. OP_TYPE_GT,
  82. OP_TYPE_GE,
  83. OP_TYPE_LT,
  84. OP_TYPE_LE,
  85. OP_TYPE_EQ,
  86. OP_TYPE_NE,
  87. OP_TYPE_AND,
  88. OP_TYPE_OR,
  89. OP_TYPE_SOUND
  90. } expOpType_t;
  91. typedef enum {
  92. EXP_REG_TIME,
  93. EXP_REG_PARM0,
  94. EXP_REG_PARM1,
  95. EXP_REG_PARM2,
  96. EXP_REG_PARM3,
  97. EXP_REG_PARM4,
  98. EXP_REG_PARM5,
  99. EXP_REG_PARM6,
  100. EXP_REG_PARM7,
  101. EXP_REG_PARM8,
  102. EXP_REG_PARM9,
  103. EXP_REG_PARM10,
  104. EXP_REG_PARM11,
  105. EXP_REG_GLOBAL0,
  106. EXP_REG_GLOBAL1,
  107. EXP_REG_GLOBAL2,
  108. EXP_REG_GLOBAL3,
  109. EXP_REG_GLOBAL4,
  110. EXP_REG_GLOBAL5,
  111. EXP_REG_GLOBAL6,
  112. EXP_REG_GLOBAL7,
  113. EXP_REG_NUM_PREDEFINED
  114. } expRegister_t;
  115. typedef struct {
  116. expOpType_t opType;
  117. int a, b, c;
  118. } expOp_t;
  119. typedef struct {
  120. int registers[4];
  121. } colorStage_t;
  122. typedef enum {
  123. TG_EXPLICIT,
  124. TG_DIFFUSE_CUBE,
  125. TG_REFLECT_CUBE,
  126. TG_SKYBOX_CUBE,
  127. TG_WOBBLESKY_CUBE,
  128. TG_SCREEN, // screen aligned, for mirrorRenders and screen space temporaries
  129. TG_SCREEN2,
  130. TG_GLASSWARP
  131. } texgen_t;
  132. typedef struct {
  133. idCinematic * cinematic;
  134. idImage * image;
  135. texgen_t texgen;
  136. bool hasMatrix;
  137. int matrix[2][3]; // we only allow a subset of the full projection matrix
  138. // dynamic image variables
  139. dynamicidImage_t dynamic;
  140. int width, height;
  141. int dynamicFrameCount;
  142. } textureStage_t;
  143. // the order BUMP / DIFFUSE / SPECULAR is necessary for interactions to draw correctly on low end cards
  144. typedef enum {
  145. SL_AMBIENT, // execute after lighting
  146. SL_BUMP,
  147. SL_DIFFUSE,
  148. SL_SPECULAR
  149. } stageLighting_t;
  150. // cross-blended terrain textures need to modulate the color by
  151. // the vertex color to smoothly blend between two textures
  152. typedef enum {
  153. SVC_IGNORE,
  154. SVC_MODULATE,
  155. SVC_INVERSE_MODULATE
  156. } stageVertexColor_t;
  157. static const int MAX_FRAGMENT_IMAGES = 8;
  158. static const int MAX_VERTEX_PARMS = 4;
  159. typedef struct {
  160. int vertexProgram;
  161. int numVertexParms;
  162. int vertexParms[MAX_VERTEX_PARMS][4]; // evaluated register indexes
  163. int fragmentProgram;
  164. int numFragmentProgramImages;
  165. idImage * fragmentProgramImages[MAX_FRAGMENT_IMAGES];
  166. idMegaTexture *megaTexture; // handles all the binding and parameter setting
  167. } newShaderStage_t;
  168. typedef struct {
  169. int conditionRegister; // if registers[conditionRegister] == 0, skip stage
  170. stageLighting_t lighting; // determines which passes interact with lights
  171. int drawStateBits;
  172. colorStage_t color;
  173. bool hasAlphaTest;
  174. int alphaTestRegister;
  175. textureStage_t texture;
  176. stageVertexColor_t vertexColor;
  177. bool ignoreAlphaTest; // this stage should act as translucent, even
  178. // if the surface is alpha tested
  179. float privatePolygonOffset; // a per-stage polygon offset
  180. newShaderStage_t *newStage; // vertex / fragment program based stage
  181. } shaderStage_t;
  182. typedef enum {
  183. MC_BAD,
  184. MC_OPAQUE, // completely fills the triangle, will have black drawn on fillDepthBuffer
  185. MC_PERFORATED, // may have alpha tested holes
  186. MC_TRANSLUCENT // blended with background
  187. } materialCoverage_t;
  188. typedef enum {
  189. SS_SUBVIEW = -3, // mirrors, viewscreens, etc
  190. SS_GUI = -2, // guis
  191. SS_BAD = -1,
  192. SS_OPAQUE, // opaque
  193. SS_PORTAL_SKY,
  194. SS_DECAL, // scorch marks, etc.
  195. SS_FAR,
  196. SS_MEDIUM, // normal translucent
  197. SS_CLOSE,
  198. SS_ALMOST_NEAREST, // gun smoke puffs
  199. SS_NEAREST, // screen blood blobs
  200. SS_POST_PROCESS = 100 // after a screen copy to texture
  201. } materialSort_t;
  202. typedef enum {
  203. CT_FRONT_SIDED,
  204. CT_BACK_SIDED,
  205. CT_TWO_SIDED
  206. } cullType_t;
  207. // these don't effect per-material storage, so they can be very large
  208. const int MAX_SHADER_STAGES = 256;
  209. const int MAX_TEXGEN_REGISTERS = 4;
  210. const int MAX_ENTITY_SHADER_PARMS = 12;
  211. // material flags
  212. typedef enum {
  213. MF_DEFAULTED = BIT(0),
  214. MF_POLYGONOFFSET = BIT(1),
  215. MF_NOSHADOWS = BIT(2),
  216. MF_FORCESHADOWS = BIT(3),
  217. MF_NOSELFSHADOW = BIT(4),
  218. MF_NOPORTALFOG = BIT(5), // this fog volume won't ever consider a portal fogged out
  219. MF_EDITOR_VISIBLE = BIT(6) // in use (visible) per editor
  220. } materialFlags_t;
  221. // contents flags, NOTE: make sure to keep the defines in doom_defs.script up to date with these!
  222. typedef enum {
  223. CONTENTS_SOLID = BIT(0), // an eye is never valid in a solid
  224. CONTENTS_OPAQUE = BIT(1), // blocks visibility (for ai)
  225. CONTENTS_WATER = BIT(2), // used for water
  226. CONTENTS_PLAYERCLIP = BIT(3), // solid to players
  227. CONTENTS_MONSTERCLIP = BIT(4), // solid to monsters
  228. CONTENTS_MOVEABLECLIP = BIT(5), // solid to moveable entities
  229. CONTENTS_IKCLIP = BIT(6), // solid to IK
  230. CONTENTS_BLOOD = BIT(7), // used to detect blood decals
  231. CONTENTS_BODY = BIT(8), // used for actors
  232. CONTENTS_PROJECTILE = BIT(9), // used for projectiles
  233. CONTENTS_CORPSE = BIT(10), // used for dead bodies
  234. CONTENTS_RENDERMODEL = BIT(11), // used for render models for collision detection
  235. CONTENTS_TRIGGER = BIT(12), // used for triggers
  236. CONTENTS_AAS_SOLID = BIT(13), // solid for AAS
  237. CONTENTS_AAS_OBSTACLE = BIT(14), // used to compile an obstacle into AAS that can be enabled/disabled
  238. CONTENTS_FLASHLIGHT_TRIGGER = BIT(15), // used for triggers that are activated by the flashlight
  239. // contents used by utils
  240. CONTENTS_AREAPORTAL = BIT(20), // portal separating renderer areas
  241. CONTENTS_NOCSG = BIT(21), // don't cut this brush with CSG operations in the editor
  242. CONTENTS_REMOVE_UTIL = ~(CONTENTS_AREAPORTAL|CONTENTS_NOCSG)
  243. } contentsFlags_t;
  244. // surface types
  245. const int NUM_SURFACE_BITS = 4;
  246. const int MAX_SURFACE_TYPES = 1 << NUM_SURFACE_BITS;
  247. typedef enum {
  248. SURFTYPE_NONE, // default type
  249. SURFTYPE_METAL,
  250. SURFTYPE_STONE,
  251. SURFTYPE_FLESH,
  252. SURFTYPE_WOOD,
  253. SURFTYPE_CARDBOARD,
  254. SURFTYPE_LIQUID,
  255. SURFTYPE_GLASS,
  256. SURFTYPE_PLASTIC,
  257. SURFTYPE_RICOCHET,
  258. SURFTYPE_10,
  259. SURFTYPE_11,
  260. SURFTYPE_12,
  261. SURFTYPE_13,
  262. SURFTYPE_14,
  263. SURFTYPE_15
  264. } surfTypes_t;
  265. // surface flags
  266. typedef enum {
  267. SURF_TYPE_BIT0 = BIT(0), // encodes the material type (metal, flesh, concrete, etc.)
  268. SURF_TYPE_BIT1 = BIT(1), // "
  269. SURF_TYPE_BIT2 = BIT(2), // "
  270. SURF_TYPE_BIT3 = BIT(3), // "
  271. SURF_TYPE_MASK = ( 1 << NUM_SURFACE_BITS ) - 1,
  272. SURF_NODAMAGE = BIT(4), // never give falling damage
  273. SURF_SLICK = BIT(5), // effects game physics
  274. SURF_COLLISION = BIT(6), // collision surface
  275. SURF_LADDER = BIT(7), // player can climb up this surface
  276. SURF_NOIMPACT = BIT(8), // don't make missile explosions
  277. SURF_NOSTEPS = BIT(9), // no footstep sounds
  278. SURF_DISCRETE = BIT(10), // not clipped or merged by utilities
  279. SURF_NOFRAGMENT = BIT(11), // dmap won't cut surface at each bsp boundary
  280. SURF_NULLNORMAL = BIT(12) // renderbump will draw this surface as 0x80 0x80 0x80, which
  281. // won't collect light from any angle
  282. } surfaceFlags_t;
  283. class idSoundEmitter;
  284. class idMaterial : public idDecl {
  285. public:
  286. idMaterial();
  287. virtual ~idMaterial();
  288. virtual size_t Size( void ) const;
  289. virtual bool SetDefaultText( void );
  290. virtual const char *DefaultDefinition( void ) const;
  291. virtual bool Parse( const char *text, const int textLength );
  292. virtual void FreeData( void );
  293. virtual void Print( void ) const;
  294. //BSM Nerve: Added for material editor
  295. bool Save( const char *fileName = NULL );
  296. // returns the internal image name for stage 0, which can be used
  297. // for the renderer CaptureRenderToImage() call
  298. // I'm not really sure why this needs to be virtual...
  299. virtual const char *ImageName( void ) const;
  300. void ReloadImages( bool force ) const;
  301. // returns number of stages this material contains
  302. const int GetNumStages( void ) const { return numStages; }
  303. // get a specific stage
  304. const shaderStage_t *GetStage( const int index ) const { assert(index >= 0 && index < numStages); return &stages[index]; }
  305. // get the first bump map stage, or NULL if not present.
  306. // used for bumpy-specular
  307. const shaderStage_t *GetBumpStage( void ) const;
  308. // returns true if the material will draw anything at all. Triggers, portals,
  309. // etc, will not have anything to draw. A not drawn surface can still castShadow,
  310. // which can be used to make a simplified shadow hull for a complex object set
  311. // as noShadow
  312. bool IsDrawn( void ) const { return ( numStages > 0 || entityGui != 0 || gui != NULL ); }
  313. // returns true if the material will draw any non light interaction stages
  314. bool HasAmbient( void ) const { return ( numAmbientStages > 0 ); }
  315. // returns true if material has a gui
  316. bool HasGui( void ) const { return ( entityGui != 0 || gui != NULL ); }
  317. // returns true if the material will generate another view, either as
  318. // a mirror or dynamic rendered image
  319. bool HasSubview( void ) const { return hasSubview; }
  320. // returns true if the material will generate shadows, not making a
  321. // distinction between global and no-self shadows
  322. bool SurfaceCastsShadow( void ) const { return TestMaterialFlag( MF_FORCESHADOWS ) || !TestMaterialFlag( MF_NOSHADOWS ); }
  323. // returns true if the material will generate interactions with fog/blend lights
  324. // All non-translucent surfaces receive fog unless they are explicitly noFog
  325. bool ReceivesFog( void ) const { return ( IsDrawn() && !noFog && coverage != MC_TRANSLUCENT ); }
  326. // returns true if the material will generate interactions with normal lights
  327. // Many special effect surfaces don't have any bump/diffuse/specular
  328. // stages, and don't interact with lights at all
  329. bool ReceivesLighting( void ) const { return numAmbientStages != numStages; }
  330. // returns true if the material should generate interactions on sides facing away
  331. // from light centers, as with noshadow and noselfshadow options
  332. bool ReceivesLightingOnBackSides( void ) const { return ( materialFlags & (MF_NOSELFSHADOW|MF_NOSHADOWS) ) != 0; }
  333. // Standard two-sided triangle rendering won't work with bump map lighting, because
  334. // the normal and tangent vectors won't be correct for the back sides. When two
  335. // sided lighting is desired. typically for alpha tested surfaces, this is
  336. // addressed by having CleanupModelSurfaces() create duplicates of all the triangles
  337. // with apropriate order reversal.
  338. bool ShouldCreateBackSides( void ) const { return shouldCreateBackSides; }
  339. // characters and models that are created by a complete renderbump can use a faster
  340. // method of tangent and normal vector generation than surfaces which have a flat
  341. // renderbump wrapped over them.
  342. bool UseUnsmoothedTangents( void ) const { return unsmoothedTangents; }
  343. // by default, monsters can have blood overlays placed on them, but this can
  344. // be overrided on a per-material basis with the "noOverlays" material command.
  345. // This will always return false for translucent surfaces
  346. bool AllowOverlays( void ) const { return allowOverlays; }
  347. // MC_OPAQUE, MC_PERFORATED, or MC_TRANSLUCENT, for interaction list linking and
  348. // dmap flood filling
  349. // The depth buffer will not be filled for MC_TRANSLUCENT surfaces
  350. // FIXME: what do nodraw surfaces return?
  351. materialCoverage_t Coverage( void ) const { return coverage; }
  352. // returns true if this material takes precedence over other in coplanar cases
  353. bool HasHigherDmapPriority( const idMaterial &other ) const { return ( IsDrawn() && !other.IsDrawn() ) ||
  354. ( Coverage() < other.Coverage() ); }
  355. // returns a idUserInterface if it has a global gui, or NULL if no gui
  356. idUserInterface * GlobalGui( void ) const { return gui; }
  357. // a discrete surface will never be merged with other surfaces by dmap, which is
  358. // necessary to prevent mutliple gui surfaces, mirrors, autosprites, and some other
  359. // special effects from being combined into a single surface
  360. // guis, merging sprites or other effects, mirrors and remote views are always discrete
  361. bool IsDiscrete( void ) const { return ( entityGui || gui || deform != DFRM_NONE || sort == SS_SUBVIEW ||
  362. ( surfaceFlags & SURF_DISCRETE ) != 0 ); }
  363. // Normally, dmap chops each surface by every BSP boundary, then reoptimizes.
  364. // For gigantic polygons like sky boxes, this can cause a huge number of planar
  365. // triangles that make the optimizer take forever to turn back into a single
  366. // triangle. The "noFragment" option causes dmap to only break the polygons at
  367. // area boundaries, instead of every BSP boundary. This has the negative effect
  368. // of not automatically fixing up interpenetrations, so when this is used, you
  369. // should manually make the edges of your sky box exactly meet, instead of poking
  370. // into each other.
  371. bool NoFragment( void ) const { return ( surfaceFlags & SURF_NOFRAGMENT ) != 0; }
  372. //------------------------------------------------------------------
  373. // light shader specific functions, only called for light entities
  374. // lightshader option to fill with fog from viewer instead of light from center
  375. bool IsFogLight() const { return fogLight; }
  376. // perform simple blending of the projection, instead of interacting with bumps and textures
  377. bool IsBlendLight() const { return blendLight; }
  378. // an ambient light has non-directional bump mapping and no specular
  379. bool IsAmbientLight() const { return ambientLight; }
  380. // implicitly no-shadows lights (ambients, fogs, etc) will never cast shadows
  381. // but individual light entities can also override this value
  382. bool LightCastsShadows() const { return TestMaterialFlag( MF_FORCESHADOWS ) ||
  383. ( !fogLight && !ambientLight && !blendLight && !TestMaterialFlag( MF_NOSHADOWS ) ); }
  384. // fog lights, blend lights, ambient lights, etc will all have to have interaction
  385. // triangles generated for sides facing away from the light as well as those
  386. // facing towards the light. It is debatable if noshadow lights should effect back
  387. // sides, making everything "noSelfShadow", but that would make noshadow lights
  388. // potentially slower than normal lights, which detracts from their optimization
  389. // ability, so they currently do not.
  390. bool LightEffectsBackSides() const { return fogLight || ambientLight || blendLight; }
  391. // NULL unless an image is explicitly specified in the shader with "lightFalloffShader <image>"
  392. idImage * LightFalloffImage() const { return lightFalloffImage; }
  393. //------------------------------------------------------------------
  394. // returns the renderbump command line for this shader, or an empty string if not present
  395. const char * GetRenderBump() const { return renderBump; };
  396. // set specific material flag(s)
  397. void SetMaterialFlag( const int flag ) const { materialFlags |= flag; }
  398. // clear specific material flag(s)
  399. void ClearMaterialFlag( const int flag ) const { materialFlags &= ~flag; }
  400. // test for existance of specific material flag(s)
  401. bool TestMaterialFlag( const int flag ) const { return ( materialFlags & flag ) != 0; }
  402. // get content flags
  403. const int GetContentFlags( void ) const { return contentFlags; }
  404. // get surface flags
  405. const int GetSurfaceFlags( void ) const { return surfaceFlags; }
  406. // gets name for surface type (stone, metal, flesh, etc.)
  407. const surfTypes_t GetSurfaceType( void ) const { return static_cast<surfTypes_t>( surfaceFlags & SURF_TYPE_MASK ); }
  408. // get material description
  409. const char * GetDescription( void ) const { return desc; }
  410. // get sort order
  411. const float GetSort( void ) const { return sort; }
  412. // this is only used by the gui system to force sorting order
  413. // on images referenced from tga's instead of materials.
  414. // this is done this way as there are 2000 tgas the guis use
  415. void SetSort( float s ) const { sort = s; };
  416. // DFRM_NONE, DFRM_SPRITE, etc
  417. deform_t Deform( void ) const { return deform; }
  418. // flare size, expansion size, etc
  419. const int GetDeformRegister( int index ) const { return deformRegisters[index]; }
  420. // particle system to emit from surface and table for turbulent
  421. const idDecl *GetDeformDecl( void ) const { return deformDecl; }
  422. // currently a surface can only have one unique texgen for all the stages
  423. texgen_t Texgen() const;
  424. // wobble sky parms
  425. const int * GetTexGenRegisters( void ) const { return texGenRegisters; }
  426. // get cull type
  427. const cullType_t GetCullType( void ) const { return cullType; }
  428. float GetEditorAlpha( void ) const { return editorAlpha; }
  429. int GetEntityGui( void ) const { return entityGui; }
  430. decalInfo_t GetDecalInfo( void ) const { return decalInfo; }
  431. // spectrums are used for "invisible writing" that can only be
  432. // illuminated by a light of matching spectrum
  433. int Spectrum( void ) const { return spectrum; }
  434. float GetPolygonOffset( void ) const { return polygonOffset; }
  435. float GetSurfaceArea( void ) const { return surfaceArea; }
  436. void AddToSurfaceArea( float area ) { surfaceArea += area; }
  437. //------------------------------------------------------------------
  438. // returns the length, in milliseconds, of the videoMap on this material,
  439. // or zero if it doesn't have one
  440. int CinematicLength( void ) const;
  441. void CloseCinematic( void ) const;
  442. void ResetCinematicTime( int time ) const;
  443. void UpdateCinematic( int time ) const;
  444. //------------------------------------------------------------------
  445. // gets an image for the editor to use
  446. idImage * GetEditorImage( void ) const;
  447. int GetImageWidth( void ) const;
  448. int GetImageHeight( void ) const;
  449. void SetGui( const char *_gui ) const;
  450. // just for resource tracking
  451. void SetImageClassifications( int tag ) const;
  452. //------------------------------------------------------------------
  453. // returns number of registers this material contains
  454. const int GetNumRegisters() const { return numRegisters; }
  455. // regs should point to a float array large enough to hold GetNumRegisters() floats
  456. void EvaluateRegisters( float *regs, const float entityParms[MAX_ENTITY_SHADER_PARMS],
  457. const struct viewDef_s *view, idSoundEmitter *soundEmitter = NULL ) const;
  458. // if a material only uses constants (no entityParm or globalparm references), this
  459. // will return a pointer to an internal table, and EvaluateRegisters will not need
  460. // to be called. If NULL is returned, EvaluateRegisters must be used.
  461. const float * ConstantRegisters() const;
  462. bool SuppressInSubview() const { return suppressInSubview; };
  463. bool IsPortalSky() const { return portalSky; };
  464. void AddReference();
  465. private:
  466. // parse the entire material
  467. void CommonInit();
  468. void ParseMaterial( idLexer &src );
  469. bool MatchToken( idLexer &src, const char *match );
  470. void ParseSort( idLexer &src );
  471. void ParseBlend( idLexer &src, shaderStage_t *stage );
  472. void ParseVertexParm( idLexer &src, newShaderStage_t *newStage );
  473. void ParseFragmentMap( idLexer &src, newShaderStage_t *newStage );
  474. void ParseStage( idLexer &src, const textureRepeat_t trpDefault = TR_REPEAT );
  475. void ParseDeform( idLexer &src );
  476. void ParseDecalInfo( idLexer &src );
  477. bool CheckSurfaceParm( idToken *token );
  478. int GetExpressionConstant( float f );
  479. int GetExpressionTemporary( void );
  480. expOp_t * GetExpressionOp( void );
  481. int EmitOp( int a, int b, expOpType_t opType );
  482. int ParseEmitOp( idLexer &src, int a, expOpType_t opType, int priority );
  483. int ParseTerm( idLexer &src );
  484. int ParseExpressionPriority( idLexer &src, int priority );
  485. int ParseExpression( idLexer &src );
  486. void ClearStage( shaderStage_t *ss );
  487. int NameToSrcBlendMode( const idStr &name );
  488. int NameToDstBlendMode( const idStr &name );
  489. void MultiplyTextureMatrix( textureStage_t *ts, int registers[2][3] ); // FIXME: for some reason the const is bad for gcc and Mac
  490. void SortInteractionStages();
  491. void AddImplicitStages( const textureRepeat_t trpDefault = TR_REPEAT );
  492. void CheckForConstantRegisters();
  493. private:
  494. idStr desc; // description
  495. idStr renderBump; // renderbump command options, without the "renderbump" at the start
  496. idImage * lightFalloffImage;
  497. int entityGui; // draw a gui with the idUserInterface from the renderEntity_t
  498. // non zero will draw gui, gui2, or gui3 from renderEnitty_t
  499. mutable idUserInterface *gui; // non-custom guis are shared by all users of a material
  500. bool noFog; // surface does not create fog interactions
  501. int spectrum; // for invisible writing, used for both lights and surfaces
  502. float polygonOffset;
  503. int contentFlags; // content flags
  504. int surfaceFlags; // surface flags
  505. mutable int materialFlags; // material flags
  506. decalInfo_t decalInfo;
  507. mutable float sort; // lower numbered shaders draw before higher numbered
  508. deform_t deform;
  509. int deformRegisters[4]; // numeric parameter for deforms
  510. const idDecl *deformDecl; // for surface emitted particle deforms and tables
  511. int texGenRegisters[MAX_TEXGEN_REGISTERS]; // for wobbleSky
  512. materialCoverage_t coverage;
  513. cullType_t cullType; // CT_FRONT_SIDED, CT_BACK_SIDED, or CT_TWO_SIDED
  514. bool shouldCreateBackSides;
  515. bool fogLight;
  516. bool blendLight;
  517. bool ambientLight;
  518. bool unsmoothedTangents;
  519. bool hasSubview; // mirror, remote render, etc
  520. bool allowOverlays;
  521. int numOps;
  522. expOp_t * ops; // evaluate to make expressionRegisters
  523. int numRegisters; //
  524. float * expressionRegisters;
  525. float * constantRegisters; // NULL if ops ever reference globalParms or entityParms
  526. int numStages;
  527. int numAmbientStages;
  528. shaderStage_t * stages;
  529. struct mtrParsingData_s *pd; // only used during parsing
  530. float surfaceArea; // only for listSurfaceAreas
  531. // we defer loading of the editor image until it is asked for, so the game doesn't load up
  532. // all the invisible and uncompressed images.
  533. // If editorImage is NULL, it will atempt to load editorImageName, and set editorImage to that or defaultImage
  534. idStr editorImageName;
  535. mutable idImage * editorImage; // image used for non-shaded preview
  536. float editorAlpha;
  537. bool suppressInSubview;
  538. bool portalSky;
  539. int refCount;
  540. };
  541. typedef idList<const idMaterial *> idMatList;
  542. #endif /* !__MATERIAL_H__ */