Material.h 26 KB

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