]> git.xonotic.org Git - xonotic/darkplaces.git/blob - r_shadow.h
Overhauled bouncegrid light splatting for performance reasons - instead of a series...
[xonotic/darkplaces.git] / r_shadow.h
1
2 #ifndef R_SHADOW_H
3 #define R_SHADOW_H
4
5 #define R_SHADOW_SHADOWMAP_NUMCUBEMAPS 8
6
7 extern cvar_t r_shadow_bumpscale_basetexture;
8 extern cvar_t r_shadow_bumpscale_bumpmap;
9 extern cvar_t r_shadow_debuglight;
10 extern cvar_t r_shadow_gloss;
11 extern cvar_t r_shadow_gloss2intensity;
12 extern cvar_t r_shadow_glossintensity;
13 extern cvar_t r_shadow_glossexponent;
14 extern cvar_t r_shadow_gloss2exponent;
15 extern cvar_t r_shadow_glossexact;
16 extern cvar_t r_shadow_lightattenuationpower;
17 extern cvar_t r_shadow_lightattenuationscale;
18 extern cvar_t r_shadow_lightintensityscale;
19 extern cvar_t r_shadow_lightradiusscale;
20 extern cvar_t r_shadow_projectdistance;
21 extern cvar_t r_shadow_frontsidecasting;
22 extern cvar_t r_shadow_realtime_dlight;
23 extern cvar_t r_shadow_realtime_dlight_shadows;
24 extern cvar_t r_shadow_realtime_dlight_svbspculling;
25 extern cvar_t r_shadow_realtime_dlight_portalculling;
26 extern cvar_t r_shadow_realtime_world;
27 extern cvar_t r_shadow_realtime_world_lightmaps;
28 extern cvar_t r_shadow_realtime_world_shadows;
29 extern cvar_t r_shadow_realtime_world_compile;
30 extern cvar_t r_shadow_realtime_world_compileshadow;
31 extern cvar_t r_shadow_realtime_world_compilesvbsp;
32 extern cvar_t r_shadow_realtime_world_compileportalculling;
33 extern cvar_t r_shadow_scissor;
34
35 // used by shader for bouncegrid feature
36 typedef struct r_shadow_bouncegrid_settings_s
37 {
38         qboolean staticmode;
39         qboolean bounceanglediffuse;
40         qboolean directionalshading;
41         qboolean includedirectlighting;
42         qboolean blur;
43         qboolean normalizevectors;
44         int floatcolors;
45         float dlightparticlemultiplier;
46         qboolean hitmodels;
47         float lightradiusscale;
48         int maxbounce;
49         float lightpathsize;
50         float particlebounceintensity;
51         float particleintensity;
52         int maxphotons;
53         float energyperphoton;
54         float spacing[3];
55         int rng_type;
56         int rng_seed;
57         float bounceminimumintensity2;
58 }
59 r_shadow_bouncegrid_settings_t;
60
61 typedef struct r_shadow_bouncegrid_state_s
62 {
63         r_shadow_bouncegrid_settings_t settings;
64         qboolean capable;
65         qboolean allowdirectionalshading;
66         qboolean directional; // copied from settings.directionalshading after createtexture is decided
67         qboolean createtexture; // set to true to recreate the texture rather than updating it - happens when size changes or directional changes
68         rtexture_t *texture;
69         matrix4x4_t matrix;
70         vec_t intensity;
71         double lastupdatetime;
72         int resolution[3];
73         int numpixels;
74         int pixelbands;
75         int pixelsperband;
76         int bytesperband;
77         float spacing[3];
78         float ispacing[3];
79         vec3_t mins;
80         vec3_t maxs;
81         vec3_t size;
82         int maxsplatpaths;
83
84         // per-frame data that is very temporary
85         int numsplatpaths;
86         struct r_shadow_bouncegrid_splatpath_s *splatpaths;
87         int highpixels_index; // which one is active - this toggles when doing blur
88         float *highpixels; // equals blurpixels[highpixels_index]
89         float *blurpixels[2];
90         unsigned char *u8pixels; // temporary processing buffer when outputting to rgba8 format
91         unsigned short *fp16pixels; // temporary processing buffer when outputting to rgba16f format
92 }
93 r_shadow_bouncegrid_state_t;
94
95 extern r_shadow_bouncegrid_state_t r_shadow_bouncegrid_state;
96
97 void R_Shadow_Init(void);
98 qboolean R_Shadow_ShadowMappingEnabled(void);
99 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);
100 int R_Shadow_CalcTriangleSideMask(const vec3_t p1, const vec3_t p2, const vec3_t p3, float bias);
101 int R_Shadow_CalcSphereSideMask(const vec3_t p1, float radius, float bias);
102 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);
103 void R_Shadow_RenderLighting(int texturenumsurfaces, const msurface_t **texturesurfacelist);
104 void R_Shadow_RenderMode_Begin(void);
105 void R_Shadow_RenderMode_ActiveLight(const rtlight_t *rtlight);
106 void R_Shadow_RenderMode_Reset(void);
107 void R_Shadow_RenderMode_Lighting(qboolean transparent, qboolean shadowmapping, qboolean noselfshadowpass);
108 void R_Shadow_RenderMode_DrawDeferredLight(qboolean shadowmapping);
109 void R_Shadow_RenderMode_VisibleLighting(qboolean transparent);
110 void R_Shadow_RenderMode_End(void);
111 void R_Shadow_ClearStencil(void);
112 void R_Shadow_SetupEntityLight(const entity_render_t *ent);
113
114 qboolean R_Shadow_ScissorForBBox(const float *mins, const float *maxs);
115
116 // these never change, they are used to create attenuation matrices
117 extern matrix4x4_t matrix_attenuationxyz;
118 extern matrix4x4_t matrix_attenuationz;
119
120 void R_Shadow_UpdateWorldLightSelection(void);
121
122 extern rtlight_t *r_shadow_compilingrtlight;
123
124 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);
125 void R_RTLight_Compile(rtlight_t *rtlight);
126 void R_RTLight_Uncompile(rtlight_t *rtlight);
127
128 void R_Shadow_PrepareLights(void);
129 void R_Shadow_ClearShadowMapTexture(void);
130 void R_Shadow_DrawPrepass(void);
131 void R_Shadow_DrawLights(void);
132 void R_Shadow_DrawCoronas(void);
133
134 extern int maxshadowmark;
135 extern int numshadowmark;
136 extern int *shadowmark;
137 extern int *shadowmarklist;
138 extern int shadowmarkcount;
139 void R_Shadow_PrepareShadowMark(int numtris);
140
141 extern int maxshadowsides;
142 extern int numshadowsides;
143 extern unsigned char *shadowsides;
144 extern int *shadowsideslist;
145 void R_Shadow_PrepareShadowSides(int numtris);
146
147 void R_Shadow_PrepareModelShadows(void);
148
149 #define LP_LIGHTMAP             1
150 #define LP_RTWORLD              2
151 #define LP_DYNLIGHT             4
152 void R_CompleteLightPoint(float *ambient, float *diffuse, float *lightdir, const vec3_t p, const int flags, float lightmapintensity, float ambientintensity);
153
154 void R_Shadow_DrawShadowMaps(void);
155
156 #endif