]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - r_shadow.h
Fix severe bugs in mul128 implementation which was breaking the Lehmer RNG.
[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 extern cvar_t r_shadow_polygonfactor;
35 extern cvar_t r_shadow_polygonoffset;
36 extern cvar_t r_shadow_texture3d;
37 extern cvar_t gl_ext_separatestencil;
38 extern cvar_t gl_ext_stenciltwoside;
39
40 // used by shader for bouncegrid feature
41 typedef struct r_shadow_bouncegrid_settings_s
42 {
43         qboolean staticmode;
44         qboolean bounceanglediffuse;
45         qboolean directionalshading;
46         qboolean includedirectlighting;
47         qboolean blur;
48         qboolean normalizevectors;
49         int floatcolors;
50         float dlightparticlemultiplier;
51         qboolean hitmodels;
52         float lightradiusscale;
53         int maxbounce;
54         int lightpathsize;
55         float particlebounceintensity;
56         float particleintensity;
57         int maxphotons;
58         float energyperphoton;
59         float spacing[3];
60         int stablerandom;
61         float bounceminimumintensity2;
62 }
63 r_shadow_bouncegrid_settings_t;
64
65 typedef struct r_shadow_bouncegrid_state_s
66 {
67         r_shadow_bouncegrid_settings_t settings;
68         qboolean capable;
69         qboolean allowdirectionalshading;
70         qboolean directional; // copied from settings.directionalshading after createtexture is decided
71         qboolean createtexture; // set to true to recreate the texture rather than updating it - happens when size changes or directional changes
72         rtexture_t *texture;
73         matrix4x4_t matrix;
74         vec_t intensity;
75         double lastupdatetime;
76         int resolution[3];
77         int numpixels;
78         int pixelbands;
79         int pixelsperband;
80         int bytesperband;
81         float spacing[3];
82         float ispacing[3];
83         vec3_t mins;
84         vec3_t maxs;
85         vec3_t size;
86         int maxsplatpaths;
87
88         // per-frame data that is very temporary
89         int numsplatpaths;
90         struct r_shadow_bouncegrid_splatpath_s *splatpaths;
91         int highpixels_index; // which one is active - this toggles when doing blur
92         float *highpixels; // equals blurpixels[highpixels_index]
93         float *blurpixels[2];
94         unsigned char *u8pixels; // temporary processing buffer when outputting to rgba8 format
95         unsigned short *fp16pixels; // temporary processing buffer when outputting to rgba16f format
96 }
97 r_shadow_bouncegrid_state_t;
98
99 extern r_shadow_bouncegrid_state_t r_shadow_bouncegrid_state;
100
101 void R_Shadow_Init(void);
102 qboolean R_Shadow_ShadowMappingEnabled(void);
103 void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, const int *elements, const int *neighbors, const vec3_t projectorigin, const vec3_t projectdirection, float projectdistance, int nummarktris, const int *marktris, vec3_t trismins, vec3_t trismaxs);
104 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);
105 void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const vec3_t projectorigin, const vec3_t projectdirection, const vec3_t lightmins, const vec3_t lightmaxs, const vec3_t surfacemins, const vec3_t surfacemaxs);
106 int R_Shadow_CalcTriangleSideMask(const vec3_t p1, const vec3_t p2, const vec3_t p3, float bias);
107 int R_Shadow_CalcSphereSideMask(const vec3_t p1, float radius, float bias);
108 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);
109 void R_Shadow_RenderLighting(int texturenumsurfaces, const msurface_t **texturesurfacelist);
110 void R_Shadow_RenderMode_Begin(void);
111 void R_Shadow_RenderMode_ActiveLight(const rtlight_t *rtlight);
112 void R_Shadow_RenderMode_Reset(void);
113 void R_Shadow_RenderMode_StencilShadowVolumes(qboolean zpass);
114 void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent, qboolean shadowmapping, qboolean noselfshadowpass);
115 void R_Shadow_RenderMode_DrawDeferredLight(qboolean shadowmapping);
116 void R_Shadow_RenderMode_VisibleShadowVolumes(void);
117 void R_Shadow_RenderMode_VisibleLighting(qboolean stenciltest, qboolean transparent);
118 void R_Shadow_RenderMode_End(void);
119 void R_Shadow_ClearStencil(void);
120 void R_Shadow_SetupEntityLight(const entity_render_t *ent);
121
122 qboolean R_Shadow_ScissorForBBox(const float *mins, const float *maxs);
123
124 // these never change, they are used to create attenuation matrices
125 extern matrix4x4_t matrix_attenuationxyz;
126 extern matrix4x4_t matrix_attenuationz;
127
128 void R_Shadow_UpdateWorldLightSelection(void);
129
130 extern rtlight_t *r_shadow_compilingrtlight;
131
132 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);
133 void R_RTLight_Compile(rtlight_t *rtlight);
134 void R_RTLight_Uncompile(rtlight_t *rtlight);
135
136 void R_Shadow_PrepareLights(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture);
137 void R_Shadow_ClearShadowMapTexture(void);
138 void R_Shadow_DrawPrepass(void);
139 void R_Shadow_DrawLights(void);
140 void R_Shadow_DrawCoronas(void);
141
142 extern int maxshadowmark;
143 extern int numshadowmark;
144 extern int *shadowmark;
145 extern int *shadowmarklist;
146 extern int shadowmarkcount;
147 void R_Shadow_PrepareShadowMark(int numtris);
148
149 extern int maxshadowsides;
150 extern int numshadowsides;
151 extern unsigned char *shadowsides;
152 extern int *shadowsideslist;
153 void R_Shadow_PrepareShadowSides(int numtris);
154
155 void R_Shadow_PrepareModelShadows(void);
156
157 #define LP_LIGHTMAP             1
158 #define LP_RTWORLD              2
159 #define LP_DYNLIGHT             4
160 void R_LightPoint(float *color, const vec3_t p, const int flags);
161 void R_CompleteLightPoint(float *ambientcolor, float *diffusecolor, float *diffusenormal, const vec3_t p, const int flags);
162
163 void R_Shadow_DrawShadowMaps(void);
164 void R_Shadow_DrawModelShadows(void);
165
166 #endif