DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
r_shadow.h
Go to the documentation of this file.
1
2#ifndef R_SHADOW_H
3#define R_SHADOW_H
4
5#include "qtypes.h"
6#include "taskqueue.h"
7#include "matrixlib.h"
8struct rtlight_s;
9struct msurface_s;
10struct entity_render_s;
11
12#define R_SHADOW_SHADOWMAP_NUMCUBEMAPS 8
13
14extern struct cvar_s r_shadow_bumpscale_basetexture;
15extern struct cvar_s r_shadow_bumpscale_bumpmap;
16extern struct cvar_s r_shadow_debuglight;
17extern struct cvar_s r_shadow_gloss;
18extern struct cvar_s r_shadow_gloss2intensity;
19extern struct cvar_s r_shadow_glossintensity;
20extern struct cvar_s r_shadow_glossexponent;
21extern struct cvar_s r_shadow_gloss2exponent;
22extern struct cvar_s r_shadow_glossexact;
23extern struct cvar_s r_shadow_lightattenuationpower;
24extern struct cvar_s r_shadow_lightattenuationscale;
25extern struct cvar_s r_shadow_lightintensityscale;
26extern struct cvar_s r_shadow_lightradiusscale;
27extern struct cvar_s r_shadow_projectdistance;
28extern struct cvar_s r_shadow_frontsidecasting;
29extern struct cvar_s r_shadow_realtime_dlight;
30extern struct cvar_s r_shadow_realtime_dlight_shadows;
31extern struct cvar_s r_shadow_realtime_dlight_svbspculling;
33extern struct cvar_s r_shadow_realtime_world;
34extern struct cvar_s r_shadow_realtime_world_lightmaps;
35extern struct cvar_s r_shadow_realtime_world_shadows;
36extern struct cvar_s r_shadow_realtime_world_compile;
37extern struct cvar_s r_shadow_realtime_world_compileshadow;
38extern struct cvar_s r_shadow_realtime_world_compilesvbsp;
40extern struct cvar_s r_shadow_scissor;
41
42// used by shader for bouncegrid feature
67
68#define PHOTON_MAX_PATHS 11
69
70typedef struct r_shadow_bouncegrid_photon_path_s
71{
75}
77
78typedef struct r_shadow_bouncegrid_photon_s
79{
80 // parameters for tracing this photon
83 float color[3];
86
87 // results
90}
92
93typedef struct r_shadow_bouncegrid_state_s
94{
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;
104 int resolution[3];
109 float spacing[3];
110 float ispacing[3];
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}
137
139
140void R_Shadow_Init(void);
142void 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);
143int R_Shadow_CalcTriangleSideMask(const vec3_t p1, const vec3_t p2, const vec3_t p3, float bias);
144int R_Shadow_CalcSphereSideMask(const vec3_t p1, float radius, float bias);
145int 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);
146void R_Shadow_RenderLighting(int texturenumsurfaces, const struct msurface_s **texturesurfacelist);
148void R_Shadow_RenderMode_ActiveLight(const struct rtlight_s *rtlight);
150void R_Shadow_RenderMode_Lighting(qbool transparent, qbool shadowmapping, qbool noselfshadowpass);
153void R_Shadow_RenderMode_End(void);
154void R_Shadow_ClearStencil(void);
155void R_Shadow_SetupEntityLight(const struct entity_render_s *ent);
156
157qbool R_Shadow_ScissorForBBox(const float *mins, const float *maxs);
158
159// these never change, they are used to create attenuation matrices
162
164
165extern struct rtlight_s *r_shadow_compilingrtlight;
166
167void 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);
168void R_RTLight_Compile(struct rtlight_s *rtlight);
169void R_RTLight_Uncompile(struct rtlight_s *rtlight);
170
171void R_Shadow_PrepareLights(void);
173void R_Shadow_DrawPrepass(void);
174void R_Shadow_DrawLights(void);
175void R_Shadow_DrawCoronas(void);
176
177extern int maxshadowmark;
178extern int numshadowmark;
179extern int *shadowmark;
180extern int *shadowmarklist;
181extern int shadowmarkcount;
182void R_Shadow_PrepareShadowMark(int numtris);
183
184extern int maxshadowsides;
185extern int numshadowsides;
186extern unsigned char *shadowsides;
187extern int *shadowsideslist;
188void R_Shadow_PrepareShadowSides(int numtris);
189
191
192#define LP_LIGHTMAP 1
193#define LP_RTWORLD 2
194#define LP_DYNLIGHT 4
195void R_CompleteLightPoint(float *ambient, float *diffuse, float *lightdir, const vec3_t p, const int flags, float lightmapintensity, float ambientintensity);
196
197void R_Shadow_DrawShadowMaps(void);
198
199#endif
float flags
vector mins
vector maxs
float style
vector color
float vec_t
Definition qtypes.h:68
vec_t vec3_t[3]
Definition qtypes.h:71
bool qbool
Definition qtypes.h:9
void R_Shadow_RenderMode_Begin(void)
Definition r_shadow.c:1369
void R_Shadow_RenderMode_Lighting(qbool transparent, qbool shadowmapping, qbool noselfshadowpass)
Definition r_shadow.c:1597
struct cvar_s r_shadow_scissor
Definition r_shadow.c:171
struct cvar_s r_shadow_gloss2exponent
Definition r_shadow.c:151
void R_Shadow_PrepareShadowSides(int numtris)
Definition r_shadow.c:848
int R_Shadow_CalcTriangleSideMask(const vec3_t p1, const vec3_t p2, const vec3_t p3, float bias)
Definition r_shadow.c:863
#define PHOTON_MAX_PATHS
Definition r_shadow.h:68
int maxshadowmark
Definition r_shadow.c:76
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)
Definition r_shadow.c:1058
struct cvar_s r_shadow_realtime_dlight_svbspculling
Definition r_shadow.c:161
qbool R_Shadow_ScissorForBBox(const float *mins, const float *maxs)
Definition r_shadow.c:2900
void R_Shadow_ClearStencil(void)
Definition r_shadow.c:1430
void R_Shadow_DrawShadowMaps(void)
Definition r_shadow.c:4204
void R_Shadow_SetupEntityLight(const struct entity_render_s *ent)
struct cvar_s r_shadow_bumpscale_basetexture
Definition r_shadow.c:141
int maxshadowsides
Definition r_shadow.c:82
void R_Shadow_PrepareShadowMark(int numtris)
Definition r_shadow.c:824
struct cvar_s r_shadow_glossexact
Definition r_shadow.c:152
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)
struct cvar_s r_shadow_lightattenuationscale
struct cvar_s r_shadow_realtime_world_shadows
Definition r_shadow.c:166
struct cvar_s r_shadow_lightintensityscale
Definition r_shadow.c:155
void R_RTLight_Compile(struct rtlight_s *rtlight)
void R_Shadow_RenderLighting(int texturenumsurfaces, const struct msurface_s **texturesurfacelist)
int numshadowsides
Definition r_shadow.c:83
struct cvar_s r_shadow_realtime_dlight_shadows
Definition r_shadow.c:160
struct rtlight_s * r_shadow_compilingrtlight
Definition r_shadow.c:272
void R_Shadow_RenderMode_DrawDeferredLight(qbool shadowmapping)
Definition r_shadow.c:1642
void R_Shadow_PrepareLights(void)
Definition r_shadow.c:4031
qbool R_Shadow_ShadowMappingEnabled(void)
Definition r_shadow.c:378
int * shadowmark
Definition r_shadow.c:78
void R_RTLight_Uncompile(struct rtlight_s *rtlight)
void R_Shadow_PrepareModelShadows(void)
Definition r_shadow.c:4242
int numshadowmark
Definition r_shadow.c:77
int R_Shadow_CalcSphereSideMask(const vec3_t p1, float radius, float bias)
Definition r_shadow.c:966
struct cvar_s r_shadow_realtime_dlight
Definition r_shadow.c:159
matrix4x4_t matrix_attenuationz
Definition r_shadow.c:744
void R_Shadow_RenderMode_VisibleLighting(qbool transparent)
Definition r_shadow.c:2860
struct cvar_s r_shadow_realtime_world_compilesvbsp
Definition r_shadow.c:169
matrix4x4_t matrix_attenuationxyz
Definition r_shadow.c:734
struct cvar_s r_shadow_realtime_world_lightmaps
Definition r_shadow.c:165
unsigned char * shadowsides
Definition r_shadow.c:84
struct cvar_s r_shadow_realtime_world
Definition r_shadow.c:163
void R_Shadow_RenderMode_Reset(void)
Definition r_shadow.c:1409
int shadowmarkcount
Definition r_shadow.c:80
int * shadowsideslist
Definition r_shadow.c:85
struct cvar_s r_shadow_realtime_world_compile
Definition r_shadow.c:167
struct cvar_s r_shadow_frontsidecasting
Definition r_shadow.c:158
void R_Shadow_DrawCoronas(void)
Definition r_shadow.c:4528
void R_Shadow_Init(void)
Definition r_shadow.c:601
void R_Shadow_RenderMode_ActiveLight(const struct rtlight_s *rtlight)
struct cvar_s r_shadow_lightradiusscale
Definition r_shadow.c:156
int * shadowmarklist
Definition r_shadow.c:79
struct cvar_s r_shadow_gloss
Definition r_shadow.c:147
void R_Shadow_DrawLights(void)
Definition r_shadow.c:4226
void R_Shadow_ClearShadowMapTexture(void)
Definition r_shadow.c:1480
struct cvar_s r_shadow_lightattenuationpower
struct cvar_s r_shadow_gloss2intensity
Definition r_shadow.c:148
struct cvar_s r_shadow_projectdistance
Definition r_shadow.c:157
struct cvar_s r_shadow_realtime_world_compileportalculling
Definition r_shadow.c:170
struct cvar_s r_shadow_debuglight
Definition r_shadow.c:143
void R_Shadow_RenderMode_End(void)
Definition r_shadow.c:2872
void R_Shadow_DrawPrepass(void)
Definition r_shadow.c:3958
struct cvar_s r_shadow_glossintensity
Definition r_shadow.c:149
void R_Shadow_UpdateWorldLightSelection(void)
Definition r_shadow.c:5289
struct cvar_s r_shadow_realtime_world_compileshadow
Definition r_shadow.c:168
struct cvar_s r_shadow_realtime_dlight_portalculling
Definition r_shadow.c:162
struct cvar_s r_shadow_bumpscale_bumpmap
Definition r_shadow.c:142
r_shadow_bouncegrid_state_t r_shadow_bouncegrid_state
Definition r_shadow.c:259
struct cvar_s r_shadow_glossexponent
Definition r_shadow.c:150
void R_CompleteLightPoint(float *ambient, float *diffuse, float *lightdir, const vec3_t p, const int flags, float lightmapintensity, float ambientintensity)
Definition r_shadow.c:6014
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)
Definition r_shadow.c:1162
taskqueue_task_t enqueuephotons_task
Definition r_shadow.h:128
taskqueue_task_t enqueue_slices_task
Definition r_shadow.h:131
taskqueue_task_t photons_done_task
Definition r_shadow.h:130
taskqueue_task_t slices_done_task
Definition r_shadow.h:133
taskqueue_task_t * photons_tasks
Definition r_shadow.h:129
unsigned char * u8pixels
Definition r_shadow.h:119
r_shadow_bouncegrid_settings_t settings
Definition r_shadow.h:95
taskqueue_task_t cleartex_task
Definition r_shadow.h:126
unsigned short * fp16pixels
Definition r_shadow.h:120
taskqueue_task_t * slices_tasks
Definition r_shadow.h:132
taskqueue_task_t blurpixels_task
Definition r_shadow.h:134
r_shadow_bouncegrid_photon_t * photons
Definition r_shadow.h:123
taskqueue_task_t assignphotons_task
Definition r_shadow.h:127
struct rtexture_s * texture
Definition r_shadow.h:100