cvar_t r_shadow_bumpscale_bumpmap = {0, "r_shadow_bumpscale_bumpmap", "4"};
cvar_t r_shadow_cull = {0, "r_shadow_cull", "1"};
cvar_t r_shadow_debuglight = {0, "r_shadow_debuglight", "-1"};
-cvar_t r_shadow_gloss = {0, "r_shadow_gloss", "1"};
+cvar_t r_shadow_gloss = {CVAR_SAVE, "r_shadow_gloss", "1"};
cvar_t r_shadow_gloss2intensity = {0, "r_shadow_gloss2intensity", "0.25"};
cvar_t r_shadow_glossintensity = {0, "r_shadow_glossintensity", "1"};
cvar_t r_shadow_lightattenuationpower = {0, "r_shadow_lightattenuationpower", "0.5"};
cvar_t r_shadow_lightintensityscale = {0, "r_shadow_lightintensityscale", "1"};
cvar_t r_shadow_portallight = {0, "r_shadow_portallight", "1"};
cvar_t r_shadow_projectdistance = {0, "r_shadow_projectdistance", "1000000"};
-cvar_t r_shadow_realtime_dlight = {0, "r_shadow_realtime_dlight", "1"};
-cvar_t r_shadow_realtime_dlight_shadows = {0, "r_shadow_realtime_dlight_shadows", "0"};
-cvar_t r_shadow_realtime_world = {0, "r_shadow_realtime_world", "0"};
-cvar_t r_shadow_realtime_world_dlightshadows = {0, "r_shadow_realtime_world_dlightshadows", "1"};
-cvar_t r_shadow_realtime_world_lightmaps = {0, "r_shadow_realtime_world_lightmaps", "0"};
-cvar_t r_shadow_realtime_world_shadows = {0, "r_shadow_realtime_world_shadows", "1"};
+cvar_t r_shadow_realtime_dlight = {CVAR_SAVE, "r_shadow_realtime_dlight", "1"};
+cvar_t r_shadow_realtime_dlight_shadows = {CVAR_SAVE, "r_shadow_realtime_dlight_shadows", "0"};
+cvar_t r_shadow_realtime_world = {CVAR_SAVE, "r_shadow_realtime_world", "0"};
+cvar_t r_shadow_realtime_world_dlightshadows = {CVAR_SAVE, "r_shadow_realtime_world_dlightshadows", "1"};
+cvar_t r_shadow_realtime_world_lightmaps = {CVAR_SAVE, "r_shadow_realtime_world_lightmaps", "0"};
+cvar_t r_shadow_realtime_world_shadows = {CVAR_SAVE, "r_shadow_realtime_world_shadows", "1"};
cvar_t r_shadow_scissor = {0, "r_shadow_scissor", "1"};
cvar_t r_shadow_shadow_polygonfactor = {0, "r_shadow_shadow_polygonfactor", "0"};
cvar_t r_shadow_shadow_polygonoffset = {0, "r_shadow_shadow_polygonoffset", "1"};
float r_shadow_attenpower, r_shadow_attenscale;
-float varray_vertex3f2[65536*3];
-
rtlight_t *r_shadow_compilingrtlight;
dlight_t *r_shadow_worldlightchain;
dlight_t *r_shadow_selectedlight;
+dlight_t r_shadow_bufferlight;
vec3_t r_editlights_cursorlocation;
rtexture_t *lighttextures[5];
}
Cmd_AddCommand("r_shadow_help", R_Shadow_Help_f);
R_Shadow_EditLights_Init();
- r_shadow_mempool = Mem_AllocPool("R_Shadow");
+ r_shadow_mempool = Mem_AllocPool("R_Shadow", 0, NULL);
r_shadow_worldlightchain = NULL;
maxshadowelements = 0;
shadowelements = NULL;
// optimize for them as noted above
}
-void R_Shadow_Stage_LightWithoutShadows(void)
+void R_Shadow_Stage_Light(int shadowtest)
{
rmeshstate_t m;
memset(&m, 0, sizeof(m));
qglPolygonOffset(0, 0);
//qglDisable(GL_POLYGON_OFFSET_FILL);
GL_Color(1, 1, 1, 1);
- GL_ColorMask(1, 1, 1, 1);
+ GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
qglDepthFunc(GL_EQUAL);
qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
qglEnable(GL_CULL_FACE);
- qglDisable(GL_STENCIL_TEST);
- if (gl_support_stenciltwoside)
- qglDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
- qglStencilMask(~0);
- qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
- qglStencilFunc(GL_EQUAL, 128, ~0);
- r_shadowstage = SHADOWSTAGE_LIGHT;
- c_rt_lights++;
-}
-
-void R_Shadow_Stage_LightWithShadows(void)
-{
- rmeshstate_t m;
- memset(&m, 0, sizeof(m));
- R_Mesh_State(&m);
- GL_BlendFunc(GL_ONE, GL_ONE);
- GL_DepthMask(false);
- GL_DepthTest(true);
- qglPolygonOffset(0, 0);
- //qglDisable(GL_POLYGON_OFFSET_FILL);
- GL_Color(1, 1, 1, 1);
- GL_ColorMask(1, 1, 1, 1);
- qglDepthFunc(GL_EQUAL);
- qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
- qglEnable(GL_STENCIL_TEST);
+ if (shadowtest)
+ qglEnable(GL_STENCIL_TEST);
+ else
+ qglDisable(GL_STENCIL_TEST);
if (gl_support_stenciltwoside)
qglDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
qglStencilMask(~0);
qglPolygonOffset(0, 0);
//qglDisable(GL_POLYGON_OFFSET_FILL);
GL_Color(1, 1, 1, 1);
- GL_ColorMask(1, 1, 1, 1);
+ GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
GL_Scissor(r_view_x, r_view_y, r_view_width, r_view_height);
qglDepthFunc(GL_LEQUAL);
qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
}
// this final code is shared
R_Mesh_State(&m);
- GL_ColorMask(1,1,1,0);
+ GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
VectorScale(lightcolor, colorscale, color2);
for (renders = 0;renders < 64 && (color2[0] > 0 || color2[1] > 0 || color2[2] > 0);renders++, color2[0]--, color2[1]--, color2[2]--)
}
}
R_Mesh_State(&m);
- GL_ColorMask(1,1,1,0);
+ GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
VectorScale(lightcolor, colorscale, color2);
GL_LockArrays(0, numverts);
int i, shadow;
entity_render_t *ent;
float f;
- vec3_t relativelightorigin, relativeeyeorigin, lightcolor;
+ vec3_t relativelightorigin, relativeeyeorigin, lightcolor, lightcolor2;
rtexture_t *cubemaptexture;
matrix4x4_t matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz;
int numclusters, numsurfaces;
}
*/
-#if 1
- shadow = rtlight->shadow && (rtlight->isstatic ? r_shadow_realtime_world_shadows.integer : (r_shadow_realtime_world.integer ? r_shadow_realtime_world_dlightshadows.integer : r_shadow_realtime_dlight_shadows.integer));
-#else
- shadow = false;
- if (rtlight->shadow)
- {
- if (rtlight->isstatic)
- shadow = r_shadow_realtime_world_shadows.integer;
- else
- {
- if (r_shadow_realtime_world.integer)
- shadow = r_shadow_realtime_world_dlightshadows.integer;
- else
- shadow = r_shadow_realtime_dlight_shadows.integer;
- }
- }
-#endif
+ shadow = rtlight->shadow && (rtlight->isstatic ? r_rtworldshadows : r_rtdlightshadows);
if (shadow && (gl_stencil || visiblevolumes))
{
if (!visiblevolumes)
{
- if (shadow && gl_stencil)
- R_Shadow_Stage_LightWithShadows();
- else
- R_Shadow_Stage_LightWithoutShadows();
+ R_Shadow_Stage_Light(shadow && gl_stencil);
ent = &cl_entities[0].render;
if (ent->model && ent->model->DrawLight)
for (i = 0;i < r_refdef.numentities;i++)
{
ent = r_refdef.entities[i];
- if (ent->visframe == r_framecount && BoxesOverlap(ent->mins, ent->maxs, cullmins, cullmaxs) && ent->model && ent->model->DrawLight && (ent->flags & RENDER_LIGHT))
+ // can't draw transparent entity lighting here because
+ // transparent meshes are deferred for later
+ if (ent->visframe == r_framecount && BoxesOverlap(ent->mins, ent->maxs, cullmins, cullmaxs) && ent->model && ent->model->DrawLight && (ent->flags & (RENDER_LIGHT | RENDER_TRANSPARENT)) == RENDER_LIGHT)
{
+ VectorScale(lightcolor, ent->alpha, lightcolor2);
Matrix4x4_Transform(&ent->inversematrix, rtlight->shadoworigin, relativelightorigin);
Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, relativeeyeorigin);
Matrix4x4_Concat(&matrix_modeltolight, &rtlight->matrix_worldtolight, &ent->matrix);
Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &rtlight->matrix_worldtoattenuationxyz, &ent->matrix);
Matrix4x4_Concat(&matrix_modeltoattenuationz, &rtlight->matrix_worldtoattenuationz, &ent->matrix);
- ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, rtlight->radius, lightcolor, &matrix_modeltolight, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, cubemaptexture, ent->model->nummodelsurfaces, ent->model->surfacelist);
+ ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, rtlight->radius, lightcolor2, &matrix_modeltolight, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, cubemaptexture, ent->model->nummodelsurfaces, ent->model->surfacelist);
}
}
}
}
else
R_Shadow_Stage_Begin();
- if (r_shadow_realtime_world.integer)
+ if (r_rtworld)
{
if (r_shadow_debuglight.integer >= 0)
{
for (lnum = 0, light = r_shadow_worldlightchain;light;lnum++, light = light->next)
R_DrawRTLight(&light->rtlight, visiblevolumes);
}
- if (r_shadow_realtime_world.integer || r_shadow_realtime_dlight.integer)
+ if (r_rtdlight)
for (lnum = 0, light = r_dlight;lnum < r_numdlights;lnum++, light++)
R_DrawRTLight(&light->rtlight, visiblevolumes);
R_FreeTexturePool(&r_shadow_filters_texturepool);
}
-void R_Shadow_NewWorldLight(vec3_t origin, vec3_t angles, vec3_t color, vec_t radius, vec_t corona, int style, int shadowenable, const char *cubemapname)
+dlight_t *R_Shadow_NewWorldLight(void)
{
dlight_t *light;
-
- if (radius < 15 || DotProduct(color, color) < 0.03)
- {
- Con_Print("R_Shadow_NewWorldLight: refusing to create a light too small/dim\n");
- return;
- }
-
light = Mem_Alloc(r_shadow_mempool, sizeof(dlight_t));
+ light->next = r_shadow_worldlightchain;
+ r_shadow_worldlightchain = light;
+ return light;
+}
+
+void R_Shadow_UpdateWorldLight(dlight_t *light, vec3_t origin, vec3_t angles, vec3_t color, vec_t radius, vec_t corona, int style, int shadowenable, const char *cubemapname)
+{
VectorCopy(origin, light->origin);
- VectorCopy(angles, light->angles);
- VectorCopy(color, light->color);
- light->radius = radius;
+ light->angles[0] = angles[0] - 360 * floor(angles[0] / 360);
+ light->angles[1] = angles[1] - 360 * floor(angles[1] / 360);
+ light->angles[2] = angles[2] - 360 * floor(angles[2] / 360);
+ light->color[0] = max(color[0], 0);
+ light->color[1] = max(color[1], 0);
+ light->color[2] = max(color[2], 0);
+ light->radius = max(radius, 0);
light->style = style;
if (light->style < 0 || light->style >= MAX_LIGHTSTYLES)
{
}
light->shadow = shadowenable;
light->corona = corona;
- if (cubemapname && cubemapname[0] && strlen(cubemapname) < sizeof(light->cubemapname))
- strcpy(light->cubemapname, cubemapname);
+ if (!cubemapname)
+ cubemapname = "";
+ strlcpy(light->cubemapname, cubemapname, strlen(light->cubemapname));
Matrix4x4_CreateFromQuakeEntity(&light->matrix, light->origin[0], light->origin[1], light->origin[2], light->angles[0], light->angles[1], light->angles[2], 1);
- light->next = r_shadow_worldlightchain;
- r_shadow_worldlightchain = light;
R_RTLight_UpdateFromDLight(&light->rtlight, light, true);
}
}
VectorScale(color, r_editlights_rtlightscolorscale.value, color);
radius *= r_editlights_rtlightssizescale.value;
- R_Shadow_NewWorldLight(origin, angles, color, radius, corona, style, shadow, cubemapname);
+ R_Shadow_UpdateWorldLight(R_Shadow_NewWorldLight(), origin, angles, color, radius, corona, style, shadow, cubemapname);
s++;
n++;
}
radius = sqrt(DotProduct(color, color) / (falloff * falloff * 8192.0f * 8192.0f));
radius = bound(15, radius, 4096);
VectorScale(color, (2.0f / (8388608.0f)), color);
- R_Shadow_NewWorldLight(origin, vec3_origin, color, radius, 0, style, true, NULL);
+ R_Shadow_UpdateWorldLight(R_Shadow_NewWorldLight(), origin, vec3_origin, color, radius, 0, style, true, NULL);
s++;
n++;
}
}
VectorAdd(origin, originhack, origin);
if (radius >= 1)
- R_Shadow_NewWorldLight(origin, angles, color, radius, (pflags & PFLAGS_CORONA) != 0, style, (pflags & PFLAGS_NOSHADOW) == 0, skin >= 16 ? va("cubemaps/%i", skin) : NULL);
+ R_Shadow_UpdateWorldLight(R_Shadow_NewWorldLight(), origin, angles, color, radius, (pflags & PFLAGS_CORONA) != 0, style, (pflags & PFLAGS_NOSHADOW) == 0, skin >= 16 ? va("cubemaps/%i", skin) : NULL);
}
}
return;
}
color[0] = color[1] = color[2] = 1;
- R_Shadow_NewWorldLight(r_editlights_cursorlocation, vec3_origin, color, 200, 0, 0, true, NULL);
+ R_Shadow_UpdateWorldLight(R_Shadow_NewWorldLight(), r_editlights_cursorlocation, vec3_origin, color, 200, 0, 0, true, NULL);
}
void R_Shadow_EditLights_Edit_f(void)
Con_Printf("Cubemap: %s\n", r_shadow_selectedlight->cubemapname);
return;
}
- R_Shadow_FreeWorldLight(r_shadow_selectedlight);
- r_shadow_selectedlight = NULL;
- R_Shadow_NewWorldLight(origin, angles, color, radius, corona, style, shadows, cubemapname);
+ R_Shadow_UpdateWorldLight(r_shadow_selectedlight, origin, angles, color, radius, corona, style, shadows, cubemapname);
+}
+
+void R_Shadow_EditLights_EditAll_f(void)
+{
+ dlight_t *light;
+
+ if (!r_editlights.integer)
+ {
+ Con_Print("Cannot edit lights when not in editing mode. Set r_editlights to 1.\n");
+ return;
+ }
+
+ for (light = r_shadow_worldlightchain;light;light = light->next)
+ {
+ R_Shadow_SelectLight(light);
+ R_Shadow_EditLights_Edit_f();
+ }
}
void R_Shadow_EditLights_DrawSelectedLightProperties(void)
{
float x, y;
char temp[256];
- if (r_shadow_selectedlight == NULL)
+ if (!r_editlights.integer)
return;
x = 0;
y = con_vislines;
+ sprintf(temp, "Cursor %f %f %f", r_editlights_cursorlocation[0], r_editlights_cursorlocation[1], r_editlights_cursorlocation[2]);DrawQ_String(x, y, temp, 0, 8, 8, 1, 1, 1, 1, 0);y += 8;
+ if (r_shadow_selectedlight == NULL)
+ return;
sprintf(temp, "Light properties");DrawQ_String(x, y, temp, 0, 8, 8, 1, 1, 1, 1, 0);y += 8;
sprintf(temp, "Origin %f %f %f", r_shadow_selectedlight->origin[0], r_shadow_selectedlight->origin[1], r_shadow_selectedlight->origin[2]);DrawQ_String(x, y, temp, 0, 8, 8, 1, 1, 1, 1, 0);y += 8;
sprintf(temp, "Angles %f %f %f", r_shadow_selectedlight->angles[0], r_shadow_selectedlight->angles[1], r_shadow_selectedlight->angles[2]);DrawQ_String(x, y, temp, 0, 8, 8, 1, 1, 1, 1, 0);y += 8;
Con_Print("No selected light.\n");
return;
}
- R_Shadow_NewWorldLight(r_shadow_selectedlight->origin, r_shadow_selectedlight->angles, r_shadow_selectedlight->color, r_shadow_selectedlight->radius, r_shadow_selectedlight->corona, r_shadow_selectedlight->style, !r_shadow_selectedlight->shadow, r_shadow_selectedlight->cubemapname);
- R_Shadow_FreeWorldLight(r_shadow_selectedlight);
- r_shadow_selectedlight = NULL;
+ R_Shadow_UpdateWorldLight(r_shadow_selectedlight, r_shadow_selectedlight->origin, r_shadow_selectedlight->angles, r_shadow_selectedlight->color, r_shadow_selectedlight->radius, r_shadow_selectedlight->corona, r_shadow_selectedlight->style, !r_shadow_selectedlight->shadow, r_shadow_selectedlight->cubemapname);
}
void R_Shadow_EditLights_ToggleCorona_f(void)
Con_Print("No selected light.\n");
return;
}
- R_Shadow_NewWorldLight(r_shadow_selectedlight->origin, r_shadow_selectedlight->angles, r_shadow_selectedlight->color, r_shadow_selectedlight->radius, !r_shadow_selectedlight->corona, r_shadow_selectedlight->style, r_shadow_selectedlight->shadow, r_shadow_selectedlight->cubemapname);
- R_Shadow_FreeWorldLight(r_shadow_selectedlight);
- r_shadow_selectedlight = NULL;
+ R_Shadow_UpdateWorldLight(r_shadow_selectedlight, r_shadow_selectedlight->origin, r_shadow_selectedlight->angles, r_shadow_selectedlight->color, r_shadow_selectedlight->radius, !r_shadow_selectedlight->corona, r_shadow_selectedlight->style, r_shadow_selectedlight->shadow, r_shadow_selectedlight->cubemapname);
}
void R_Shadow_EditLights_Remove_f(void)
);
}
+void R_Shadow_EditLights_CopyInfo_f(void)
+{
+ if (!r_editlights.integer)
+ {
+ Con_Print("Cannot copy light info when not in editing mode. Set r_editlights to 1.\n");
+ return;
+ }
+ if (!r_shadow_selectedlight)
+ {
+ Con_Print("No selected light.\n");
+ return;
+ }
+ VectorCopy(r_shadow_selectedlight->angles, r_shadow_bufferlight.angles);
+ VectorCopy(r_shadow_selectedlight->color, r_shadow_bufferlight.color);
+ r_shadow_bufferlight.radius = r_shadow_selectedlight->radius;
+ r_shadow_bufferlight.style = r_shadow_selectedlight->style;
+ if (r_shadow_selectedlight->cubemapname)
+ strcpy(r_shadow_bufferlight.cubemapname, r_shadow_selectedlight->cubemapname);
+ else
+ r_shadow_bufferlight.cubemapname[0] = 0;
+ r_shadow_bufferlight.shadow = r_shadow_selectedlight->shadow;
+ r_shadow_bufferlight.corona = r_shadow_selectedlight->corona;
+}
+
+void R_Shadow_EditLights_PasteInfo_f(void)
+{
+ if (!r_editlights.integer)
+ {
+ Con_Print("Cannot paste light info when not in editing mode. Set r_editlights to 1.\n");
+ return;
+ }
+ if (!r_shadow_selectedlight)
+ {
+ Con_Print("No selected light.\n");
+ return;
+ }
+ R_Shadow_UpdateWorldLight(r_shadow_selectedlight, r_shadow_selectedlight->origin, r_shadow_bufferlight.angles, r_shadow_bufferlight.color, r_shadow_bufferlight.radius, r_shadow_bufferlight.corona, r_shadow_bufferlight.style, r_shadow_bufferlight.shadow, r_shadow_bufferlight.cubemapname);
+}
+
void R_Shadow_EditLights_Init(void)
{
Cvar_RegisterVariable(&r_editlights);
Cmd_AddCommand("r_editlights_save", R_Shadow_EditLights_Save_f);
Cmd_AddCommand("r_editlights_spawn", R_Shadow_EditLights_Spawn_f);
Cmd_AddCommand("r_editlights_edit", R_Shadow_EditLights_Edit_f);
+ Cmd_AddCommand("r_editlights_editall", R_Shadow_EditLights_EditAll_f);
Cmd_AddCommand("r_editlights_remove", R_Shadow_EditLights_Remove_f);
Cmd_AddCommand("r_editlights_toggleshadow", R_Shadow_EditLights_ToggleShadow_f);
Cmd_AddCommand("r_editlights_togglecorona", R_Shadow_EditLights_ToggleCorona_f);
Cmd_AddCommand("r_editlights_importlightentitiesfrommap", R_Shadow_EditLights_ImportLightEntitiesFromMap_f);
Cmd_AddCommand("r_editlights_importlightsfile", R_Shadow_EditLights_ImportLightsFile_f);
+ Cmd_AddCommand("r_editlights_copyinfo", R_Shadow_EditLights_CopyInfo_f);
+ Cmd_AddCommand("r_editlights_pasteinfo", R_Shadow_EditLights_PasteInfo_f);
}