From b6767e567f46f54feec519fa1332d8cf280348ee Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 14 Apr 2004 08:47:14 +0000 Subject: [PATCH] r_ambient no longer alters the lightmap in q1bsp, instead it adds another render pass (this makes sense for performance as it's a cheat anyway, no optimization needed) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4106 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rsurf.c | 104 ++++++++++++++++++++++++++++--------------------- model_shared.h | 1 - 2 files changed, 60 insertions(+), 45 deletions(-) diff --git a/gl_rsurf.c b/gl_rsurf.c index 01fa9408..56daf49e 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -279,14 +279,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf) else { // clear to no light - j = r_ambient.value * 512.0f; // would be 128.0f logically, but using 512.0f to match winquake style - if (j) - { - for (i = 0;i < size3;i++) - *bl++ = j; - } - else - memset(bl, 0, size*3*sizeof(unsigned int)); + memset(bl, 0, size*3*sizeof(unsigned int)); if (surf->dlightframe == r_framecount) { @@ -360,33 +353,29 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf) // set to full bright if no light data bl = floatblocklights; if (!ent->model->brushq1.lightdata) - j = 255*256; - else - j = r_ambient.value * 512.0f; // would be 128.0f logically, but using 512.0f to match winquake style - - // clear to no light - if (j) { for (i = 0;i < size3;i++) - *bl++ = j; + bl[i] = 255*256; } else - memset(bl, 0, size*3*sizeof(float)); - - if (surf->dlightframe == r_framecount) { - surf->cached_dlight = R_FloatAddDynamicLights(&ent->inversematrix, surf); - if (surf->cached_dlight) - c_light_polys++; - } - - // add all the lightmaps - if (lightmap) - { - bl = floatblocklights; - for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3) - for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++) - bl[i] += lightmap[i] * scale; + memset(bl, 0, size*3*sizeof(float)); + + if (surf->dlightframe == r_framecount) + { + surf->cached_dlight = R_FloatAddDynamicLights(&ent->inversematrix, surf); + if (surf->cached_dlight) + c_light_polys++; + } + + // add all the lightmaps + if (lightmap) + { + bl = floatblocklights; + for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3) + for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++) + bl[i] += lightmap[i] * scale; + } } stain = surf->stainsamples; @@ -1138,6 +1127,30 @@ static void RSurfShader_OpaqueWall_Pass_BaseLightmap(const entity_render_t *ent, } } +static void RSurfShader_OpaqueWall_Pass_BaseAmbient(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain) +{ + const msurface_t *surf; + rmeshstate_t m; + memset(&m, 0, sizeof(m)); + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE); + GL_DepthMask(false); + GL_DepthTest(true); + m.tex[0] = R_GetTexture(texture->skin.base); + GL_Color(r_ambient.value * (1.0f / 128.0f), r_ambient.value * (1.0f / 128.0f), r_ambient.value * (1.0f / 128.0f), 1); + while((surf = *surfchain++) != NULL) + { + if (surf->visframe == r_framecount) + { + m.pointer_vertex = surf->mesh.data_vertex3f; + m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f; + R_Mesh_State(&m); + GL_LockArrays(0, surf->mesh.num_vertices); + R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i); + GL_LockArrays(0, 0); + } + } +} + static void RSurfShader_OpaqueWall_Pass_Fog(const entity_render_t *ent, const texture_t *texture, msurface_t **surfchain) { const msurface_t *surf; @@ -1306,6 +1319,18 @@ static void R_DrawSurfaceChain(const entity_render_t *ent, const texture_t *text if (fogenabled) RSurfShader_OpaqueWall_Pass_Fog(ent, texture, surfchain); } + else if (r_ambient.value > 0) + { + RSurfShader_OpaqueWall_Pass_BaseTexture(ent, texture, surfchain); + RSurfShader_OpaqueWall_Pass_BaseLightmap(ent, texture, surfchain); + RSurfShader_OpaqueWall_Pass_BaseAmbient(ent, texture, surfchain); + if (r_detailtextures.integer) + RSurfShader_OpaqueWall_Pass_BaseDetail(ent, texture, surfchain); + if (texture->skin.glow) + RSurfShader_OpaqueWall_Pass_Glow(ent, texture, surfchain); + if (fogenabled) + RSurfShader_OpaqueWall_Pass_Fog(ent, texture, surfchain); + } else if (r_textureunits.integer >= 4 && gl_combine.integer && r_detailtextures.integer) { RSurfShader_OpaqueWall_Pass_BaseCombine_TextureLightmapDetailGlow(ent, texture, surfchain); @@ -1400,22 +1425,13 @@ void R_UpdateLightmapInfo(entity_render_t *ent) return; if (r_dynamic.integer && !r_shadow_realtime_dlight.integer) R_MarkLights(ent); - if (model->brushq1.light_ambient != r_ambient.value) + for (i = 0;i < model->brushq1.light_styles;i++) { - model->brushq1.light_ambient = r_ambient.value; - for (i = 0;i < model->nummodelsurfaces;i++) - model->brushq1.surfaces[i + model->firstmodelsurface].cached_dlight = true; - } - else - { - for (i = 0;i < model->brushq1.light_styles;i++) + if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]]) { - if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]]) - { - model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]]; - for (surfacechain = model->brushq1.light_styleupdatechains[i];(surface = *surfacechain);surfacechain++) - surface->cached_dlight = true; - } + model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]]; + for (surfacechain = model->brushq1.light_styleupdatechains[i];(surface = *surfacechain);surfacechain++) + surface->cached_dlight = true; } } } diff --git a/model_shared.h b/model_shared.h index 04012cd5..5cb24514 100644 --- a/model_shared.h +++ b/model_shared.h @@ -277,7 +277,6 @@ typedef struct model_brushq1_s int *light_stylevalue; msurface_t ***light_styleupdatechains; msurface_t **light_styleupdatechainsbuffer; - float light_ambient; mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p); void (*BuildPVSTextureChains)(struct model_s *model); -- 2.39.2