10 struct entity_render_s;
12 #define R_SHADOW_SHADOWMAP_NUMCUBEMAPS 8
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;
42 // used by shader for bouncegrid feature
43 typedef struct r_shadow_bouncegrid_settings_s
46 qbool directionalshading;
47 qbool includedirectlighting;
49 qbool normalizevectors;
51 float dlightparticlemultiplier;
53 float lightradiusscale;
56 float particlebounceintensity;
57 float particleintensity;
59 float energyperphoton;
63 float bounceminimumintensity2;
66 r_shadow_bouncegrid_settings_t;
68 #define PHOTON_MAX_PATHS 11
70 typedef struct r_shadow_bouncegrid_photon_path_s
76 r_shadow_bouncegrid_photon_path_t;
78 typedef struct r_shadow_bouncegrid_photon_s
80 // parameters for tracing this photon
84 float bounceminimumintensity2;
85 float startrefractiveindex;
89 r_shadow_bouncegrid_photon_path_t paths[PHOTON_MAX_PATHS];
91 r_shadow_bouncegrid_photon_t;
93 typedef struct r_shadow_bouncegrid_state_s
95 r_shadow_bouncegrid_settings_t settings;
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;
103 double lastupdatetime;
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
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
136 r_shadow_bouncegrid_state_t;
138 extern r_shadow_bouncegrid_state_t r_shadow_bouncegrid_state;
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);
157 qbool R_Shadow_ScissorForBBox(const float *mins, const float *maxs);
159 // these never change, they are used to create attenuation matrices
160 extern matrix4x4_t matrix_attenuationxyz;
161 extern matrix4x4_t matrix_attenuationz;
163 void R_Shadow_UpdateWorldLightSelection(void);
165 extern struct rtlight_s *r_shadow_compilingrtlight;
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);
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);
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);
184 extern int maxshadowsides;
185 extern int numshadowsides;
186 extern unsigned char *shadowsides;
187 extern int *shadowsideslist;
188 void R_Shadow_PrepareShadowSides(int numtris);
190 void R_Shadow_PrepareModelShadows(void);
192 #define LP_LIGHTMAP 1
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);
197 void R_Shadow_DrawShadowMaps(void);