X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=gl_rmain.c;h=e5bd8576989c4c0aca27ce7d7577075a21343f76;hb=14bd731965d8d345372660d8b500a734d5c6a6b2;hp=3b9994f0ffdc2bf250d0ed538979a772de0f60d0;hpb=abfdafcf23981b3de44fcb031d462a568368111f;p=xonotic%2Fdarkplaces.git diff --git a/gl_rmain.c b/gl_rmain.c index 3b9994f0..e5bd8576 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -156,10 +156,6 @@ cvar_t gl_skyclip = {CF_CLIENT, "gl_skyclip", "4608", "nehahra farclip distance cvar_t r_texture_dds_load = {CF_CLIENT | CF_ARCHIVE, "r_texture_dds_load", "0", "load compressed dds/filename.dds texture instead of filename.tga, if the file exists (requires driver support)"}; cvar_t r_texture_dds_save = {CF_CLIENT | CF_ARCHIVE, "r_texture_dds_save", "0", "save compressed dds/filename.dds texture when filename.tga is loaded, so that it can be loaded instead next time"}; -cvar_t r_textureunits = {CF_CLIENT, "r_textureunits", "32", "number of texture units to use in GL 1.1 and GL 1.3 rendering paths"}; -static cvar_t gl_combine = {CF_CLIENT | CF_READONLY, "gl_combine", "1", "indicates whether the OpenGL 1.3 rendering path is active"}; -static cvar_t r_glsl = {CF_CLIENT | CF_READONLY, "r_glsl", "1", "indicates whether the OpenGL 2.0 rendering path is active"}; - cvar_t r_usedepthtextures = {CF_CLIENT | CF_ARCHIVE, "r_usedepthtextures", "1", "use depth texture instead of depth renderbuffer where possible, uses less video memory but may render slower (or faster) depending on hardware"}; cvar_t r_viewfbo = {CF_CLIENT | CF_ARCHIVE, "r_viewfbo", "0", "enables use of an 8bit (1) or 16bit (2) or 32bit (3) per component float framebuffer render, which may be at a different resolution than the video mode"}; cvar_t r_rendertarget_debug = {CF_CLIENT, "r_rendertarget_debug", "-1", "replaces the view with the contents of the specified render target (by number - note that these can fluctuate depending on scene)"}; @@ -191,6 +187,7 @@ cvar_t r_glsl_postprocess_uservec2_enable = {CF_CLIENT | CF_ARCHIVE, "r_glsl_pos cvar_t r_glsl_postprocess_uservec3_enable = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec3_enable", "1", "enables postprocessing uservec3 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"}; cvar_t r_glsl_postprocess_uservec4_enable = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec4_enable", "1", "enables postprocessing uservec4 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"}; cvar_t r_colorfringe = {CF_CLIENT | CF_ARCHIVE, "r_colorfringe", "0", "Chromatic aberration. Values higher than 0.025 will noticeably distort the image"}; +cvar_t r_fxaa = {CF_CLIENT | CF_ARCHIVE, "r_fxaa", "0", "fast approximate anti aliasing"}; cvar_t r_water = {CF_CLIENT | CF_ARCHIVE, "r_water", "0", "whether to use reflections and refraction on water surfaces (note: r_wateralpha must be set below 1)"}; cvar_t r_water_cameraentitiesonly = {CF_CLIENT | CF_ARCHIVE, "r_water_cameraentitiesonly", "0", "whether to only show QC-defined reflections/refractions (typically used for camera- or portal-like effects)"}; @@ -247,6 +244,7 @@ cvar_t r_glsl_saturation_redcompensate = {CF_CLIENT | CF_ARCHIVE, "r_glsl_satura cvar_t r_glsl_vertextextureblend_usebothalphas = {CF_CLIENT | CF_ARCHIVE, "r_glsl_vertextextureblend_usebothalphas", "0", "use both alpha layers on vertex blended surfaces, each alpha layer sets amount of 'blend leak' on another layer, requires mod_q3shader_force_terrain_alphaflag on."}; +// FIXME: This cvar would grow to a ridiculous size after several launches and clean exits when used during surface sorting. cvar_t r_framedatasize = {CF_CLIENT | CF_ARCHIVE, "r_framedatasize", "0.5", "size of renderer data cache used during one frame (for skeletal animation caching, light processing, etc)"}; cvar_t r_buffermegs[R_BUFFERDATA_COUNT] = { @@ -3070,9 +3068,6 @@ static void gl_main_start(void) { case RENDERPATH_GL32: case RENDERPATH_GLES2: - Cvar_SetValueQuick(&r_textureunits, MAX_TEXTUREUNITS); - Cvar_SetValueQuick(&gl_combine, 1); - Cvar_SetValueQuick(&r_glsl, 1); r_loadnormalmap = true; r_loadgloss = true; r_loadfog = false; @@ -3197,7 +3192,7 @@ static void gl_main_shutdown(void) r_texture_numcubemaps = 0; //r_texture_fogintensity = NULL; memset(&r_fb, 0, sizeof(r_fb)); - R_GLSL_Restart_f(cmd_client); + R_GLSL_Restart_f(cmd_local); r_glsl_permutation = NULL; memset(r_glsl_permutationhash, 0, sizeof(r_glsl_permutationhash)); @@ -3334,8 +3329,6 @@ void GL_Main_Init(void) Cvar_RegisterVariable(&r_transparent_sortarraysize); Cvar_RegisterVariable(&r_texture_dds_load); Cvar_RegisterVariable(&r_texture_dds_save); - Cvar_RegisterVariable(&r_textureunits); - Cvar_RegisterVariable(&gl_combine); Cvar_RegisterVariable(&r_usedepthtextures); Cvar_RegisterVariable(&r_viewfbo); Cvar_RegisterVariable(&r_rendertarget_debug); @@ -3346,7 +3339,6 @@ void GL_Main_Init(void) Cvar_RegisterVariable(&r_viewscale_fpsscaling_stepsize); Cvar_RegisterVariable(&r_viewscale_fpsscaling_stepmax); Cvar_RegisterVariable(&r_viewscale_fpsscaling_target); - Cvar_RegisterVariable(&r_glsl); Cvar_RegisterVariable(&r_glsl_deluxemapping); Cvar_RegisterVariable(&r_glsl_offsetmapping); Cvar_RegisterVariable(&r_glsl_offsetmapping_steps); @@ -3367,6 +3359,7 @@ void GL_Main_Init(void) Cvar_RegisterVariable(&r_glsl_postprocess_uservec4_enable); Cvar_RegisterVariable(&r_celshading); Cvar_RegisterVariable(&r_celoutlines); + Cvar_RegisterVariable(&r_fxaa); Cvar_RegisterVariable(&r_water); Cvar_RegisterVariable(&r_water_cameraentitiesonly); @@ -3446,107 +3439,48 @@ void Render_Init(void) R_Particles_Init(); R_Explosion_Init(); R_LightningBeams_Init(); + CL_MeshEntities_Init(); Mod_RenderInit(); } -int R_CullBox(const vec3_t mins, const vec3_t maxs) +static void R_GetCornerOfBox(vec3_t out, const vec3_t mins, const vec3_t maxs, int signbits) { - int i; - mplane_t *p; - if (r_trippy.integer) - return false; - for (i = 0;i < r_refdef.view.numfrustumplanes;i++) - { - p = r_refdef.view.frustum + i; - switch(p->signbits) - { - default: - case 0: - if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 1: - if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 2: - if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 3: - if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 4: - if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - case 5: - if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - case 6: - if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - case 7: - if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - } - } - return false; + out[0] = ((signbits & 1) ? mins : maxs)[0]; + out[1] = ((signbits & 2) ? mins : maxs)[1]; + out[2] = ((signbits & 4) ? mins : maxs)[2]; } -int R_CullBoxCustomPlanes(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes) +static qbool _R_CullBox(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes, int ignore) { int i; const mplane_t *p; + vec3_t corner; if (r_trippy.integer) return false; for (i = 0;i < numplanes;i++) { + if(i == ignore) + continue; p = planes + i; - switch(p->signbits) - { - default: - case 0: - if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 1: - if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 2: - if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 3: - if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*maxs[2] < p->dist) - return true; - break; - case 4: - if (p->normal[0]*maxs[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - case 5: - if (p->normal[0]*mins[0] + p->normal[1]*maxs[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - case 6: - if (p->normal[0]*maxs[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - case 7: - if (p->normal[0]*mins[0] + p->normal[1]*mins[1] + p->normal[2]*mins[2] < p->dist) - return true; - break; - } + R_GetCornerOfBox(corner, mins, maxs, p->signbits); + if (DotProduct(p->normal, corner) < p->dist) + return true; } return false; } +qbool R_CullFrustum(const vec3_t mins, const vec3_t maxs) +{ + // skip nearclip plane, it often culls portals when you are very close, and is almost never useful + return _R_CullBox(mins, maxs, r_refdef.view.numfrustumplanes, r_refdef.view.frustum, 4); +} + +qbool R_CullBox(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes) +{ + // nothing to ignore + return _R_CullBox(mins, maxs, numplanes, planes, -1); +} + //================================================================================== // LadyHavoc: this stores temporary data used within the same frame @@ -4018,13 +3952,13 @@ qbool R_CanSeeBox(int numsamples, vec_t eyejitter, vec_t entboxenlarge, vec_t en if (BoxesOverlap(boxmins, boxmaxs, eyemins, eyemaxs)) return true; + VectorCopy(eye, start); // try specific positions in the box first - note that these can be cached if (r_cullentities_trace_entityocclusion.integer) { for (i = 0; i < sizeof(positions) / sizeof(positions[0]); i++) { trace_t trace; - VectorCopy(eye, start); end[0] = boxmins[0] + (boxmaxs[0] - boxmins[0]) * positions[i][0]; end[1] = boxmins[1] + (boxmaxs[1] - boxmins[1]) * positions[i][1]; end[2] = boxmins[2] + (boxmaxs[2] - boxmins[2]) * positions[i][2]; @@ -4035,8 +3969,13 @@ qbool R_CanSeeBox(int numsamples, vec_t eyejitter, vec_t entboxenlarge, vec_t en return true; } } - else if (model->brush.TraceLineOfSight(model, start, end, padmins, padmaxs)) - return true; + else + { + // try center + VectorMAM(0.5f, boxmins, 0.5f, boxmaxs, end); + if (model->brush.TraceLineOfSight(model, start, end, padmins, padmaxs)) + return true; + } // try various random positions for (j = 0; j < numsamples; j++) @@ -4088,7 +4027,7 @@ static void R_View_UpdateEntityVisible (void) continue; } if (!(ent->flags & renderimask)) - if (!R_CullBox(ent->mins, ent->maxs) || (ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE))) + if (!R_CullFrustum(ent->mins, ent->maxs) || (ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE))) if ((ent->flags & (RENDER_NODEPTHTEST | RENDER_WORLDOBJECT | RENDER_VIEWMODEL)) || r_refdef.scene.worldmodel->brush.BoxTouchingVisibleLeafs(r_refdef.scene.worldmodel, r_refdef.viewcache.world_leafvisible, ent->mins, ent->maxs)) r_refdef.viewcache.entityvisible[i] = true; } @@ -4100,7 +4039,7 @@ static void R_View_UpdateEntityVisible (void) { ent = r_refdef.scene.entities[i]; if (!(ent->flags & renderimask)) - if (!R_CullBox(ent->mins, ent->maxs) || (ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE))) + if (!R_CullFrustum(ent->mins, ent->maxs) || (ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE))) r_refdef.viewcache.entityvisible[i] = true; } } @@ -5692,7 +5631,7 @@ void R_RenderView(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, i rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity if(R_CompileShader_CheckStaticParms()) - R_GLSL_Restart_f(cmd_client); + R_GLSL_Restart_f(cmd_local); if (!r_drawentities.integer) r_refdef.scene.numentities = 0; @@ -6183,7 +6122,7 @@ static void R_DrawEntityBBoxes(prvm_prog_t *prog) for (i = 0; i < prog->num_edicts; i++) { edict = PRVM_EDICT_NUM(i); - if (edict->priv.server->free) + if (edict->free) continue; // exclude the following for now, as they don't live in world coordinate space and can't be solid: if (PRVM_gameedictedict(edict, tag_entity) != 0) @@ -9835,7 +9774,7 @@ static void R_DrawDebugModel(void) GL_PolygonOffset(r_refdef.polygonfactor + r_showcollisionbrushes_polygonfactor.value, r_refdef.polygonoffset + r_showcollisionbrushes_polygonoffset.value); for (bihleafindex = 0, bihleaf = bih->leafs;bihleafindex < bih->numleafs;bihleafindex++, bihleaf++) { - if (cullbox && R_CullBox(bihleaf->mins, bihleaf->maxs)) + if (cullbox && R_CullFrustum(bihleaf->mins, bihleaf->maxs)) continue; switch (bihleaf->type) {