From 785307fd9aad19c8ca00bc9de407dfbaf064ac7f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 27 Apr 2004 22:18:23 +0000 Subject: [PATCH] Grievre's lighting tweeks --- include/r_cvar.h | 1 + libs/video/renderer/gl/gl_mod_alias.c | 58 ++++++++++++++++----------- libs/video/renderer/gl/gl_rmain.c | 20 +++++---- libs/video/targets/vid_common_gl.c | 10 ++++- 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/include/r_cvar.h b/include/r_cvar.h index 47e7a45ca..5eac14db5 100644 --- a/include/r_cvar.h +++ b/include/r_cvar.h @@ -43,6 +43,7 @@ extern struct cvar_s *gl_tessellate; extern struct cvar_s *gl_texsort; extern struct cvar_s *gl_textures_bgra; extern struct cvar_s *gl_triplebuffer; +extern struct cvar_s *gl_viewmodel_hack; extern struct cvar_s *r_aliasstats; extern struct cvar_s *r_aliastransadj; diff --git a/libs/video/renderer/gl/gl_mod_alias.c b/libs/video/renderer/gl/gl_mod_alias.c index 4900fa3ac..c9e58b096 100644 --- a/libs/video/renderer/gl/gl_mod_alias.c +++ b/libs/video/renderer/gl/gl_mod_alias.c @@ -65,10 +65,11 @@ static __attribute__ ((unused)) const char rcsid[] = #include "r_dynamic.h" #include "r_local.h" #include "view.h" +#include "varrays.h" typedef struct { - vec3_t vert; - vec3_t normal; + vec3_t normal; + vec3_t vert; } blended_vert_t; typedef struct { @@ -100,13 +101,11 @@ GL_DrawAliasFrameTri (vert_order_t *vo) qfglBegin (GL_TRIANGLES); do { - // texture coordinates come from the draw list qfglTexCoord2fv (tex_coord->st); - tex_coord++; - - // normals and vertices come from the frame list qfglNormal3fv (verts->normal); qfglVertex3fv (verts->vert); + + tex_coord++; verts++; } while (count--); qfglEnd (); @@ -537,19 +536,30 @@ R_DrawAliasModel (entity_t *e) for (l = r_dlights, lnum = 0; lnum < r_maxdlights; lnum++, l++) { if (l->die >= r_realtime) { - VectorSubtract (l->origin, e->origin, dist); - if ((d = DotProduct (dist, dist)) > - ((l->radius + radius) * (l->radius + radius))) { - continue; // Out of range + // Argh, hax + if (e == r_view_model) { + VectorSubtract (l->origin, r_refdef.vieworg, dist); + + if ((d = DotProduct (dist, dist)) > + ((l->radius + 32) * (l->radius + 32))) { + continue; + } + } else { + VectorSubtract (l->origin, e->origin, dist); + + if ((d = DotProduct (dist, dist)) > + ((l->radius + radius) * (l->radius + radius))) { + continue; // Out of range + } } - if (d < (radius * radius * 0.25)) { // Inside the model - VectorMultAdd (emission, 1.5, l->color, emission); + + if (d < 512) { // Argh, more hax + VectorMultAdd (emission, 2.0, l->color, emission); continue; } if (used_lights >= gl_max_lights) { // too many, use emission - VectorMultAdd (emission, - 1.5 * (1 - (d / (l->radius * l->radius))), - l->color, emission); + VectorMultAdd (emission, 2.0 * (1 - (d / (l->radius * l->radius))), + l->color, emission); continue; } @@ -564,19 +574,20 @@ R_DrawAliasModel (entity_t *e) qfglLightfv (gl_light, GL_AMBIENT, color); qfglLightfv (gl_light, GL_DIFFUSE, color); qfglLightfv (gl_light, GL_SPECULAR, color); - qfglLightf (gl_light, GL_QUADRATIC_ATTENUATION, - 5.0 / (l->radius * l->radius)); + qfglLightf (gl_light, GL_QUADRATIC_ATTENUATION, 2 / (l->radius * l->radius)); + qfglLightf (gl_light, GL_CONSTANT_ATTENUATION, 100 / l->radius); used_lights++; } } VectorAdd (ambientcolor, emission, emission); d = max (emission[0], max (emission[1], emission[2])); - if (d > 1.0) { - VectorScale (emission, 1.0 / d, emission); - } else if (d < model->min_light && !used_lights) { - ambientcolor[2] = ambientcolor[1] = - ambientcolor[0] = model->min_light; + if (d > 1.3) { + VectorScale (emission, 1.3 / d, emission); + } else if ((d = model->min_light - d) > 0) { + emission[0] += d; + emission[1] += d; + emission[2] += d; } qfglMaterialfv (GL_FRONT, GL_EMISSION, emission); @@ -701,8 +712,9 @@ R_DrawAliasModel (entity_t *e) if (!tess) qfglDisable (GL_NORMALIZE); - qfglDisable (GL_LIGHTING); + qfglDisable (GL_TEXTURE_2D); + qfglDisable (GL_LIGHTING); qfglDepthMask (GL_FALSE); if (modelalpha < 1.0) { diff --git a/libs/video/renderer/gl/gl_rmain.c b/libs/video/renderer/gl/gl_rmain.c index 1d2e01bb9..3bb831074 100644 --- a/libs/video/renderer/gl/gl_rmain.c +++ b/libs/video/renderer/gl/gl_rmain.c @@ -333,11 +333,16 @@ R_DrawViewModel (void) || !currententity->model) return; - // hack the depth range to prevent view model from poking into walls - qfglDepthRange (gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin)); - qfglEnable (GL_CULL_FACE); - qfglEnable (GL_LIGHTING); - qfglEnable (GL_NORMALIZE); + + switch (gl_viewmodel_hack->int_val) { + case 1: // sometimes buggy + qfglDepthRange (gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin)); + break; + case 2: // sometimes slow + qfglClear (GL_DEPTH_BUFFER_BIT); + break; + } + if (gl_affinemodels->int_val) qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); if (gl_mtex_active_tmus >= 2) { @@ -524,7 +529,6 @@ R_SetupGL (void) qfglGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix); // set drawing parms -// qfglEnable (GL_CULL_FACE); qfglDisable (GL_ALPHA_TEST); qfglAlphaFunc (GL_GREATER, 0.5); qfglEnable (GL_DEPTH_TEST); @@ -658,10 +662,10 @@ R_RenderView_ (void) // render normal view R_RenderScene (); - R_DrawViewModel (); R_DrawWaterSurfaces (); R_DrawParticles (); - + R_DrawViewModel (); + // render mirror view R_Mirror (); diff --git a/libs/video/targets/vid_common_gl.c b/libs/video/targets/vid_common_gl.c index beef73079..38d13786c 100644 --- a/libs/video/targets/vid_common_gl.c +++ b/libs/video/targets/vid_common_gl.c @@ -119,6 +119,7 @@ cvar_t *gl_multitexture; cvar_t *gl_tessellate; cvar_t *gl_textures_bgra; cvar_t *gl_vaelements_max; +cvar_t *gl_viewmodel_hack; cvar_t *gl_screenshot_byte_swap; cvar_t *vid_mode; cvar_t *vid_use8bit; @@ -275,6 +276,13 @@ GL_Common_Init_Cvars (void) "Limit the vertex array size for buggy " "drivers. 0 (default) uses driver provided " "limit, -1 disables use of vertex arrays."); + gl_viewmodel_hack = Cvar_Get ("gl_viewmodel_hack", "1", CVAR_ARCHIVE, NULL, + "Depth buffer kludge to get weapon model to draw " + "on top. 0 - don't kludge, weapon pokes through " + "walls. 1 - fast method, some buggy drivers don't " + "like it. 2 - slow method, should work with all " + "drivers"); + } static void @@ -445,7 +453,7 @@ CheckLights (void) for (i = 0; i < gl_max_lights; i++) { qfglEnable (GL_LIGHT0 + i); - qfglLightf (GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 0.25); + qfglLightf (GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 0.5); qfglDisable (GL_LIGHT0 + i); }