]> git.xonotic.org Git - xonotic/darkplaces.git/blob - r_shadow.h
Add a third masterextra and default it to dpm.dpmaster.org
[xonotic/darkplaces.git] / r_shadow.h
1
2 #ifndef R_SHADOW_H
3 #define R_SHADOW_H
4
5 #include "qtypes.h"
6 #include "taskqueue.h"
7 #include "matrixlib.h"
8 struct rtlight_s;
9 struct msurface_s;
10 struct entity_render_s;
11
12 #define R_SHADOW_SHADOWMAP_NUMCUBEMAPS 8
13
14 extern struct cvar_s r_shadow_bumpscale_basetexture;
15 extern struct cvar_s r_shadow_bumpscale_bumpmap;
16 extern struct cvar_s r_shadow_debuglight;
17 extern struct cvar_s r_shadow_gloss;
18 extern struct cvar_s r_shadow_gloss2intensity;
19 extern struct cvar_s r_shadow_glossintensity;
20 extern struct cvar_s r_shadow_glossexponent;
21 extern struct cvar_s r_shadow_gloss2exponent;
22 extern struct cvar_s r_shadow_glossexact;
23 extern struct cvar_s r_shadow_lightattenuationpower;
24 extern struct cvar_s r_shadow_lightattenuationscale;
25 extern struct cvar_s r_shadow_lightintensityscale;
26 extern struct cvar_s r_shadow_lightradiusscale;
27 extern struct cvar_s r_shadow_projectdistance;
28 extern struct cvar_s r_shadow_frontsidecasting;
29 extern struct cvar_s r_shadow_realtime_dlight;
30 extern struct cvar_s r_shadow_realtime_dlight_shadows;
31 extern struct cvar_s r_shadow_realtime_dlight_svbspculling;
32 extern struct cvar_s r_shadow_realtime_dlight_portalculling;
33 extern struct cvar_s r_shadow_realtime_world;
34 extern struct cvar_s r_shadow_realtime_world_lightmaps;
35 extern struct cvar_s r_shadow_realtime_world_shadows;
36 extern struct cvar_s r_shadow_realtime_world_compile;
37 extern struct cvar_s r_shadow_realtime_world_compileshadow;
38 extern struct cvar_s r_shadow_realtime_world_compilesvbsp;
39 extern struct cvar_s r_shadow_realtime_world_compileportalculling;
40 extern struct cvar_s r_shadow_scissor;
41
42 // used by shader for bouncegrid feature
43 typedef struct r_shadow_bouncegrid_settings_s
44 {
45         qbool staticmode;
46         qbool directionalshading;
47         qbool includedirectlighting;
48         qbool blur;
49         qbool normalizevectors;
50         int floatcolors;
51         float dlightparticlemultiplier;
52         qbool hitmodels;
53         float lightradiusscale;
54         int maxbounce;
55         float lightpathsize;
56         float particlebounceintensity;
57         float particleintensity;
58         int maxphotons;
59         float energyperphoton;
60         float spacing[3];
61         int rng_type;
62         int rng_seed;
63         float bounceminimumintensity2;
64         int subsamples;
65 }
66 r_shadow_bouncegrid_settings_t;
67
68 #define PHOTON_MAX_PATHS 11
69
70 typedef struct r_shadow_bouncegrid_photon_path_s
71 {
72         vec3_t start;
73         vec3_t end;
74         vec3_t color;
75 }
76 r_shadow_bouncegrid_photon_path_t;
77
78 typedef struct r_shadow_bouncegrid_photon_s
79 {
80         // parameters for tracing this photon
81         vec3_t start;
82         vec3_t end;
83         float color[3];
84         float bounceminimumintensity2;
85         float startrefractiveindex;
86
87         // results
88         int numpaths;
89         r_shadow_bouncegrid_photon_path_t paths[PHOTON_MAX_PATHS];
90 }
91 r_shadow_bouncegrid_photon_t;
92
93 typedef struct r_shadow_bouncegrid_state_s
94 {
95         r_shadow_bouncegrid_settings_t settings;
96         qbool capable;
97         qbool allowdirectionalshading;
98         qbool directional; // copied from settings.directionalshading after createtexture is decided
99         qbool createtexture; // set to true to recreate the texture rather than updating it - happens when size changes or directional changes
100         struct rtexture_s *texture;
101         matrix4x4_t matrix;
102         vec_t intensity;
103         double lastupdatetime;
104         int resolution[3];
105         int numpixels;
106         int pixelbands;
107         int pixelsperband;
108         int bytesperband;
109         float spacing[3];
110         float ispacing[3];
111         vec3_t mins;
112         vec3_t maxs;
113         vec3_t size;
114
115         // per-frame data that is very temporary
116         int highpixels_index; // which one is active - this toggles when doing blur
117         float *highpixels; // equals blurpixels[highpixels_index]
118         float *blurpixels[2];
119         unsigned char *u8pixels; // temporary processing buffer when outputting to rgba8 format
120         unsigned short *fp16pixels; // temporary processing buffer when outputting to rgba16f format
121                                                                 // describe the photons we intend to shoot for threaded dispatch
122         int numphotons; // number of photons to shoot this frame, always <= settings.maxphotons
123         r_shadow_bouncegrid_photon_t *photons; // describes the photons being shot this frame
124
125         // tasks
126         taskqueue_task_t cleartex_task; // clears the highpixels array
127         taskqueue_task_t assignphotons_task; // sets the photon counts on lights, etc
128         taskqueue_task_t enqueuephotons_task; // enqueues tasks to shoot the photons
129         taskqueue_task_t *photons_tasks; // [maxphotons] taskqueue entries to perform the photon shots
130         taskqueue_task_t photons_done_task; // checks that all photon shots are completed
131         taskqueue_task_t enqueue_slices_task; // enqueues slice tasks to render the light accumulation into the texture
132         taskqueue_task_t *slices_tasks; // [resolution[1]] taskqueue entries to perform the light path accumulation into the texture
133         taskqueue_task_t slices_done_task; // checks that light accumulation in the texture is done
134         taskqueue_task_t blurpixels_task; // blurs the highpixels array
135 }
136 r_shadow_bouncegrid_state_t;
137
138 extern r_shadow_bouncegrid_state_t r_shadow_bouncegrid_state;
139
140 void R_Shadow_Init(void);
141 qbool R_Shadow_ShadowMappingEnabled(void);
142 void R_Shadow_ShadowMapFromList(int numverts, int numtris, const float *vertex3f, const int *elements, int numsidetris, const int *sidetotals, const unsigned char *sides, const int *sidetris);
143 int R_Shadow_CalcTriangleSideMask(const vec3_t p1, const vec3_t p2, const vec3_t p3, float bias);
144 int R_Shadow_CalcSphereSideMask(const vec3_t p1, float radius, float bias);
145 int R_Shadow_ChooseSidesFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const matrix4x4_t *worldtolight, const vec3_t projectorigin, const vec3_t projectdirection, const vec3_t lightmins, const vec3_t lightmaxs, const vec3_t surfacemins, const vec3_t surfacemaxs, int *totals);
146 void R_Shadow_RenderLighting(int texturenumsurfaces, const struct msurface_s **texturesurfacelist);
147 void R_Shadow_RenderMode_Begin(void);
148 void R_Shadow_RenderMode_ActiveLight(const struct rtlight_s *rtlight);
149 void R_Shadow_RenderMode_Reset(void);
150 void R_Shadow_RenderMode_Lighting(qbool transparent, qbool shadowmapping, qbool noselfshadowpass);
151 void R_Shadow_RenderMode_DrawDeferredLight(qbool shadowmapping);
152 void R_Shadow_RenderMode_VisibleLighting(qbool transparent);
153 void R_Shadow_RenderMode_End(void);
154 void R_Shadow_ClearStencil(void);
155 void R_Shadow_SetupEntityLight(const struct entity_render_s *ent);
156
157 qbool R_Shadow_ScissorForBBox(const float *mins, const float *maxs);
158
159 // these never change, they are used to create attenuation matrices
160 extern matrix4x4_t matrix_attenuationxyz;
161 extern matrix4x4_t matrix_attenuationz;
162
163 void R_Shadow_UpdateWorldLightSelection(void);
164
165 extern struct rtlight_s *r_shadow_compilingrtlight;
166
167 void R_RTLight_Update(struct rtlight_s *rtlight, int isstatic, matrix4x4_t *matrix, vec3_t color, int style, const char *cubemapname, int shadow, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags);
168 void R_RTLight_Compile(struct rtlight_s *rtlight);
169 void R_RTLight_Uncompile(struct rtlight_s *rtlight);
170
171 void R_Shadow_PrepareLights(void);
172 void R_Shadow_ClearShadowMapTexture(void);
173 void R_Shadow_DrawPrepass(void);
174 void R_Shadow_DrawLights(void);
175 void R_Shadow_DrawCoronas(void);
176
177 extern int maxshadowmark;
178 extern int numshadowmark;
179 extern int *shadowmark;
180 extern int *shadowmarklist;
181 extern int shadowmarkcount;
182 void R_Shadow_PrepareShadowMark(int numtris);
183
184 extern int maxshadowsides;
185 extern int numshadowsides;
186 extern unsigned char *shadowsides;
187 extern int *shadowsideslist;
188 void R_Shadow_PrepareShadowSides(int numtris);
189
190 void R_Shadow_PrepareModelShadows(void);
191
192 #define LP_LIGHTMAP             1
193 #define LP_RTWORLD              2
194 #define LP_DYNLIGHT             4
195 void R_CompleteLightPoint(float *ambient, float *diffuse, float *lightdir, const vec3_t p, const int flags, float lightmapintensity, float ambientintensity);
196
197 void R_Shadow_DrawShadowMaps(void);
198
199 #endif