Skip to content

Commit

Permalink
Add cvar r_dynlight_radius_scale and r_studio_legacy_elight_radius_sc…
Browse files Browse the repository at this point in the history
…ale which are basically self-explained cvars.
  • Loading branch information
hzqst committed Oct 26, 2022
1 parent e0983a3 commit d1ffbd7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions Plugins/Renderer/gl_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MapConVar *r_dynlight_ambient = NULL;
MapConVar *r_dynlight_diffuse = NULL;
MapConVar *r_dynlight_specular = NULL;
MapConVar *r_dynlight_specularpow = NULL;
MapConVar *r_dynlight_radius_scale = NULL;

cvar_t *r_ssr = NULL;
MapConVar *r_ssr_ray_step = NULL;
Expand Down Expand Up @@ -412,6 +413,7 @@ void R_InitLight(void)
r_dynlight_diffuse = R_RegisterMapCvar("r_dynlight_diffuse", "0.4", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_dynlight_specular = R_RegisterMapCvar("r_dynlight_specular", "0.1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_dynlight_specularpow = R_RegisterMapCvar("r_dynlight_specularpow", "10", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_dynlight_radius_scale = R_RegisterMapCvar("r_dynlight_radius_scale", "1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);

r_flashlight_ambient = R_RegisterMapCvar("r_flashlight_ambient", "0.0", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_flashlight_diffuse = R_RegisterMapCvar("r_flashlight_diffuse", "0.5", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
Expand Down Expand Up @@ -679,7 +681,7 @@ void R_IterateDynamicLights(fnPointLightCallback pointlight_callback, fnSpotLigh

if (dynlight.type == DLIGHT_POINT)
{
float radius = dynlight.distance;
float radius = dynlight.distance * clamp(r_dynlight_radius_scale->GetValue(), 0.001f, 1000.0f);

vec3_t distToLight;
VectorSubtract((*r_refdef.vieworg), dynlight.origin, distToLight);
Expand Down Expand Up @@ -812,28 +814,30 @@ void R_IterateDynamicLights(fnPointLightCallback pointlight_callback, fnSpotLigh
float specular = r_dynlight_specular->GetValue();
float specularpow = r_dynlight_specularpow->GetValue();

float radius = dl->radius * clamp(r_dynlight_radius_scale->GetValue(), 0.001f, 1000.0f);

vec3_t distToLight;
VectorSubtract((*r_refdef.vieworg), dl->origin, distToLight);

if (VectorLength(distToLight) > dl->radius + 32)
if (VectorLength(distToLight) > radius + 32)
{
vec3_t mins, maxs;
for (int j = 0; j < 3; j++)
{
mins[j] = dl->origin[j] - dl->radius;
maxs[j] = dl->origin[j] + dl->radius;
mins[j] = dl->origin[j] - radius;
maxs[j] = dl->origin[j] + radius;
}

if (R_CullBox(mins, maxs))
continue;

if(pointlight_callback)
pointlight_callback(dl->radius, dl->origin, color, ambient, diffuse, specular, specularpow, &cl_dlight_shadow_textures[i], true);
pointlight_callback(radius, dl->origin, color, ambient, diffuse, specular, specularpow, &cl_dlight_shadow_textures[i], true);
}
else
{
if (pointlight_callback)
pointlight_callback(dl->radius, dl->origin, color, ambient, diffuse, specular, specularpow, &cl_dlight_shadow_textures[i], false);
pointlight_callback(radius, dl->origin, color, ambient, diffuse, specular, specularpow, &cl_dlight_shadow_textures[i], false);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_light.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern MapConVar *r_dynlight_ambient;
extern MapConVar *r_dynlight_diffuse;
extern MapConVar *r_dynlight_specular;
extern MapConVar *r_dynlight_specularpow;
extern MapConVar *r_dynlight_radius_scale;

extern cvar_t *r_ssr;
extern MapConVar *r_ssr_ray_step;
Expand Down
4 changes: 3 additions & 1 deletion Plugins/Renderer/gl_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ cvar_t *r_studio_hair_shadow_offset = NULL;

cvar_t *r_studio_legacy_dlight = NULL;
cvar_t *r_studio_legacy_elight = NULL;
cvar_t *r_studio_legacy_elight_radius_scale = NULL;

cvar_t *r_studio_bone_caches = NULL;

Expand Down Expand Up @@ -1015,6 +1016,7 @@ void R_InitStudio(void)

r_studio_legacy_dlight = gEngfuncs.pfnRegisterVariable("r_studio_legacy_dlight", "0", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_studio_legacy_elight = gEngfuncs.pfnRegisterVariable("r_studio_legacy_elight", "1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_studio_legacy_elight_radius_scale = gEngfuncs.pfnRegisterVariable("r_studio_legacy_elight_radius_scale", "1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
r_studio_bone_caches = gEngfuncs.pfnRegisterVariable("r_studio_bone_caches", "1", FCVAR_ARCHIVE | FCVAR_CLIENTDLL);
}

Expand Down Expand Up @@ -1118,7 +1120,7 @@ void R_EnableStudioVBO(studio_vbo_t *VBOData)
StudioUBO.r_elight_origin[i][2] = (*locallight)[i]->origin[2];
StudioUBO.r_elight_origin[i][3] = 0;

StudioUBO.r_elight_radius[i] = (*locallight)[i]->radius;
StudioUBO.r_elight_radius[i] = (*locallight)[i]->radius * clamp(r_studio_legacy_elight_radius_scale->value, 0.001f, 1000.0f);
}
}
else
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_wsurf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3249,6 +3249,7 @@ void R_ParseBSPEntity_Env_DynamicLight_Control(bspentity_t *ent)
R_ParseMapCvarSetMapValue(r_dynlight_diffuse, ValueForKey(ent, "diffuse"));
R_ParseMapCvarSetMapValue(r_dynlight_specular, ValueForKey(ent, "specular"));
R_ParseMapCvarSetMapValue(r_dynlight_specularpow, ValueForKey(ent, "specularpow"));
R_ParseMapCvarSetMapValue(r_dynlight_radius_scale, ValueForKey(ent, "radius_scale"));
}

void R_ParseBSPEntity_Env_FlashLight_Control(bspentity_t *ent)
Expand Down

0 comments on commit d1ffbd7

Please sign in to comment.