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