light.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "cmdlib.h"
  19. #include "mathlib.h"
  20. #include "bspfile.h"
  21. #include "polylib.h"
  22. #include "imagelib.h"
  23. #include "threads.h"
  24. #include "scriplib.h"
  25. #include "shaders.h"
  26. #include "mesh.h"
  27. typedef enum
  28. {
  29. emit_point,
  30. emit_area,
  31. emit_spotlight,
  32. emit_sun
  33. } emittype_t;
  34. #define MAX_LIGHT_EDGES 8
  35. typedef struct light_s
  36. {
  37. struct light_s *next;
  38. emittype_t type;
  39. struct shaderInfo_s *si;
  40. vec3_t origin;
  41. vec3_t normal; // for surfaces, spotlights, and suns
  42. float dist; // plane location along normal
  43. qboolean linearLight;
  44. int photons;
  45. int style;
  46. vec3_t color;
  47. float radiusByDist; // for spotlights
  48. qboolean twosided; // fog lights both sides
  49. winding_t *w;
  50. vec3_t emitColor; // full out-of-gamut value
  51. } light_t;
  52. extern float lightscale;
  53. extern float ambient;
  54. extern float maxlight;
  55. extern float direct_scale;
  56. extern float entity_scale;
  57. extern qboolean noSurfaces;
  58. //===============================================================
  59. // light_trace.c
  60. // a facet is a subdivided element of a patch aproximation or model
  61. typedef struct cFacet_s {
  62. float surface[4];
  63. int numBoundaries; // either 3 or 4, anything less is degenerate
  64. float boundaries[4][4]; // positive is outside the bounds
  65. vec3_t points[4]; // needed for area light subdivision
  66. float textureMatrix[2][4]; // compute texture coordinates at point of impact for translucency
  67. } cFacet_t;
  68. typedef struct {
  69. vec3_t mins, maxs;
  70. vec3_t origin;
  71. float radius;
  72. qboolean patch;
  73. int numFacets;
  74. cFacet_t *facets;
  75. shaderInfo_t *shader; // for translucency
  76. } surfaceTest_t;
  77. typedef struct {
  78. vec3_t filter; // starts out 1.0, 1.0, 1.0, may be reduced if
  79. // transparent surfaces are crossed
  80. vec3_t hit; // the impact point of a completely opaque surface
  81. float hitFraction; // 0 = at start, 1.0 = at end
  82. qboolean passSolid;
  83. } trace_t;
  84. extern surfaceTest_t *surfaceTest[MAX_MAP_DRAW_SURFS];
  85. void InitTrace( void );
  86. // traceWork_t is only a parameter to crutch up poor large local allocations on
  87. // winNT and macOS. It should be allocated in the worker function, but never
  88. // looked at.
  89. typedef struct {
  90. vec3_t start, end;
  91. int numOpenLeafs;
  92. int openLeafNumbers[MAX_MAP_LEAFS];
  93. trace_t *trace;
  94. int patchshadows;
  95. } traceWork_t;
  96. void TraceLine( const vec3_t start, const vec3_t stop, trace_t *trace,
  97. qboolean testAll, traceWork_t *tw );
  98. qboolean PointInSolid( vec3_t start );
  99. //===============================================================
  100. //===============================================================
  101. typedef struct {
  102. int textureNum;
  103. int x, y, width, height;
  104. // for patches
  105. qboolean patch;
  106. mesh_t mesh;
  107. // for faces
  108. vec3_t origin;
  109. vec3_t vecs[3];
  110. } lightmap_t;