mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-04 08:25:34 +00:00
[renderer] Merge light setup code from glsl and sw
I'll look into gl later, but this means I don't need yet another copy for vulkan's forward renderer.
This commit is contained in:
parent
3551b542c3
commit
b22f104163
4 changed files with 50 additions and 82 deletions
|
@ -304,6 +304,7 @@ void R_PrintAliasStats (void);
|
|||
void R_PrintTimes (void);
|
||||
void R_AnimateLight (void);
|
||||
int R_LightPoint (mod_brush_t *brush, vec4f_t p);
|
||||
void R_Setup_Lighting (struct entity_s ent, alight_t *lighting);
|
||||
void R_SetupFrame (void);
|
||||
void R_cshift_f (void);
|
||||
void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1);
|
||||
|
|
|
@ -151,39 +151,6 @@ glsl_R_InitAlias (void)
|
|||
GLSL_FreeShader (frag_shader);
|
||||
}
|
||||
|
||||
static void
|
||||
calc_lighting (entity_t ent, float *ambient, float *shadelight,
|
||||
vec3_t lightvec)
|
||||
{
|
||||
float add;
|
||||
vec3_t dist;
|
||||
int light;
|
||||
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
vec4f_t entorigin = Transform_GetWorldPosition (transform);
|
||||
|
||||
VectorSet ( -1, 0, 0, lightvec); //FIXME
|
||||
light = R_LightPoint (&r_refdef.worldmodel->brush, entorigin);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
*ambient = max (light, max (renderer->model->min_light,
|
||||
renderer->min_light) * 128);
|
||||
*shadelight = *ambient;
|
||||
|
||||
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
|
||||
auto dlight_data = (dlight_t *) dlight_pool->data;
|
||||
for (uint32_t i = 0; i < dlight_pool->count; i++) {
|
||||
auto dlight = &dlight_data[i];
|
||||
VectorSubtract (entorigin, dlight->origin, dist);
|
||||
add = dlight->radius - VectorLength (dist);
|
||||
if (add > 0)
|
||||
*ambient += add;
|
||||
}
|
||||
if (*ambient >= 128)
|
||||
*ambient = 128;
|
||||
if (*shadelight > 192 - *ambient)
|
||||
*shadelight = 192 - *ambient;
|
||||
}
|
||||
|
||||
static void
|
||||
set_arrays (const shaderparam_t *vert, const shaderparam_t *norm,
|
||||
const shaderparam_t *st, aliasvrt_t *pose)
|
||||
|
@ -229,9 +196,6 @@ glsl_R_DrawAlias (entity_t ent)
|
|||
};
|
||||
#endif
|
||||
static quat_t color = { 1, 1, 1, 1};
|
||||
static vec3_t lightvec;
|
||||
float ambient;
|
||||
float shadelight;
|
||||
float skin_size[2];
|
||||
float blend;
|
||||
aliashdr_t *hdr;
|
||||
|
@ -239,8 +203,9 @@ glsl_R_DrawAlias (entity_t ent)
|
|||
aliasvrt_t *pose1 = 0; // VBO's are null based
|
||||
aliasvrt_t *pose2 = 0; // VBO's are null based
|
||||
mat4f_t worldMatrix;
|
||||
alight_t lighting;
|
||||
|
||||
calc_lighting (ent, &ambient, &shadelight, lightvec);
|
||||
R_Setup_Lighting (ent, &lighting);
|
||||
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if (renderer->onlyshadows) {
|
||||
|
@ -307,9 +272,9 @@ glsl_R_DrawAlias (entity_t ent)
|
|||
qfeglVertexAttrib4fv (quake_mdl.colora.location, color);
|
||||
qfeglVertexAttrib4fv (quake_mdl.colorb.location, color);
|
||||
qfeglUniform1f (quake_mdl.blend.location, blend);
|
||||
qfeglUniform1f (quake_mdl.ambient.location, ambient);
|
||||
qfeglUniform1f (quake_mdl.shadelight.location, shadelight);
|
||||
qfeglUniform3fv (quake_mdl.lightvec.location, 1, lightvec);
|
||||
qfeglUniform1f (quake_mdl.ambient.location, lighting.ambientlight);
|
||||
qfeglUniform1f (quake_mdl.shadelight.location, lighting.shadelight);
|
||||
qfeglUniform3fv (quake_mdl.lightvec.location, 1, lighting.lightvec);
|
||||
qfeglUniform2fv (quake_mdl.skin_size.location, 1, skin_size);
|
||||
qfeglUniformMatrix4fv (quake_mdl.mvp_matrix.location, 1, false,
|
||||
(vec_t*)&mvp_mat[0]);//FIXME
|
||||
|
|
|
@ -475,3 +475,45 @@ R_LightPoint (mod_brush_t *brush, vec4f_t p)
|
|||
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
R_Setup_Lighting (entity_t ent, alight_t *lighting)
|
||||
{
|
||||
float minlight = 0;
|
||||
int j;
|
||||
// FIXME: remove and do real lighting
|
||||
vec3_t dist;
|
||||
float add;
|
||||
float lightvec[3] = { -1, 0, 0 };
|
||||
|
||||
auto transform = Entity_Transform (ent);
|
||||
vec4f_t origin = Transform_GetWorldPosition (transform);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
minlight = max (renderer->model->min_light, renderer->min_light);
|
||||
|
||||
// 128 instead of 255 due to clamping below
|
||||
j = max (R_LightPoint (&r_refdef.worldmodel->brush, origin),
|
||||
minlight * 128);
|
||||
|
||||
lighting->ambientlight = j;
|
||||
lighting->shadelight = j;
|
||||
|
||||
VectorCopy (lightvec, lighting->lightvec);
|
||||
|
||||
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
|
||||
auto dlight_data = (dlight_t *) dlight_pool->data;
|
||||
for (uint32_t i = 0; i < dlight_pool->count; i++) {
|
||||
auto dlight = &dlight_data[i];
|
||||
VectorSubtract (origin, dlight->origin, dist);
|
||||
add = dlight->radius - VectorLength (dist);
|
||||
|
||||
if (add > 0)
|
||||
lighting->ambientlight += add;
|
||||
}
|
||||
|
||||
// clamp lighting so it doesn't overbright as much
|
||||
if (lighting->ambientlight > 128)
|
||||
lighting->ambientlight = 128;
|
||||
if (lighting->ambientlight + lighting->shadelight > 192)
|
||||
lighting->shadelight = 192 - lighting->ambientlight;
|
||||
}
|
||||
|
|
|
@ -265,46 +265,6 @@ draw_sprite_entity (entity_t ent)
|
|||
R_DrawSprite (ent);
|
||||
}
|
||||
|
||||
static inline void
|
||||
setup_lighting (entity_t ent, alight_t *lighting)
|
||||
{
|
||||
float minlight = 0;
|
||||
int j;
|
||||
// FIXME: remove and do real lighting
|
||||
vec3_t dist;
|
||||
float add;
|
||||
float lightvec[3] = { -1, 0, 0 };
|
||||
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
minlight = max (renderer->model->min_light, renderer->min_light);
|
||||
|
||||
// 128 instead of 255 due to clamping below
|
||||
j = max (R_LightPoint (&r_refdef.worldmodel->brush, r_entorigin),
|
||||
minlight * 128);
|
||||
|
||||
lighting->ambientlight = j;
|
||||
lighting->shadelight = j;
|
||||
|
||||
VectorCopy (lightvec, lighting->lightvec);
|
||||
|
||||
auto dlight_pool = &r_refdef.registry->comp_pools[s_dynlight];
|
||||
auto dlight_data = (dlight_t *) dlight_pool->data;
|
||||
for (uint32_t i = 0; i < dlight_pool->count; i++) {
|
||||
auto dlight = &dlight_data[i];
|
||||
VectorSubtract (r_entorigin, dlight->origin, dist);
|
||||
add = dlight->radius - VectorLength (dist);
|
||||
|
||||
if (add > 0)
|
||||
lighting->ambientlight += add;
|
||||
}
|
||||
|
||||
// clamp lighting so it doesn't overbright as much
|
||||
if (lighting->ambientlight > 128)
|
||||
lighting->ambientlight = 128;
|
||||
if (lighting->ambientlight + lighting->shadelight > 192)
|
||||
lighting->shadelight = 192 - lighting->ambientlight;
|
||||
}
|
||||
|
||||
static inline void
|
||||
draw_alias_entity (entity_t ent)
|
||||
{
|
||||
|
@ -315,7 +275,7 @@ draw_alias_entity (entity_t ent)
|
|||
visibility->trivial_accept = 0; //FIXME
|
||||
if (R_AliasCheckBBox (ent)) {
|
||||
alight_t lighting;
|
||||
setup_lighting (ent, &lighting);
|
||||
R_Setup_Lighting (ent, &lighting);
|
||||
R_AliasDrawModel (ent, &lighting);
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +290,7 @@ draw_iqm_entity (entity_t ent)
|
|||
visibility->trivial_accept = 0; //FIXME
|
||||
|
||||
alight_t lighting;
|
||||
setup_lighting (ent, &lighting);
|
||||
R_Setup_Lighting (ent, &lighting);
|
||||
R_IQMDrawModel (ent, &lighting);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue